Blaze 3.9
Functions

Functions

template<size_t I, size_t... Is, typename MT , bool SO, typename... RRAs>
decltype(auto) blaze::rows (Matrix< MT, SO > &matrix, RRAs... args)
 Creating a view on a selection of rows of the given matrix. More...
 
template<size_t I, size_t... Is, typename MT , bool SO, typename... RRAs>
decltype(auto) blaze::rows (const Matrix< MT, SO > &matrix, RRAs... args)
 Creating a view on a selection of rows of the given constant matrix. More...
 
template<size_t I, size_t... Is, typename MT , bool SO, typename... RRAs>
decltype(auto) blaze::rows (Matrix< MT, SO > &&matrix, RRAs... args)
 Creating a view on a selection of rows of the given temporary matrix. More...
 
template<typename MT , bool SO, typename T , typename... RRAs>
decltype(auto) blaze::rows (Matrix< MT, SO > &matrix, T *indices, size_t n, RRAs... args)
 Creating a view on a selection of rows of the given matrix. More...
 
template<typename MT , bool SO, typename T , typename... RRAs>
decltype(auto) blaze::rows (const Matrix< MT, SO > &matrix, T *indices, size_t n, RRAs... args)
 Creating a view on a selection of rows of the given constant matrix. More...
 
template<typename MT , bool SO, typename T , typename... RRAs>
decltype(auto) blaze::rows (Matrix< MT, SO > &&matrix, T *indices, size_t n, RRAs... args)
 Creating a view on a selection of rows of the given temporary matrix. More...
 
template<typename MT , bool SO, typename P , typename... RRAs>
decltype(auto) blaze::rows (Matrix< MT, SO > &matrix, P p, size_t n, RRAs... args)
 Creating a view on a selection of rows of the given matrix. More...
 
template<typename MT , bool SO, typename P , typename... RRAs>
decltype(auto) blaze::rows (const Matrix< MT, SO > &matrix, P p, size_t n, RRAs... args)
 Creating a view on a selection of rows of the given constant matrix. More...
 
template<typename MT , bool SO, typename P , typename... RRAs>
decltype(auto) blaze::rows (Matrix< MT, SO > &&matrix, P p, size_t n, RRAs... args)
 Creating a view on a selection of rows of the given temporary matrix. More...
 
template<typename MT , size_t... Is, typename... RRAs>
decltype(auto) blaze::rows (MT &&matrix, index_sequence< Is... > indices, RRAs... args)
 Creating a view on a selection of rows of the given matrix. More...
 
template<typename MT , typename T , typename... RRAs>
decltype(auto) blaze::rows (MT &&matrix, initializer_list< T > indices, RRAs... args)
 Creating a view on a selection of rows of the given matrix. More...
 
template<typename MT , typename T , size_t N, typename... RRAs>
decltype(auto) blaze::rows (MT &&matrix, const std::array< T, N > &indices, RRAs... args)
 Creating a view on a selection of rows of the given matrix. More...
 
template<typename MT , typename T , typename... RRAs>
decltype(auto) blaze::rows (MT &&matrix, const std::vector< T > &indices, RRAs... args)
 Creating a view on a selection of rows of the given matrix. More...
 
template<typename MT , typename T , size_t N, typename... RRAs>
decltype(auto) blaze::rows (MT &&matrix, const SmallArray< T, N > &indices, RRAs... args)
 Creating a view on a selection of rows of the given matrix. More...
 

Detailed Description

Row selections provide views on arbitrary compositions of rows of dense and sparse matrices. These views act as a reference to the selected rows and represent them as another dense or sparse matrix. This reference is valid and can be used in every way any other dense or sparse matrix can be used as long as the matrix containing the rows is not resized or entirely destroyed. The row selection also acts as an alias to the matrix elements in the specified range: Changes made to the rows (e.g. modifying values, inserting or erasing elements) are immediately visible in the matrix and changes made via the matrix are immediately visible in the rows.


Setup of Row Selections

A row selection can be created very conveniently via the rows() function. It can be included via the header files

#include <blaze/Blaze.h>
// or
#include <blaze/Math.h>
// or
Primary include file of the Blaze library.
Header file for the inclusion of the math module of the Blaze library.
Header file for the complete Rows implementation.

