A NVector<T>
object represents the coordinates of a finite dimension dense vector \( x \).
More...
Public Member Functions | |
NVector (const std::vector< T > &data) | |
Construct a vector using a std::vector . \( x_k \) represents data[k] . More... | |
NVector (std::initializer_list< T > list) | |
Construct a vector using an initializer list {} . More... | |
NVector (size_t dim=0) | |
Construct a vector of a given size. More... | |
NVector (const NVector< T > &u) | |
Construct a vector by using copy() method. More... | |
virtual | ~NVector ()=default |
virtual std::string | str () const |
Creates a string representing the vector. More... | |
size_t | dim () const |
Dimension of the vector. More... | |
std::vector< T > | array () const |
Creates an array with this vector. More... | |
NVector< T > & | operator+= (const NVector< T > &u) |
NVector< T > & | operator-= (const NVector< T > &u) |
virtual NVector< T > & | operator*= (T s) |
virtual NVector< T > & | operator/= (T s) |
NVector< T > & | operator= (const NVector< T > &u) |
Copy source object on this object using copy() . More... | |
Extremums | |
Methods related to maximum minimum value research. They all use | |
T | max () const |
Maximum of the coordinates of the vector \( (x_0, x_1, .. x_{(n-1)}) \). More... | |
T | min () const |
Minimum of the coordinates of the vector \( (x_0, x_1, .. x_{(n-1)}) \). More... | |
size_t | maxIndex () const |
Index of maximum of the coordinates of vector \( (x_0, x_1, ..., x_{(n-1)}) \). More... | |
size_t | minIndex () const |
Index of minimum of the coordinates of vector \( (x_0, x_1, ..., x_{(n-1)}) \). More... | |
T | maxAbs () const |
Maximum of the coordinates of the vector \( (|x_0|, |x_1|, ..., |x_{(n-1)}|) \). More... | |
T | minAbs () const |
Minimum of the coordinates of the vector \( (|x_0|, |x_1|, ..., |x_{(n-1)}|) \). More... | |
size_t | maxAbsIndex () const |
Index of maximum of the coordinates of vector \( (|x_0|, |x_1|, ..., |x_{(n-1)}|) \). More... | |
size_t | minAbsIndex () const |
Index of minimum of the coordinates of vector \( (|x_0|, |x_1|, ..., |x_{(n-1)}|) \). More... | |
Manipulators | |
NVector< T > & | swap (size_t k1, size_t k2) |
Permutation of two elements. More... | |
NVector< T > & | shift (long iterations) |
Shifts this vector iterations times. More... | |
NVector< T > & | fill (T s) |
Fill vector with a scalar. For example fill(3) will set \( (3, 3, 3, ..., 3) \). More... | |
Function Operator | |
Access to components and sub-matrix C++ function operator are here used to give intuitive access to the vector. It behaves like numpy | |
T & | operator() (long k) |
Simple access operator. More... | |
T | operator() (long k) const |
NVector< T > | operator() (size_t k1, size_t k2) const |
Manipulate sub-vector. More... | |
NVector< T > & | operator() (size_t k1, size_t k2) |
Manipulate sub-vector. More... | |
Iterators | |
Similar iterators as | |
iterator | begin () |
const_iterator | begin () const |
iterator | end () |
const_iterator | end () const |
Static Public Member Functions | |
static NVector< T > | zeros (size_t dim) |
static NVector< T > | ones (size_t dim) |
static NVector< T > | scalar (T s, size_t dim) |
static NVector< T > | cano (size_t k, size_t dim) |
static NVector< T > | sum (const std::vector< NVector > &vectors) |
Sum of multiples vectors. More... | |
static NVector< T > | sumProd (const std::vector< T > &scalars, const std::vector< NVector > &vectors) |
Linear combination of scalars and vectors . More... | |
Protected Member Functions | |
NVector (const std::vector< T > &data, size_t k1, size_t k2) | |
Vector with regularly spaced components. More... | |
NVector< T > & | add (const NVector< T > &u) |
NVector< T > & | sub (const NVector< T > &u) |
virtual NVector< T > & | opp () |
virtual NVector< T > & | prod (T s) |
virtual NVector< T > & | div (T s) |
T | dotProduct (const NVector< T > &u) const |
T | norm () const |
T | distance (const NVector< T > &u) const |
bool | isValidIndex (size_t k) const |
bool | isBetweenK12 (size_t k) const |
bool | isNull () const |
bool | isEqual (const NVector< T > &u) const |
bool | hasSameSize (const NVector< T > &u) const |
virtual bool | hasDefaultBrowseIndices () const |
virtual void | setDefaultBrowseIndices () const |
NVector< T > & | forEach (const NVector< T > &u, const std::function< void(T &, const T &)> &binary_op) |
virtual NVector< T > & | forEach (T s, const std::function< void(T &, T)> &binary_op) |
NVector< T > & | copy (const NVector< T > &u) |
NVector< T > | subVector (size_t k1, size_t k2) const |
void | setSubVector (const NVector< T > &u) |
Protected Attributes | |
size_t | _k1 {} |
size_t | _k2 {} |
Friends | |
std::ostream & | operator<< (std::ostream &os, const NVector< T > &u) |
Usual stream insertion of vector. More... | |
Algebra | |
Vector algebraical operations. Represent euclidean vector space operations such as sum, inner product, distance... | |
NVector< T > | operator+ (NVector< T > u, const NVector< T > &v) |
Add two vectors. More... | |
NVector< T > | operator- (NVector< T > u, const NVector< T > &v) |
Substract two vectors. More... | |
NVector< T > | operator- (NVector< T > u) |
Opposite of vector. More... | |
NVector< T > | operator* (T s, NVector< T > u) |
Multiply vector by scalar. More... | |
NVector< T > | operator* (const NVector< T > &u, T s) |
NVector< T > | operator/ (NVector< T > u, T s) |
Divide vector by scalar. More... | |
T | operator| (const NVector< T > &u, const NVector< T > &v) |
Dot product of two vectors. More... | |
T | operator! (const NVector< T > &u) |
Norm of the vector. More... | |
T | operator/ (const NVector< T > &u, const NVector< T > &v) |
Distance between two vectors. More... | |
Comparaison | |
Norm based comparaison between two vectors. | |
bool | operator== (const NVector< T > &u, const NVector< T > &v) |
Equality of two vectors. More... | |
bool | operator== (const NVector< T > &u, T s) |
Equality to zero. More... | |
bool | operator== (T s, const NVector< T > &u) |
bool | operator!= (const NVector< T > &u, const NVector< T > &v) |
Non equality of two vector. More... | |
bool | operator!= (const NVector< T > &u, T s) |
bool | operator!= (T s, const NVector< T > &u) |
A NVector<T>
object represents the coordinates of a finite dimension dense vector \( x \).
Coordinates are stored in the form [
\( x_0, x_1, ..., x_{(n-1)} \) ]
. where [...]
is a std::vector<T>
, \( n \) is the dimension and \( (x_0, x_1, ..., x_{(n-1)}) \) are the coordinates.
This object inherits from `std::vector<T>`, it is a STL container, iterators and STL library functions can be used.
Featuring algebraical operations \form#72, swaps, shifts and classic vectors generator such as ones, zeros...
The `NVector` class provides a function operator which behaves like a classic array subscript operator of `std::vector` except that it comes on two version detailed further in the documentation. It allows operations on sub-ranges.
We will often refer to the following variables in this page :
x
/u
/v
: An arbitrary given NVector. By default, \( x \) denotes this
vectorn
/dim
: Size of this vector, can be seen as the dimension of the underlying vector spaces
: a scalar of type T
k
: index of vector \( u_k \)T
Construct a vector using a std::vector
. \( x_k \) represents data[k]
.
data | std::vector source. |
Construct a vector using an initializer list {}
.
list | std::initializer_list source. |
Convert list
and uses array constructor.
Construct a vector of a given size.
dim | vector size |
|
explicitprotected |
Vector with regularly spaced components.
x | start value of the range |
y | end value of the range |
h | step between elements |
|
virtual |
Creates a string representing the vector.
The returned string has the following form :
```commandline "(x(0), x(1), ..., x((n-1)))" `` Each
x(k)is formatted using the default
<<operator of the type
T`.
Reimplemented in NPMatrix< T >, and NPMatrix< double_t >.
size_t NVector< T >::dim | ( | ) | const |
Dimension of the vector.
std::vector< T > NVector< T >::array | ( | ) | const |
Creates an array with this
vector.
std::vector
representing this
. T NVector< T >::max | ( | ) | const |
Maximum of the coordinates of the vector \( (x_0, x_1, .. x_{(n-1)}) \).
T NVector< T >::min | ( | ) | const |
Minimum of the coordinates of the vector \( (x_0, x_1, .. x_{(n-1)}) \).
size_t NVector< T >::maxIndex | ( | ) | const |
Index of maximum of the coordinates of vector \( (x_0, x_1, ..., x_{(n-1)}) \).
size_t NVector< T >::minIndex | ( | ) | const |
Index of minimum of the coordinates of vector \( (x_0, x_1, ..., x_{(n-1)}) \).
T NVector< T >::maxAbs | ( | ) | const |
Maximum of the coordinates of the vector \( (|x_0|, |x_1|, ..., |x_{(n-1)}|) \).
T NVector< T >::minAbs | ( | ) | const |
Minimum of the coordinates of the vector \( (|x_0|, |x_1|, ..., |x_{(n-1)}|) \).
size_t NVector< T >::maxAbsIndex | ( | ) | const |
Index of maximum of the coordinates of vector \( (|x_0|, |x_1|, ..., |x_{(n-1)}|) \).
size_t NVector< T >::minAbsIndex | ( | ) | const |
Index of minimum of the coordinates of vector \( (|x_0|, |x_1|, ..., |x_{(n-1)}|) \).
Permutation of two elements.
k1 | First index to swap |
k2 | Second index to swap |
The vector is set to \( (x_0, ..., x_{(k_1 - 1)}, x_{k_2}, ..., x_{(k_2 - 1)}, x_{k_1}, ..., x_{(n-1)}) \). \( x_{k_1} \) and \( x_{k_2} \) have been swaped used std::swap
.
Shifts this
vector iterations
times.
iterations | number of times to shift. |
If iterations is positive, shift is powered to the left, else to the right. For example shift(2)
will set \( (x_2, x_3, ..., x_{(n-1)}, x_0, x_1) \).
Fill vector with a scalar. For example fill(3)
will set \( (3, 3, 3, ..., 3) \).
s | value to fill the vector with |
Reimplemented in NPMatrix< T >, and NPMatrix< double_t >.
Reimplemented in NPMatrix< T >, and NPMatrix< double_t >.
T & NVector< T >::operator() | ( | long | k | ) |
Simple access operator.
Access operator equivalent to [k]
on std::vector
. Operator can be used to read or write values. const
version returns const
reference to the element. For example, x(-1)
returns the last element, x(0)
returns the first element.
T NVector< T >::operator() | ( | long | k | ) | const |
Manipulate sub-vector.
k1 | first element to take |
k2 | last element to take \( n \gt k_2 \geq k_1 \geq 0 \) |
Allows operations on a restricted range of the vector \( (x_{k_1}, x_{(k_1+1)}, ...,x_{k_2}) \) . The two arguments function operator has the following behavior :
u(0, 1) + v(1, 2)
, x(1, 4).max()
, ...Most of methods or operators can be chained. It will be explicitly specified if it's not the case. For example x(1, 3)
will return the value of \( (x_1, x_2, x_3) \).
Manipulate sub-vector.
This operator is similar to previous operator()(size_t, size_t) const "operator" except that it sets browse indices _k1
and _k2
in order to modify efficiently non const
reference.
*this
.
|
inline |
|
inline |
|
inline |
|
inline |
dim | dimension of the vector |
0
vector \( (0, 0, ..., 0) \). dim | dimension of the vector |
1
\( (1, 1, ..., 1) \). s | value of the scalar vector |
dim | dimension of the scalar vector |
s
\( (s, s, ..., s) \). k | index of vector in base |
dim | dimension of vector space represented by the base. |
\[ \begin{align*} & e_{0} &=& (1, 0, 0, ..., 0) \\ & e_{1} &=& (0, 1, 0, ..., 0) \\ & &\vdots & \\ &e_{(n - 1)} &=& (0, 0, 0, ..., 1) \\ \end{align*} \]
|
static |
Sum of multiples vectors.
vectors | an array of vectors \( (u, v, ..., x) \). |
Sum of the vectors contained in vectors
array.
|
static |
Linear combination of scalars
and vectors
.
scalars | coefficients of linear combination [ \( \alpha, \beta, ..., \lambda \)] . |
vectors | vectors of linear combination \( (u, v, ..., x) \) |
Reimplemented in NPMatrix< T >, and NPMatrix< double_t >.
Reimplemented in NPMatrix< T >, and NPMatrix< double_t >.
Reimplemented in NPMatrix< T >, and NPMatrix< double_t >.
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotectedvirtual |
Reimplemented in NPMatrix< T >, and NPMatrix< double_t >.
|
inlineprotectedvirtual |
Reimplemented in NPMatrix< T >, and NPMatrix< double_t >.
|
protected |
|
protectedvirtual |
Add two vectors.
Using usual addition \( (u_0 + v_0, u_1 + v_1, ...) \).
Substract two vectors.
Using usual difference \( (u_0 - v_0, u_1 - v_1, ...) \).
Opposite of vector.
Multiply vector by scalar.
Using usual scalar multiplication difference \( (s \cdot u_0, s \cdot u_1, ...) \).
Divide vector by scalar.
Usual scalar division based on multiplication.
Dot product of two vectors.
Usual inner product \( u_0 \cdot v_0 + u_1 \cdot v_1 + ... + u_{(n-1)} \cdot v_{(n-1)} \).
|
friend |
Norm of the vector.
The norm of vector \( ||u|| = \sqrt{u \cdot u} \) derived from dot product.
Distance between two vectors.
|
friend |
Usual stream insertion of vector.
os | output stream |
u | vector source |
Inserts u.str()
into os
stream.
os
. Equality of two vectors.
|
friend |
Equality to zero.
s
is 0 and \( u \lt \epsilon \).
|
friend |
Non equality of two vector.
|
mutableprotected |
|
mutableprotected |