Public Types | Public Member Functions | List of all members
blaze::SparseMatrixProxy< PT, MT > Class Template Reference

Proxy backend for sparse matrix types.The SparseMatrixProxy class serves as a backend for the Proxy class. It is used in case the data type represented by the proxy is a sparse matrix and augments the Proxy interface by the complete interface required of sparse matrices. More...

#include <SparseMatrixProxy.h>

Inherits blaze::SparseMatrix< PT, IsColumnMajorMatrix< MT >::value >.

Public Types

enum  { smpAssignable = MT::smpAssignable }
 Compilation flag for SMP assignments.
 
typedef MT::ResultType ResultType
 Result type for expression template evaluations.
 
typedef MT::OppositeType OppositeType
 Result type with opposite storage order for expression template evaluations.
 
typedef MT::TransposeType TransposeType
 Transpose type for expression template evaluations.
 
typedef MT::ElementType ElementType
 Type of the sparse matrix elements.
 
typedef MT::ReturnType ReturnType
 Return type for expression template evaluations.
 
typedef MT::CompositeType CompositeType
 Data type for composite expression templates.
 
typedef MT::Reference Reference
 Reference to a non-constant matrix value.
 
typedef MT::ConstReference ConstReference
 Reference to a constant matrix value.
 
typedef MT::Iterator Iterator
 Iterator over non-constant elements.
 
typedef MT::ConstIterator ConstIterator
 Iterator over constant elements.
 
typedef PT MatrixType
 Type of the matrix.
 

Public Member Functions

BLAZE_ALWAYS_INLINE MatrixTypeoperator~ ()
 Conversion operator for non-constant matrices. More...
 
BLAZE_ALWAYS_INLINE const MatrixTypeoperator~ () const
 Conversion operator for constant matrices. More...
 
Data access functions
Reference operator() (size_t i, size_t j) const
 Function call operator for the direct access to matrix elements. More...
 
Iterator begin (size_t i) const
 Returns an iterator to the first element of row/column i of the represented matrix. More...
 
ConstIterator cbegin (size_t i) const
 Returns an iterator to the first element of row/column i of the represented matrix. More...
 
Iterator end (size_t i) const
 Returns an iterator just past the last element of row/column i of the represented matrix. More...
 
ConstIterator cend (size_t i) const
 Returns an iterator just past the last element of row/column i of the represented matrix. More...
 
Utility functions
size_t rows () const
 Returns the current number of rows of the represented matrix. More...
 
size_t columns () const
 Returns the current number of columns of the represented matrix. More...
 
size_t capacity () const
 Returns the maximum capacity of the represented matrix. More...
 
size_t capacity (size_t i) const
 Returns the current capacity of the specified row/column of the represented matrix. More...
 
size_t nonZeros () const
 Returns the number of non-zero elements in the represented matrix. More...
 
size_t nonZeros (size_t i) const
 Returns the number of non-zero elements in the specified row/column of the represented matrix. More...
 
void reset () const
 Reset to the default initial value. More...
 
void reset (size_t i) const
 Reset the specified row/column to the default initial values. More...
 
void clear () const
 Clearing the represented vector. More...
 
Iterator set (size_t i, size_t j, const ElementType &value) const
 Setting an element of the represented sparse matrix. More...
 
Iterator insert (size_t i, size_t j, const ElementType &value) const
 Inserting an element into the represented sparse matrix. More...
 
void append (size_t i, size_t j, const ElementType &value, bool check=false) const
 Appending an element to the specified row/column of the sparse matrix. More...
 
void finalize (size_t i) const
 Finalizing the element insertion of a row/column. More...
 
void erase (size_t i, size_t j) const
 Erasing an element from the sparse matrix. More...
 
Iterator erase (size_t i, Iterator pos) const
 Erasing an element from the sparse matrix. More...
 
Iterator erase (size_t i, Iterator first, Iterator last) const
 Erasing a range of elements from the sparse matrix. More...
 
void resize (size_t m, size_t n, bool preserve=true) const
 Changing the size of the represented matrix. More...
 
void reserve (size_t n) const
 Setting the minimum capacity of the represented matrix. More...
 
void reserve (size_t i, size_t n) const
 Setting the minimum capacity of a specific row/column of the sparse matrix. More...
 
void trim () const
 Removing all excessive capacity from all rows/columns. More...
 
void trim (size_t i) const
 Removing all excessive capacity of a specific row/column of the sparse matrix. More...
 
void transpose () const
 In-place transpose of the represented matrix. More...
 
void ctranspose () const
 In-place conjugate transpose of the represented matrix. More...
 