and forward declared via the header file

#include <blaze/Forward.h>
Header file for all forward declarations of the Blaze library.

The indices of the rows to be selected can be specified either at compile time or at runtime (by means of an initializer list, array or vector):

// ... Resizing and initialization
// Selecting the rows 4, 6, 8, and 10 (compile time arguments)
auto rs1 = rows<4UL,6UL,8UL,10UL>( A );
// Selecting the rows 3, 2, and 1 (runtime arguments via an initializer list)
const std::initializer_list<size_t> list{ 3UL, 2UL, 1UL };
auto rs2 = rows( A, { 3UL, 2UL, 1UL } );
auto rs3 = rows( A, list );
// Selecting the rows 1, 2, 3, 3, 2, and 1 (runtime arguments via a std::array)
const std::array<size_t> array{ 1UL, 2UL, 3UL, 3UL, 2UL, 1UL };
auto rs4 = rows( A, array );
auto rs5 = rows( A, array.data(), array.size() );
// Selecting the row 4 fives times (runtime arguments via a std::vector)
const std::vector<size_t> vector{ 4UL, 4UL, 4UL, 4UL, 4UL };
auto rs6 = rows( A, vector );
auto rs7 = rows( A, vector.data(), vector.size() );
Efficient implementation of a dynamic matrix.
Definition: DynamicMatrix.h:242
constexpr size_t rows(const Matrix< MT, SO > &matrix) noexcept
Returns the current number of rows of the matrix.
Definition: Matrix.h:644

Note that it is possible to alias the rows of the underlying matrix in any order. Also note that it is possible to use the same index multiple times.

Alternatively it is possible to pass a callable such as a lambda or functor that produces the indices:

// Selecting all even rows of the matrix, i.e. selecting the rows 0, 2, 4, 6, and 8
auto rs1 = rows( A, []( size_t i ){ return i*2UL; }, 5UL );
// Selecting all odd rows of the matrix, i.e. selecting the rows 1, 3, 5, and 7
auto rs2 = rows( x, []( size_t i ){ return i*2UL+1UL; }, 4UL );
// Reversing the rows of the matrix, i.e. selecting the rows 8, 7, 6, 5, 4, 3, 2, 1, and 0
auto rs3 = rows( v, [max=A.rows()-1UL]( size_t i ){ return max-i; }, 9UL );
size_t rows() const noexcept
Returns the current number of rows of the matrix.
Definition: DynamicMatrix.h:1782
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1375

The rows() function returns an expression representing the view on the selected rows. The type of this expression depends on the given arguments, primarily the type of the matrix and the compile time arguments. If the type is required, it can be determined via the decltype specifier:

using MatrixType = blaze::DynamicMatrix<int>;
using RowsType = decltype( blaze::rows<3UL,0UL,4UL,8UL>( std::declval<MatrixType>() ) );

The resulting view can be treated as any other dense or sparse matrix, i.e. it can be assigned to, it can be copied from, and it can be used in arithmetic operations. Note, however, that a row selection will always be treated as a row-major matrix, regardless of the storage order of the matrix containing the rows. The view can also be used on both sides of an assignment: It can either be used as an alias to grant write access to specific rows of a matrix primitive on the left-hand side of an assignment or to grant read-access to specific rows of a matrix primitive or expression on the right-hand side of an assignment. The following example demonstrates this in detail:

// ... Resizing and initialization
// Selecting the rows 1, 3, 5, and 7 of A
auto rs = rows( A, { 1UL, 3UL, 5UL, 7UL } );
// Setting rows 1, 3, 5, and 7 of A to row 4 of B
rs = rows( B, { 4UL, 4UL, 4UL, 4UL } );
// Setting the rows 2, 4, 6, and 8 of A to C
rows( A, { 2UL, 4UL, 6UL, 8UL } ) = C;
// Setting the first 4 rows of A to the rows 5, 4, 3, and 2 of C
submatrix( A, 0UL, 0UL, 4UL, A.columns() ) = rows( C, { 5UL, 4UL, 3UL, 2UL } );
// Rotating the result of the addition between rows 1, 3, 5, and 7 of A and C
B = rows( rs + C, { 2UL, 3UL, 0UL, 1UL } );
Efficient implementation of a compressed matrix.
Definition: CompressedMatrix.h:239
size_t columns() const noexcept
Returns the current number of columns of the matrix.
Definition: DynamicMatrix.h:1798
decltype(auto) submatrix(Matrix< MT, SO > &, RSAs...)
Creating a view on a specific submatrix of the given matrix.
Definition: Submatrix.h:181


