2012-05-25 23:52:11 +08:00
namespace Eigen {
Big changes in Eigen documentation:
- Organize the documentation into "chapters".
- Each chapter include many documentation pages, reference pages organized as modules, and a quick reference page.
- The "Chapters" tree is created using the defgroup/ingroup mechanism, even for the documentation pages (i.e., .dox files for which I added an \eigenManualPage macro that we can switch between \page or \defgroup ).
- Add a "General topics" entry for all pages that do not fit well in the previous "chapters".
- The highlevel struture is managed by a new eigendoxy_layout.xml file.
- remove the "index" and quite useless pages (namespace list, class hierarchy, member list, file list, etc.)
- add the javascript search-engine.
- add the "treeview" panel.
- remove \tableofcontents (replace them by a custom \eigenAutoToc macro to be able to easily re-enable if needed).
- add javascript to automatically generate a TOC from the h1/h2 tags of the current page, and put the TOC in the left side panel.
- overload various javascript function generated by doxygen to:
- remove the root of the treeview
- remove links to section/subsection from the treeview
- automatically expand the "Chapters" section
- automatically expand the current section
- adjust the height of the treeview to take into account the TOC
- always use the default .css file, eigendoxy.css now only includes our modifications
- use Doxyfile to specify our logo
- remove cross references to unsupported modules (temporarily)
2013-01-05 23:37:11 +08:00
/** \eigenManualPage SparseQuickRefPage Quick reference guide for sparse matrices
\eigenAutoToc
2012-05-25 23:52:11 +08:00
<hr>
2013-03-05 19:55:03 +08:00
In this page, we give a quick summary of the main operations available for sparse matrices in the class SparseMatrix. First, it is recommended to read the introductory tutorial at \ref TutorialSparse. The important point to have in mind when working on sparse matrices is how they are stored :
i.e either row major or column major. The default is column major. Most arithmetic operations on sparse matrices will assert that they have the same storage order.
2012-05-25 23:52:11 +08:00
2013-03-05 19:55:03 +08:00
\section SparseMatrixInit Sparse Matrix Initialization
<table class="manual">
<tr><th> Category </th> <th> Operations</th> <th>Notes</th></tr>
<tr><td>Constructor</td>
<td>
2012-05-25 23:52:11 +08:00
\code
2013-03-05 19:55:03 +08:00
SparseMatrix<double> sm1(1000,1000);
SparseMatrix<std::complex<double>,RowMajor> sm2;
2012-05-25 23:52:11 +08:00
\endcode
2013-03-05 19:55:03 +08:00
</td> <td> Default is ColMajor</td> </tr>
<tr class="alt">
<td> Resize/Reserve</td>
<td>
\code
2016-02-03 23:08:43 +08:00
sm1.resize(m,n); // Change sm1 to a m x n matrix.
2013-03-05 19:55:03 +08:00
sm1.reserve(nnz); // Allocate room for nnz nonzeros elements.
\endcode
</td>
<td> Note that when calling reserve(), it is not required that nnz is the exact number of nonzero elements in the final matrix. However, an exact estimation will avoid multiple reallocations during the insertion phase. </td>
</tr>
<tr>
<td> Assignment </td>
<td>
2012-05-25 23:52:11 +08:00
\code
SparseMatrix<double,Colmajor> sm1;
2013-03-05 19:55:03 +08:00
// Initialize sm2 with sm1.
SparseMatrix<double,Rowmajor> sm2(sm1), sm3;
// Assignment and evaluations modify the storage order.
sm3 = sm1;
2012-05-25 23:52:11 +08:00
\endcode
2013-03-05 19:55:03 +08:00
</td>
<td> The copy constructor can be used to convert from a storage order to another</td>
</tr>
<tr class="alt">
<td> Element-wise Insertion</td>
<td>
2012-05-25 23:52:11 +08:00
\code
2013-03-05 19:55:03 +08:00
// Insert a new element;
sm1.insert(i, j) = v_ij;
2012-05-25 23:52:11 +08:00
2013-03-05 19:55:03 +08:00
// Update the value v_ij
sm1.coeffRef(i,j) = v_ij;
sm1.coeffRef(i,j) += v_ij;
sm1.coeffRef(i,j) -= v_ij;
2012-05-25 23:52:11 +08:00
\endcode
2013-03-05 19:55:03 +08:00
</td>
<td> insert() assumes that the element does not already exist; otherwise, use coeffRef()</td>
</tr>
<tr>
<td> Batch insertion</td>
<td>
2012-05-25 23:52:11 +08:00
\code
2013-03-05 19:55:03 +08:00
std::vector< Eigen::Triplet<double> > tripletList;
tripletList.reserve(estimation_of_entries);
// -- Fill tripletList with nonzero elements...
2012-05-25 23:52:11 +08:00
sm1.setFromTriplets(TripletList.begin(), TripletList.end());
\endcode
2013-03-05 19:55:03 +08:00
</td>
<td>A complete example is available at \link TutorialSparseFilling Triplet Insertion \endlink.</td>
</tr>
<tr class="alt">
<td> Constant or Random Insertion</td>
<td>
2012-05-25 23:52:11 +08:00
\code
2015-01-15 05:06:09 +08:00
sm1.setZero();
2012-05-25 23:52:11 +08:00
\endcode
2013-03-05 19:55:03 +08:00
</td>
2015-01-15 05:06:09 +08:00
<td>Remove all non-zero coefficients</td>
2013-03-05 19:55:03 +08:00
</tr>
</table>
2012-05-25 23:52:11 +08:00
\section SparseBasicInfos Matrix properties
2013-03-05 19:55:03 +08:00
Beyond the basic functions rows() and cols(), there are some useful functions that are available to easily get some informations from the matrix.
2012-05-25 23:52:11 +08:00
<table class="manual">
<tr>
<td> \code
sm1.rows(); // Number of rows
sm1.cols(); // Number of columns
sm1.nonZeros(); // Number of non zero values
sm1.outerSize(); // Number of columns (resp. rows) for a column major (resp. row major )
sm1.innerSize(); // Number of rows (resp. columns) for a row major (resp. column major)
2013-03-05 19:55:03 +08:00
sm1.norm(); // Euclidian norm of the matrix
sm1.squaredNorm(); // Squared norm of the matrix
sm1.blueNorm();
2012-05-25 23:52:11 +08:00
sm1.isVector(); // Check if sm1 is a sparse vector or a sparse matrix
2013-03-05 19:55:03 +08:00
sm1.isCompressed(); // Check if sm1 is in compressed form
2012-05-25 23:52:11 +08:00
...
\endcode </td>
</tr>
</table>
\section SparseBasicOps Arithmetic operations
2013-03-05 19:55:03 +08:00
It is easy to perform arithmetic operations on sparse matrices provided that the dimensions are adequate and that the matrices have the same storage order. Note that the evaluation can always be done in a matrix with a different storage order. In the following, \b sm denotes a sparse matrix, \b dm a dense matrix and \b dv a dense vector.
2012-05-25 23:52:11 +08:00
<table class="manual">
<tr><th> Operations </th> <th> Code </th> <th> Notes </th></tr>
<tr>
<td> add subtract </td>
<td> \code
sm3 = sm1 + sm2;
sm3 = sm1 - sm2;
sm2 += sm1;
sm2 -= sm1; \endcode
</td>
<td>
sm1 and sm2 should have the same storage order
</td>
</tr>
<tr class="alt"><td>
scalar product</td><td>\code
sm3 = sm1 * s1; sm3 *= s1;
sm3 = s1 * sm1 + s2 * sm2; sm3 /= s1;\endcode
</td>
<td>
Many combinations are possible if the dimensions and the storage order agree.
</tr>
<tr>
2013-03-05 19:55:03 +08:00
<td> %Sparse %Product </td>
2012-05-25 23:52:11 +08:00
<td> \code
sm3 = sm1 * sm2;
dm2 = sm1 * dm1;
dv2 = sm1 * dv1;
\endcode </td>
<td>
</td>
</tr>
<tr class='alt'>
<td> transposition, adjoint</td>
<td> \code
sm2 = sm1.transpose();
sm2 = sm1.adjoint();
\endcode </td>
<td>
Note that the transposition change the storage order. There is no support for transposeInPlace().
</td>
</tr>
2013-03-05 19:55:03 +08:00
<tr>
<td> Permutation </td>
<td>
\code
2016-02-03 23:08:43 +08:00
perm.indices(); // Reference to the vector of indices
2013-03-05 19:55:03 +08:00
sm1.twistedBy(perm); // Permute rows and columns
2016-02-03 23:08:43 +08:00
sm2 = sm1 * perm; // Permute the columns
sm2 = perm * sm1; // Permute the columns
2013-03-05 19:55:03 +08:00
\endcode
</td>
<td>
</td>
</tr>
2012-05-25 23:52:11 +08:00
<tr>
<td>
Component-wise ops
</td>
<td>\code
sm1.cwiseProduct(sm2);
sm1.cwiseQuotient(sm2);
sm1.cwiseMin(sm2);
sm1.cwiseMax(sm2);
sm1.cwiseAbs();
sm1.cwiseSqrt();
\endcode</td>
<td>
sm1 and sm2 should have the same storage order
</td>
</tr>
</table>
2013-03-05 19:55:03 +08:00
\section sparseotherops Other supported operations
<table class="manual">
2016-02-03 23:08:43 +08:00
<tr><th style="min-width:initial"> Code </th> <th> Notes</th> </tr>
<tr><td colspan="2">Sub-matrices</td></tr>
2013-03-05 19:55:03 +08:00
<tr>
<td>
\code
sm1.block(startRow, startCol, rows, cols);
sm1.block(startRow, startCol);
sm1.topLeftCorner(rows, cols);
sm1.topRightCorner(rows, cols);
sm1.bottomLeftCorner( rows, cols);
sm1.bottomRightCorner( rows, cols);
\endcode
2016-02-03 23:08:43 +08:00
</td><td>
Contrary to dense matrices, here <strong>all these methods are read-only</strong>.\n
See \ref TutorialSparse_SubMatrices and below for read-write sub-matrices.
</td>
2013-03-05 19:55:03 +08:00
</tr>
2016-02-03 23:08:43 +08:00
<tr class="alt"><td colspan="2"> Range </td></tr>
<tr class="alt">
2013-03-05 19:55:03 +08:00
<td>
\code
2016-02-03 23:08:43 +08:00
sm1.innerVector(outer); // RW
sm1.innerVectors(start, size); // RW
sm1.leftCols(size); // RW
sm2.rightCols(size); // RO because sm2 is row-major
sm1.middleRows(start, numRows); // RO becasue sm1 is column-major
sm1.middleCols(start, numCols); // RW
sm1.col(j); // RW
2013-03-05 19:55:03 +08:00
\endcode
</td>
2016-02-03 23:08:43 +08:00
<td>
A inner vector is either a row (for row-major) or a column (for column-major).\n
As stated earlier, for a read-write sub-matrix (RW), the evaluation can be done in a matrix with different storage order.
</td>
2013-03-05 19:55:03 +08:00
</tr>
2016-02-03 23:08:43 +08:00
<tr><td colspan="2"> Triangular and selfadjoint views</td></tr>
2013-03-05 19:55:03 +08:00
<tr>
<td>
2012-05-25 23:52:11 +08:00
\code
2013-03-05 19:55:03 +08:00
sm2 = sm1.triangularview<Lower>();
sm2 = sm1.selfadjointview<Lower>();
2012-05-25 23:52:11 +08:00
\endcode
2013-03-05 19:55:03 +08:00
</td>
<td> Several combination between triangular views and blocks views are possible
\code
\endcode </td>
</tr>
2016-02-03 23:08:43 +08:00
<tr class="alt"><td colspan="2">Triangular solve </td></tr>
<tr class="alt">
2013-03-05 19:55:03 +08:00
<td>
\code
dv2 = sm1.triangularView<Upper>().solve(dv1);
2016-02-03 23:08:43 +08:00
dv2 = sm1.topLeftCorner(size, size)
.triangularView<Lower>().solve(dv1);
2013-03-05 19:55:03 +08:00
\endcode
</td>
<td> For general sparse solve, Use any suitable module described at \ref TopicSparseSystems </td>
</tr>
2016-02-03 23:08:43 +08:00
<tr><td colspan="2"> Low-level API</td></tr>
2013-03-05 19:55:03 +08:00
<tr>
<td>
\code
2016-02-03 23:08:43 +08:00
sm1.valuePtr(); // Pointer to the values
sm1.innerIndextr(); // Pointer to the indices.
sm1.outerIndexPtr(); // Pointer to the beginning of each inner vector
2013-03-05 19:55:03 +08:00
\endcode
</td>
2016-02-03 23:08:43 +08:00
<td>
If the matrix is not in compressed form, makeCompressed() should be called before.\n
Note that these functions are mostly provided for interoperability purposes with external libraries.\n
A better access to the values of the matrix is done by using the InnerIterator class as described in \link TutorialSparse the Tutorial Sparse \endlink section</td>
2013-03-05 19:55:03 +08:00
</tr>
</table>
2012-05-25 23:52:11 +08:00
*/
2012-06-20 15:28:32 +08:00
}