NABLA  Nabla Ain't Basic Linear Algebra
Friends | List of all members
shaped_expression< value_t, expr_t, tag_t, shape > Struct Template Reference

Shaped matrix expression template class. More...

Inheritance diagram for shaped_expression< value_t, expr_t, tag_t, shape >:
Inheritance graph

Friends

util::non_zero_in_column
< shape >::first_type 
first_non_zero_in_column (const expr_t &m, size_t column)
 Returns index of the first non zero element in column column.
util::non_zero_in_row< shape >
::first_type 
first_non_zero_in_row (const expr_t &m, size_t row)
 Returns index of the first non zero element in row row.
util::non_zero_in_column
< shape >::last_type 
last_non_zero_in_column (const expr_t &m, size_t column)
 Returns index of the last non zero element in column column.
util::non_zero_in_row< shape >
::last_type 
last_non_zero_in_row (const expr_t &m, size_t row)
 Returns index of the last non zero element in row row.

Related Functions

(Note that these are not member functions.)

Miscellaneous
template<typename value_t , typename expr_t , typename shape >
void swap (shaped_expression< value_t, expr_t, tag::storage, shape > &a, shaped_expression< value_t, expr_t, tag::storage, shape > &b)
 Swaps contents of two matrices.
Matrix operations
template<typename value_t , typename expr_t , typename tag , typename shape >
const unary< shaped_expression
< value_t, expr_t, tag, shape >
, op::plus
operator+ (const shaped_expression< value_t, expr_t, tag, shape > &a)
 Unary plus operator.
template<typename value_t , typename expr_t , typename tag , typename shape >
const unary< shaped_expression
< value_t, expr_t, tag, shape >
, op::minus
operator- (const shaped_expression< value_t, expr_t, tag, shape > &a)
 Unary minus operator.
template<typename value_t , typename expr_t , typename tag , typename shape >
const unary< shaped_expression
< value_t, expr_t, tag, shape >
, op::conj
conj (const shaped_expression< value_t, expr_t, tag, shape > &a)
 Returns conjugated matrix.
template<typename value_t , typename expr_t , typename tag , typename shape >
const transposed
< shaped_expression< value_t,
expr_t, tag, shape > > 
transpose (const shaped_expression< value_t, expr_t, tag, shape > &a)
 Returns transposed matrix.
template<typename value_t , typename expr_t , typename tag >
const expr_t & transpose (const shaped_expression< value_t, expr_t, tag, symmetric > &a)
 Returns transposed matrix.
template<typename value_t , typename expr_t , typename tag >
const reshaped
< shaped_expression< value_t,
expr_t, tag, lower_triangular >
, upper_triangular,
lower_triangular
transpose (const shaped_expression< value_t, expr_t, tag, lower_triangular > &a)
 Returns transposed matrix.
template<typename value_t , typename expr_t , typename tag >
const reshaped
< shaped_expression< value_t,
expr_t, tag, upper_triangular >
, lower_triangular,
upper_triangular
transpose (const shaped_expression< value_t, expr_t, tag, upper_triangular > &a)
 Returns transposed matrix.
template<typename value_t , typename expr_t , typename tag , typename shape >
const scaled
< shaped_expression< value_t,
expr_t, tag, shape > > 
operator* (const shaped_expression< value_t, expr_t, tag, shape > &a, const typename expr_t::value_type &s)
 Binary multiplication operator.
template<typename value_t , typename expr_t , typename tag , typename shape >
const scaled
< shaped_expression< value_t,
expr_t, tag, shape > > 
operator* (const typename expr_t::value_type &s, const shaped_expression< value_t, expr_t, tag, shape > &a)
 Binary multiplication operator.
template<typename value_t , typename expr1 , typename tag1 , typename shape1 , typename expr2 , typename tag2 , typename shape2 >
const binary
< shaped_expression< value_t,
expr1, tag1, shape1 >
, shaped_expression< value_t,
expr2, tag2, shape1 >, op::add
operator+ (const shaped_expression< value_t, expr1, tag1, shape1 > &left, const shaped_expression< value_t, expr2, tag2, shape2 > &right)
 Binary addition operator.
template<typename value_t , typename expr1 , typename tag1 , typename shape1 , typename expr2 , typename tag2 , typename shape2 >
const binary
< shaped_expression< value_t,
expr1, tag1, shape1 >
, shaped_expression< value_t,
expr2, tag2, shape2 >, op::sub
operator- (const shaped_expression< value_t, expr1, tag1, shape1 > &left, const shaped_expression< value_t, expr2, tag2, shape2 > &right)
 Binary subtraction operator.