Element access

The elements of a row selection can be directly accessed via the function call operator:

// ... Resizing and initialization
// Creating a view on the first four rows of A in reverse order
auto rs = rows( A, { 3UL, 2UL, 1UL, 0UL } );
// Setting the element (0,0) of the row selection, which corresponds
// to the element at position (3,0) in matrix A
rs(0,0) = 2.0;

Alternatively, the elements of a row selection can be traversed via (const) iterators. Just as with matrices, in case of non-const row selection, begin() and end() return an iterator, which allows to manipuate the elements, in case of constant row selection an iterator to immutable elements is returned:

// ... Resizing and initialization
// Creating a reference to a selection of rows of matrix A
auto rs = rows( A, { 16UL, 32UL, 64UL, 128UL } );
// Traversing the elements of the 0th row via iterators to non-const elements
for( auto it=rs.begin(0); it!=rs.end(0); ++it ) {
*it = ...; // OK: Write access to the dense value.
... = *it; // OK: Read access to the dense value.
}
// Traversing the elements of the 1st row via iterators to const elements
for( auto it=rs.cbegin(1); it!=rs.cend(1); ++it ) {
*it = ...; // Compilation error: Assignment to the value via iterator-to-const is invalid.
... = *it; // OK: Read access to the dense value.
}
// ... Resizing and initialization
// Creating a reference to a selection of rows of matrix A
auto rs = rows( A, { 16UL, 32UL, 64UL, 128UL } );
// Traversing the elements of the 0th row via iterators to non-const elements
for( auto it=rs.begin(0); it!=rs.end(0); ++it ) {
it->value() = ...; // OK: Write access to the value of the non-zero element.
... = it->value(); // OK: Read access to the value of the non-zero element.
it->index() = ...; // Compilation error: The index of a non-zero element cannot be changed.
... = it->index(); // OK: Read access to the index of the sparse element.
}
// Traversing the elements of the 1st row via iterators to const elements
for( auto it=rs.cbegin(1); it!=rs.cend(1); ++it ) {
it->value() = ...; // Compilation error: Assignment to the value via iterator-to-const is invalid.
... = it->value(); // OK: Read access to the value of the non-zero element.
it->index() = ...; // Compilation error: The index of a non-zero element cannot be changed.
... = it->index(); // OK: Read access to the index of the sparse element.
}


Element Insertion

Inserting/accessing elements in a sparse row selection can be done by several alternative functions. The following example demonstrates all options:

blaze::CompressedMatrix<double,blaze::rowMajor> A( 256UL, 512UL ); // Non-initialized matrix of size 256x512
auto rs = rows( A, { 10UL, 20UL, 30UL, 40UL } ); // View on the rows 10, 20, 30, and 40 of A
// The function call operator provides access to all possible elements of the sparse row
// selection, including the zero elements. In case the function call operator is used to
// access an element that is currently not stored in the sparse row selection, the element
// is inserted into the row selection.
rs(2,4) = 2.0;
// The second operation for inserting elements is the set() function. In case the element is
// not contained in the row selection it is inserted into the row selection, if it is already
// contained in the row selection its value is modified.
rs.set( 2UL, 5UL, -1.2 );
// An alternative for inserting elements into the row selection is the \c insert() function.
// However, it inserts the element only in case the element is not already contained in the
// row selection.
rs.insert( 2UL, 6UL, 3.7 );
// Just as in the case of sparse matrices, elements can also be inserted via the \c append()
// function. In case of row selections, \c append() also requires that the appended element's
// index is strictly larger than the currently largest non-zero index in the according row
// of the row selection and that the according row's capacity is large enough to hold the new
// element. Note however that due to the nature of a row selection, which may be an alias to
// an arbitrary collection of rows, the \c append() function does not work as efficiently for
// a row selection as it does for a matrix.
rs.reserve( 2UL, 10UL );
rs.append( 2UL, 10UL, -2.1 );