template<typename Other >
void scale (const Other &scalar) const
 Scaling of the sparse matrix by the scalar value scalar ( $ A=B*s $). More...
 
Lookup functions
Iterator find (size_t i, size_t j) const
 Searches for a specific matrix element. More...
 
Iterator lowerBound (size_t i, size_t j) const
 Returns an iterator to the first index not less then the given index. More...
 
Iterator upperBound (size_t i, size_t j) const
 Returns an iterator to the first index greater then the given index. More...
 

Detailed Description

template<typename PT, typename MT>
class blaze::SparseMatrixProxy< PT, MT >

Proxy backend for sparse matrix types.

The SparseMatrixProxy class serves as a backend for the Proxy class. It is used in case the data type represented by the proxy is a sparse matrix and augments the Proxy interface by the complete interface required of sparse matrices.

Member Function Documentation

template<typename PT , typename MT >
void blaze::SparseMatrixProxy< PT, MT >::append ( size_t  i,
size_t  j,
const ElementType value,
bool  check = false 
) const
inline

Appending an element to the specified row/column of the sparse 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 sparse 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 sparse 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.

Note
: Although append() does not allocate new memory, it still invalidates all iterators returned by the end() functions!
template<typename PT , typename MT >
SparseMatrixProxy< PT, MT >::Iterator blaze::SparseMatrixProxy< PT, MT >::begin ( size_t  i) const
inline

Returns an iterator to the first element of row/column i of the represented matrix.

Parameters
iThe row/column index.
Returns
Iterator to the first 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.

template<typename PT , typename MT >
size_t blaze::SparseMatrixProxy< PT, MT >::capacity ( ) const
inline

Returns the maximum capacity of the represented matrix.

Returns
The capacity of the matrix.
template<typename PT , typename MT >
size_t blaze::SparseMatrixProxy< PT, MT >::capacity ( size_t  i) const
inline

Returns the current capacity of the specified row/column of the represented matrix.

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.

template<typename PT , typename MT >
SparseMatrixProxy< PT, MT >::ConstIterator blaze::SparseMatrixProxy< PT, MT >::cbegin ( size_t  i) const
inline

Returns an iterator to the first element of row/column i of the represented matrix.

Parameters
iThe row/column index.
Returns
Iterator to the first 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.

template<typename PT , typename MT >
SparseMatrixProxy< PT, MT >::ConstIterator blaze::SparseMatrixProxy< PT, MT >::cend ( size_t  i) const
inline

Returns an iterator just past the last element of row/column i of the represented matrix.

Parameters
iThe row/column index.
Returns
Iterator just past the last 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.

template<typename PT , typename MT >
void blaze::SparseMatrixProxy< PT, MT >::clear ( ) const
inline

Clearing the represented vector.

Returns
void

This function clears the matrix to its default initial state.

template<typename PT , typename MT >
size_t blaze::SparseMatrixProxy< PT, MT >::columns ( ) const
inline

Returns the current number of columns of the represented matrix.

Returns
The number of columns of the matrix.
template<typename PT , typename MT >
void blaze::SparseMatrixProxy< PT, MT >::ctranspose ( ) const
inline

In-place conjugate transpose of the represented matrix.

Returns
Reference to the transposed matrix.
template<typename PT , typename MT >
SparseMatrixProxy< PT, MT >::Iterator blaze::SparseMatrixProxy< PT, MT >::end ( size_t  i) const
inline

Returns an iterator just past the last element of row/column i of the represented matrix.

Parameters
iThe row/column index.
Returns
Iterator just past the last 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.

template<typename PT , typename MT >
void blaze::SparseMatrixProxy< PT, MT >::erase ( size_t  i,
size_t  j 
) const
inline

Erasing an element from the sparse 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 sparse matrix.

template<typename PT , typename MT >
SparseMatrixProxy< PT, MT >::Iterator blaze::SparseMatrixProxy< PT, MT >::erase ( size_t  i,
Iterator  pos 
) const
inline

Erasing an element from the sparse 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 sparse 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.

template<typename PT , typename MT >
SparseMatrixProxy< PT, MT >::Iterator blaze::SparseMatrixProxy< PT, MT >::erase ( size_t  i,
Iterator  first,
Iterator  last 
) const
inline

Erasing a range of elements from the sparse matrix.

Parameters
iThe row/column index of the element 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 element from the sparse 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.

template<typename PT , typename MT >
void blaze::SparseMatrixProxy< PT, MT >::finalize ( size_t  i) const
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!
template<typename PT , typename MT >
SparseMatrixProxy< PT, MT >::Iterator blaze::SparseMatrixProxy< PT, MT >::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 sparse matrix iterator is subject to invalidation due to inserting operations via the function call operator or the insert() function!

