CMR  1.3.0
Classes | Public Types | Public Member Functions | List of all members
tu::SparseMatrix< V > Class Template Reference

Sparse matrix with entries of type V. More...

#include <matrix.hpp>

Inheritance diagram for tu::SparseMatrix< V >:
tu::Matrix< V >

Classes

struct  Data
 Matrix data, row-wise or column-wise. More...
 
struct  NonzeroIterator
 Iterator for row- or column-wise iteration over the entries. More...
 

Public Types

typedef Matrix< V >::Value Value
 
typedef Matrix< V >::Index Index
 
typedef Matrix< V >::Nonzero Nonzero
 
typedef detail::Range< NonzeroIterator< true > > NonzeroRowRange
 
typedef detail::Range< NonzeroIterator< false > > NonzeroColumnRange
 
- Public Types inherited from tu::Matrix< V >
typedef V Value
 
typedef std::size_t Index
 Type of entries. More...
 

Public Member Functions

 SparseMatrix ()
 Constructs a 0x0 matrix. More...
 
 SparseMatrix (SparseMatrix &&other)
 Move constructor. More...
 
SparseMatrixoperator= (SparseMatrix &&other)
 Move assignment operator. More...
 
 SparseMatrix (bool majorRow, Index numMajor, Index numMinor, Index numEntries, Index *first, Index *beyond, Index *entryMinors, Value *entryValues, bool mayContainZeros=true, bool isSorted=false)
 Constructs a matrix. More...
 
 SparseMatrix (bool majorRow, const Data &data, Index numMinor, bool majorIsSorted=false)
 Constructs a matrix. More...
 
 SparseMatrix (bool majorRow, Data &&data, Index numMinor)
 Constructs a matrix. More...
 
 SparseMatrix (const Data &rowData, const Data &columnData)
 Constructs a matrix. More...
 
 SparseMatrix (Data &&rowData, Data &&columnData)
 Constructs a matrix. More...
 
void set (bool majorRow, Index numMajor, Index numMinor, Index numEntries, const Index *first, const Index *beyond, const Index *entryMinors, const Value *entryValues, bool mayContainZeros=true, bool isSorted=false)
 Sets the contents of the matrix. More...
 
void set (bool majorRow, const Data &data, Index numMinor)
 Sets the contents of the matrix. More...
 
void set (bool majorRow, Data &&data, Index numMinor)
 Sets the contents of the matrix. More...
 
void set (const Data &rowData, const Data &columnData)
 Sets the contents of the matrix. More...
 
void set (Data &&rowData, Data &&columnData)
 Sets the contents of the matrix. More...
 
 ~SparseMatrix ()=default
 Destructor. More...
 
std::size_t numRows () const
 Returns the number of rows. More...
 
std::size_t numColumns () const
 Returns the number of columns. More...
 
bool hasSortedRows () const
 Indicates if the row data is sorted by column. More...
 
bool hasSortedColumns () const
 Indicates if the column data is sorted by row. More...
 
const Valueget (Index row, Index column) const
 Returns entry at row, column. More...
 
std::size_t numNonzeros () const
 Returns the number of nonzeros. More...
 
std::size_t countRowNonzeros (Index row) const
 Returns the number of nonzeros in row. More...
 
std::size_t countColumnNonzeros (Index column) const
 Returns the number of nonzeros in column. More...
 
NonzeroRowRange iterateRowNonzeros (Index row) const
 Returns a range for iterating over the nonzeros of row. More...
 
NonzeroColumnRange iterateColumnNonzeros (Index column) const
 Returns a range for iterating over the nonzeros of column. More...
 
SparseMatrix transposed () const
 Returns a copy of the matrix' transpose. More...
 
void ensureConsistency () const
 Checks for consistency, raising a std::runtime_error if inconsistent. More...
 
void transpose ()
 Transposes the matrix. More...
 
void sortRows ()
 Sort row data (by column). More...
 
void sortColumns ()
 Sort column data (by row). More...
 
void sort ()
 Sort row and column data (by column and row, respectively). More...
 

Detailed Description

template<typename V>
class tu::SparseMatrix< V >

Sparse matrix with entries of type V.

Member Typedef Documentation

◆ Index

template<typename V >
typedef Matrix<V>::Index tu::SparseMatrix< V >::Index

◆ Nonzero

template<typename V >
typedef Matrix<V>::Nonzero tu::SparseMatrix< V >::Nonzero

◆ NonzeroColumnRange

template<typename V >
typedef detail::Range<NonzeroIterator<false> > tu::SparseMatrix< V >::NonzeroColumnRange