Common Operations

A view on specific rows of a matrix can be used like any other dense or sparse matrix. For instance, the current size of the matrix, i.e. the number of rows or columns can be obtained via the rows() and columns() functions, the current total capacity via the capacity() function, and the number of non-zero elements via the nonZeros() function. However, since row selections are views on specific rows of a matrix, several operations are not possible, such as resizing and swapping:

// ... Resizing and initialization
// Creating a view on the rows 8, 16, 24, and 32 of matrix A
auto rs = rows( A, { 8UL, 16UL, 24UL, 32UL } );
rs.rows(); // Returns the number of rows of the row selection
rs.columns(); // Returns the number of columns of the row selection
rs.capacity(); // Returns the capacity of the row selection
rs.nonZeros(); // Returns the number of non-zero elements contained in the row selection
rs.resize( 10UL, 8UL ); // Compilation error: Cannot resize a row selection
auto rs2 = rows( A, 9UL, 17UL, 25UL, 33UL );
swap( rs, rs2 ); // Compilation error: Swap operation not allowed
void swap(DiagonalMatrix< MT, SO, DF > &a, DiagonalMatrix< MT, SO, DF > &b) noexcept
Swapping the contents of two matrices.
Definition: DiagonalMatrix.h:225


Arithmetic Operations

Both dense and sparse row selections can be used in all arithmetic operations that any other dense or sparse matrix can be used in. The following example gives an impression of the use of dense row selctions within arithmetic operations. All operations (addition, subtraction, multiplication, scaling, ...) can be performed on all possible combinations of dense and sparse matrices with fitting element types:

// ... Resizing and initialization
std::initializer_list<size_t> indices1{ 0UL, 3UL, 6UL, 9UL, 12UL, 15UL, 18UL, 21UL };
std::initializer_list<size_t> indices2{ 1UL, 4UL, 7UL, 10UL, 13UL, 16UL, 19UL, 22UL };
std::initializer_list<size_t> indices3{ 2UL, 5UL, 8UL, 11UL, 14UL, 17UL, 20UL, 23UL };
auto rs = rows( D1, indices1 ); // Selecting the every third row of D1 in the range [0..21]
rs = D2; // Dense matrix assignment to the selected rows
rows( D1, indices2 ) = S1; // Sparse matrix assignment to the selected rows
D3 = rs + D2; // Dense matrix/dense matrix addition
S2 = S1 - rows( D1, indices2 ); // Sparse matrix/dense matrix subtraction
D2 = rs % rows( D1, indices3 ); // Dense matrix/dense matrix Schur product
D2 = rows( D1, indices2 ) * D1; // Dense matrix/dense matrix multiplication
rows( D1, indices2 ) *= 2.0; // In-place scaling of the second selection of rows
D2 = rows( D1, indices3 ) * 2.0; // Scaling of the elements in the third selection of rows
D2 = 2.0 * rows( D1, indices3 ); // Scaling of the elements in the third selection of rows
rows( D1, indices1 ) += D2; // Addition assignment
rows( D1, indices2 ) -= S1; // Subtraction assignment
rows( D1, indices3 ) %= rs; // Schur product assignment
a = rows( D1, indices1 ) * b; // Dense matrix/sparse vector multiplication
Efficient implementation of an arbitrary sized sparse vector.
Definition: CompressedVector.h:220


Row Selections on Column-Major Matrices

Especially noteworthy is that row selections can be created for both row-major and column-major matrices. Whereas the interface of a row-major matrix only allows to traverse a row directly and the interface of a column-major matrix only allows to traverse a column, via views it is possible to traverse a row of a column-major matrix or a column of a row-major matrix. For instance:

// ... Resizing and initialization
// Creating a reference to the 1st and 3rd row of a column-major matrix A
auto rs = rows( A, { 1UL, 3UL } );
// Traversing row 0 of the selection, which corresponds to the 1st row of matrix A
for( auto it=rs.begin( 0UL ); it!=rs.end( 0UL ); ++it ) {
// ...
}

However, please note that creating a row selection on a matrix stored in a column-major fashion can result in a considerable performance decrease in comparison to a row selection on a matrix with row-major storage format. This is due to the non-contiguous storage of the matrix elements. Therefore care has to be taken in the choice of the most suitable storage order:

