26 #include <core/exceptions/software.h>
63 m_manage_memory = manage_memory;
67 m_data =
new float[m_size];
69 for (
unsigned int i = 0; i < m_size; ++i)
72 { m_data[i] = data[i]; }
89 m_manage_memory =
true;
90 m_data =
new float[m_size];
92 for (
unsigned int i = 0; i < m_size; ++i)
94 m_data[i] = v.m_data[i];
122 float* t =
new float[
size];
125 while( i < size && i < m_size)
136 { m_manage_memory =
true;}
163 printf(
"This column vector has %u elements -- element %u not "
164 "available", m_size, d);
165 throw std::exception();
180 printf(
"This column vector has %u elements -- element %u not "
181 "available", m_size, d);
182 throw std::exception();
294 printf(
"This column vector has %u elements -- element %u not "
295 "available", m_size, d);
296 throw std::exception();
309 Vector result(m_size, m_data);
311 for (
unsigned int i = 0; i < m_size; ++i)
312 { result.m_data[i] *= f; }
324 for (
unsigned int i = 0; i < m_size; ++i)
337 Vector result(m_size, m_data);
339 for (
unsigned int i = 0; i < m_size; ++i)
340 { result.m_data[i] /= f; }
352 for (
unsigned int i = 0; i < m_size; ++i)
367 Vector result(m_size, m_data);
369 for (
unsigned int i = 0; i < m_size; ++i)
371 result.m_data[i] += cv[i];
386 for (
unsigned int i = 0; i < m_size; ++i)
403 Vector result(m_size, m_data);
405 for (
unsigned int i = 0; i < m_size; ++i)
407 result.m_data[i] -= cv[i];
422 for (
unsigned int i = 0; i < m_size; ++i)
437 if (m_size != v.m_size)
443 m_manage_memory =
true;
445 m_data =
new float[m_size];
448 for (
unsigned int i = 0; i < m_size; ++i)
449 { m_data[i] = v.m_data[i]; }
461 if (m_size != v.m_size)
464 for (
unsigned int i = 0; i < m_size; ++i)
466 if (m_data[i] != v.m_data[i])
481 { printf(
"%s: [ ", name); }
485 for (
unsigned int i = 0; i < m_size; ++i)
487 printf(
"%f ",
get(i));
501 for (
unsigned int i = 0; i < m_size; ++i)
502 res += this->
get(i) * v.
get(i);
517 for (
unsigned int i = 0; i < v.m_size; ++i)
521 if (i + 1 < v.m_size)
525 return stream <<
"]";
float z() const
Convenience getter to obtain the third element.
Vector operator+(const Vector &v) const
Adds two vectors.
Vector operator*(const float &f) const
Multiply the vector with a scalar.
Vector(unsigned int size=3, float *elems=0, bool manage_memory=true)
Constructor.
void set_size(unsigned int size)
Set a new size.
float x() const
Convenience getter to obtain the first element.
float get(unsigned int d) const
Get a certain element.
Vector & operator/=(const float &f)
In-place scalar division.
Vector operator-(const Vector &v) const
Substract two vectors.
unsigned int size() const
Get the number of elements.
void print_info(const char *name=0) const
Prints the vector data to standard out.
Vector & operator*=(const float &f)
In-place scalar multiplication.
float operator[](unsigned int d) const
Access operator.
bool operator==(const Vector &v)
Comparison operator.
virtual ~Vector()
Destructor.
Vector & operator+=(const Vector &v)
In-place vector addition.
Vector & operator-=(const Vector &v)
In-place vector substraction.
Vector & operator=(const Vector &v)
Assignment operator.
void set(unsigned int d, float v)
Set a certain element.
float y() const
Convenience getter to obtain the second element.
std::ostream & operator<<(std::ostream &stream, const Vector &v)
Appends the components of the Vector to the ostream.
Vector operator/(const float &f) const
Divide every element of the vector by a scalar.