◆ NonzeroRowRange

template<typename V >
typedef detail::Range<NonzeroIterator<true> > tu::SparseMatrix< V >::NonzeroRowRange

◆ Value

template<typename V >
typedef Matrix<V>::Value tu::SparseMatrix< V >::Value

Constructor & Destructor Documentation

◆ SparseMatrix() [1/7]

template<typename V >
tu::SparseMatrix< V >::SparseMatrix ( )
inline

Constructs a 0x0 matrix.

◆ SparseMatrix() [2/7]

template<typename V >
tu::SparseMatrix< V >::SparseMatrix ( SparseMatrix< V > &&  other)
inline

Move constructor.

◆ SparseMatrix() [3/7]

template<typename V >
tu::SparseMatrix< V >::SparseMatrix ( bool  majorRow,
Index  numMajor,
Index  numMinor,
Index  numEntries,
Index first,
Index beyond,
Index entryMinors,
Value entryValues,
bool  mayContainZeros = true,
bool  isSorted = false 
)
inline

Constructs a matrix.

Constructs a matrix. Given entries may contain zeros, but they are filtered.

Parameters
majorRowIndicates if data is row-wise.
numMajorNumber of rows (resp. columns) of the matrix.
numMinorNumber of columns (resp. rows) of the matrix.
numEntriesNumber of provided entries.
firstArray of size numMajor with first index of each row (resp. column).
beyondArray of size numMajor with beyond index of each row (resp. column). May be NULL in which case the first-entry of the next major is considered, i.e., the rows (resp. columns) need to be given in an ordered way.
entryMinorsArray of size numEntries with column (resp. row) of each entry.
entryValuesArray of size numEntries with value of each entry.
mayContainZerosWhether we have to check for zero entries.
isSortedWhether the entries of each row (resp. column) are already sorted.

◆ SparseMatrix() [4/7]

template<typename V >
tu::SparseMatrix< V >::SparseMatrix ( bool  majorRow,
const Data data,
Index  numMinor,
bool  majorIsSorted = false 
)
inline

Constructs a matrix.

Constructs a matrix from a prepared data structure.

Parameters
majorRowIndicates if data is row-wise.
majorIsSortedWhether the data of each major is sorted by minor.
dataMatrix data.

◆ SparseMatrix() [5/7]

template<typename V >
tu::SparseMatrix< V >::SparseMatrix ( bool  majorRow,
Data &&  data,
Index  numMinor 
)
inline

Constructs a matrix.

Constructs a matrix from a prepared data structure.

Parameters
majorRowIndicates if data is row-wise.
dataMatrix data.

◆ SparseMatrix() [6/7]

template<typename V >
tu::SparseMatrix< V >::SparseMatrix ( const Data rowData,
const Data columnData 
)
inline

Constructs a matrix.

Constructs a matrix from two prepared data structures.

Parameters
rowDataMatrix row data.
columnDataMatrix column data.

◆ SparseMatrix() [7/7]

template<typename V >
tu::SparseMatrix< V >::SparseMatrix ( Data &&  rowData,
Data &&  columnData 
)
inline

Constructs a matrix.

Constructs a matrix from a two prepared data structures.

Parameters
rowDataMatrix row data.
columnDataMatrix column data.

◆ ~SparseMatrix()

template<typename V >
tu::SparseMatrix< V >::~SparseMatrix ( )
default

Destructor.

Member Function Documentation

◆ countColumnNonzeros()

template<typename V >
std::size_t tu::SparseMatrix< V >::countColumnNonzeros ( Index  column) const
inline

Returns the number of nonzeros in column.

◆ countRowNonzeros()

template<typename V >
std::size_t tu::SparseMatrix< V >::countRowNonzeros ( Index  row) const
inline

Returns the number of nonzeros in row.

◆ ensureConsistency()

template<typename V >
void tu::SparseMatrix< V >::ensureConsistency ( ) const
inline

Checks for consistency, raising a std::runtime_error if inconsistent.

Checks for consistency of row- and column-data, which includes that all entries must be nonzeros and that entries are sorted and free of duplicates (if stated so).

◆ get()

template<typename V >
const Value& tu::SparseMatrix< V >::get ( Index  row,
Index  column 
) const
inline

Returns entry at row, column.

Returns entry at row, column. If the row or column data is sorted (resp. not sorted) then the time is logarithmic (resp. linear) in the number of nonzeros of the row or column.

◆ hasSortedColumns()

template<typename V >
bool tu::SparseMatrix< V >::hasSortedColumns ( ) const
inline