// Setup of two column-major matrices
// ... Resizing and initialization
// The computation of the 15th, 30th, and 45th row of the multiplication between A and B ...
blaze::DynamicMatrix<double,blaze::rowMajor> x = rows( A * B, { 15UL, 30UL, 45UL } );
// ... is essentially the same as the following computation, which multiplies
// the 15th, 30th, and 45th row of the column-major matrix A with B.
blaze::DynamicMatrix<double,blaze::rowMajor> x = rows( A, { 15UL, 30UL, 45UL } ) * B;

Although Blaze performs the resulting matrix/matrix multiplication as efficiently as possible using a row-major storage order for matrix A would result in a more efficient evaluation.

Function Documentation

◆ rows() [1/14]

template<typename MT , bool SO, typename P , typename... RRAs>
decltype(auto) blaze::rows ( const Matrix< MT, SO > &  matrix,
p,
size_t  n,
RRAs...  args 
)
inline

Creating a view on a selection of rows of the given constant matrix.

Parameters
matrixThe constant matrix containing the rows.
pCallable producing the indices.
nThe total number of indices.
argsOptional arguments.
Returns
View on the specified rows of the matrix.
Exceptions
std::invalid_argumentInvalid row access index.

This function returns an expression representing a selection of rows of the given constant matrix.

// ... Resizing and initialization
// Creating a view on the 1st and 3rd row of the dense matrix D
auto rows1 = rows( D, []( size_t i ){ return 2UL*i + 1UL; }, 2UL );
// Creating a view on the 4th and 2nd row of the sparse matrix S
auto rows2 = rows( S, []( size_t i ){ return 4UL - 2UL*i; }, 2UL );
constexpr bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71

By default, the provided row indices are checked at runtime. In case any row is not properly specified (i.e. if any specified index is greater than or equal to the total number of rows in the given matrix) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.

auto rows1 = rows( D, []( size_t i ){ return 2UL*i + 1UL; }, 2UL, unchecked );
auto rows2 = rows( S, []( size_t i ){ return 4UL - 2UL*i; }, 2UL, unchecked );
constexpr Unchecked unchecked
Global Unchecked instance.
Definition: Check.h:146

◆ rows() [2/14]

template<size_t I, size_t... Is, typename MT , bool SO, typename... RRAs>
decltype(auto) blaze::rows ( const Matrix< MT, SO > &  matrix,
RRAs...  args 
)
inline

Creating a view on a selection of rows of the given constant matrix.

Parameters
matrixThe constant matrix containing the rows.
argsOptional arguments.
Returns
View on the specified rows of the matrix.
Exceptions
std::invalid_argumentInvalid row access index.

This function returns an expression representing a selection of rows of the given constant matrix.

// Creating a view on the 1st and 3rd row of the dense matrix D
auto rows1 = rows<1UL,3UL>( D );
// Creating a view on the 4th and 2nd row of the sparse matrix S
auto rows2 = rows<4UL,2UL>( S );

By default, the provided row indices are checked at runtime. In case any row is not properly specified (i.e. if any specified index is greater than or equal to the total number of rows in the given matrix) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.

auto rows1 = rows<1UL,3UL>( D, unchecked );
auto rows2 = rows<4UL,2UL>( S, unchecked );

◆ rows() [3/14]

template<typename MT , bool SO, typename T , typename... RRAs>
decltype(auto) blaze::rows ( const Matrix< MT, SO > &  matrix,
T *  indices,
size_t  n,
RRAs...  args 
)
inline

Creating a view on a selection of rows of the given constant matrix.

Parameters
matrixThe constant matrix containing the rows.
indicesPointer to the first index of the selected rows.
nThe total number of indices.
argsOptional arguments.
Returns
View on the specified rows of the matrix.
Exceptions
std::invalid_argumentInvalid row access index.

This function returns an expression representing a selection of rows of the given constant matrix.