template<typename value_t , typename expr1 , typename tag1 , typename shape1 , typename expr2 , typename tag2 , typename shape2 >
const binary
< shaped_expression< value_t,
expr1, tag1, shape1 >
, shaped_expression< value_t,
expr2, tag2, shape2 >, op::mul
mul (const shaped_expression< value_t, expr1, tag1, shape1 > &left, const shaped_expression< value_t, expr2, tag2, shape2 > &right)
 Binary element-wise multiplication operation.
template<typename value_t , typename expr1 , typename tag1 , typename shape1 , typename expr2 , typename tag2 , typename shape2 >
const binary
< shaped_expression< value_t,
expr1, tag1, shape1 >
, shaped_expression< value_t,
expr2, tag2, shape2 >, op::div
div (const shaped_expression< value_t, expr1, tag1, shape1 > &left, const shaped_expression< value_t, expr2, tag2, shape2 > &right)
 Binary element-wise multiplication operation.
template<typename value_t , typename expr1 , typename tag1 , typename shape1 , typename expr2 , typename tag2 , typename shape2 >
product< shaped_expression
< value_t, expr1, tag1, shape1 >
, shaped_expression< value_t,
expr2, tag2, shape2 > > 
operator* (const shaped_expression< value_t, expr1, tag1, shape1 > &left, const shaped_expression< value_t, expr2, tag2, shape2 > &right)
 Binary matrix multiplication operator.
template<typename value_t , typename expr1 , typename shape , typename expr2 , typename tag2 >
expr1 & operator+= (shaped_expression< value_t, expr1, tag::storage, shape > &left, const shaped_expression< value_t, expr2, tag2, shape > &right)
 Matrix addition assignment operator.
template<typename value_t , typename expr1 , typename shape , typename expr2 , typename tag2 >
expr1 & operator-= (shaped_expression< value_t, expr1, tag::storage, shape > &left, const shaped_expression< value_t, expr2, tag2, shape > &right)
 Matrix subtraction assignment operator.
template<typename value_t , typename expr_t , typename shape >
expr_t & operator*= (shaped_expression< value_t, expr_t, tag::storage, shape > &left, const value_t &right)
 Matrix multiplication assignment operator.
template<typename value_t , typename expr1 , typename expr2 , typename tag2 >
expr1 & operator*= (shaped_expression< value_t, expr1, tag::storage, lower_triangular > &left, const shaped_expression< value_t, expr2, tag2, lower_triangular > &right)
 Matrix multiplication assignment operator.
template<typename value_t , typename expr1 , typename expr2 , typename tag2 >
expr1 & operator*= (shaped_expression< value_t, expr1, tag::storage, upper_triangular > &left, const shaped_expression< value_t, expr2, tag2, upper_triangular > &right)
 Matrix multiplication assignment operator.

Detailed Description

template<typename value_t, typename expr_t, typename tag_t, typename shape>
struct nabla::shaped_expression< value_t, expr_t, tag_t, shape >

Shaped matrix expression template class.

This class helps to restrict use of matrix expressions which have a shape other than rectangular. See also Matrix Shape.

For details about matrix expressions in general see documentation for matrix_expression .

This is an extension of matrix_expression concept to allow handling of matrices of different shapes, e.g. symmetric (see Extending Matrix Expressions). It is obvious that when two, say, upper triangular matrices are added or subtracted the resulting matrix is also upper triangular. This also applies to any shape. It's not obvious but can be proved that a product of two upper triangular matrices... guess what? ...is also upper triangular. The same story with lower triangular matrices.

Note
Unfortunately the reality is such that a product of two symmetric matrices is not symmetric in general. A product is symmetric only if the matrix multipliers commute (i.e. A*B==B*A) which is impossible to determine at compile time.

This class and it's supporting routines implement such design.

At the same time an arbitrarily shaped matrix can always be presented as a rectangular matrix, whatever the shape is. So any shaped matrix expression can be handled as ordinary matrix_expression if needed. Furthermore if a function explicitly wants a rectangular storage type (see Using Matrix Expressions)

template<typename value_t, typename expr_t>
void foo(matrix_expression<value_t, expr_t, tag::storage> &e);

shaped storage types (like matrix<double, symmetric>) will not be handled because the function is only aware of general rectangular shape and not of symmetric. This happens because every shaped expression simultaneously acts as an expression tagged with tag::expression<complexity> (read read only expression) which is incompatible with mutable expressions (and thus with foo() signature). This appears to be the only safe way to interact with it as a general rectangular matrix.

To define a shaped matrix expression one needs to inherit shaped_expression like this:

