Class Vector

Class Documentation

class Vector

The Vector class represents a basic vector with double coefficients.

Public Functions

Vector()

Default constructor

Vector(count dimension, double initialValue = 0, bool transpose = false)

Constructs the Vector with dimension elements with value initialValue.

Parameters:
  • dimension – The dimension of this vector.

  • initialValue – All coefficients will be initialized to initialValue.

  • transpose – Indicates whether this vector is transposed (row vector) or not (column vector).

Vector(const std::vector<double> &values, bool transpose = false)

Constructs the Vector with the contents of values.

Parameters:
  • values – The values of this Vector.

  • transpose – Indicates whether this vector is transposed (row vector) or not (column vector).

Vector(const std::initializer_list<double> &list)

Constructs the Vector from the contents of the initializer list list.

Parameters:

list – The initializer list.

inline count getDimension() const
Returns:

dimension of vector

bool isTransposed() const

A transposed vector is a row vector.

Returns:

True, if this vector is transposed, otherwise false.

Vector transpose() const
Returns:

Transposed copy of this vector.

double length() const

Calculates and returns the Euclidean length of this vector

Returns:

The Euclidean length of this vector.

double mean() const

Calculates and returns the arithmetic mean of this vector

Returns:

The arithmetic mean of this vector.

inline double &operator[](index idx)

Returns a reference to the element at index idx without checking the range of this vector.

Parameters:

idx – The index of the element.

Returns:

Reference to the element at index idx.

inline void fill(double val)

Assigns the given value to all the elements in the vector.

Parameters:

val – The value to be assigned.

inline double operator[](index idx) const

Returns the element at index idx without checking the range of this vector. idx The index of the element.

Returns:

Constant reference to the element at index idx.

inline double &at(index idx)

Returns a reference to the element at index idx. If idx is not a valid index an exception is thrown.

Parameters:

idx – The index of the element.

Returns:

Reference to the element at index idx.

bool operator==(const Vector &other) const

Compares this vector and other element-wise.

Returns:

True, if this vector is element-wise equal to other, otherwise false.

bool operator!=(const Vector &other) const

Compares this vector and other element-wise.

Returns:

True, if this vector is element-wise unequal to other, otherwise false.

double operator*(const Vector &other) const

Computes the inner product (dot product) of this vector and other.

Returns:

The result of the inner product.

template<typename Matrix = DynamicMatrix>
Vector operator*(const Matrix &matrix) const

Multiplies this vector with matrix and returns the result.

Returns:

The result of multiplying this vector with matrix.

Vector operator*(double scalar) const

Multiplies this vector with a scalar specified in scalar and returns the result in a new vector.

Returns:

The result of multiplying this vector with scalar.

Vector &operator*=(double scalar)
Vector operator/(double divisor) const

Divides this vector by a divisor specified in divisor and returns the result in a new vector.

Returns:

The result of dividing this vector by divisor.

Vector &operator/=(double divisor)

Divides this vector by a divisor specified in divisor.

Returns:

Reference to this vector.

Vector operator+(const Vector &other) const

Adds this vector to other and returns the result. Note that the dimensions of the vectors have to be the same.

Returns:

The sum of this vector and other.

Vector operator+(double value) const

Adds value to each element of this vector and returns the result.

Vector &operator+=(const Vector &other)

Adds other to this vector. Note that the dimensions of the vectors have to be the same.

Returns:

Reference to this vector.

Vector &operator+=(double value)

Adds value to each element of this vector.

Vector operator-(const Vector &other) const

Subtracts other from this vector and returns the result. Note that the dimensions of the vectors have to be the same.

Returns:

The difference of this vector and other.

Vector operator-(double value) const

Subtracts value from each element of this vector and returns the result.

Vector &operator-=(const Vector &other)

Subtracts other from this vector. Note that the dimensions of the vectors have to be the same.

Returns:

Reference to this vector.

Vector &operator-=(double value)

Subtracts value from each element of this vector.

template<typename F>
void apply(F unaryElementFunction)

Applies the unary function unaryElementFunction to each value in the Vector. Note that it must hold that the function applied to the zero element of this matrix returns the zero element.

Parameters:

unaryElementFunction

template<typename L>
inline void forElements(L handle)

Iterate over all elements of the vector and call handler (lambda closure).

template<typename L>
inline void forElements(L handle) const

Iterate over all elements of the vector and call handler (lambda closure).

template<typename L>
inline void parallelForElements(L handle)

Iterate in parallel over all elements of the vector and call handler (lambda closure).

template<typename L>
inline void parallelForElements(L handle) const

Iterate in parallel over all elements of the vector and call handler (lambda closure).

Public Static Functions

template<class Matrix = DynamicMatrix>
static Matrix outerProduct(const Vector &v1, const Vector &v2)

Computes the outer product of v1 and v2.

Parameters:
Returns:

The resulting matrix from the outer product.

static double innerProduct(const Vector &v1, const Vector &v2)

Computes the inner product (dot product) of the vectors v1 and v2.

Returns:

The result of the inner product.