// ... Resizing and initialization
// Creating a view on the 1st and 3rd row of the dense matrix D
const std::vector<size_t> indices1{ 1UL, 3UL };
auto rows1 = rows( D, indices1.data(), indices1.size() );
// Creating a view on the 4th and 2nd row of the sparse matrix S
const std::array<size_t,2UL> indices2{ 4UL, 2UL };
auto rows2 = rows( S, indices2.data(), indices2.size() );

By default, the provided row indices are checked at runtime. In case any row is not properly specified (i.e. if any specified index is greater than or equal to the total number of rows in the given matrix) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.

auto rows1 = rows( D, indices1.data(), indices1.size(), unchecked );
auto rows2 = rows( S, indices2.data(), indices2.size(), unchecked );

◆ rows() [4/14]

template<typename MT , bool SO, typename P , typename... RRAs>
decltype(auto) blaze::rows ( Matrix< MT, SO > &&  matrix,
p,
size_t  n,
RRAs...  args 
)
inline

Creating a view on a selection of rows of the given temporary matrix.

Parameters
matrixThe temporary matrix containing the rows.
pCallable producing the indices.
nThe total number of indices.
argsOptional arguments.
Exceptions
std::invalid_argumentInvalid row access index.

This function returns an expression representing a selection of rows of the given temporary matrix. In case any row is not properly specified (i.e. if any specified index is greater than or equal to the total number of rows in the given matrix) a std::invalid_argument exception is thrown.

◆ rows() [5/14]

template<size_t I, size_t... Is, typename MT , bool SO, typename... RRAs>
decltype(auto) blaze::rows ( Matrix< MT, SO > &&  matrix,
RRAs...  args 
)
inline

Creating a view on a selection of rows of the given temporary matrix.

Parameters
matrixThe temporary matrix containing the rows.
argsOptional arguments.
Returns
View on the specified rows of the matrix.
Exceptions
std::invalid_argumentInvalid row access index.

This function returns an expression representing a selection of rows of the given temporary matrix. In case any row is not properly specified (i.e. if any specified index is greater than or equal to the total number of rows in the given matrix) a std::invalid_argument exception is thrown.

◆ rows() [6/14]

template<typename MT , bool SO, typename T , typename... RRAs>
decltype(auto) blaze::rows ( Matrix< MT, SO > &&  matrix,
T *  indices,
size_t  n,
RRAs...  args 
)
inline

Creating a view on a selection of rows of the given temporary matrix.

Parameters
matrixThe temporary matrix containing the rows.
indicesPointer to the first index of the selected rows.
nThe total number of indices.
argsOptional arguments.
Exceptions
std::invalid_argumentInvalid row access index.

This function returns an expression representing a selection of rows of the given temporary matrix. In case any row is not properly specified (i.e. if any specified index is greater than or equal to the total number of rows in the given matrix) a std::invalid_argument exception is thrown.

◆ rows() [7/14]

template<typename MT , bool SO, typename P , typename... RRAs>
decltype(auto) blaze::rows ( Matrix< MT, SO > &  matrix,
p,
size_t  n,
RRAs...  args 
)
inline

Creating a view on a selection of rows of the given matrix.

Parameters
matrixThe matrix containing the rows.
pCallable producing the indices.
nThe total number of indices.
argsOptional arguments.
Returns
View on the specified rows of the matrix.
Exceptions
std::invalid_argumentInvalid row access index.

This function returns an expression representing a selection of rows of the given matrix.

// ... Resizing and initialization
// Creating a view on the 1st and 3rd row of the dense matrix D
auto rows1 = rows( D, []( size_t i ){ return 2UL*i + 1UL; }, 2UL );
// Creating a view on the 4th and 2nd row of the sparse matrix S
auto rows2 = rows( S, []( size_t i ){ return 4UL - 2UL*i; }, 2UL );

By default, the provided row indices are checked at runtime. In case any row is not properly specified (i.e. if any specified index is greater than or equal to the total number of rows in the given matrix) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.

auto rows1 = rows( D, []( size_t i ){ return 2UL*i + 1UL; }, 2UL, unchecked );
auto rows2 = rows( S, []( size_t i ){ return 4UL - 2UL*i; }, 2UL, unchecked );

◆ rows() [8/14]

template<size_t I, size_t... Is, typename MT , bool SO, typename... RRAs>
decltype(auto) blaze::rows ( Matrix< MT, SO > &  matrix,
RRAs...  args 
)
inline

