Blaze 3.9
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Types | List of all members
blaze::CompressedMatrix< Type, SO, Tag > Class Template Reference

Efficient implementation of a $ M \times N $ compressed matrix. More...

#include <CompressedMatrix.h>

Inherits blaze::SparseMatrix< CompressedMatrix< Type, SO, Tag >, SO >.

Classes

struct  Rebind
 Rebind mechanism to obtain a CompressedMatrix with different data/element type. More...
 
struct  Resize
 Resize mechanism to obtain a CompressedMatrix with different fixed dimensions. More...
 

Public Types

using This = CompressedMatrix< Type, SO, Tag >
 Type of this CompressedMatrix instance.
 
using BaseType = SparseMatrix< This, SO >
 Base type of this CompressedMatrix instance.
 
using ResultType = This
 Result type for expression template evaluations.
 
using OppositeType = CompressedMatrix< Type,!SO, Tag >
 Result type with opposite storage order for expression template evaluations.
 
using TransposeType = CompressedMatrix< Type,!SO, Tag >
 Transpose type for expression template evaluations.
 
using ElementType = Type
 Type of the compressed matrix elements.
 
using TagType = Tag
 Tag type of this CompressedMatrix instance.
 
using ReturnType = const Type &
 Return type for expression template evaluations.
 
using CompositeType = const This &
 Data type for composite expression templates.
 
using Reference = MatrixAccessProxy< This >
 Reference to a compressed matrix value.
 
using ConstReference = const Type &
 Reference to a constant compressed matrix value.
 
using Iterator = Element *
 Iterator over non-constant elements.
 
using ConstIterator = const Element *
 Iterator over constant elements.
 
using MatrixType = CompressedMatrix< Type, SO, Tag >
 Type of the matrix.
 

Public Member Functions

template<typename MT , bool SO2>
CompressedMatrix< Type, SO, Tag > & operator= (const DenseMatrix< MT, SO2 > &rhs) &
 Assignment operator for dense matrices. More...
 
template<typename MT , bool SO2>
CompressedMatrix< Type, SO, Tag > & operator= (const SparseMatrix< MT, SO2 > &rhs) &
 Assignment operator for different sparse matrices. More...
 
template<typename MT , bool SO2>
CompressedMatrix< Type, SO, Tag > & operator+= (const Matrix< MT, SO2 > &rhs) &
 Addition assignment operator for the addition of a matrix ( $ A+=B $). More...
 
template<typename MT , bool SO2>
CompressedMatrix< Type, SO, Tag > & operator-= (const Matrix< MT, SO2 > &rhs) &
 Subtraction assignment operator for the subtraction of a matrix ( $ A-=B $). More...
 
template<typename MT , bool SO2>
CompressedMatrix< Type, SO, Tag > & operator%= (const DenseMatrix< MT, SO2 > &rhs) &
 Schur product assignment operator for the multiplication of a dense matrix ( $ A\circ=B $). More...
 
template<typename MT , bool SO2>
CompressedMatrix< Type, SO, Tag > & operator%= (const SparseMatrix< MT, SO2 > &rhs) &
 Schur product assignment operator for the multiplication of a sparse matrix ( $ A\circ=B $). More...
 
template<typename Other >
CompressedMatrix< Type, SO, Tag > & scale (const Other &scalar)
 Scaling of the compressed matrix by the scalar value scalar ( $ A=B*s $). More...
 
Destructor
 ~CompressedMatrix ()
 The destructor for CompressedMatrix.
 
Data access functions
Reference operator() (size_t i, size_t j) noexcept
 2D-access to the compressed matrix elements. More...
 
ConstReference operator() (size_t i, size_t j) const noexcept
 2D-access to the compressed matrix elements. More...
 
Reference at (size_t i, size_t j)
 Checked access to the matrix elements. More...
 
ConstReference at (size_t i, size_t j) const
 Checked access to the matrix elements. More...
 
Iterator begin (size_t i) noexcept
 Returns an iterator to the first non-zero element of row/column i. More...
 
ConstIterator begin (size_t i) const noexcept
 Returns an iterator to the first non-zero element of row/column i. More...
 
ConstIterator cbegin (size_t i) const noexcept
 Returns an iterator to the first non-zero element of row/column i. More...
 
Iterator end (size_t i) noexcept
 Returns an iterator just past the last non-zero element of row/column i. More...
 
ConstIterator end (size_t i) const noexcept
 Returns an iterator just past the last non-zero element of row/column i. More...
 
ConstIterator cend (size_t i) const noexcept
 Returns an iterator just past the last non-zero element of row/column i. More...
 
Assignment operators
CompressedMatrixoperator= (initializer_list< initializer_list< Type > > list) &
 List assignment to all matrix elements. More...
 
CompressedMatrixoperator= (const CompressedMatrix &rhs) &
 Copy assignment operator for CompressedMatrix. More...
 
CompressedMatrixoperator= (CompressedMatrix &&rhs) &noexcept
 
template<typename MT , bool SO2>
CompressedMatrixoperator= (const DenseMatrix< MT, SO2 > &rhs) &
 
template<typename MT , bool SO2>
CompressedMatrixoperator= (const SparseMatrix< MT, SO2 > &rhs) &
 
template<typename MT , bool SO2>
CompressedMatrixoperator+= (const Matrix< MT, SO2 > &rhs) &
 
template<typename MT , bool SO2>
CompressedMatrixoperator-= (const Matrix< MT, SO2 > &rhs) &
 
template<typename MT , bool SO2>
CompressedMatrixoperator%= (const DenseMatrix< MT, SO2 > &rhs) &
 
template<typename MT , bool SO2>
CompressedMatrixoperator%= (const SparseMatrix< MT, SO2 > &rhs) &
 
Erase functions
void erase (size_t i, size_t j)
 Erasing an element from the compressed matrix. More...
 
Iterator erase (size_t i, Iterator pos)
 Erasing an element from the compressed matrix. More...
 
Iterator erase (size_t i, Iterator first, Iterator last)
 Erasing a range of elements from the compressed matrix. More...
 
template<typename Pred >
void erase (Pred predicate)
 Erasing specific elements from the compressed matrix. More...
 
template<typename Pred >
void erase (size_t i, Iterator first, Iterator last, Pred predicate)
 Erasing specific elements from a range of the compressed matrix. More...
 
Lookup functions
Iterator find (size_t i, size_t j)
 Searches for a specific matrix element. More...
 
ConstIterator find (size_t i, size_t j) const
 Searches for a specific matrix element. More...
 
Iterator lowerBound (size_t i, size_t j)
 Returns an iterator to the first index not less than the given index. More...
 
ConstIterator lowerBound (size_t i, size_t j) const
 Returns an iterator to the first index not less than the given index. More...
 
Iterator upperBound (size_t i, size_t j)
 Returns an iterator to the first index greater than the given index. More...
 
ConstIterator upperBound (size_t i, size_t j) const
 Returns an iterator to the first index greater than the given index. More...
 
Numeric functions
CompressedMatrixtranspose ()
 In-place transpose of the matrix. More...
 
CompressedMatrixctranspose ()
 In-place conjugate transpose of the matrix. More...
 
template<typename Other >
CompressedMatrixscale (const Other &scalar)
 
Expression template evaluation functions
template<typename Other >
bool canAlias (const Other *alias) const noexcept
 Returns whether the matrix can alias with the given address alias. More...
 
template<typename Other >
bool isAliased (const Other *alias) const noexcept
 Returns whether the matrix is aliased with the given address alias. More...
 
bool canSMPAssign () const noexcept
 Returns whether the matrix can be used in SMP assignments. More...
 
template<typename MT , bool SO2>
void assign (const DenseMatrix< MT, SO2 > &rhs)
 Default implementation of the assignment of a row-major dense matrix. More...
 
