NABLA
Nabla Ain't Basic Linear Algebra
|
Vector expression template class. More...
Related Functions | |
(Note that these are not member functions.) | |
template<typename value_t , typename expr1 , typename tag1 , typename expr2 , typename tag2 > | |
op::mul< value_t, value_t > ::result_type | sum_of_products (const vector_expression< value_t, expr1, tag1 > &a, const vector_expression< value_t, expr2, tag2 > &b) |
Returns sum of products of corresponding elements. | |
Miscellaneous | |
template<typename value_t , typename expr_t , typename tag > | |
expr_t & | get_vector (vector_expression< value_t, expr_t, tag > &a) |
Returns underlying vector expression. | |
template<typename value_t , typename expr_t , typename tag > | |
const expr_t & | get_vector (const vector_expression< value_t, expr_t, tag > &a) |
Returns underlying vector expression. | |
template<typename value_t , typename expr_t > | |
void | swap (vector_expression< value_t, expr_t, tag::storage > &a, vector_expression< value_t, expr_t, tag::storage > &b) |
Swaps contents of two vectors. | |
template<typename value_t , typename expr1 , typename expr2 > | |
void | swap (vector_expression< value_t, expr1, tag::storage > &a, vector_expression< value_t, expr2, tag::storage > &b) |
Swaps contents of two vector expressions. | |
template<typename value_t , typename expr1 , typename expr2 , typename orientation > | |
void | swap (vector_expression< value_t, expr1, tag::storage > &a, vector_ref< expr2, tag::reference, orientation > b) |
Swaps contents of two vector expressions. | |
template<typename expr1 , typename orientation , typename value_t , typename expr2 > | |
void | swap (vector_ref< expr1, tag::reference, orientation > a, vector_expression< value_t, expr2, tag::storage > &b) |
Swaps contents of two vector expressions. | |
template<typename expr1 , typename orientation1 , typename expr2 , typename orientation2 > | |
void | swap (vector_ref< expr1, tag::reference, orientation1 > a, vector_ref< expr2, tag::reference, orientation2 > b) |
Swaps contents of two vector expressions. | |
Matrix operations | |
template<typename value_t , typename expr1 , typename tag1 , typename expr2 , typename tag2 > | |
product< matrix_expression < value_t, expr1, tag1 > , vector_expression< value_t, expr2, tag2 > > | operator* (const matrix_expression< value_t, expr1, tag1 > &left, const vector_expression< value_t, expr2, tag2, orientation::column > &right) |
Binary matrix-vector multiplication operator. | |
template<typename value_t , typename expr1 , typename tag1 , typename shape , typename expr2 , typename tag2 > | |
product< shaped_expression < value_t, expr1, tag1, shape > , vector_expression< value_t, expr2, tag2 > > | operator* (const shaped_expression< value_t, expr1, tag1, shape > &left, const vector_expression< value_t, expr2, tag2, orientation::column > &right) |
Binary matrix-vector multiplication operator. | |
template<typename value_t , typename expr1 , typename tag1 , typename expr2 , typename tag2 > | |
product< matrix_expression < value_t, expr1, tag1 > , vector_expression< value_t, expr2, tag2 > > | map (const matrix_expression< value_t, expr1, tag1 > &linear_map, const vector_expression< value_t, expr2, tag2 > &v) |
Transforms a vector using provided transformation map. | |
template<typename value_t , typename expr1 , typename tag1 , typename shape , typename expr2 , typename tag2 > | |
product< shaped_expression < value_t, expr1, tag1, shape > , vector_expression< value_t, expr2, tag2 > > | map (const shaped_expression< value_t, expr1, tag1, shape > &linear_map, const vector_expression< value_t, expr2, tag2 > &v) |
Transforms a vector using provided transformation map. | |
Vector operations | |
template<typename value_t , typename expr1 , typename tag1 , typename expr2 , typename tag2 > | |
util::mul_conj< value_t, value_t >::result_type | dot_product (const vector_expression< value_t, expr1, tag1 > &v1, const vector_expression< value_t, expr2, tag2 > &v2) |
Dot product is a sum of products of corresponding elements of first vector and conjugated elements of the second one: | |
template<typename value_t , typename expr_t , typename tag > | |
value_t | sqrnorm (const vector_expression< value_t, expr_t, tag > &v) |
Returns squared Euclidean norm of a vector. | |
template<typename value_t , typename expr_t , typename tag > | |
value_t | norm (const vector_expression< value_t, expr_t, tag > &v) |
Returns Euclidean norm of a vector. | |
template<typename value_t , typename expr_t , typename tag > | |
const unary< vector_expression < value_t, expr_t, tag > , op::plus > | operator+ (const vector_expression< value_t, expr_t, tag > &a) |
Unary plus operator. | |
template<typename value_t , typename expr_t , typename tag > | |
const unary< vector_expression < value_t, expr_t, tag > , op::minus > | operator- (const vector_expression< value_t, expr_t, tag > &a) |
Unary minus operator. | |
template<typename value_t , typename expr_t , typename tag > | |
const unary< vector_expression < value_t, expr_t, tag > , op::conj > | conj (const vector_expression< value_t, expr_t, tag > &a) |
Returns conjugated vector. | |
template<typename value_t , typename expr_t , typename tag > | |
const scaled < vector_expression< value_t, expr_t, tag > > | operator* (const vector_expression< value_t, expr_t, tag > &a, const typename expr_t::value_type &s) |
Binary multiplication operator. | |
template<typename value_t , typename expr_t , typename tag > | |
const scaled < vector_expression< value_t, expr_t, tag > > | operator* (const typename expr_t::value_type &s, const vector_expression< value_t, expr_t, tag > &a) |
Binary multiplication operator. | |
template<typename value_t , typename expr1 , typename tag1 , typename expr2 , typename tag2 > | |
const binary < vector_expression< value_t, expr1, tag1 > , vector_expression< value_t, expr2, tag2 >, op::add > | operator+ (const vector_expression< value_t, expr1, tag1 > &left, const vector_expression< value_t, expr2, tag2 > &right) |
Binary addition operator. | |
template<typename value_t , typename expr1 , typename tag1 , typename expr2 , typename tag2 > | |
const binary < vector_expression< value_t, expr1, tag1 > , vector_expression< value_t, expr2, tag2 >, op::sub > | operator- (const vector_expression< value_t, expr1, tag1 > &left, const vector_expression< value_t, expr2, tag2 > &right) |
Binary subtraction operator. | |
template<typename value_t , typename expr1 , typename tag1 , typename expr2 , typename tag2 > | |
const binary < vector_expression< value_t, expr1, tag1 > , vector_expression< value_t, expr2, tag2 >, op::mul > | mul (const vector_expression< value_t, expr1, tag1 > &left, const vector_expression< value_t, expr2, tag2 > &right) |
Binary element-wise multiplication operator. | |
template<typename value_t , typename expr1 , typename tag1 , typename expr2 , typename tag2 > | |
const binary < vector_expression< value_t, expr1, tag1 > , vector_expression< value_t, expr2, tag2 >, op::div > | div (const vector_expression< value_t, expr1, tag1 > &left, const vector_expression< value_t, expr2, tag2 > &right) |
Binary element-wise division operator. | |
template<typename value_t , typename expr1 , typename expr2 , typename tag2 > | |
expr1 & | operator+= (vector_expression< value_t, expr1, tag::storage > &left, const vector_expression< value_t, expr2, tag2 > &right) |
Vector addition assignment operator. | |
template<typename value_t , typename expr1 , typename expr2 , typename tag2 > | |
expr1 & | operator+= (vector_expression< value_t, expr1, tag::reference > &left, const vector_expression< value_t, expr2, tag2 > &right) |
Vector addition assignment operator. | |
template<typename value_t , typename expr1 , typename expr2 , typename tag2 > | |
expr1 & | operator-= (vector_expression< value_t, expr1, tag::storage > &left, const vector_expression< value_t, expr2, tag2 > &right) |
Vector subtraction assignment operator. | |
template<typename value_t , typename expr1 , typename expr2 , typename tag2 > | |
expr1 & | operator-= (vector_expression< value_t, expr1, tag::reference > &left, const vector_expression< value_t, expr2, tag2 > &right) |
Vector subtraction assignment operator. | |
template<typename value_t , typename expr_t > | |
expr_t & | operator*= (vector_expression< value_t, expr_t, tag::storage > &left, const value_t &right) |
Vector multiplication assignment operator. | |
template<typename value_t , typename expr_t > | |
expr_t & | operator*= (vector_expression< value_t, expr_t, tag::reference > &left, const value_t &right) |
Vector multiplication assignment operator. |
Vector expression template class.
This class is the base class for all vector expressions including class vector
.
For explanation about template parameters value_t, expr_t and tag see documentation for matrix_expression
.
vector_expression
is almost fully analogous to matrix_expression
.
Actually all vectors are just straight strings of values and nobody cares about their orientation in space. But it is very convenient to think of a vector simultaneously being a matrix which consists of either one row or one column. To reflect this design two specializations of vector_expression
are defined, namely vector_expression<value_t, expr_t, tag, orientation::column>
and vector_expression<value_t, expr_t, tag, orientation::row>
, which define column vector and row vector expressions respectively.
The choice of concept to model affects only the implicit conversion to matrix expression:
orientation::undefined
orientation::column
is explicitly specified v.size()
by 1 matrix, and finallyorientation::row
is specified v.size()
matrix.Here v.size()
denotes the size of the vector.
Such design allows to restrict the orientation of the argument vector for a function. See details below.
There is another question about orientation: What is the orientation of a combination of vectors with different orientations?
In this library when two vectors are combined somehow yielding a vector its orientation is defined the following way:
undefined
then the resulting orientation is that of another vector,orientation::undefined
.For example if a column vector is added to another column vector the result is also a column vector:
A difference of a row vector and a column vector is a vector with undefined orientation:
column()
and row()
functions can be used to explicitly define orientation of a vector expression.
The definition of vector expressions is fully analogous to the case of matrix_expression
. See Defining Matrix Expressions.
For example definition of a vector class may look like this:
In this case a set of members must conform to storage
tag requirements to make my_vector
seamlessly integrated into the library (see Storage Concept Description). For more information see Expression Tags.
As an alternative the base could be specified like
In this case my_vector
type models the column vector concept and can be implicitly converted to a matrix consisting of one column.
The usage of vector expressions is very similar to that of matrix_expression
(see Using Matrix Expressions).
For example this function handles all vector expressions:
Such definitions are irrelevant to the orientation (column/row) of an arbitrary vector.
However if you want to restrict the usage of vector expressions in the sense of vector orientation you can write something like this:
This function handles only expressions that are explicitly defined as column vectors.
|
related |
Returns conjugated vector.
This function returns an expression which represents conjugated vector, i.e. a vector with conjugated corresponding elements.
For real valued vectors it just returns a constant reference to the argument, i.e. it actually does nothing.
For some important details check out Using complex types.
conj(v)
: algorithmic complexity of this operation is constant (i.e. O(1)).By convention the resulting expression has complexity of its subexpression.
|
related |
Binary element-wise division operator.
Sizes of argument vectors must be equal. Otherwise an exception (size_error
) is thrown.
div(v, v)
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Dot product is a sum of products of corresponding elements of first vector and conjugated elements of the second one:
It may be referred to as "scalar product" in other sources.
size_error | thrown if argument vectors have different sizes. |
Sizes of argument vectors must be equal. Otherwise an exception is thrown.
For some important details check out Using complex types.
traits<value_t>::zero
. dot_product(v, v)
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Returns underlying vector expression.
This template function deduces the actual type of the underlying vector expression and returns a reference to it. This scheme is called Curiously Recurring Template Pattern.
|
related |
Returns underlying vector expression.
This template function deduces the actual type of the underlying vector expression and returns a reference to it. This scheme is called Curiously Recurring Template Pattern.
|
related |
Transforms a vector using provided transformation map.
Number of columns of the matrix linear_map and size of the vector v must be equal. Otherwise an exception (size_error
) is thrown.
The vector is mapped the following way:
That is, the number of rows of the matrix representing linear map is the dimension of space the resulting vector (mapped
) belongs to.
This function preserves vector orientation, that is the orientation of the resulting vector expression is the same as that of the source vector.
This operation is analogous to matrix-vector multiplication.
map(m, v)
: algorithmic complexity of this operation is square (i.e. O(n2)).
|
related |
Transforms a vector using provided transformation map.
This is an overload for shaped matrix expressions.
Number of columns of the matrix linear_map and size of the vector v must be equal. Otherwise an exception (size_error
) is thrown.
|
related |
Binary element-wise multiplication operator.
Sizes of argument vectors must be equal. Otherwise an exception (size_error
) is thrown.
mul(v, v)
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Returns Euclidean norm of a vector.
Euclidean norm of a vector is a square root of the sum of products of corresponding elements and their conjugates:
It is equivalent to the square root of dot product of a vector and itself
For some important details check out Using complex types.
By the way this entity uses sqrt()
function to find the square root. It must be defined for the value_t
type in order to use this operation.
traits<value_t>::zero
. norm(v)
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Binary matrix-vector multiplication operator.
Number of columns of the matrix left and size of the vector right must be equal. Otherwise an exception (size_error
) is thrown.
This operation is analogous to map()
.
m*v
: algorithmic complexity of this operation is square (i.e. O(n2)).
|
related |
Binary matrix-vector multiplication operator.
This is an overload for shaped matrix expressions.
Number of columns of the matrix left and size of the vector right must be equal. Otherwise an exception (size_error
) is thrown.
|
related |
Binary multiplication operator.
v*s
: algorithmic complexity of this operation is linear (i.e.O(n)).
|
related |
Binary multiplication operator.
s*v
: algorithmic complexity of this operation is linear (i.e.O(n)).
|
related |
Vector multiplication assignment operator.
v *= s
: algorithmic complexity of this operation is linear (i.e.O(n)).
|
related |
Vector multiplication assignment operator.
This function is provided for convenience.
This function performs multiplication assignment element by element in a cycle.
v *= s
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Unary plus operator.
+v
: algorithmic complexity of this operation is constant (i.e.O(1)).
By convention the resulting expression has complexity of its subexpression.
|
related |
Binary addition operator.
Sizes of argument vectors must be equal. Otherwise an exception (size_error
) is thrown.
v + v
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Vector addition assignment operator.
Sizes of argument vectors must be equal. Otherwise an exception is thrown.
v += v
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Vector addition assignment operator.
This function is provided for convenience.
This function performs addition assignment element by element in a cycle.
For efficiency reasons this function does not check sizes of argument vectors for equality and does not throw an exception in case sizes are different. It only makes an assertion in debug configuration.
v += v
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Unary minus operator.
-v
: algorithmic complexity of this operation is constant (i.e.O(1)).
By convention the resulting expression has complexity of its subexpression.
|
related |
Binary subtraction operator.
Sizes of argument vectors must be equal. Otherwise an exception (size_error
) is thrown.
v - v
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Vector subtraction assignment operator.
Sizes of argument vectors must be equal. Otherwise an exception is thrown.
v -= v
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Vector subtraction assignment operator.
This function is provided for convenience.
This function performs subtraction assignment element by element in a cycle.
For efficiency reasons this function does not check sizes of argument vectors for equality and does not throw an exception in case sizes are different. It only makes an assertion in debug configuration.
v -= v
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Returns squared Euclidean norm of a vector.
Euclidean norm of a vector is a square root of the sum of products of corresponding elements and their conjugates. This function performs:
Note that this function returns squared Euclidean norm, that is |v|2.
It is equivalent to the dot product of a vector and itself
For some important details check out Using complex types.
traits<value_t>::zero
. sqrnorm(v)
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Returns sum of products of corresponding elements.
This function performs a convenient operation – it computes a sum of products of corresponding elements of two vectors:
For efficiency reasons this function does not check sizes of argument vectors for equality and does not throw an exception in case sizes are different. It only makes an assertion in debug configuration.
traits<value_t>::zero
. sum_of_products(v, v)
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Swaps contents of two vectors.
This template function handles all vector expressions with storage
tag. Such expressions are meant to be storage types and by definition provide efficient swap operation.
The actual effect of this function is
This function is not meant to throw any exceptions.
|
related |
Swaps contents of two vector expressions.
This function is provided for convenience.
This function swaps contents of two vector expressions with storage
tag. Such expressions are meant to be storage types.
This function does not actually swaps objects' storages or the like. Rather it swaps contents in the following manner:
temp
and assignment operation involved this function may throw an exception. swap(v, v)
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Swaps contents of two vector expressions.
This function is provided for convenience.
This function swaps contents of two vector expressions element by element in a cycle.
This function does not actually swaps objects' storages or the like. Rather it swaps contents element by element in a cycle like this:
min(a.size(), b.size())
elements.Thus this function is not meant to throw any exceptions.
swap(v, v)
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Swaps contents of two vector expressions.
This function is provided for convenience.This function swaps contents of two vector expressions element by element in a cycle.This function does not actually swaps objects' storages or the like. Rather it swaps contents element by element in a cycle like this:
min(a.size(), b.size())
elements.Thus this function is not meant to throw any exceptions.
swap(v, v)
: algorithmic complexity of this operation is linear (i.e. O(n)).
|
related |
Swaps contents of two vector expressions.
This function is provided for convenience.This function swaps contents of two vector expressions element by element in a cycle.This function does not actually swaps objects' storages or the like. Rather it swaps contents element by element in a cycle like this:
min(a.size(), b.size())
elements.Thus this function is not meant to throw any exceptions.
swap(v, v)
: algorithmic complexity of this operation is linear (i.e. O(n)).