Creating a view on a selection of rows of the given matrix.

Parameters
matrixThe matrix containing the rows.
argsOptional arguments.
Returns
View on the specified rows of the matrix.
Exceptions
std::invalid_argumentInvalid row access index.

This function returns an expression representing a selection of rows of the given matrix.

// ... Resizing and initialization
// Creating a view on the 1st and 3rd row of the dense matrix D
auto rows1 = rows<1UL,3UL>( D );
// Creating a view on the 4th and 2nd row of the sparse matrix S
auto rows2 = rows<4UL,2UL>( S );

By default, the provided row indices are checked at runtime. In case any row is not properly specified (i.e. if any specified index is greater than or equal to the total number of rows in the given matrix) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.

auto rows1 = rows<1UL,3UL>( D, unchecked );
auto rows2 = rows<4UL,2UL>( S, unchecked );

◆ rows() [9/14]

template<typename MT , bool SO, typename T , typename... RRAs>
decltype(auto) blaze::rows ( Matrix< MT, SO > &  matrix,
T *  indices,
size_t  n,
RRAs...  args 
)
inline

Creating a view on a selection of rows of the given matrix.

Parameters
matrixThe matrix containing the rows.
indicesPointer to the first index of the selected rows.
nThe total number of indices.
argsOptional arguments.
Returns
View on the specified rows of the matrix.
Exceptions
std::invalid_argumentInvalid row access index.

This function returns an expression representing a selection of rows of the given matrix.

// ... Resizing and initialization
// Creating a view on the 1st and 3rd row of the dense matrix D
const std::vector<size_t> indices1{ 1UL, 3UL };
auto rows1 = rows( D, indices1.data(), indices1.size() );
// Creating a view on the 4th and 2nd row of the sparse matrix S
const std::array<size_t,2UL> indices2{ 4UL, 2UL };
auto rows2 = rows( S, indices2.data(), indices2.size() );

By default, the provided row indices are checked at runtime. In case any row is not properly specified (i.e. if any specified index is greater than or equal to the total number of rows in the given matrix) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.

auto rows1 = rows( D, indices1.data(), indices1.size(), unchecked );
auto rows2 = rows( S, indices2.data(), indices2.size(), unchecked );

◆ rows() [10/14]

template<typename MT , typename T , size_t N, typename... RRAs>
decltype(auto) blaze::rows ( MT &&  matrix,
const SmallArray< T, N > &  indices,
RRAs...  args 
)
inline

Creating a view on a selection of rows of the given matrix.

Parameters
matrixThe matrix containing the rows.
indicesThe vector of row indices.
argsOptional arguments.
Returns
View on the specified rows of the matrix.
Exceptions
std::invalid_argumentInvalid row access index.

This function returns an expression representing a selection of rows of the given matrix.

// ... Resizing and initialization
// Creating a view on the 1st and 3rd row of the dense matrix D
blaze::SmallArray<size_t,2UL> indices1{ 1UL, 3UL };
auto rows1 = rows( D, indices1 );
// Creating a view on the 4th and 2nd row of the sparse matrix S
blaze::SmallArray<size_t,2UL> indices2{ 4UL, 2UL };
auto rows2 = rows( S, indices2 );
Implementation of a dynamic array with small array optimization.
Definition: SmallArray.h:84

By default, the provided row indices are checked at runtime. In case any row is not properly specified (i.e. if any specified index is greater than or equal to the total number of rows in the given matrix) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.

auto rows1 = rows( D, indices1, unchecked );
auto rows2 = rows( S, indices2, unchecked );

◆ rows() [11/14]

template<typename MT , typename T , size_t N, typename... RRAs>
decltype(auto) blaze::rows ( MT &&  matrix,
const std::array< T, N > &  indices,
RRAs...  args 
)
inline

Creating a view on a selection of rows of the given matrix.

Parameters
matrixThe matrix containing the rows.
indicesThe array of row indices.
argsOptional arguments.
Returns
View on the specified rows of the matrix.
Exceptions
std::invalid_argumentInvalid row access index.

This function returns an expression representing a selection of rows of the given matrix.