template<typename MT >
void assign (const SparseMatrix< MT, SO > &rhs)
 Default implementation of the assignment of a row-major compressed matrix. More...
 
template<typename MT >
void assign (const SparseMatrix< MT,!SO > &rhs)
 Default implementation of the assignment of a column-major compressed matrix. More...
 
template<typename MT , bool SO2>
void addAssign (const DenseMatrix< MT, SO2 > &rhs)
 Default implementation of the addition assignment of a dense matrix. More...
 
template<typename MT , bool SO2>
void addAssign (const SparseMatrix< MT, SO2 > &rhs)
 Default implementation of the addition assignment of a compressed matrix. More...
 
template<typename MT , bool SO2>
void subAssign (const DenseMatrix< MT, SO2 > &rhs)
 Default implementation of the subtraction assignment of a dense matrix. More...
 
template<typename MT , bool SO2>
void subAssign (const SparseMatrix< MT, SO2 > &rhs)
 Default implementation of the subtraction assignment of a compressed matrix. More...
 
template<typename MT , bool SO2>
void schurAssign (const DenseMatrix< MT, SO2 > &rhs)
 Default implementation of the Schur product assignment of a dense matrix. More...
 
Conversion operators
BLAZE_ALWAYS_INLINE constexpr CompressedMatrix< Type, SO, Tag > & operator~ () noexcept
 CRTP-based conversion operation for non-constant matrices. More...
 
BLAZE_ALWAYS_INLINE constexpr const CompressedMatrix< Type, SO, Tag > & operator~ () const noexcept
 CRTP-based conversion operation for constant matrices. More...
 
constexpr CompressedMatrix< Type, SO, Tag > & operator* () noexcept
 CRTP-based conversion operation for non-constant matrices. More...
 
constexpr const CompressedMatrix< Type, SO, Tag > & operator* () const noexcept
 CRTP-based conversion operation for constant matrices. More...
 

Static Public Attributes

static constexpr bool smpAssignable = !IsSMPAssignable_v<Type>
 Compilation flag for SMP assignments. More...
 
static constexpr bool storageOrder
 Storage order of the matrix.
 

Private Types

using ElementBase = ValueIndexPair< Type >
 Base class for the compressed matrix element.
 
using IteratorBase = ElementBase *
 Iterator over non-constant base elements.
 

Member variables

size_t m_
 The current number of rows of the compressed matrix.
 
size_t n_
 The current number of columns of the compressed matrix.
 
size_t capacity_
 The current capacity of the pointer array.
 
Iteratorbegin_
 Pointers to the first non-zero element of each row.
 
Iteratorend_
 Pointers one past the last non-zero element of each row.
 
static const Type zero_ {}
 Neutral element for accesses to zero elements.
 

Constructors

 CompressedMatrix ()
 The default constructor for CompressedMatrix.
 
 CompressedMatrix (size_t m, size_t n)
 Constructor for a matrix of size $ M \times N $. More...
 
 CompressedMatrix (size_t m, size_t n, size_t nonzeros)
 Constructor for a matrix of size $ M \times N $. More...
 
 CompressedMatrix (size_t m, size_t n, const std::vector< size_t > &nonzeros)
 Constructor for a matrix of size $ M \times N $. More...
 
 CompressedMatrix (initializer_list< initializer_list< Type > > list)
 List initialization of all matrix elements. More...
 
 CompressedMatrix (const CompressedMatrix &sm)
 The copy constructor for CompressedMatrix. More...
 
 CompressedMatrix (CompressedMatrix &&sm) noexcept
 The move constructor for CompressedMatrix. More...
 
template<typename MT , bool SO2>
 CompressedMatrix (const DenseMatrix< MT, SO2 > &dm)
 Conversion constructor from dense matrices. More...
 
template<typename MT , bool SO2>
 CompressedMatrix (const SparseMatrix< MT, SO2 > &sm)
 Conversion constructor from different sparse matrices. More...
 
 CompressedMatrix (size_t m, size_t n, Uninitialized)
 Constructor for an uninitialized matrix of size $ M \times N $. More...
 

Utility functions

size_t rows () const noexcept
 Returns the current number of rows of the compressed matrix. More...
 
size_t columns () const noexcept
 Returns the current number of columns of the compressed matrix. More...
 
size_t capacity () const noexcept
 Returns the maximum capacity of the compressed matrix. More...
 
size_t capacity (size_t i) const noexcept
 Returns the current capacity of the specified row/column. More...
 
size_t nonZeros () const
 Returns the number of non-zero elements in the compressed matrix. More...
 
size_t nonZeros (size_t i) const
 Returns the number of non-zero elements in the specified row/column. More...
 
void reset ()
 Reset to the default initial values. More...
 
void reset (size_t i)
 Reset the specified row/column to the default initial values. More...
 
void clear ()
 Clearing the compressed matrix. More...
 
void resize (size_t m, size_t n, bool preserve=true)
 Changing the size of the compressed matrix. More...
 
void reserve (size_t nonzeros)
 Setting the minimum capacity of the compressed matrix. More...
 
void reserve (size_t i, size_t nonzeros)
 Setting the minimum capacity of a specific row/column of the compressed matrix. More...
 
void trim ()
 Removing all excessive capacity from all rows/columns. More...
 
void trim (size_t i)
 Removing all excessive capacity of a specific row/column of the compressed matrix. More...
 
void shrinkToFit ()
 Requesting the removal of unused capacity. More...
 
void swap (CompressedMatrix &sm) noexcept
 Swapping the contents of two sparse matrices. More...
 
size_t extendCapacity () const noexcept
 Calculating a new matrix capacity. More...
 
void reserveElements (size_t nonzeros)
 Reserving the specified number of compressed matrix elements. More...
 
Iterator castDown (IteratorBase it) const noexcept
 Performs a down-cast of the given iterator. More...
 
IteratorBase castUp (Iterator it) const noexcept
 Performs an up-cast of the given iterator. More...
 

Insertion functions

Iterator set (size_t i, size_t j, const Type &value)
 Setting an element of the compressed matrix. More...
 
Iterator insert (size_t i, size_t j, const Type &value)
 Inserting an element into the compressed matrix. More...
 
void append (size_t i, size_t j, const Type &value, bool check=false)
 Appending an element to the specified row/column of the compressed matrix. More...
 
void finalize (size_t i)
 Finalizing the element insertion of a row/column. More...
 
Iterator insert (Iterator pos, size_t i, size_t j, const Type &value)
 Inserting an element into the compressed matrix. More...
 

Detailed Description

template<typename Type, bool SO, typename Tag>
class blaze::CompressedMatrix< Type, SO, Tag >

Efficient implementation of a $ M \times N $ compressed matrix.

The CompressedMatrix class template is the representation of an arbitrary sized sparse matrix with $ M \cdot N $ dynamically allocated elements of arbitrary type. The type of the elements, the storage order, and the group tag of the matrix can be specified via the three template parameters:

namespace blaze {
template< typename Type, bool SO, typename Tag >
} // namespace blaze
CompressedMatrix()
The default constructor for CompressedMatrix.
Definition: CompressedMatrix.h:598

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