Indicates if the column data is sorted by row.

◆ hasSortedRows()

template<typename V >
bool tu::SparseMatrix< V >::hasSortedRows ( ) const
inline

Indicates if the row data is sorted by column.

◆ iterateColumnNonzeros()

template<typename V >
NonzeroColumnRange tu::SparseMatrix< V >::iterateColumnNonzeros ( Index  column) const
inline

Returns a range for iterating over the nonzeros of column.

◆ iterateRowNonzeros()

template<typename V >
NonzeroRowRange tu::SparseMatrix< V >::iterateRowNonzeros ( Index  row) const
inline

Returns a range for iterating over the nonzeros of row.

◆ numColumns()

template<typename V >
std::size_t tu::SparseMatrix< V >::numColumns ( ) const
inline

Returns the number of columns.

◆ numNonzeros()

template<typename V >
std::size_t tu::SparseMatrix< V >::numNonzeros ( ) const
inline

Returns the number of nonzeros.

◆ numRows()

template<typename V >
std::size_t tu::SparseMatrix< V >::numRows ( ) const
inline

Returns the number of rows.

◆ operator=()

template<typename V >
SparseMatrix& tu::SparseMatrix< V >::operator= ( SparseMatrix< V > &&  other)
inline

Move assignment operator.

◆ set() [1/5]

template<typename V >
void tu::SparseMatrix< V >::set ( bool  majorRow,
const Data data,
Index  numMinor 
)
inline

Sets the contents of the matrix.

Sets the contents of the matrix from a prepared data structure.

Parameters
majorRowIndicates if data is row-wise.
dataMatrix data.
numMinorNumber of columns (resp. rows).

◆ set() [2/5]

template<typename V >
void tu::SparseMatrix< V >::set ( bool  majorRow,
Data &&  data,
Index  numMinor 
)
inline

Sets the contents of the matrix.

Sets the contents of the matrix from a prepared data structure.

Parameters
majorRowIndicates if data is row-wise.
dataMatrix data.
numMinorNumber of columns (resp. rows).

◆ set() [3/5]

template<typename V >
void tu::SparseMatrix< V >::set ( bool  majorRow,
Index  numMajor,
Index  numMinor,
Index  numEntries,
const Index first,
const Index beyond,
const Index entryMinors,
const Value entryValues,
bool  mayContainZeros = true,
bool  isSorted = false 
)
inline

Sets the contents of the matrix.

Sets the contents of the matrix. Given entries may contain zeros, but they are filtered.

Parameters
majorRowIndicates if data is row-wise.
numMajorNumber of rows (resp. columns) of the matrix.
numMinorNumber of columns (resp. rows) of the matrix.
numEntriesNumber of provided entries.
firstArray of size numMajor with first index of each row (resp. column).
beyondArray of size numMajor with beyond index of each row (resp. column). May be nullptr in which case the first-entry of the next major is considered, i.e., the rows (resp. columns) need to be ordered.
entryMinorsArray of size numEntries with column (resp. row) of each entry.
entryValuesArray of size numEntries with value of each entry.
mayContainZerosWhether zero entries shall be skipped.
isSortedWhether the entries of each major are sorted by minor.

◆ set() [4/5]

template<typename V >
void tu::SparseMatrix< V >::set ( const Data rowData,
const Data columnData 
)
inline

Sets the contents of the matrix.

Sets the contents of the matrix from a prepared data structure.

Parameters
rowDataMatrix row data.
columnDataMatrix column data.

◆ set() [5/5]

template<typename V >
void tu::SparseMatrix< V >::set ( Data &&  rowData,
Data &&  columnData 
)
inline

Sets the contents of the matrix.

Sets the contents of the matrix from a prepared data structure.

Parameters
rowDataMatrix row data.
columnDataMatrix column data.

◆ sort()

template<typename V >
void tu::SparseMatrix< V >::sort ( )
inline

Sort row and column data (by column and row, respectively).

◆ sortColumns()

template<typename V >
void tu::SparseMatrix< V >::sortColumns ( )
inline

Sort column data (by row).

◆ sortRows()

template<typename V >
void tu::SparseMatrix< V >::sortRows ( )
inline

Sort row data (by column).

◆ transpose()

template<typename V >
void tu::SparseMatrix< V >::transpose ( )
inline

Transposes the matrix.

Transposes the matrix in constant time.

◆ transposed()

template<typename V >
SparseMatrix tu::SparseMatrix< V >::transposed ( ) const
inline

Returns a copy of the matrix' transpose.


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