Wiki

Clone wiki

blaze / Views


General Concepts

Views represents parts of a vector or matrix, such as a subvector, a submatrix, or a specific row, column, or band of a matrix. As such, views act as a reference to specific elements of a vector or matrix. This reference is valid and can be used in every way as any other vector or matrix can be used as long as the referenced vector or matrix is not resized or entirely destroyed. Views also act as alias to the elements of the vector or matrix: Changes made to the elements (e.g. modifying values, inserting or erasing elements) via the view are immediately visible in the vector or matrix and changes made via the vector or matrix are immediately visible in the view.

It is also possible to create nested views (compound views), such as for instance bands of submatrices or row selections on column selections. A compound view also acts as reference to specific elements of the underlying vector or matrix and is valid as long as the underlying, referenced vector or matrix is not resized or entirely destroyed.

The Blaze library provides the following views on vectors and matrices:

Vector views:

Matrix views:


Examples

using blaze::DynamicMatrix;
using blaze::StaticVector;

// Setup of the 3x5 row-major matrix
DynamicMatrix<int> A{ { 1,  0, -2,  3,  0 },
                      { 0,  2,  5, -1, -1 },
                      { 1,  0,  0,  2,  1 } };

// Setup of the 2-dimensional row vector
StaticVector<int,2UL,rowVector> vec{ 18, 19 };

// Assigning to the elements (1,2) and (1,3) via a subvector of a row
//
//  ( 1  0 -2  3  0 )
//  ( 0  2 18 19 -1 )
//  ( 1  0  0  2  1 )
//
subvector( row( A, 1UL ), 2UL, 2UL ) = vec;

// Switching rows 0 and 2 of A
//
//  ( 1  0  0  2  1 )
//  ( 0  2 18 19 -1 )
//  ( 1  0 -2  3  0 )
//
rows<0,2>( A ) = rows<2,0>( A );

// Warning: It is the programmer's responsibility to ensure the view does not outlive
//          the viewed vector or matrix (dangling reference)!
auto row1 = row<1UL>( DynamicMatrix<int>{ { 1, 2, 3 }, { 4, 5, 6 } } );

Previous: Triangular Matrices ---- Next: Subvectors

Updated