Operations | Code | Notes |
add subtract |
\code
sm3 = sm1 + sm2;
sm3 = sm1 - sm2;
sm2 += sm1;
sm2 -= sm1; \endcode
|
sm1 and sm2 should have the same storage order
|
scalar product | \code
sm3 = sm1 * s1; sm3 *= s1;
sm3 = s1 * sm1 + s2 * sm2; sm3 /= s1;\endcode
|
Many combinations are possible if the dimensions and the storage order agree.
|
Product |
\code
sm3 = sm1 * sm2;
dm2 = sm1 * dm1;
dv2 = sm1 * dv1;
\endcode |
|
transposition, adjoint |
\code
sm2 = sm1.transpose();
sm2 = sm1.adjoint();
\endcode |
Note that the transposition change the storage order. There is no support for transposeInPlace().
|
Component-wise ops
|
\code
sm1.cwiseProduct(sm2);
sm1.cwiseQuotient(sm2);
sm1.cwiseMin(sm2);
sm1.cwiseMax(sm2);
sm1.cwiseAbs();
sm1.cwiseSqrt();
\endcode |
sm1 and sm2 should have the same storage order
|
\section SparseInterops Low-level storage
There are a set of low-levels functions to get the standard compressed storage pointers. The matrix should be in compressed mode which can be checked by calling isCompressed(); makeCompressed() should do the job otherwise.
\code
// Scalar pointer to the values of the matrix, size nnz
sm1.valuePtr();
// Index pointer to get the row indices (resp. column indices) for column major (resp. row major) matrix, size nnz
sm1.innerIndexPtr();
// Index pointer to the beginning of each row (resp. column) in valuePtr() and innerIndexPtr() for column major (row major). The size is outersize()+1;
sm1.outerIndexPtr();
\endcode
These pointers can therefore be easily used to send the matrix to some external libraries/solvers that are not yet supported by Eigen.
\section sparsepermutation Permutations, submatrices and Selfadjoint Views
In many cases, it is necessary to reorder the rows and/or the columns of the sparse matrix for several purposes : fill-in reducing during matrix decomposition, better data locality for sparse matrix-vector products... The class PermutationMatrix is available to this end.
\code
PermutationMatrix