template<typename PT , typename MT >
SparseMatrixProxy< PT, MT >::Iterator blaze::SparseMatrixProxy< PT, MT >::insert ( size_t  i,
size_t  j,
const ElementType value 
) const
inline

Inserting an element into the represented sparse 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 sparse matrix access index.

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

template<typename PT , typename MT >
SparseMatrixProxy< PT, MT >::Iterator blaze::SparseMatrixProxy< PT, MT >::lowerBound ( size_t  i,
size_t  j 
) const
inline

Returns an iterator to the first index not less then 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 then 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 then 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 then 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 or the insert() function!

template<typename PT , typename MT >
size_t blaze::SparseMatrixProxy< PT, MT >::nonZeros ( ) const
inline

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

Returns
The number of non-zero elements in the matrix.
template<typename PT , typename MT >
size_t blaze::SparseMatrixProxy< PT, MT >::nonZeros ( size_t  i) const
inline

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

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.

template<typename PT , typename MT >
SparseMatrixProxy< PT, MT >::Reference blaze::SparseMatrixProxy< PT, MT >::operator() ( size_t  i,
size_t  j 
) const
inline

Function call operator for the direct access to 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.
BLAZE_ALWAYS_INLINE MatrixType& blaze::Matrix< PT , SO >::operator~ ( )
inlineinherited

Conversion operator for non-constant matrices.

Returns
Reference of the actual type of the matrix.
BLAZE_ALWAYS_INLINE const MatrixType& blaze::Matrix< PT , SO >::operator~ ( ) const
inlineinherited

Conversion operator for constant matrices.

Returns
Constant reference of the actual type of the matrix.
template<typename PT , typename MT >
void blaze::SparseMatrixProxy< PT, MT >::reserve ( size_t  n) const
inline

Setting the minimum capacity of the represented matrix.

Parameters
nThe new minimum capacity of the matrix.
Returns
void

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

template<typename PT , typename MT >
void blaze::SparseMatrixProxy< PT, MT >::reserve ( size_t  i,
size_t  n 
) const
inline

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

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

This function increases the capacity of row/column i of the sparse matrix to at least nonzeros elements. The current values of the sparse 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]$.

template<typename PT , typename MT >
void blaze::SparseMatrixProxy< PT, MT >::reset ( ) const
inline

Reset to the default initial value.

Returns
void

This function resets all elements of the matrix to the default initial values.

template<typename PT , typename MT >
void blaze::SparseMatrixProxy< PT, MT >::reset ( size_t  i) const
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.

template<typename PT , typename MT >
void blaze::SparseMatrixProxy< PT, MT >::resize ( size_t  m,
size_t  n,
bool  preserve = true 
) const
inline

Changing the size of the represented matrix.

Parameters
mThe new number of rows of the matrix.
nThe new number of columns of the 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 $. Depending on the type of the matrix, 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.

template<typename PT , typename MT >
size_t blaze::SparseMatrixProxy< PT, MT >::rows ( ) const
inline

Returns the current number of rows of the represented matrix.

Returns
The number of rows of the matrix.
template<typename PT , typename MT >
template<typename Other >
void blaze::SparseMatrixProxy< PT, MT >::scale ( const Other &  scalar) const
inline

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

Parameters
scalarThe scalar value for the matrix scaling.
Returns
void
template<typename PT , typename MT >
SparseMatrixProxy< PT, MT >::Iterator blaze::SparseMatrixProxy< PT, MT >::set ( size_t  i,
size_t  j,
const ElementType value 
) const
inline

Setting an element of the represented sparse 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.
Exceptions
std::invalid_argumentInvalid sparse matrix access index.

This function sets the value of an element of the sparse matrix. In case the sparse 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.

template<typename PT , typename MT >
void blaze::SparseMatrixProxy< PT, MT >::transpose ( ) const
inline

In-place transpose of the represented matrix.

Returns
Reference to the transposed matrix.
template<typename PT , typename MT >
void blaze::SparseMatrixProxy< PT, MT >::trim ( ) const
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.

template<typename PT , typename MT >
void blaze::SparseMatrixProxy< PT, MT >::trim ( size_t  i) const
inline

Removing all excessive capacity of a specific row/column of the sparse 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.

template<typename PT , typename MT >
SparseMatrixProxy< PT, MT >::Iterator blaze::SparseMatrixProxy< PT, MT >::upperBound ( size_t  i,
size_t  j 
) const
inline

Returns an iterator to the first index greater then 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 then 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 then 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 then 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 or the insert() function!


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