// ... Resizing and initialization
// Creating a view on the 1st and 3rd row of the dense matrix D
const std::array<size_t,2UL> indices1{ 1UL, 3UL };
auto rows1 = rows( D, indices1 );
// Creating a view on the 4th and 2nd row of the sparse matrix S
const std::array<size_t,2UL> indices2{ 4UL, 2UL };
auto rows2 = rows( S, indices2 );

By default, the provided row indices are checked at runtime. In case any row is not properly specified (i.e. if any specified index is greater than or equal to the total number of rows in the given matrix) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.

auto rows1 = rows( D, indices1, unchecked );
auto rows2 = rows( S, indices2, unchecked );

◆ rows() [12/14]

template<typename MT , typename T , typename... RRAs>
decltype(auto) blaze::rows ( MT &&  matrix,
const std::vector< T > &  indices,
RRAs...  args 
)
inline

Creating a view on a selection of rows of the given matrix.

Parameters
matrixThe matrix containing the rows.
indicesThe vector of row indices.
argsOptional arguments.
Returns
View on the specified rows of the matrix.
Exceptions
std::invalid_argumentInvalid row access index.

This function returns an expression representing a selection of rows of the given matrix.

// ... Resizing and initialization
// Creating a view on the 1st and 3rd row of the dense matrix D
const std::vector<size_t,2UL> indices1{ 1UL, 3UL };
auto rows1 = rows( D, indices1 );
// Creating a view on the 4th and 2nd row of the sparse matrix S
const std::vector<size_t,2UL> indices2{ 4UL, 2UL };
auto rows2 = rows( S, indices2 );

By default, the provided row indices are checked at runtime. In case any row is not properly specified (i.e. if any specified index is greater than or equal to the total number of rows in the given matrix) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.

auto rows1 = rows( D, indices1, unchecked );
auto rows2 = rows( S, indices2, unchecked );

◆ rows() [13/14]

template<typename MT , size_t... Is, typename... RRAs>
decltype(auto) blaze::rows ( MT &&  matrix,
index_sequence< Is... >  indices,
RRAs...  args 
)
inline

Creating a view on a selection of rows of the given matrix.

Parameters
matrixThe matrix containing the rows.
indicesThe sequence of row indices.
argsOptional arguments.
Returns
View on the specified rows of the matrix.
Exceptions
std::invalid_argumentInvalid row access index.

This function returns an expression representing a selection of rows of the given matrix.

using blaze::index_sequence;
// ... Resizing and initialization
// Creating a view on the 1st and 3rd row of the dense matrix D
auto rows1 = rows( D, index_sequence<1UL,3UL>() );
// Creating a view on the 4th and 2nd row of the sparse matrix S
auto rows2 = rows( S, index_sequence<4UL,2UL>() );

By default, the provided row indices are checked at runtime. In case any row is not properly specified (i.e. if any specified index is greater than or equal to the total number of rows in the given matrix) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.

auto rows1 = rows( D, index_sequence<1UL,3UL>(), unchecked );
auto rows2 = rows( S, index_sequence<4UL,2UL>(), unchecked );

◆ rows() [14/14]

template<typename MT , typename T , typename... RRAs>
decltype(auto) blaze::rows ( MT &&  matrix,
initializer_list< T >  indices,
RRAs...  args 
)
inline

Creating a view on a selection of rows of the given matrix.

Parameters
matrixThe matrix containing the rows.
indicesThe list of row indices.
argsOptional arguments.
Returns
View on the specified rows of the matrix.
Exceptions
std::invalid_argumentInvalid row access index.

This function returns an expression representing a selection of rows of the given matrix.

// ... Resizing and initialization
// Creating a view on the 1st and 3rd row of the dense matrix D
auto rows1 = rows( D, { 1UL, 3UL } );
// Creating a view on the 4th and 2nd row of the sparse matrix S
auto rows2 = rows( S, { 4UL, 2UL } );

By default, the provided row indices are checked at runtime. In case any row is not properly specified (i.e. if any specified index is greater than or equal to the total number of rows in the given matrix) a std::invalid_argument exception is thrown. The checks can be skipped by providing the optional blaze::unchecked argument.

auto rows1 = rows( D, { 1UL, 3UL }, unchecked );
auto rows2 = rows( S, { 4UL, 2UL }, unchecked );