// Creating a row-major 4x3 compressed matrix with 4 rows and 3 columns
CompressedMatrix<double,rowMajor> A( 4, 3 );
// The function call operator provides access to all possible elements of the compressed matrix,
// including the zero elements. In case the function call operator is used to access an element
// that is currently not stored in the sparse matrix, the element is inserted into the matrix.
A(1,2) = 2.0;
// The second operation for inserting elements is the set() function. In case the element
// is not contained in the matrix it is inserted into the matrix, if it is already contained
// in the matrix its value is modified.
A.set( 2, 0, -1.2 );
// An alternative for inserting elements into the matrix is the insert() function. However,
// it inserts the element only in case the element is not already contained in the matrix.
A.insert( 2, 1, 3.7 );
// A very efficient way to add new elements to a sparse matrix is the append() function.
// Note that append() requires that the appended element's index is strictly larger than
// the currently largest non-zero index of the specified row and that the matrix's capacity
// is large enough to hold the new element.
A.reserve( 3, 2 ); // Reserving space for 2 non-zero elements in row 3
A.append( 3, 1, -2.1 ); // Appending the value -2.1 at column index 1 in row 3
A.append( 3, 2, 1.4 ); // Appending the value 1.4 at column index 2 in row 3
// The most efficient way to fill a (newly created) sparse matrix with elements, however, is
// a combination of reserve(), append(), and the finalize() function.
CompressedMatrix<double,rowMajor> B( 4, 3 );
B.reserve( 3 ); // Reserving enough space for 3 non-zero elements
B.append( 0, 1, 1 ); // Appending the value 1 in row 0 with column index 1
B.finalize( 0 ); // Finalizing row 0
B.append( 1, 1, 2 ); // Appending the value 2 in row 1 with column index 1
B.finalize( 1 ); // Finalizing row 1
B.append( 2, 0, 3 ); // Appending the value 3 in row 2 with column index 0
B.finalize( 2 ); // Finalizing row 2
// In order to traverse all non-zero elements currently stored in the matrix, the begin()
// and end() functions can be used. In the example, all non-zero elements of the 2nd row
// of A are traversed.
for( CompressedMatrix<double,rowMajor>::Iterator i=A.begin(1); i!=A.end(1); ++i ) {
... = i->value(); // Access to the value of the non-zero element
... = i->index(); // Access to the index of the non-zero element
}
Element * Iterator
Iterator over non-constant elements.
Definition: CompressedMatrix.h:343
constexpr bool rowMajor
Storage order flag for row-major matrices.
Definition: StorageOrder.h:71
constexpr bool columnMajor
Storage order flag for column-major matrices.
Definition: StorageOrder.h:99

The use of CompressedMatrix is very natural and intuitive. All operations (addition, subtraction, multiplication, scaling, ...) can be performed on all possible combinations of row-major and column-major dense and sparse matrices with fitting element types. The following example gives an impression of the use of CompressedMatrix:

CompressedMatrix<double,rowMajor> A( 2, 3 ); // Empty row-major compressed double precision 2x3 matrix
A(0,0) = 1.0; A(0,2) = 3.0; A(1,1) = 5.0; // Element initialization
CompressedMatrix<float,columnMajor> B( 2, 3 ); // Empty column-major compressed single precision 2x3 matrix
B(0,1) = 3.0F; B(1,0) = 2.0F; B(1,2) = 6.0F; // Element initialization
DynamicMatrixMatrix<float> C( 2, 3, 4.0F ); // Directly, homogeneously initialized single precision dense 2x3 matrix
CompressedMatrix<float> D( 3, 2 ); // Empty row-major compressed single precision 3x2 matrix
CompressedMatrix<double,rowMajor> E( A ); // Creation of a new row-major matrix as a copy of A
CompressedMatrix<double,columnMajor> F; // Creation of a default column-major matrix
E = A + B; // Matrix addition and assignment to a row-major matrix
E = A - C; // Matrix subtraction and assignment to a column-major matrix
F = A * D; // Matrix multiplication between two matrices of different element types
A *= 2.0; // In-place scaling of matrix A
E = 2.0 * B; // Scaling of matrix B
F = D * 2.0; // Scaling of matrix D
E += A - B; // Addition assignment
E -= A + C; // Subtraction assignment
F *= A * D; // Multiplication assignment
Efficient implementation of a compressed matrix.
Definition: CompressedMatrix.h:239
Efficient implementation of a dynamic matrix.
Definition: DynamicMatrix.h:242

Constructor & Destructor Documentation

◆ CompressedMatrix() [1/9]

template<typename Type , bool SO, typename Tag >
blaze::CompressedMatrix< Type, SO, Tag >::CompressedMatrix ( size_t  m,
size_t  n 
)
inline

Constructor for a matrix of size $ M \times N $.

Parameters
mThe number of rows of the matrix.
nThe number of columns of the matrix.

The matrix is initialized to the zero matrix and has no free capacity.

◆ CompressedMatrix() [2/9]

template<typename Type , bool SO, typename Tag >
blaze::CompressedMatrix< Type, SO, Tag >::CompressedMatrix ( size_t  m,
size_t  n,
size_t  nonzeros 
)
inline

Constructor for a matrix of size $ M \times N $.

Parameters
mThe number of rows of the matrix.
nThe number of columns of the matrix.
nonzerosThe number of expected non-zero elements.

The matrix is initialized to the zero matrix.

◆ CompressedMatrix() [3/9]

template<typename Type , bool SO, typename Tag >
blaze::CompressedMatrix< Type, SO, Tag >::CompressedMatrix ( size_t  m,
size_t  n,
const std::vector< size_t > &  nonzeros 
)

Constructor for a matrix of size $ M \times N $.

Parameters
mThe number of rows of the matrix.
nThe number of columns of the matrix.
nonzerosThe expected number of non-zero elements in each row/column.

The matrix is initialized to the zero matrix and will have the specified capacity in each row/column. Note that in case of a row-major matrix the given vector must have at least m elements, in case of a column-major matrix at least n elements.

◆ CompressedMatrix() [4/9]

template<typename Type , bool SO, typename Tag >
blaze::CompressedMatrix< Type, SO, Tag >::CompressedMatrix ( initializer_list< initializer_list< Type > >  list)
inline

List initialization of all matrix elements.

Parameters
listThe initializer list.

This constructor provides the option to explicitly initialize the elements of the matrix by means of an initializer list:

{ 4, 5 },
{ 7, 8, 9 } };

The matrix is sized according to the size of the initializer list and all its elements are initialized by the values of the given initializer list. Missing values are considered to be default values.

◆ CompressedMatrix() [5/9]

template<typename Type , bool SO, typename Tag >
blaze::CompressedMatrix< Type, SO, Tag >::CompressedMatrix ( const CompressedMatrix< Type, SO, Tag > &  sm)
inline

The copy constructor for CompressedMatrix.

Parameters
smSparse matrix to be copied.

◆ CompressedMatrix() [6/9]

template<typename Type , bool SO, typename Tag >
blaze::CompressedMatrix< Type, SO, Tag >::CompressedMatrix ( CompressedMatrix< Type, SO, Tag > &&  sm)
inlinenoexcept

The move constructor for CompressedMatrix.

Parameters
smThe compressed matrix to be moved into this instance.

◆ CompressedMatrix() [7/9]

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
blaze::CompressedMatrix< Type, SO, Tag >::CompressedMatrix ( const DenseMatrix< MT, SO2 > &  dm)
inline

Conversion constructor from dense matrices.

Parameters
dmDense matrix to be copied.

◆ CompressedMatrix() [8/9]

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
blaze::CompressedMatrix< Type, SO, Tag >::CompressedMatrix ( const SparseMatrix< MT, SO2 > &  sm)
inline

Conversion constructor from different sparse matrices.

Parameters
smSparse matrix to be copied.

◆ CompressedMatrix() [9/9]

template<typename Type , bool SO, typename Tag >
blaze::CompressedMatrix< Type, SO, Tag >::CompressedMatrix ( size_t  m,
size_t  n,
Uninitialized   
)
inlineprivate

Constructor for an uninitialized matrix of size $ M \times N $.

Parameters
mThe number of rows of the matrix.
nThe number of columns of the matrix.

Member Function Documentation

◆ addAssign() [1/2]

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
void blaze::CompressedMatrix< Type, SO, Tag >::addAssign ( const DenseMatrix< MT, SO2 > &  rhs)
inline

Default implementation of the addition assignment of a dense matrix.

Parameters
rhsThe right-hand side dense matrix to be added.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

