mu
|
A generic vector. More...
#include <vector.h>
Public Member Functions | |
constexpr | Vector ()=default |
Construct a new Vector object. More... | |
template<typename... TArgs> | |
Vector (TArgs &&... args) | |
Construct a new Vector object from a number of N values. More... | |
template<std::size_t Nn, class U > | |
Vector (const Vector< Nn, U > &v) | |
Construct a new Vector from an existing Vector of a different type. More... | |
Vector (const std::array< T, N > &a) | |
Construct a new Vector object from an std::array. More... | |
template<typename U = T, std::enable_if_t< std::is_arithmetic< U >::value, int > = 0> | |
Vector (const std::array< U, N > &a) | |
Construct a new Vector object from an std::array of a different type. More... | |
template<typename U = T, std::enable_if_t< std::is_arithmetic< U >::value, int > = 0> | |
Vector (const U &value) | |
Construct a new Vector object from a single value. More... | |
~Vector ()=default | |
Destroy the Vector object. | |
Vector (const Vector &other)=default | |
Copy construct a new Vector object. More... | |
Vector (Vector &&other) noexcept=default | |
Move construct a new Vector object. More... | |
Vector & | operator= (const Vector &other)=default |
Copy assignment operator. More... | |
Vector & | operator= (Vector &&other) noexcept=default |
Move assignment operator. More... | |
T & | operator[] (size_type idx) noexcept |
access an element within the vector More... | |
const T & | operator[] (size_type idx) const noexcept |
const access an element within the vector More... | |
T & | at (size_type idx) |
access an element within the vector More... | |
const T & | at (size_type idx) const |
const access an element within the vector More... | |
constexpr size_type | size () const noexcept |
returns the size of the vector More... | |
iterator | begin () noexcept |
returns an iterator pointing to the first element More... | |
const_iterator | begin () const noexcept |
returns a const iterator pointing to the first element More... | |
iterator | end () noexcept |
returns an iterator pointing to the element following the last element More... | |
const_iterator | end () const noexcept |
returns a const iterator pointing to the element following the last element More... | |
T | min () const |
get the min value of the vector More... | |
T | max () const |
get the max value of the vector More... | |
T | sum () const |
sum up all the elements of the vector More... | |
template<typename U = T> | |
U | mean () const |
mean of all the elements of the vector More... | |
template<typename U = void, std::size_t N2, typename T2 > | |
std::conditional_t< std::is_same< U, void >::value, T, U > | dot (const Vector< N2, T2 > &rhs) const |
dot product of two vectors More... | |
template<typename U = void, std::size_t N2, std::size_t M2, typename T2 > | |
std::conditional_t< std::is_same< U, void >::value, Vector< M2, T >, Vector< M2, U > > | dot (const Matrix< N2, M2, T2 > &rhs) const |
dot product of a vector and a matrix More... | |
template<class U = T> | |
U | std () const |
calculates the standard deviation More... | |
template<class U = T> | |
U | length () const |
euclidean vector length More... | |
void | normalize () |
normalizes this vector More... | |
Vector< N, T > | normalized () |
returns a normalized vector More... | |
void | flip () |
flips this vector, i.e. reverses its elements More... | |
Vector< N, T > | flipped () const |
returns a flipped vector More... | |
void | sort () |
sort vector elements in ascending order More... | |
template<typename Compare > | |
void | sort (const Compare &comp) |
sort vector elements by providing a condition More... | |
Vector< N, T > | sorted () const |
returns a sorted vector More... | |
template<typename Compare > | |
Vector< N, T > | sorted (const Compare &comp) const |
template<typename U = T> | |
bool | operator== (const Vector< N, U > &rhs) const |
equality operator More... | |
template<typename U = T> | |
bool | operator!= (const Vector< N, U > &rhs) const |
unequality operator More... | |
template<typename U = T> | |
Vector< N, T > & | operator+= (const Vector< N, U > &rhs) |
plus equal operator More... | |
template<typename U = T> | |
Vector< N, T > & | operator-= (const Vector< N, U > &rhs) |
minus equal operator More... | |
template<typename U = T> | |
Vector< N, T > & | operator*= (const Vector< N, U > &rhs) |
multiplication equal operator More... | |
template<typename U = T> | |
Vector< N, T > & | operator/= (const Vector< N, U > &rhs) |
divison equal operator More... | |
template<class TScalar > | |
std::enable_if_t< std::is_arithmetic< TScalar >::value, Vector< N, T > & > | operator+= (const TScalar &scalar) |
add a scalar to this vector More... | |
template<class TScalar > | |
std::enable_if_t< std::is_arithmetic< TScalar >::value, Vector< N, T > & > | operator-= (const TScalar &scalar) |
subtract a scalar from every element of this vector More... | |
template<class TScalar > | |
std::enable_if_t< std::is_arithmetic< TScalar >::value, Vector< N, T > & > | operator*= (const TScalar &scalar) |
multiply a scalar with this vector More... | |
template<class TScalar > | |
std::enable_if_t< std::is_arithmetic< TScalar >::value, Vector< N, T > & > | operator/= (const TScalar &scalar) |
divide every element of this vector by a scalar More... | |
Protected Attributes | |
std::array< T, N > | data_ |
Friends | |
template<std::size_t Nn, class U > | |
std::ostream & | operator<< (std::ostream &os, const Vector< Nn, U > &v) |
print vector values More... | |
A generic vector.
Can be instantiated with an arithmetic type as defined by the standard library.
N | size |
T | the type of the values inside the vector |
|
default |
|
inline |
Construct a new Vector object from a number of N values.
the number of values must match the static size of this Vector
the type must be arithmetic or a reference of an arithmetic
TArgs |
args |
|
inline |
Construct a new Vector from an existing Vector of a different type.
implicit narrowing may be applied
it is checked that the Vector sizes are the same
Nn | |
U |
v |
|
inline |
Construct a new Vector object from an std::array.
a |
|
inline |
Construct a new Vector object from an std::array of a different type.
implicit narrowing may be applied
U |
a |
|
inline |
Construct a new Vector object from a single value.
all the values inside the vector will be set to this value
U |
value |
|
default |
Copy construct a new Vector object.
other |
|
defaultnoexcept |
Move construct a new Vector object.
other |
|
inline |
access an element within the vector
out | of range |
idx |
|
inline |
const access an element within the vector
out | of range |
idx |
|
inlinenoexcept |
returns an iterator pointing to the first element
|
inlinenoexcept |
returns a const iterator pointing to the first element
|
inline |
dot product of two vectors
For a Vector \( a \) of size \( N \) and a Vector \( b \) of size \( N \) the result is a scalar,
\( a \cdot b = \sum_{i=1}^{N} a_i b_i \)
Vector sizes must be equal
For two Vectors of the same type, specifying the return type is optional. It will be of the type of the two Vectors by default.
For two Vectors of different types, specifying the return type is required.
return value is a scalar of the type of the two Vectors or else of the explicitly stated type
U | |
N2 | |
T2 |
rhs |
|
inline |
dot product of a vector and a matrix
For a Vector \( a \) of size \( N \) and a Matrix \( B \) of size \( N \times M \) the result is a Vector \( c \) of size \( M \),
\( c = a \cdot B \) with
\( c_{j} = a_1 b_{1j} + a_2 b_{2j} + ... + a_N b_{Nj} = \sum_{i=1}^{N} a_i B_{ij} \)
Vector size must be equal to the size of the first Matrix dimension (N)
For two objects of the same type, specifying the return type is optional. It will be of the type of the two objects by default.
For two objects of different types, specifying the return type is required.
return value is a Vector of the size of the second Matrix dimension (M) containing the type of the two objects or else of the explicitly stated type
U | |
N2 | |
M2 | |
T2 |
rhs |
|
inlinenoexcept |
returns an iterator pointing to the element following the last element
|
inlinenoexcept |
returns a const iterator pointing to the element following the last element
|
inline |
flips this vector, i.e. reverses its elements
|
inline |
returns a flipped vector
|
inline |
euclidean vector length
returns the length as
U |
|
inline |
get the max value of the vector
|
inline |
mean of all the elements of the vector
\( \mu = \frac{\sum(x_i)}{N} \)
returns the mean as
U |
|
inline |
get the min value of the vector
|
inline |
normalizes this vector
\( v_{norm} = \frac{v}{\sqrt \sum_{i=1}^{N} v_i^2} \)
divides every element by the euclidean vector length
the resulting euclidean vector length will be 1
|
inline |
returns a normalized vector
|
inline |
unequality operator
rhs |
|
inline |
multiplication equal operator
subject to implicit conversions
U |
rhs |
|
inline |
multiply a scalar with this vector
TScalar |
scalar |
|
inline |
plus equal operator
subject to implicit conversions
U |
rhs |
|
inline |
add a scalar to this vector
TScalar |
scalar |
|
inline |
minus equal operator
subject to implicit conversions
U |
rhs |
|
inline |
subtract a scalar from every element of this vector
TScalar |
scalar |
|
inline |
divison equal operator
subject to implicit conversions division by zero on integral type vector elements results in undefined behavior
U |
rhs |
|
inline |
divide every element of this vector by a scalar
division by zero on integral types triggers an assert
TScalar |
scalar |
|
default |
Copy assignment operator.
other |
|
defaultnoexcept |
Move assignment operator.
other |
|
inline |
equality operator
comparisons between different arithmetic types are possible. they are subject to the c++ usual arithmetic conversions!
checked both ways for equality. First, casting both values to the type of the first argument, then casting both values to the type of the second argument.
rhs |
|
inlinenoexcept |
access an element within the vector
does not throw an exception if idx
is out of range
idx |
|
inlinenoexcept |
const access an element within the vector
does not throw an exception if idx
is out of range
idx |
|
inlinenoexcept |
|
inline |
sort vector elements in ascending order
|
inline |
sort vector elements by providing a condition
the condition should be a lambda function. it must return a bool
Compare |
comp |
|
inline |
returns a sorted vector
|
inline |
Compare |
comp |
|
inline |
calculates the standard deviation
$$ = {{(x_i - )^2}{N}} $$
U |
|
inline |
sum up all the elements of the vector
|
friend |
print vector values
Nn | |
U |
os | |
v |