    

 ## On this page

  

 

 # SymSparseMatrix Class Reference

 Last update: 16.07.2025 

Symmetric sparse matrix class with selfadjoint storage. [More...](class_sym_sparse_matrix.xhtml#details)

## <a name="pub-types"></a>Public Types

<a id="a1b5357921e32b1f6d262754172689b02"></a>typedef Eigen::SparseMatrix&lt; [TScalar](class_sym_sparse_matrix.xhtml#ad33f729eda6e45412aac71cee702012f) &gt; [Base](class_sym_sparse_matrix.xhtml#a1b5357921e32b1f6d262754172689b02) the underlying Eigen sparse matrix type   
 enum [some\_enums](class_sym_sparse_matrix.xhtml#ac260c934c749111f08dbbd4f34fa6b31) { [EIGENFLAGS](class_sym_sparse_matrix.xhtml#ac260c934c749111f08dbbd4f34fa6b31aa3a6b8ca43e2cc4066bcd713dce45946) = Eigen::ColMajor|Eigen::SelfAdjoint|Eigen::Lower, [EIGENSYM](class_sym_sparse_matrix.xhtml#ac260c934c749111f08dbbd4f34fa6b31a8951c38e5eb664af9398881f9a4929c7) = Eigen::Lower } defines Eigen flags to be used for modfying Eigen's algebra operators [More...](class_sym_sparse_matrix.xhtml#ac260c934c749111f08dbbd4f34fa6b31)  
 <a id="a353dbc81e718cd4640b7c719b512892f"></a>typedef Base::Index [TEigenIndex](class_sym_sparse_matrix.xhtml#a353dbc81e718cd4640b7c719b512892f) index type for Eigen matrices   
 <a id="ad33f729eda6e45412aac71cee702012f"></a>typedef number [TScalar](class_sym_sparse_matrix.xhtml#ad33f729eda6e45412aac71cee702012f) the data type of the coefficients (real number)   
 <a id="ab423d248b103558b5903c702c13335ae"></a>typedef number [TUnsignedIndex](class_sym_sparse_matrix.xhtml#ab423d248b103558b5903c702c13335ae) an unsigned index type   
 ## <a name="pub-methods"></a>Public Member Functions

[SymSparseMatrix](class_sym_sparse_matrix.xhtml) [\_\_neg\_\_](class_sym_sparse_matrix.xhtml#a84632b22bf5fafc23544ac244ed7cf4c) () const char \* [\_\_str\_\_](class_sym_sparse_matrix.xhtml#adb0255d0035cd7783ce87f41a3cae5cc) () transforms this objects into a string, required by SWIG [More...](#adb0255d0035cd7783ce87f41a3cae5cc)  
  [Assign](class_sym_sparse_matrix.xhtml#a18041cdb9f56d534e804a8663a42f96f) ([SymSparseMatrix](class_sym_sparse_matrix.xhtml) other, bool keep\_data=true) assigns a new matrix to this object [More...](#a18041cdb9f56d534e804a8663a42f96f)  
 [Base](class_sym_sparse_matrix.xhtml#a1b5357921e32b1f6d262754172689b02) [cast](class_sym_sparse_matrix.xhtml#a3ecd74799c1d759b4b637bde5924e0f6) () const [TUnsignedIndex](class_sym_sparse_matrix.xhtml#ab423d248b103558b5903c702c13335ae) [Cols](class_sym_sparse_matrix.xhtml#a2ec082b93696e449a0eb430f1f00196e) () [TUnsignedIndex](class_sym_sparse_matrix.xhtml#ab423d248b103558b5903c702c13335ae) [InnerSize](class_sym_sparse_matrix.xhtml#a9c5c5e3890bd6be32b732fa324ca0954) () [TUnsignedIndex](class_sym_sparse_matrix.xhtml#ab423d248b103558b5903c702c13335ae) [NonZeros](class_sym_sparse_matrix.xhtml#ac83d198cac5c9247233b7024b3f2742a) () [Matrix](class_matrix.xhtml) [operator\*](class_sym_sparse_matrix.xhtml#ac20eea8e7bdf72e549208fcb4ad002f9) ([Matrix](class_matrix.xhtml) x) const [Matrix](class_matrix.xhtml) [operator\*](class_sym_sparse_matrix.xhtml#ab20c65b6af96b99b1154078d249d8e38) ([MatrixBlock](class_matrix_block.xhtml) x) const sparse::SparseMatrix [operator\*](class_sym_sparse_matrix.xhtml#ace104707c6359044a60cfbe690450f0a) ([SymSparseMatrix](class_sym_sparse_matrix.xhtml) x) const [SymSparseMatrix](class_sym_sparse_matrix.xhtml) [operator\*](class_sym_sparse_matrix.xhtml#a28f7f66cb52fb2c2f35c4a7bd7ed62bb) (number x) const [SymSparseMatrix](class_sym_sparse_matrix.xhtml) [operator+](class_sym_sparse_matrix.xhtml#ac0c3dd32cb15da921dfec8981f7f4cb4) ([SymSparseMatrix](class_sym_sparse_matrix.xhtml) x) const [SymSparseMatrix](class_sym_sparse_matrix.xhtml) [operator-](class_sym_sparse_matrix.xhtml#a34b2b4995ec1686198c90c538d0582d0) ([SymSparseMatrix](class_sym_sparse_matrix.xhtml) x) const [SymSparseMatrix](class_sym_sparse_matrix.xhtml) [operator/](class_sym_sparse_matrix.xhtml#aaf4f97c6a5b85f197dafa600d32fc0dd) (number x) const [TUnsignedIndex](class_sym_sparse_matrix.xhtml#ab423d248b103558b5903c702c13335ae) [OuterSize](class_sym_sparse_matrix.xhtml#ac8a32a382f45637a59b805a83a1399e0) ()  [Print](class_sym_sparse_matrix.xhtml#a6a84471f08e9842cce4e162251b007fd) (string format="%g ", TUnsignedIndex rows=20, [TUnsignedIndex](class_sym_sparse_matrix.xhtml#ab423d248b103558b5903c702c13335ae) cols=20) const  [Prune](class_sym_sparse_matrix.xhtml#a611c0976718f1af2c5a0ee6a0f5e34a0) ([TScalar](class_sym_sparse_matrix.xhtml#ad33f729eda6e45412aac71cee702012f) reference) sets all elements with absolute value &lt;= reference to zero and removes from storage [More...](#a611c0976718f1af2c5a0ee6a0f5e34a0)  
  [Prune](class_sym_sparse_matrix.xhtml#a95e65c4fd2e14633c28dc24b75811ef7) ([TScalar](class_sym_sparse_matrix.xhtml#ad33f729eda6e45412aac71cee702012f) reference, [TScalar](class_sym_sparse_matrix.xhtml#ad33f729eda6e45412aac71cee702012f) epsilon) sets all elements with absolute value &lt;= reference\*epsilon to zero and removes from storage [More...](#a95e65c4fd2e14633c28dc24b75811ef7)  
 [TUnsignedIndex](class_sym_sparse_matrix.xhtml#ab423d248b103558b5903c702c13335ae) [Rows](class_sym_sparse_matrix.xhtml#a3c3320817fc198207404606c52e47fa3) () <a id="a82fdaa2aa8c930c663007796e9aaa03f"></a> [SetZero](class_sym_sparse_matrix.xhtml#a82fdaa2aa8c930c663007796e9aaa03f) () sets the object to zero (clears it)   
  [Swap](class_sym_sparse_matrix.xhtml#afd25d9b25754a820a98a56f5de06f799) ([SymSparseMatrix](class_sym_sparse_matrix.xhtml) other) swaps the contents of this object [More...](#afd25d9b25754a820a98a56f5de06f799)  
  [SymSparseMatrix](class_sym_sparse_matrix.xhtml#a15b046fc5367041a7f1d20a651404efe) ([SymSparseMatrix](class_sym_sparse_matrix.xhtml) ar, bool keep\_data=true) destructor [More...](#a15b046fc5367041a7f1d20a651404efe)  
  [SymSparseMatrix](class_sym_sparse_matrix.xhtml#a61ea47d9c774e26f36e076d140804575) ([SymSparseMatrix](class_sym_sparse_matrix.xhtml) ar) copy constructor [More...](#a61ea47d9c774e26f36e076d140804575)  
  [SymSparseMatrix](class_sym_sparse_matrix.xhtml#a7130f007f96ca68ce125aceb84e7ecf2) (sparse::SparseMatrix ar, bool keep\_data=true) copy constructor [More...](#a7130f007f96ca68ce125aceb84e7ecf2)  
 [SymSparseMatrix](class_sym_sparse_matrix.xhtml) [Transpose](class_sym_sparse_matrix.xhtml#afb5bc09a448327c9bf87f011d8715303) () <a id="details" name="details"></a>## Detailed Description

Symmetric sparse matrix class with selfadjoint storage.

This class represents a symmetric sparse matrix. Only the lower triangular part and the diagonal are stored. The upper triangular part is "emulated".



## Member Enumeration Documentation

<a id="ac260c934c749111f08dbbd4f34fa6b31"></a>## [◆ ](#ac260c934c749111f08dbbd4f34fa6b31)some\_enums

 enum [some\_enums](class_sym_sparse_matrix.xhtml#ac260c934c749111f08dbbd4f34fa6b31)

defines Eigen flags to be used for modfying Eigen's algebra operators

Enumerator<a id="ac260c934c749111f08dbbd4f34fa6b31aa3a6b8ca43e2cc4066bcd713dce45946"></a>EIGENFLAGS column major, symmetric, lower triangular

<a id="ac260c934c749111f08dbbd4f34fa6b31a8951c38e5eb664af9398881f9a4929c7"></a>EIGENSYM lower triangular





## Constructor &amp; Destructor Documentation

<a id="a15b046fc5367041a7f1d20a651404efe"></a>## [◆ ](#a15b046fc5367041a7f1d20a651404efe)SymSparseMatrix() \[1/3\]

 [SymSparseMatrix](class_sym_sparse_matrix.xhtml)  ( [SymSparseMatrix](class_sym_sparse_matrix.xhtml)  *ar*,    bool  *keep\_data* = `true`   ) 

destructor

copy constructor

Parameters arthe source matrix keep\_dataif true, this is a copy constructor. If false, the source matrix will be empty afterwards 



<a id="a61ea47d9c774e26f36e076d140804575"></a>## [◆ ](#a61ea47d9c774e26f36e076d140804575)SymSparseMatrix() \[2/3\]

 [SymSparseMatrix](class_sym_sparse_matrix.xhtml)  ( [SymSparseMatrix](class_sym_sparse_matrix.xhtml)  *ar*) 

copy constructor

Parameters arthe source matrix 



<a id="a7130f007f96ca68ce125aceb84e7ecf2"></a>## [◆ ](#a7130f007f96ca68ce125aceb84e7ecf2)SymSparseMatrix() \[3/3\]

 [SymSparseMatrix](class_sym_sparse_matrix.xhtml)  ( sparse::SparseMatrix  *ar*,    bool  *keep\_data* = `true`   ) 

copy constructor

Parameters arthe source matrix keep\_dataif true, this is a copy constructor. If false, the source matrix will be empty afterwards 



## Member Function Documentation

<a id="a84632b22bf5fafc23544ac244ed7cf4c"></a>## [◆ ](#a84632b22bf5fafc23544ac244ed7cf4c)\_\_neg\_\_()

 [SymSparseMatrix](class_sym_sparse_matrix.xhtml) \_\_neg\_\_  ( )  const

Returnsreturns the unary minus (i.e. B = -A = -(\*this)) of this matric 



<a id="adb0255d0035cd7783ce87f41a3cae5cc"></a>## [◆ ](#adb0255d0035cd7783ce87f41a3cae5cc)\_\_str\_\_()

 char\* \_\_str\_\_  ( ) 

transforms this objects into a string, required by SWIG

Returnsa 0-terminated string 



<a id="a18041cdb9f56d534e804a8663a42f96f"></a>## [◆ ](#a18041cdb9f56d534e804a8663a42f96f)Assign()

 Assign  ( [SymSparseMatrix](class_sym_sparse_matrix.xhtml)  *other*,    bool  *keep\_data* = `true`   ) 

assigns a new matrix to this object

Parameters otherthe other sparse matrix keep\_dataif false, then the other matrix will be cleared 



<a id="a3ecd74799c1d759b4b637bde5924e0f6"></a>## [◆ ](#a3ecd74799c1d759b4b637bde5924e0f6)cast()

 [Base](class_sym_sparse_matrix.xhtml#a1b5357921e32b1f6d262754172689b02) cast  ( )  const

Returnsa reference to this object, casted to the base class 



<a id="a2ec082b93696e449a0eb430f1f00196e"></a>## [◆ ](#a2ec082b93696e449a0eb430f1f00196e)Cols()

 [TUnsignedIndex](class_sym_sparse_matrix.xhtml#ab423d248b103558b5903c702c13335ae) Cols  ( ) 

Returnsthe number of columns 



<a id="a9c5c5e3890bd6be32b732fa324ca0954"></a>## [◆ ](#a9c5c5e3890bd6be32b732fa324ca0954)InnerSize()

 [TUnsignedIndex](class_sym_sparse_matrix.xhtml#ab423d248b103558b5903c702c13335ae) InnerSize  ( ) 

Returnsthe number of inner elements 



<a id="ac83d198cac5c9247233b7024b3f2742a"></a>## [◆ ](#ac83d198cac5c9247233b7024b3f2742a)NonZeros()

 [TUnsignedIndex](class_sym_sparse_matrix.xhtml#ab423d248b103558b5903c702c13335ae) NonZeros  ( ) 

Returnsthe number of nonzeros 



<a id="ac20eea8e7bdf72e549208fcb4ad002f9"></a>## [◆ ](#ac20eea8e7bdf72e549208fcb4ad002f9)operator\*() \[1/4\]

 [Matrix](class_matrix.xhtml) operator\*  ( [Matrix](class_matrix.xhtml)  *x*)  const

overrides the sparsematrix-densematrix product.

Returnsreturns the product of \*this and another dense matrix Parameters xthe other dense matrix 



<a id="ab20c65b6af96b99b1154078d249d8e38"></a>## [◆ ](#ab20c65b6af96b99b1154078d249d8e38)operator\*() \[2/4\]

 [Matrix](class_matrix.xhtml) operator\*  ( [MatrixBlock](class_matrix_block.xhtml)  *x*)  const

Returnsreturns the product of \*this and another dense matrix Parameters xthe other dense matrix 



<a id="ace104707c6359044a60cfbe690450f0a"></a>## [◆ ](#ace104707c6359044a60cfbe690450f0a)operator\*() \[3/4\]

 sparse::SparseMatrix operator\*  ( [SymSparseMatrix](class_sym_sparse_matrix.xhtml)  *x*)  const

Returns[SparseMatrix](class_sparse_matrix.xhtml "encapsulates sparse matrix classes and algorithms ") returns the product of \*this and another symmetric sparse matrix Parameters xthe other sparse matrix 



<a id="a28f7f66cb52fb2c2f35c4a7bd7ed62bb"></a>## [◆ ](#a28f7f66cb52fb2c2f35c4a7bd7ed62bb)operator\*() \[4/4\]

 [SymSparseMatrix](class_sym_sparse_matrix.xhtml) operator\*  ( number  *x*)  const

Returnsreturns the product of \*this and a scalar Parameters xthe other scalar 



<a id="ac0c3dd32cb15da921dfec8981f7f4cb4"></a>## [◆ ](#ac0c3dd32cb15da921dfec8981f7f4cb4)operator+()

 [SymSparseMatrix](class_sym_sparse_matrix.xhtml) operator+  ( [SymSparseMatrix](class_sym_sparse_matrix.xhtml)  *x*)  const

Returnsreturns the sum of two sparse matrices Parameters xthe other matrix 



<a id="a34b2b4995ec1686198c90c538d0582d0"></a>## [◆ ](#a34b2b4995ec1686198c90c538d0582d0)operator-()

 [SymSparseMatrix](class_sym_sparse_matrix.xhtml) operator-  ( [SymSparseMatrix](class_sym_sparse_matrix.xhtml)  *x*)  const

Returnsreturns the subtraction of two sparse matrices Parameters xthe other matrix 



<a id="aaf4f97c6a5b85f197dafa600d32fc0dd"></a>## [◆ ](#aaf4f97c6a5b85f197dafa600d32fc0dd)operator/()

 [SymSparseMatrix](class_sym_sparse_matrix.xhtml) operator/  ( number  *x*)  const

Returnsreturns the division of \*this by a scalar Parameters xthe other sparse matrix 



<a id="ac8a32a382f45637a59b805a83a1399e0"></a>## [◆ ](#ac8a32a382f45637a59b805a83a1399e0)OuterSize()

 [TUnsignedIndex](class_sym_sparse_matrix.xhtml#ab423d248b103558b5903c702c13335ae) OuterSize  ( ) 

Returnsthe number of sparse column vectors 



<a id="a6a84471f08e9842cce4e162251b007fd"></a>## [◆ ](#a6a84471f08e9842cce4e162251b007fd)Print()

 Print  ( string  *format* = `"%g "`,    [TUnsignedIndex](class_sym_sparse_matrix.xhtml#ab423d248b103558b5903c702c13335ae)  *rows* = `20`,    [TUnsignedIndex](class_sym_sparse_matrix.xhtml#ab423d248b103558b5903c702c13335ae)  *cols* = `20`   )  const

prints the sparse matrix up to the given rows and columns (internally a temporary dense matrix will be created)

Parameters formatthe format of a single element, see *printf* for details rowsonly print the first *rows* rows colsonly print the first *cols* columns 



<a id="a611c0976718f1af2c5a0ee6a0f5e34a0"></a>## [◆ ](#a611c0976718f1af2c5a0ee6a0f5e34a0)Prune() \[1/2\]

 Prune  ( [TScalar](class_sym_sparse_matrix.xhtml#ad33f729eda6e45412aac71cee702012f)  *reference*) 

sets all elements with absolute value &lt;= reference to zero and removes from storage

Parameters referencethe reference value (tolerance) 



<a id="a95e65c4fd2e14633c28dc24b75811ef7"></a>## [◆ ](#a95e65c4fd2e14633c28dc24b75811ef7)Prune() \[2/2\]

 Prune  ( [TScalar](class_sym_sparse_matrix.xhtml#ad33f729eda6e45412aac71cee702012f)  *reference*,    [TScalar](class_sym_sparse_matrix.xhtml#ad33f729eda6e45412aac71cee702012f)  *epsilon*   ) 

sets all elements with absolute value &lt;= reference\*epsilon to zero and removes from storage

Parameters referencethe reference value epsilonepsilon 



<a id="a3c3320817fc198207404606c52e47fa3"></a>## [◆ ](#a3c3320817fc198207404606c52e47fa3)Rows()

 [TUnsignedIndex](class_sym_sparse_matrix.xhtml#ab423d248b103558b5903c702c13335ae) Rows  ( ) 

Returnsthe number of rows 



<a id="afd25d9b25754a820a98a56f5de06f799"></a>## [◆ ](#afd25d9b25754a820a98a56f5de06f799)Swap()

 Swap  ( [SymSparseMatrix](class_sym_sparse_matrix.xhtml)  *other*) 

swaps the contents of this object

Parameters otherthe other object 



<a id="afb5bc09a448327c9bf87f011d8715303"></a>## [◆ ](#afb5bc09a448327c9bf87f011d8715303)Transpose()

 [SymSparseMatrix](class_sym_sparse_matrix.xhtml) Transpose  ( ) 

Returnsthe transpose