8 #ifndef META_OCEAN_MATH_SPARSE_MATRIX_H
9 #define META_OCEAN_MATH_SPARSE_MATRIX_H
20 template <
typename T>
class MatrixT;
23 template <
typename T>
class SparseMatrixT;
90 inline Entry(
const size_t row,
const size_t column,
const T value);
96 inline size_t row()
const;
102 inline size_t column()
const;
108 inline T value()
const;
114 inline bool isValid()
const;
122 inline bool operator<(
const Entry& second)
const;
245 bool isZero(
const size_t row,
const size_t column)
const;
466 template <
typename T>
468 entryRow(size_t(-1)),
469 entryColumn(size_t(-1)),
475 template <
typename T>
484 template <
typename T>
490 template <
typename T>
496 template <
typename T>
502 template <
typename T>
505 return entryRow != size_t(-1) && entryColumn != size_t(-1);
508 template <
typename T>
514 template <
typename T>
517 *
this = (*this) * matrix;
521 template <
typename T>
527 template <
typename T>
This class implements a matrix with arbitrary size.
Definition: Matrix.h:63
This class provides basic numeric functionalities.
Definition: Numeric.h:57
This class implements a triple object for matrix entries.
Definition: SparseMatrix.h:76
bool isValid() const
Returns whether this entry is valid.
Definition: SparseMatrix.h:503
size_t column() const
Returns the column of this entry.
Definition: SparseMatrix.h:491
T value() const
Returns the value of this entry.
Definition: SparseMatrix.h:497
size_t entryRow
The row of this entry.
Definition: SparseMatrix.h:136
size_t entryColumn
The column of this entry.
Definition: SparseMatrix.h:139
static bool hasOneEntry(const size_t rows, const size_t columns, const Entries &entries)
Checks whether a set of given entries have at least one entry in each row and in each column of a mat...
bool operator<(const Entry &second) const
Compares two entries and returns whether this entry is 'lesser' than the second entry.
Definition: SparseMatrix.h:509
Entry()
Creates an invalid entry object.
Definition: SparseMatrix.h:467
size_t row() const
Returns the row of this entry.
Definition: SparseMatrix.h:485
T entryValue
The value of this entry.
Definition: SparseMatrix.h:142
This class implements a sparse matrix using a float type for its elements that is specified by T.
Definition: SparseMatrix.h:61
void reserve(const size_t elements)
Reserves memory for a specified number of non zero elements.
bool invertBlockDiagonal3()
Inverts this square block diagonal matrix with 3x3 block size.
T sum() const
Determines the sum of all elements of this matrix.
SparseMatrixT< T > operator*(const SparseMatrixT< T > &matrix) const
Multiplies two sparse matrix objects and returns the matrix result.
SparseMatrixT(const size_t rows, const size_t columns, const Entries &entries)
Creates a new spare matrix with given dimensions.
bool isZero(const size_t row, const size_t column) const
Returns whether a specified elements is zero.
SparseMatrixT< T > submatrix(const size_t row, const size_t column, const size_t rows, const size_t columns) const
Returns a submatrix of this matrix.
bool isEqual(const SparseMatrixT< T > &matrix, const T eps) const
Returns whether two matrices are almost identical up to a specified epsilon.
SparseMatrixT(const size_t rows, const size_t columns)
Creates a new spare matrix with given dimensions.
SparseMatrixT< T > & operator=(SparseMatrixT< T > &&matrix) noexcept
Move operator.
MatrixT< T > operator*(const MatrixT< T > &matrix) const
Multiplies a dense matrix object on this sparse matrix object and returns the dense matrix result.
size_t rows() const
Returns the number of rows this matrix has.
SparseMatrixT(const MatrixT< T > &denseMatrix)
Creates a new sparse matrix with defined rows and columns and copies all non-zero values from a dense...
bool isEqual(const MatrixT< T > &matrix, const T eps) const
Returns whether two matrices are almost identical up to a specified epsilon.
size_t nonZeroElements() const
Returns the number of non zero elements stored in this matrix.
~SparseMatrixT()
Destructs a sparse matrix object.
SparseMatrixT(const SparseMatrixT< T > &matrix)
Copy constructor.
std::vector< Entry > Entries
Definition of a vector holding entries.
Definition: SparseMatrix.h:65
void * internalMatrix
Abstract pointer to the internal matrix object.
Definition: SparseMatrix.h:463
SparseMatrixT< T > & operator=(const SparseMatrixT< T > &matrix)
Assign operator.
SparseMatrixT()
Creates an empty sparse matrix object.
size_t columns() const
Returns the number of columns this matrix has.
void setEntries(const Entries &entries)
(Re-)sets the non-zero entries of this sparse matrix.
bool solve(const MatrixT< T > &b, MatrixT< T > &x) const
Solves the given linear system.
bool operator==(const SparseMatrixT< T > &matrix) const
Returns whether this matrix is equal to an other one up to an epsilon value.
Definition: SparseMatrix.h:522
void transpose()
Transposes this matrix.
bool invertDiagonal()
Inverts this square diagonal matrix.
bool invertBlockDiagonal(const size_t size)
Inverts this square block diagonal matrix with size x size block size.
size_t rank() const
Computes the rank of this matrix.
SparseMatrixT(const size_t rows, const size_t columns, const size_t nonZeroElements)
Creates a new spare matrix with given dimensions.
SparseMatrixT< T > operator+(const SparseMatrixT< T > &matrix) const
Adds two sparse matrix objects and returns the matrix result.
SparseMatrixT< T > & operator*=(const SparseMatrixT< T > &matrix)
Multiplies a second sparse matrix object to this matrix object.
Definition: SparseMatrix.h:515
MatrixT< T > denseMatrix() const
Returns the dense matrix of this matrix.
SparseMatrixT< T > operator-(const SparseMatrixT< T > &matrix) const
Subtracts two sparse matrix objects and returns the matrix result.
MatrixT< T > diagonal() const
Returns a vector containing the values of the diagonal.
bool nonNegativeMatrixFactorization(MatrixT< T > &subcomponents, MatrixT< T > &weights, const unsigned int components=0u, const unsigned int iterations=100u, const T convergenceThreshold=T(0.0001)) const
Performs a non-negative matrix factorization with multiplicative update rules V = W * H,...
T & operator()(const size_t row, const size_t column)
Returns the reference to a specific element of the sparse matrix.
SparseMatrixT(const size_t rows, const size_t columns, const MatrixT< T > &diagonal, const bool forceNonZeros=false)
Creates a new sparse matrix with defined rows and columns and initializes the diagonal with small sub...
SparseMatrixT(SparseMatrixT< T > &&matrix) noexcept
Move constructor.
SparseMatrixT< T > transposed() const
Returns the transposes matrix of this matrix.
SparseMatrixT< T > & operator-=(const SparseMatrixT< T > &matrix)
Subtracts a second sparse matrix object from this matrix.
T operator()(const size_t row, const size_t column) const
Returns a specific element of the sparse matrix.
SparseMatrixT< T > & operator+=(const SparseMatrixT< T > &matrix)
Adds a second sparse matrix object to this matrix.
std::vector< SparseMatrix > SparseMatrices
Definition of a vector holding sparse matrix objects.
Definition: SparseMatrix.h:51
SparseMatrixT< Scalar > SparseMatrix
Definition of the SparseMatrix object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with s...
Definition: SparseMatrix.h:23
SparseMatrixT< double > SparseMatrixD
Instantiation of the SparseMatrixT template class using a double precision float data type.
Definition: SparseMatrix.h:37
SparseMatrixT< float > SparseMatrixF
Instantiation of the SparseMatrixT template class using a single precision float data type.
Definition: SparseMatrix.h:44
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15