template<typename type, typename shape>
class my_shaped_matrix :
public shaped_expression<type, //element type
my_shaped_matrix<type, shape>, //actual type
tag::storage, //tag
shape //shape of expression
>
{
//rest of definition
};

This is very similar to the case of matrix_expression (see Defining Matrix Expressions).

Additionally if you want your operation to handle such expressions you have to overload it:

template<typename value_t, typename expr1, typename tag1, typename expr2, typename tag2, typename shape>
value_t bar(const shaped_expression<value_t, expr1, tag1, shape> &e1,
const shaped_expression<value_t, expr2, tag2, shape> &e2
)
{
const expr1 &d = get_matrix(dest); //get underlying objects
const expr2 &s = get_matrix(src);
value_t answer;
//doing calculations (possibly in a shape optimized manner)
return answer;
}

(compare to the definition in section Using Matrix Expressions). Now shaped expressions with the same shape (notice corresponding template argument) are handled by bar() defined above while any other combination of shapes is handled by
bar(const matrix_expression<value_t, expr1, tag1>&, const matrix_expression<value_t, expr2, tag2>&).

See Also
matrix_expression, vector_expression, matrix

Definition at line 1404 of file matrix.h.

Friends And Related Function Documentation

const unary< shaped_expression< value_t, expr_t, tag, shape >, op::conj > conj ( const shaped_expression< value_t, expr_t, tag, shape > &  a)
related

Returns conjugated matrix.

This is an overload for shaped matrix expressions.

Definition at line 3929 of file matrix.h.

const binary< shaped_expression< value_t, expr1, tag1, shape1 >, shaped_expression< value_t, expr2, tag2, shape2 >, op::div > div ( const shaped_expression< value_t, expr1, tag1, shape1 > &  left,
const shaped_expression< value_t, expr2, tag2, shape2 > &  right 
)
related

Binary element-wise multiplication operation.

This is an overload for shaped matrix expressions.

Sizes of argument matrices must be equal. Otherwise an exception (size_error) is thrown.

Definition at line 4308 of file matrix.h.

const binary< shaped_expression< value_t, expr1, tag1, shape1 >, shaped_expression< value_t, expr2, tag2, shape2 >, op::mul > mul ( const shaped_expression< value_t, expr1, tag1, shape1 > &  left,
const shaped_expression< value_t, expr2, tag2, shape2 > &  right 
)
related

Binary element-wise multiplication operation.

This is an overload for shaped matrix expressions.

Sizes of argument matrices must be equal. Otherwise an exception (size_error) is thrown.

Definition at line 4278 of file matrix.h.

const scaled< shaped_expression< value_t, expr_t, tag, shape > > operator* ( const shaped_expression< value_t, expr_t, tag, shape > &  a,
const typename expr_t::value_type &  s 
)
related

Binary multiplication operator.

This is an overload for shaped matrix expressions.

Definition at line 4089 of file matrix.h.

const scaled< shaped_expression< value_t, expr_t, tag, shape > > operator* ( const typename expr_t::value_type &  s,
const shaped_expression< value_t, expr_t, tag, shape > &  a 
)
related

Binary multiplication operator.

This is an overload for shaped matrix expressions.

Definition at line 4106 of file matrix.h.

product< shaped_expression< value_t, expr1, tag1, shape1 >, shaped_expression< value_t, expr2, tag2, shape2 > > operator* ( const shaped_expression< value_t, expr1, tag1, shape1 > &  left,
const shaped_expression< value_t, expr2, tag2, shape2 > &  right 
)
related

Binary matrix multiplication operator.

This is an overload for shaped matrix expressions.

Sizes of argument matrices must be equal. Otherwise an exception (size_error) is thrown.

Note that a product of two upper or lower triangular matrices has respective shape. Any other combination of shapes produces rectangular matrix, including a product of two symmetric matrices.

Definition at line 4850 of file matrix.h.

expr_t & operator*= ( shaped_expression< value_t, expr_t, tag::storage, shape > &  left,
const value_t &  right 
)
related

Matrix multiplication assignment operator.

This is an overload for shaped matrix expressions.

Definition at line 5066 of file matrix.h.

expr1 & operator*= ( shaped_expression< value_t, expr1, tag::storage, lower_triangular > &  left,
const shaped_expression< value_t, expr2, tag2, lower_triangular > &  right 
)
related

Matrix multiplication assignment operator.

This is an overload for lower triangular matrix expressions.

Sizes of argument matrices must be equal. Otherwise an exception is thrown.

Definition at line 5097 of file matrix.h.

expr1 & operator*= ( shaped_expression< value_t, expr1, tag::storage, upper_triangular > &  left,
const shaped_expression< value_t, expr2, tag2, upper_triangular > &  right 
)
related

