template<iDynTree::MatrixStorageOrdering ordering>
iDynTree::SparseMatrix class

Sparse Matrix class.

This class uses the Compressed Column (Row) Storage scheme (see https://en.wikipedia.org/wiki/Sparse_matrix#Compressed_sparse_row_.28CSR.2C_CRS_or_Yale_format.29) which is compatible with the format used in the Eigen library (by using Map).

Public types

class ConstIterator
class Iterator
using iterator = Iterator
using const_iterator = ConstIterator

Public static functions

static auto sparseMatrixFromTriplets(std::size_t rows, std::size_t cols, const iDynTree::Triplets& nonZeroElements) -> SparseMatrix

Constructors, destructors, conversion operators

SparseMatrix()
Creates an empty sparse matrix.
SparseMatrix(std::size_t rows, std::size_t cols)
Creates a zero sparse matrix with the specified dimensions.
SparseMatrix(std::size_t rows, std::size_t cols, const iDynTree::VectorDynSize& memoryReserveDescription)
template<iDynTree::MatrixStorageOrdering otherOrdering>
SparseMatrix(const SparseMatrix<otherOrdering>&)
~SparseMatrix()
Default destructor.

Public functions

template<iDynTree::MatrixStorageOrdering otherOrdering>
auto operator=(const SparseMatrix<otherOrdering>&) -> SparseMatrix&
auto numberOfNonZeros() const -> std::size_t
Returns the number of nonzero elements in this sparse matrix.
void resize(std::size_t rows, std::size_t columns)
Resize the matrix to the specified new dimensions.
void resize(std::size_t rows, std::size_t columns, const iDynTree::VectorDynSize& innerIndicesInformation)
Resize the matrix to the specified new dimensions.
void reserve(std::size_t nonZeroElements)
void zero()
Set the sparse matrix to be zero.
void setFromConstTriplets(const iDynTree::Triplets& triplets)
Sets the content of this sparse matrix to the content of triplets.
void setFromTriplets(iDynTree::Triplets& triplets)
Sets the content of this sparse matrix to the content of triplets.
auto operator()(std::size_t row, std::size_t col) const -> double
Access operation to the element of the matrix identified by row-col.
auto operator()(std::size_t row, std::size_t col) -> double&
Access operation to the element of the matrix identified by row-col.
auto getValue(std::size_t row, std::size_t col) const -> double
void setValue(std::size_t row, std::size_t col, double newValue)
auto rows() const -> std::size_t
Returns the number of rows of the matrix.
auto columns() const -> std::size_t
Returns the number of columns of the matrix.
auto valuesBuffer() -> double*
auto valuesBuffer() const -> double const *
auto innerIndicesBuffer() -> int*
auto innerIndicesBuffer() const -> int const *
auto outerIndicesBuffer() -> int*
auto outerIndicesBuffer() const -> int const *
auto description(bool fullMatrix = false) const -> std::string
Returns a textual description of the matrix.
auto internalDescription() const -> std::string
auto begin() -> iterator
auto begin() const -> const_iterator
auto end() -> iterator
auto end() const -> const_iterator

Function documentation

template<iDynTree::MatrixStorageOrdering ordering>
std::size_t iDynTree::SparseMatrix<ordering>::numberOfNonZeros() const

Returns the number of nonzero elements in this sparse matrix.

Returns the number of non zero elements

template<iDynTree::MatrixStorageOrdering ordering>
void iDynTree::SparseMatrix<ordering>::resize(std::size_t rows, std::size_t columns)

Resize the matrix to the specified new dimensions.

Parameters
rows the new number of rows of this matrix
columns the new number of columns of this matrix

template<iDynTree::MatrixStorageOrdering ordering>
void iDynTree::SparseMatrix<ordering>::resize(std::size_t rows, std::size_t columns, const iDynTree::VectorDynSize& innerIndicesInformation)

Resize the matrix to the specified new dimensions.

Parameters
rows the new number of rows of this matrix
columns the new number of columns of this matrix
innerIndicesInformation information on the NNZ for each column (row), used to reserve memory in advance. It depends on the storage ordering

template<iDynTree::MatrixStorageOrdering ordering>
void iDynTree::SparseMatrix<ordering>::zero()

Set the sparse matrix to be zero.

template<iDynTree::MatrixStorageOrdering ordering>
void iDynTree::SparseMatrix<ordering>::setFromConstTriplets(const iDynTree::Triplets& triplets)

Sets the content of this sparse matrix to the content of triplets.

Parameters
triplets triplets containing the non zero elements

This function does not set the dimensions of the matrix which must be set beforehand. If the dimensions are wrong the behaviour is undefined.

template<iDynTree::MatrixStorageOrdering ordering>
void iDynTree::SparseMatrix<ordering>::setFromTriplets(iDynTree::Triplets& triplets)

Sets the content of this sparse matrix to the content of triplets.

Parameters
triplets triplets containing the non zero elements

This function does not set the dimensions of the matrix which must be set beforehand. If the dimensions are wrong the behaviour is undefined.

template<iDynTree::MatrixStorageOrdering ordering>
double iDynTree::SparseMatrix<ordering>::operator()(std::size_t row, std::size_t col) const

Access operation to the element of the matrix identified by row-col.

Parameters
row row index
col column index
Returns the value at the specified row and column

template<iDynTree::MatrixStorageOrdering ordering>
double& iDynTree::SparseMatrix<ordering>::operator()(std::size_t row, std::size_t col)

Access operation to the element of the matrix identified by row-col.

Parameters
row row index
col column index
Returns reference to the value at the specified row and column

template<iDynTree::MatrixStorageOrdering ordering>
std::size_t iDynTree::SparseMatrix<ordering>::rows() const

Returns the number of rows of the matrix.

Returns the number of rows

template<iDynTree::MatrixStorageOrdering ordering>
std::size_t iDynTree::SparseMatrix<ordering>::columns() const

Returns the number of columns of the matrix.

Returns the number of columns

template<iDynTree::MatrixStorageOrdering ordering>
std::string iDynTree::SparseMatrix<ordering>::description(bool fullMatrix = false) const

Returns a textual description of the matrix.

Parameters
fullMatrix true to return the full matrix, false for only the non zero elements. Default to false
Returns a textual representation of the matrix

If true is passed, the whole matrix (with also zero elements) is printed Default to false