◆ addAssign() [2/2]

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
void blaze::CompressedMatrix< Type, SO, Tag >::addAssign ( const SparseMatrix< MT, SO2 > &  rhs)
inline

Default implementation of the addition assignment of a compressed matrix.

Parameters
rhsThe right-hand side compressed matrix to be added.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

◆ append()

template<typename Type , bool SO, typename Tag >
void blaze::CompressedMatrix< Type, SO, Tag >::append ( size_t  i,
size_t  j,
const Type &  value,
bool  check = false 
)
inline

Appending an element to the specified row/column of the compressed matrix.

Parameters
iThe row index of the new element. The index has to be in the range $[0..M-1]$.
jThe column index of the new element. The index has to be in the range $[0..N-1]$.
valueThe value of the element to be appended.
checktrue if the new value should be checked for default values, false if not.
Returns
void

This function provides a very efficient way to fill a compressed matrix with elements. It appends a new element to the end of the specified row/column without any additional memory allocation. Therefore it is strictly necessary to keep the following preconditions in mind:

  • the index of the new element must be strictly larger than the largest index of non-zero elements in the specified row/column of the compressed matrix
  • the current number of non-zero elements in the matrix must be smaller than the capacity of the matrix

Ignoring these preconditions might result in undefined behavior! The optional check parameter specifies whether the new value should be tested for a default value. If the new value is a default value (for instance 0 in case of an integral element type) the value is not appended. Per default the values are not tested.

In combination with the reserve() and the finalize() function, append() provides the most efficient way to add new elements to a (newly created) compressed matrix:

// Setup of the compressed row-major matrix
//
// ( 0 1 0 )
// A = ( 0 2 0 )
// ( 0 0 0 )
// ( 3 0 0 )
//
A.reserve( 3 ); // Reserving enough capacity for 3 non-zero elements
A.append( 0, 1, 1.0 ); // Appending the value 1 in row 0 with column index 1
A.finalize( 0 ); // Finalizing row 0
A.append( 1, 1, 2.0 ); // Appending the value 2 in row 1 with column index 1
A.finalize( 1 ); // Finalizing row 1
A.finalize( 2 ); // Finalizing the empty row 2 to prepare row 3
A.append( 3, 0, 3.0 ); // Appending the value 3 in row 3 with column index 0
A.finalize( 3 ); // Finalizing row 3
Note
The finalize() function has to be explicitly called for each row/column, even for empty ones!
Although append() does not allocate new memory, it still invalidates all iterators returned by the end() functions!

◆ assign() [1/3]

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
void blaze::CompressedMatrix< Type, SO, Tag >::assign ( const DenseMatrix< MT, SO2 > &  rhs)
inline

Default implementation of the assignment of a row-major dense matrix.

Parameters
rhsThe right-hand side dense matrix to be assigned.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

◆ assign() [2/3]

template<typename Type , bool SO, typename Tag >
template<typename MT >
void blaze::CompressedMatrix< Type, SO, Tag >::assign ( const SparseMatrix< MT, SO > &  rhs)
inline

Default implementation of the assignment of a row-major compressed matrix.

Parameters
rhsThe right-hand side compressed matrix to be assigned.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

◆ assign() [3/3]

template<typename Type , bool SO, typename Tag >
template<typename MT >
void blaze::CompressedMatrix< Type, SO, Tag >::assign ( const SparseMatrix< MT,!SO > &  rhs)
inline

Default implementation of the assignment of a column-major compressed matrix.

Parameters
rhsThe right-hand side compressed matrix to be assigned.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

◆ at() [1/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::Reference blaze::CompressedMatrix< Type, SO, Tag >::at ( size_t  i,
size_t  j 
)
inline

Checked access to the matrix elements.

Parameters
iAccess index for the row. The index has to be in the range $[0..M-1]$.
jAccess index for the column. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.
Exceptions
std::out_of_rangeInvalid matrix access index.

This function returns a reference to the accessed value at position (i,j). In case the compressed matrix does not yet store an element at position (i,j) , a new element is inserted into the compressed matrix. In contrast to the function call operator this function always performs a check of the given access indices.

◆ at() [2/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::ConstReference blaze::CompressedMatrix< Type, SO, Tag >::at ( size_t  i,
size_t  j 
) const
inline

Checked access to the matrix elements.

Parameters
iAccess index for the row. The index has to be in the range $[0..M-1]$.
jAccess index for the column. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.
Exceptions
std::out_of_rangeInvalid matrix access index.

In contrast to the function call operator this function always performs a check of the given access indices.

◆ begin() [1/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::ConstIterator blaze::CompressedMatrix< Type, SO, Tag >::begin ( size_t  i) const
inlinenoexcept

Returns an iterator to the first non-zero element of row/column i.

Parameters
iThe row/column index.
Returns
Iterator to the first non-zero element of row/column i.

This function returns a row/column iterator to the first non-zero element of row/column i. In case the storage order is set to rowMajor the function returns an iterator to the first non-zero element of row i, in case the storage flag is set to columnMajor the function returns an iterator to the first non-zero element of column i.

◆ begin() [2/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::Iterator blaze::CompressedMatrix< Type, SO, Tag >::begin ( size_t  i)
inlinenoexcept

Returns an iterator to the first non-zero element of row/column i.

Parameters
iThe row/column index.
Returns
Iterator to the first non-zero element of row/column i.

This function returns a row/column iterator to the first non-zero element of row/column i. In case the storage order is set to rowMajor the function returns an iterator to the first non-zero element of row i, in case the storage flag is set to columnMajor the function returns an iterator to the first non-zero element of column i.

◆ canAlias()

template<typename Type , bool SO, typename Tag >
template<typename Other >
bool blaze::CompressedMatrix< Type, SO, Tag >::canAlias ( const Other *  alias) const
inlinenoexcept

Returns whether the matrix can alias with the given address alias.

Parameters
aliasThe alias to be checked.
Returns
true in case the alias corresponds to this matrix, false if not.

This function returns whether the given address can alias with the matrix. In contrast to the isAliased() function this function is allowed to use compile time expressions to optimize the evaluation.

◆ canSMPAssign()

template<typename Type , bool SO, typename Tag >
bool blaze::CompressedMatrix< Type, SO, Tag >::canSMPAssign
inlinenoexcept

Returns whether the matrix can be used in SMP assignments.

Returns
true in case the matrix can be used in SMP assignments, false if not.

This function returns whether the matrix can be used in SMP assignments. In contrast to the smpAssignable member enumeration, which is based solely on compile time information, this function additionally provides runtime information (as for instance the current number of rows and/or columns of the matrix).

◆ capacity() [1/2]

template<typename Type , bool SO, typename Tag >
size_t blaze::CompressedMatrix< Type, SO, Tag >::capacity
inlinenoexcept

Returns the maximum capacity of the compressed matrix.

Returns
The capacity of the compressed matrix.

◆ capacity() [2/2]

template<typename Type , bool SO, typename Tag >
size_t blaze::CompressedMatrix< Type, SO, Tag >::capacity ( size_t  i) const
inlinenoexcept

Returns the current capacity of the specified row/column.

Parameters
iThe index of the row/column.
Returns
The current capacity of row/column i.

This function returns the current capacity of the specified row/column. In case the storage order is set to rowMajor the function returns the capacity of row i, in case the storage flag is set to columnMajor the function returns the capacity of column i.

◆ castDown()

template<typename Type , typename Tag >
CompressedMatrix< Type, true, Tag >::Iterator blaze::CompressedMatrix< Type, Tag >::castDown ( IteratorBase  it) const
inlineprivatenoexcept

Performs a down-cast of the given iterator.

Returns
The casted iterator.

This function performs a down-cast of the given iterator to base elements to an iterator to derived elements.

◆ castUp()

template<typename Type , typename Tag >
CompressedMatrix< Type, true, Tag >::IteratorBase blaze::CompressedMatrix< Type, Tag >::castUp ( Iterator  it) const
inlineprivatenoexcept

Performs an up-cast of the given iterator.

Returns
The casted iterator.

This function performs an up-cast of the given iterator to derived elements to an iterator to base elements.

◆ cbegin()

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::ConstIterator blaze::CompressedMatrix< Type, SO, Tag >::cbegin ( size_t  i) const
inlinenoexcept

Returns an iterator to the first non-zero element of row/column i.

Parameters
iThe row/column index.
Returns
Iterator to the first non-zero element of row/column i.

This function returns a row/column iterator to the first non-zero element of row/column i. In case the storage order is set to rowMajor the function returns an iterator to the first non-zero element of row i, in case the storage flag is set to columnMajor the function returns an iterator to the first non-zero element of column i.

◆ cend()

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::ConstIterator blaze::CompressedMatrix< Type, SO, Tag >::cend ( size_t  i) const
inlinenoexcept

Returns an iterator just past the last non-zero element of row/column i.

Parameters
iThe row/column index.
Returns
Iterator just past the last non-zero element of row/column i.

This function returns an row/column iterator just past the last non-zero element of row/column i. In case the storage order is set to rowMajor the function returns an iterator just past the last non-zero element of row i, in case the storage flag is set to columnMajor the function returns an iterator just past the last non-zero element of column i.

◆ clear()

template<typename Type , bool SO, typename Tag >
void blaze::CompressedMatrix< Type, SO, Tag >::clear
inline

Clearing the compressed matrix.

Returns
void

After the clear() function, the size of the compressed matrix is 0.

◆ columns()

template<typename Type , bool SO, typename Tag >
size_t blaze::CompressedMatrix< Type, SO, Tag >::columns
inlinenoexcept

Returns the current number of columns of the compressed matrix.

Returns
The number of columns of the compressed matrix.

◆ ctranspose()

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag > & blaze::CompressedMatrix< Type, SO, Tag >::ctranspose
inline

In-place conjugate transpose of the matrix.

Returns
Reference to the transposed matrix.

◆ end() [1/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::ConstIterator blaze::CompressedMatrix< Type, SO, Tag >::end ( size_t  i) const
inlinenoexcept

Returns an iterator just past the last non-zero element of row/column i.

Parameters
iThe row/column index.
Returns
Iterator just past the last non-zero element of row/column i.

This function returns an row/column iterator just past the last non-zero element of row/column i. In case the storage order is set to rowMajor the function returns an iterator just past the last non-zero element of row i, in case the storage flag is set to columnMajor the function returns an iterator just past the last non-zero element of column i.

◆ end() [2/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::Iterator blaze::CompressedMatrix< Type, SO, Tag >::end ( size_t  i)
inlinenoexcept

Returns an iterator just past the last non-zero element of row/column i.

Parameters
iThe row/column index.
Returns
Iterator just past the last non-zero element of row/column i.

This function returns an row/column iterator just past the last non-zero element of row/column i. In case the storage order is set to rowMajor the function returns an iterator just past the last non-zero element of row i, in case the storage flag is set to columnMajor the function returns an iterator just past the last non-zero element of column i.

◆ erase() [1/5]

template<typename Type , bool SO, typename Tag >
template<typename Pred >
void blaze::CompressedMatrix< Type, SO, Tag >::erase ( Pred  predicate)
inline

Erasing specific elements from the compressed matrix.

Parameters
predicateThe unary predicate for the element selection.
Returns
void.

This function erases specific elements from the compressed matrix. The elements are selected by the given unary predicate predicate, which is expected to accept a single argument of the type of the elements and to be pure. The following example demonstrates how to remove all elements that are smaller than a certain threshold value:

// ... Resizing and initialization
A.erase( []( double value ){ return value < 1E-8; } );
void erase(size_t i, size_t j)
Erasing an element from the compressed matrix.
Definition: CompressedMatrix.h:2338
Note
The predicate is required to be pure, i.e. to produce deterministic results for elements with the same value. The attempt to use an impure predicate leads to undefined behavior!

◆ erase() [2/5]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::Iterator blaze::CompressedMatrix< Type, SO, Tag >::erase ( size_t  i,
Iterator  first,
Iterator  last 
)
inline

Erasing a range of elements from the compressed matrix.

Parameters
iThe row/column index of the elements to be erased. The index has to be in the range $[0..M-1]$.
firstIterator to first element to be erased.
lastIterator just past the last element to be erased.
Returns
Iterator to the element after the erased element.

This function erases a range of elements from the compressed matrix. In case the storage order is set to rowMajor the function erases a range of elements from row i, in case the storage flag is set to columnMajor the function erases a range of elements from column i.

◆ erase() [3/5]

template<typename Type , bool SO, typename Tag >
template<typename Pred >
void blaze::CompressedMatrix< Type, SO, Tag >::erase ( size_t  i,
Iterator  first,
Iterator  last,
Pred  predicate 
)
inline

Erasing specific elements from a range of the compressed matrix.

Parameters
iThe row/column index of the elements to be erased. The index has to be in the range $[0..M-1]$.
firstIterator to first element of the range.
lastIterator just past the last element of the range.
predicateThe unary predicate for the element selection.
Returns
void

This function erases specific elements from a range of elements of the compressed matrix. The elements are selected by the given unary predicate predicate, which is expected to accept a single argument of the type of the elements and to be pure. In case the storage order is set to rowMajor the function erases a range of elements from row i, in case the storage flag is set to columnMajor the function erases a range of elements from column i. The following example demonstrates how to remove all elements that are smaller than a certain threshold value:

// ... Resizing and initialization
A.erase( 2UL, A.begin(2UL), A.end(2UL), []( double value ){ return value < 1E-8; } );
Iterator begin(size_t i) noexcept
Returns an iterator to the first non-zero element of row/column i.
Definition: CompressedMatrix.h:1000
Iterator end(size_t i) noexcept
Returns an iterator just past the last non-zero element of row/column i.
Definition: CompressedMatrix.h:1069
Note
The predicate is required to be pure, i.e. to produce deterministic results for elements with the same value. The attempt to use an impure predicate leads to undefined behavior!

◆ erase() [4/5]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::Iterator blaze::CompressedMatrix< Type, SO, Tag >::erase ( size_t  i,
Iterator  pos 
)
inline

Erasing an element from the compressed matrix.

Parameters
iThe row/column index of the element to be erased. The index has to be in the range $[0..M-1]$.
posIterator to the element to be erased.
Returns
Iterator to the element after the erased element.

This function erases an element from the compressed matrix. In case the storage order is set to rowMajor the function erases an element from row i, in case the storage flag is set to columnMajor the function erases an element from column i.

◆ erase() [5/5]

template<typename Type , bool SO, typename Tag >
void blaze::CompressedMatrix< Type, SO, Tag >::erase ( size_t  i,
size_t  j 
)
inline

Erasing an element from the compressed matrix.

Parameters
iThe row index of the element to be erased. The index has to be in the range $[0..M-1]$.
jThe column index of the element to be erased. The index has to be in the range $[0..N-1]$.
Returns
void

This function erases an element from the compressed matrix.

◆ extendCapacity()

template<typename Type , bool SO, typename Tag >
size_t blaze::CompressedMatrix< Type, SO, Tag >::extendCapacity
inlineprivatenoexcept

Calculating a new matrix capacity.

Returns
The new compressed matrix capacity.

This function calculates a new matrix capacity based on the current capacity of the sparse matrix. Note that the new capacity is restricted to the interval $[7..M \cdot N]$.

◆ finalize()

template<typename Type , bool SO, typename Tag >
void blaze::CompressedMatrix< Type, SO, Tag >::finalize ( size_t  i)
inline

Finalizing the element insertion of a row/column.

Parameters
iThe index of the row/column to be finalized $[0..M-1]$.
Returns
void

This function is part of the low-level interface to efficiently fill a matrix with elements. After completion of row/column i via the append() function, this function can be called to finalize row/column i and prepare the next row/column for insertion process via append().

Note
Although finalize() does not allocate new memory, it still invalidates all iterators returned by the end() functions!

◆ find() [1/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::Iterator blaze::CompressedMatrix< Type, SO, Tag >::find ( size_t  i,
size_t  j 
)
inline

Searches for a specific matrix element.

Parameters
iThe row index of the search element. The index has to be in the range $[0..M-1]$.
jThe column index of the search element. The index has to be in the range $[0..N-1]$.
Returns
Iterator to the element in case the index is found, end() iterator otherwise.

This function can be used to check whether a specific element is contained in the sparse matrix. It specifically searches for the element with row index i and column index j. In case the element is found, the function returns an row/column iterator to the element. Otherwise an iterator just past the last non-zero element of row i or column j (the end() iterator) is returned. Note that the returned compressed matrix iterator is subject to invalidation due to inserting operations via the function call operator, the set() function or the insert() function!

◆ find() [2/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::ConstIterator blaze::CompressedMatrix< Type, SO, Tag >::find ( size_t  i,
size_t  j 
) const
inline

Searches for a specific matrix element.

Parameters
iThe row index of the search element. The index has to be in the range $[0..M-1]$.
jThe column index of the search element. The index has to be in the range $[0..N-1]$.
Returns
Iterator to the element in case the index is found, end() iterator otherwise.

This function can be used to check whether a specific element is contained in the sparse matrix. It specifically searches for the element with row index i and column index j. In case the element is found, the function returns an row/column iterator to the element. Otherwise an iterator just past the last non-zero element of row i or column j (the end() iterator) is returned. Note that the returned compressed matrix iterator is subject to invalidation due to inserting operations via the function call operator, the set() function or the insert() function!

◆ insert() [1/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::Iterator blaze::CompressedMatrix< Type, SO, Tag >::insert ( Iterator  pos,
size_t  i,
size_t  j,
const Type &  value 
)
private

Inserting an element into the compressed matrix.

Parameters
posThe position of the new element.
iThe row index of the new element. The index has to be in the range $[0..M-1]$.
jThe column index of the new element. The index has to be in the range $[0..N-1]$.
valueThe value of the element to be inserted.
Returns
Iterator to the newly inserted element.
Exceptions
std::invalid_argumentInvalid compressed matrix access index.

◆ insert() [2/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::Iterator blaze::CompressedMatrix< Type, SO, Tag >::insert ( size_t  i,
size_t  j,
const Type &  value 
)
inline

Inserting an element into the compressed matrix.

Parameters
iThe row index of the new element. The index has to be in the range $[0..M-1]$.
jThe column index of the new element. The index has to be in the range $[0..N-1]$.
valueThe value of the element to be inserted.
Returns
Iterator to the newly inserted element.
Exceptions
std::invalid_argumentInvalid compressed matrix access index.

This function inserts a new element into the compressed matrix. However, duplicate elements are not allowed. In case the compressed matrix already contains an element with row index i and column index j, a std::invalid_argument exception is thrown.

◆ isAliased()

template<typename Type , bool SO, typename Tag >
template<typename Other >
bool blaze::CompressedMatrix< Type, SO, Tag >::isAliased ( const Other *  alias) const
inlinenoexcept

Returns whether the matrix is aliased with the given address alias.

Parameters
aliasThe alias to be checked.
Returns
true in case the alias corresponds to this matrix, false if not.

This function returns whether the given address is aliased with the matrix. In contrast to the canAlias() function this function is not allowed to use compile time expressions to optimize the evaluation.

◆ lowerBound() [1/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::Iterator blaze::CompressedMatrix< Type, SO, Tag >::lowerBound ( size_t  i,
size_t  j 
)
inline

Returns an iterator to the first index not less than the given index.

Parameters
iThe row index of the search element. The index has to be in the range $[0..M-1]$.
jThe column index of the search element. The index has to be in the range $[0..N-1]$.
Returns
Iterator to the first index not less than the given index, end() iterator otherwise.

In case of a row-major matrix, this function returns a row iterator to the first element with an index not less than the given column index. In case of a column-major matrix, the function returns a column iterator to the first element with an index not less than the given row index. In combination with the upperBound() function this function can be used to create a pair of iterators specifying a range of indices. Note that the returned compressed matrix iterator is subject to invalidation due to inserting operations via the function call operator, the set() function or the insert() function!

◆ lowerBound() [2/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::ConstIterator blaze::CompressedMatrix< Type, SO, Tag >::lowerBound ( size_t  i,
size_t  j 
) const
inline

Returns an iterator to the first index not less than the given index.

Parameters
iThe row index of the search element. The index has to be in the range $[0..M-1]$.
jThe column index of the search element. The index has to be in the range $[0..N-1]$.
Returns
Iterator to the first index not less than the given index, end() iterator otherwise.

In case of a row-major matrix, this function returns a row iterator to the first element with an index not less than the given column index. In case of a column-major matrix, the function returns a column iterator to the first element with an index not less than the given row index. In combination with the upperBound() function this function can be used to create a pair of iterators specifying a range of indices. Note that the returned compressed matrix iterator is subject to invalidation due to inserting operations via the function call operator, the set() function or the insert() function!

◆ nonZeros() [1/2]

template<typename Type , bool SO, typename Tag >
size_t blaze::CompressedMatrix< Type, SO, Tag >::nonZeros
inline

Returns the number of non-zero elements in the compressed matrix.

Returns
The number of non-zero elements in the compressed matrix.

◆ nonZeros() [2/2]

template<typename Type , bool SO, typename Tag >
size_t blaze::CompressedMatrix< Type, SO, Tag >::nonZeros ( size_t  i) const
inline

Returns the number of non-zero elements in the specified row/column.

Parameters
iThe index of the row/column.
Returns
The number of non-zero elements of row/column i.

This function returns the current number of non-zero elements in the specified row/column. In case the storage order is set to rowMajor the function returns the number of non-zero elements in row i, in case the storage flag is set to columnMajor the function returns the number of non-zero elements in column i.

◆ operator%=() [1/2]

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
CompressedMatrix< Type, SO, Tag > & blaze::CompressedMatrix< Type, SO, Tag >::operator%= ( const DenseMatrix< MT, SO2 > &  rhs) &
inline

Schur product assignment operator for the multiplication of a dense matrix ( $ A\circ=B $).

Parameters
rhsThe right-hand side dense matrix for the Schur product.
Returns
Reference to the matrix.
Exceptions
std::invalid_argumentMatrix sizes do not match.

In case the current sizes of the two matrices don't match, a std::invalid_argument exception is thrown.

◆ operator%=() [2/2]

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
CompressedMatrix< Type, SO, Tag > & blaze::CompressedMatrix< Type, SO, Tag >::operator%= ( const SparseMatrix< MT, SO2 > &  rhs) &
inline

Schur product assignment operator for the multiplication of a sparse matrix ( $ A\circ=B $).

Parameters
rhsThe right-hand side sparse matrix for the Schur product.
Returns
Reference to the matrix.
Exceptions
std::invalid_argumentMatrix sizes do not match.

In case the current sizes of the two matrices don't match, a std::invalid_argument exception is thrown.

◆ operator()() [1/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::ConstReference blaze::CompressedMatrix< Type, SO, Tag >::operator() ( size_t  i,
size_t  j 
) const
inlinenoexcept

2D-access to the compressed matrix elements.

Parameters
iAccess index for the row. The index has to be in the range $[0..M-1]$.
jAccess index for the column. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.

This function only performs an index check in case BLAZE_USER_ASSERT() is active. In contrast, the at() function is guaranteed to perform a check of the given access indices.

◆ operator()() [2/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::Reference blaze::CompressedMatrix< Type, SO, Tag >::operator() ( size_t  i,
size_t  j 
)
inlinenoexcept

2D-access to the compressed matrix elements.

Parameters
iAccess index for the row. The index has to be in the range $[0..M-1]$.
jAccess index for the column. The index has to be in the range $[0..N-1]$.
Returns
Reference to the accessed value.

This function returns a reference to the accessed value at position (i,j). In case the compressed matrix does not yet store an element at position (i,j) , a new element is inserted into the compressed matrix. Note that this function only performs an index check in case BLAZE_USER_ASSERT() is active. In contrast, the at() function is guaranteed to perform a check of the given access indices.

◆ operator*() [1/2]

BLAZE_ALWAYS_INLINE constexpr const CompressedMatrix< Type, SO, Tag > & blaze::Matrix< CompressedMatrix< Type, SO, Tag > , SO >::operator*
constexprnoexceptinherited

CRTP-based conversion operation for constant matrices.

Returns
Constant reference of the actual type of the matrix.

This operator performs the CRTP-based type-safe downcast to the actual type MT of the matrix. It will return a constant reference to the actual type MT.

◆ operator*() [2/2]

BLAZE_ALWAYS_INLINE constexpr CompressedMatrix< Type, SO, Tag > & blaze::Matrix< CompressedMatrix< Type, SO, Tag > , SO >::operator*
constexprnoexceptinherited

CRTP-based conversion operation for non-constant matrices.

Returns
Mutable reference of the actual type of the matrix.

This operator performs the CRTP-based type-safe downcast to the actual type MT of the matrix. It will return a mutable reference to the actual type MT.

◆ operator+=()

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
CompressedMatrix< Type, SO, Tag > & blaze::CompressedMatrix< Type, SO, Tag >::operator+= ( const Matrix< MT, SO2 > &  rhs) &
inline

Addition assignment operator for the addition of a matrix ( $ A+=B $).

Parameters
rhsThe right-hand side matrix to be added to the matrix.
Returns
Reference to the matrix.
Exceptions
std::invalid_argumentMatrix sizes do not match.

In case the current sizes of the two matrices don't match, a std::invalid_argument exception is thrown.

◆ operator-=()

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
CompressedMatrix< Type, SO, Tag > & blaze::CompressedMatrix< Type, SO, Tag >::operator-= ( const Matrix< MT, SO2 > &  rhs) &
inline

Subtraction assignment operator for the subtraction of a matrix ( $ A-=B $).

Parameters
rhsThe right-hand side matrix to be subtracted from the matrix.
Returns
Reference to the matrix.
Exceptions
std::invalid_argumentMatrix sizes do not match.

In case the current sizes of the two matrices don't match, a std::invalid_argument exception is thrown.

◆ operator=() [1/4]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag > & blaze::CompressedMatrix< Type, SO, Tag >::operator= ( const CompressedMatrix< Type, SO, Tag > &  rhs) &
inline

Copy assignment operator for CompressedMatrix.

Parameters
rhsSparse matrix to be copied.
Returns
Reference to the assigned compressed matrix.

The compressed matrix is resized according to the given compressed matrix and initialized as a copy of this matrix.

◆ operator=() [2/4]

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
CompressedMatrix< Type, SO, Tag > & blaze::CompressedMatrix< Type, SO, Tag >::operator= ( const DenseMatrix< MT, SO2 > &  rhs) &
inline

Assignment operator for dense matrices.

Parameters
rhsDense matrix to be copied.
Returns
Reference to the assigned matrix.

The matrix is resized according to the given $ M \times N $ matrix and initialized as a copy of this matrix.

◆ operator=() [3/4]

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
CompressedMatrix< Type, SO, Tag > & blaze::CompressedMatrix< Type, SO, Tag >::operator= ( const SparseMatrix< MT, SO2 > &  rhs) &
inline

Assignment operator for different sparse matrices.

Parameters
rhsSparse matrix to be copied.
Returns
Reference to the assigned matrix.

The matrix is resized according to the given $ M \times N $ matrix and initialized as a copy of this matrix.

◆ operator=() [4/4]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag > & blaze::CompressedMatrix< Type, SO, Tag >::operator= ( initializer_list< initializer_list< Type > >  list) &
inline

List assignment to all matrix elements.

Parameters
listThe initializer list.

This assignment operator offers the option to directly assign to all elements of the matrix by means of an initializer list:

A = { { 1, 2, 3 },
{ 4, 5 },
{ 7, 8, 9 } };

The matrix is resized according to the given initializer list and all its elements are assigned the values from the given initializer list. Missing values are considered to be default values.

◆ operator~() [1/2]

BLAZE_ALWAYS_INLINE constexpr const CompressedMatrix< Type, SO, Tag > & blaze::Matrix< CompressedMatrix< Type, SO, Tag > , SO >::operator~
constexprnoexceptinherited

CRTP-based conversion operation for constant matrices.

Parameters
matrixThe matrix to be downcast.
Returns
Constant reference of the actual type of the matrix.

This operator performs the CRTP-based type-safe downcast to the actual type MT of the matrix. It will return a constant reference to the actual type MT.

◆ operator~() [2/2]

BLAZE_ALWAYS_INLINE constexpr CompressedMatrix< Type, SO, Tag > & blaze::Matrix< CompressedMatrix< Type, SO, Tag > , SO >::operator~
constexprnoexceptinherited

CRTP-based conversion operation for non-constant matrices.

Parameters
matrixThe matrix to be downcast.
Returns
Mutable reference of the actual type of the matrix.

This operator performs the CRTP-based type-safe downcast to the actual type MT of the matrix. It will return a mutable reference to the actual type MT.

◆ reserve() [1/2]

template<typename Type , bool SO, typename Tag >
void blaze::CompressedMatrix< Type, SO, Tag >::reserve ( size_t  i,
size_t  nonzeros 
)

Setting the minimum capacity of a specific row/column of the compressed matrix.

Parameters
iThe row/column index $[0..M-1]$ or $[0..N-1]$.
nonzerosThe new minimum capacity of the specified row/column.
Returns
void

This function increases the capacity of row/column i of the compressed matrix to at least nonzeros elements. The current values of the compressed matrix and all other individual row/column capacities are preserved. In case the storage order is set to rowMajor, the function reserves capacity for row i and the index has to be in the range $[0..M-1]$. In case the storage order is set to columnMajor, the function reserves capacity for column i and the index has to be in the range $[0..N-1]$.

◆ reserve() [2/2]

template<typename Type , bool SO, typename Tag >
void blaze::CompressedMatrix< Type, SO, Tag >::reserve ( size_t  nonzeros)
inline

Setting the minimum capacity of the compressed matrix.

Parameters
nonzerosThe new minimum capacity of the compressed matrix.
Returns
void

This function increases the capacity of the compressed matrix to at least nonzeros elements. The current values of the matrix elements and the individual capacities of the matrix rows are preserved.

◆ reserveElements()

template<typename Type , bool SO, typename Tag >
void blaze::CompressedMatrix< Type, SO, Tag >::reserveElements ( size_t  nonzeros)
private

Reserving the specified number of compressed matrix elements.

Parameters
nonzerosThe number of matrix elements to be reserved.
Returns
void

◆ reset() [1/2]

template<typename Type , bool SO, typename Tag >
void blaze::CompressedMatrix< Type, SO, Tag >::reset
inline

Reset to the default initial values.

Returns
void

◆ reset() [2/2]

template<typename Type , bool SO, typename Tag >
void blaze::CompressedMatrix< Type, SO, Tag >::reset ( size_t  i)
inline

Reset the specified row/column to the default initial values.

Parameters
iThe index of the row/column.
Returns
void

This function resets the values in the specified row/column to their default value. In case the storage order is set to rowMajor the function resets the values in row i, in case the storage order is set to columnMajor the function resets the values in column i. Note that the capacity of the row/column remains unchanged.

◆ resize()

template<typename Type , bool SO, typename Tag >
void blaze::CompressedMatrix< Type, SO, Tag >::resize ( size_t  m,
size_t  n,
bool  preserve = true 
)

Changing the size of the compressed matrix.

Parameters
mThe new number of rows of the compressed matrix.
nThe new number of columns of the compressed matrix.
preservetrue if the old values of the matrix should be preserved, false if not.
Returns
void

This function resizes the matrix using the given size to $ m \times n $. During this operation, new dynamic memory may be allocated in case the capacity of the matrix is too small. Note that this function may invalidate all existing views (submatrices, rows, columns, ...) on the matrix if it is used to shrink the matrix. Additionally, the resize operation potentially changes all matrix elements. In order to preserve the old matrix values, the preserve flag can be set to true.

◆ rows()

template<typename Type , bool SO, typename Tag >
size_t blaze::CompressedMatrix< Type, SO, Tag >::rows
inlinenoexcept

Returns the current number of rows of the compressed matrix.

Returns
The number of rows of the compressed matrix.

◆ scale()

template<typename Type , bool SO, typename Tag >
template<typename Other >
CompressedMatrix< Type, SO, Tag > & blaze::CompressedMatrix< Type, SO, Tag >::scale ( const Other &  scalar)
inline

Scaling of the compressed matrix by the scalar value scalar ( $ A=B*s $).

Parameters
scalarThe scalar value for the matrix scaling.
Returns
Reference to the compressed matrix.

This function scales the matrix by applying the given scalar value scalar to each element of the matrix. For built-in and complex data types it has the same effect as using the multiplication assignment operator:

// ... Resizing and initialization
A *= 4; // Scaling of the matrix
A.scale( 4 ); // Same effect as above

◆ schurAssign()

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
void blaze::CompressedMatrix< Type, SO, Tag >::schurAssign ( const DenseMatrix< MT, SO2 > &  rhs)
inline

Default implementation of the Schur product assignment of a dense matrix.

Parameters
rhsThe right-hand side dense matrix for the Schur product.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

◆ set()

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::Iterator blaze::CompressedMatrix< Type, SO, Tag >::set ( size_t  i,
size_t  j,
const Type &  value 
)
inline

Setting an element of the compressed matrix.

Parameters
iThe row index of the new element. The index has to be in the range $[0..M-1]$.
jThe column index of the new element. The index has to be in the range $[0..N-1]$.
valueThe value of the element to be set.
Returns
Iterator to the set element.

This function sets the value of an element of the compressed matrix. In case the compressed matrix already contains an element with row index i and column index j its value is modified, else a new element with the given value is inserted.

◆ shrinkToFit()

template<typename Type , bool SO, typename Tag >
void blaze::CompressedMatrix< Type, SO, Tag >::shrinkToFit
inline

Requesting the removal of unused capacity.

Returns
void

This function minimizes the capacity of the matrix by removing unused capacity. Please note that in case a reallocation occurs, all iterators (including end() iterators), all pointers and references to elements of this matrix are invalidated.

◆ subAssign() [1/2]

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
void blaze::CompressedMatrix< Type, SO, Tag >::subAssign ( const DenseMatrix< MT, SO2 > &  rhs)
inline

Default implementation of the subtraction assignment of a dense matrix.

Parameters
rhsThe right-hand side dense matrix to be subtracted.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

◆ subAssign() [2/2]

template<typename Type , bool SO, typename Tag >
template<typename MT , bool SO2>
void blaze::CompressedMatrix< Type, SO, Tag >::subAssign ( const SparseMatrix< MT, SO2 > &  rhs)
inline

Default implementation of the subtraction assignment of a compressed matrix.

Parameters
rhsThe right-hand side compressed matrix to be subtracted.
Returns
void

This function must NOT be called explicitly! It is used internally for the performance optimized evaluation of expression templates. Calling this function explicitly might result in erroneous results and/or in compilation errors. Instead of using this function use the assignment operator.

◆ swap()

template<typename Type , bool SO, typename Tag >
void blaze::CompressedMatrix< Type, SO, Tag >::swap ( CompressedMatrix< Type, SO, Tag > &  sm)
inlinenoexcept

Swapping the contents of two sparse matrices.

Parameters
smThe compressed matrix to be swapped.
Returns
void

◆ transpose()

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag > & blaze::CompressedMatrix< Type, SO, Tag >::transpose
inline

In-place transpose of the matrix.

Returns
Reference to the transposed matrix.

◆ trim() [1/2]

template<typename Type , bool SO, typename Tag >
void blaze::CompressedMatrix< Type, SO, Tag >::trim
inline

Removing all excessive capacity from all rows/columns.

Returns
void

The trim() function can be used to reverse the effect of all row/column-specific reserve() calls. The function removes all excessive capacity from all rows (in case of a rowMajor matrix) or columns (in case of a columnMajor matrix). Note that this function does not remove the overall capacity but only reduces the capacity per row/column.

◆ trim() [2/2]

template<typename Type , bool SO, typename Tag >
void blaze::CompressedMatrix< Type, SO, Tag >::trim ( size_t  i)
inline

Removing all excessive capacity of a specific row/column of the compressed matrix.

Parameters
iThe index of the row/column to be trimmed ( $[0..M-1]$ or $[0..N-1]$).
Returns
void

This function can be used to reverse the effect of a row/column-specific reserve() call. It removes all excessive capacity from the specified row (in case of a rowMajor matrix) or column (in case of a columnMajor matrix). The excessive capacity is assigned to the subsequent row/column.

◆ upperBound() [1/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::Iterator blaze::CompressedMatrix< Type, SO, Tag >::upperBound ( size_t  i,
size_t  j 
)
inline

Returns an iterator to the first index greater than the given index.

Parameters
iThe row index of the search element. The index has to be in the range $[0..M-1]$.
jThe column index of the search element. The index has to be in the range $[0..N-1]$.
Returns
Iterator to the first index greater than the given index, end() iterator otherwise.

In case of a row-major matrix, this function returns a row iterator to the first element with an index greater than the given column index. In case of a column-major matrix, the function returns a column iterator to the first element with an index greater than the given row index. In combination with the lowerBound() function this function can be used to create a pair of iterators specifying a range of indices. Note that the returned compressed matrix iterator is subject to invalidation due to inserting operations via the function call operator, the set() function or or the insert() function!

◆ upperBound() [2/2]

template<typename Type , bool SO, typename Tag >
CompressedMatrix< Type, SO, Tag >::ConstIterator blaze::CompressedMatrix< Type, SO, Tag >::upperBound ( size_t  i,
size_t  j 
) const
inline

Returns an iterator to the first index greater than the given index.

Parameters
iThe row index of the search element. The index has to be in the range $[0..M-1]$.
jThe column index of the search element. The index has to be in the range $[0..N-1]$.
Returns
Iterator to the first index greater than the given index, end() iterator otherwise.

In case of a row-major matrix, this function returns a row iterator to the first element with an index greater than the given column index. In case of a column-major matrix, the function returns a column iterator to the first element with an index greater than the given row index. In combination with the lowerBound() function this function can be used to create a pair of iterators specifying a range of indices. Note that the returned compressed matrix iterator is subject to invalidation due to inserting operations via the function call operator, the set() function or the insert() function!

Member Data Documentation

◆ smpAssignable

template<typename Type , bool SO, typename Tag >
constexpr bool blaze::CompressedMatrix< Type, SO, Tag >::smpAssignable = !IsSMPAssignable_v<Type>
staticconstexpr

Compilation flag for SMP assignments.

The smpAssignable compilation flag indicates whether the matrix can be used in SMP (shared memory parallel) assignments (both on the left-hand and right-hand side of the assignment).


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