Matrix multiplication assignment operator.

This is an overload for upper triangular matrix expressions.

Sizes of argument matrices must be equal. Otherwise an exception is thrown.

Definition at line 5112 of file matrix.h.

const unary< shaped_expression< value_t, expr_t, tag, shape >, op::plus > operator+ ( const shaped_expression< value_t, expr_t, tag, shape > &  a)
related

Unary plus operator.

This overload is for shaped matrix expressions.

Definition at line 3884 of file matrix.h.

const binary< shaped_expression< value_t, expr1, tag1, shape1 >, shaped_expression< value_t, expr2, tag2, shape1 >, op::add > operator+ ( const shaped_expression< value_t, expr1, tag1, shape1 > &  left,
const shaped_expression< value_t, expr2, tag2, shape2 > &  right 
)
related

Binary addition operator.

This is an overload for shaped matrix expressions.

Sizes of argument matrices must be equal. Otherwise an exception (size_error) is thrown.

Definition at line 4222 of file matrix.h.

expr1 & operator+= ( shaped_expression< value_t, expr1, tag::storage, shape > &  left,
const shaped_expression< value_t, expr2, tag2, shape > &  right 
)
related

Matrix addition assignment operator.

This is an overload for shaped matrix expressions.

Sizes of argument matrices must be equal. Otherwise an exception is thrown.

Definition at line 5004 of file matrix.h.

const unary< shaped_expression< value_t, expr_t, tag, shape >, op::minus > operator- ( const shaped_expression< value_t, expr_t, tag, shape > &  a)
related

Unary minus operator.

This overload is for shaped matrix expressions.

Definition at line 3903 of file matrix.h.

const binary< shaped_expression< value_t, expr1, tag1, shape1 >, shaped_expression< value_t, expr2, tag2, shape2 >, op::sub > operator- ( const shaped_expression< value_t, expr1, tag1, shape1 > &  left,
const shaped_expression< value_t, expr2, tag2, shape2 > &  right 
)
related

Binary subtraction operator.

This is an overload for shaped matrix expressions.

Sizes of argument matrices must be equal. Otherwise an exception (size_error) is thrown.

Definition at line 4248 of file matrix.h.

expr1 & operator-= ( shaped_expression< value_t, expr1, tag::storage, shape > &  left,
const shaped_expression< value_t, expr2, tag2, shape > &  right 
)
related

Matrix subtraction assignment operator.

This is an overload for shaped matrix expressions.

Sizes of argument matrices must be equal. Otherwise an exception is thrown.

Definition at line 5034 of file matrix.h.

void swap ( shaped_expression< value_t, expr_t, tag::storage, shape > &  a,
shaped_expression< value_t, expr_t, tag::storage, shape > &  b 
)
related

Swaps contents of two matrices.

This template function handles all shaped matrix 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

get_matrix(a).swap(get_matrix(b));

This function is not meant to throw any exceptions.

Definition at line 3278 of file matrix.h.

const transposed< shaped_expression< value_t, expr_t, tag, shape > > transpose ( const shaped_expression< value_t, expr_t, tag, shape > &  a)
related

Returns transposed matrix.

This is an overload for shaped matrix expressions.

Definition at line 3990 of file matrix.h.

const expr_t & transpose ( const shaped_expression< value_t, expr_t, tag, symmetric > &  a)
related

Returns transposed matrix.

This is an overload for symmetric matrix expressions.

Since a transposed symmetric matrix is itself (A==AT) this function returns a reference to the argument. The equivalent effect is

Definition at line 4002 of file matrix.h.

const reshaped< shaped_expression< value_t, expr_t, tag, lower_triangular >, upper_triangular, lower_triangular > transpose ( const shaped_expression< value_t, expr_t, tag, lower_triangular > &  a)
related

Returns transposed matrix.

This is an overload for lower triangular matrix expressions.

Since a transposed lower triangular matrix is an upper triangular one this function returnes reshaped expression. The equivalent effect is

reshape<upper_tr, lower_tr>(a);

Definition at line 4015 of file matrix.h.

const reshaped< shaped_expression< value_t, expr_t, tag, upper_triangular >, lower_triangular, upper_triangular > transpose ( const shaped_expression< value_t, expr_t, tag, upper_triangular > &  a)
related

Returns transposed matrix.

This is an overload for upper triangular matrix expressions.

Since a transposed upper triangular matrix is a lower triangular one this function returnes reshaped expression. The equivalent effect is

reshape<lower_tr, upper_tr>(a);

Definition at line 4028 of file matrix.h.


The documentation for this struct was generated from the following file: