#include <itpp/base/smat.h>
Public Member Functions | |
Sparse_Mat () | |
Default constructor. | |
Sparse_Mat (int rows, int cols, int row_data_init=200) | |
Initiate an empty sparse matrix. | |
Sparse_Mat (const Sparse_Mat< T > &m) | |
Initiate a new sparse matrix. The elements of m are copied into the new sparse matrix. | |
Sparse_Mat (const Mat< T > &m) | |
Initiate a new sparse matrix from a dense matrix. The elements of m are copied into the new sparse matrix. | |
Sparse_Mat (const Mat< T > &m, T epsilon) | |
Initiate a new sparse matrix from a dense matrix. Elements of m larger than epsilon are copied into the new sparse matrix. | |
~Sparse_Mat () | |
Destructor. | |
void | set_size (int rows, int cols, int row_data_init=-1) |
Set the size of the sparse matrix. | |
int | rows () const |
Returns the number of rows of the sparse matrix. | |
int | cols () const |
Returns the number of columns of the sparse matrix. | |
int | nnz () |
The number of non-zero elements in the sparse matrix. | |
double | density () |
Returns the density of the sparse matrix: (number of non-zero elements)/(total number of elements). | |
void | compact () |
Set the maximum number of non-zero elements in each column equal to the actual number of non-zero elements in each column. | |
void | full (Mat< T > &m) const |
Returns a full, dense matrix in m . | |
Mat< T > | full () const |
Returns a full, dense matrix. | |
T | operator() (int r, int c) const |
Returns element of row r and column c . | |
void | set (int r, int c, T v) |
Set element (r , c ) equal to v . | |
void | set_new (int r, int c, T v) |
Set a new element with index (r , c ) equal to v . | |
void | add_elem (const int r, const int c, const T v) |
Add the element in row r and column c with v . | |
void | zeros () |
Set the sparse matrix to the all zero matrix (removes all non-zero elements). | |
void | zero_elem (const int r, const int c) |
Set the element in row r and column c to zero (i.e. clear that element if it contains a non-zero value). | |
void | clear () |
Clear all non-zero elements of the sparse matrix. | |
void | clear_elem (const int r, const int c) |
Clear the element in row r and column c (if it contains a non-zero value). | |
void | set_submatrix (int r1, int r2, int c1, int c2, const Mat< T > &m) |
Set submatrix defined by rows r1,r2 and columns c1,c2 to matrix m. | |
void | set_submatrix (int r, int c, const Mat< T > &m) |
Set submatrix defined by upper-left element (r ,c ) and the size of matrix m to m . | |
Sparse_Mat< T > | get_submatrix (int r1, int r2, int c1, int c2) const |
Returns the sub-matrix from rows r1 to r2 and columns c1 to c2 . | |
Sparse_Mat< T > | get_submatrix_cols (int c1, int c2) const |
Returns the sub-matrix from columns c1 to c2 (all rows). | |
void | get_col (int c, Sparse_Vec< T > &v) const |
Returns column c of the Sparse_Mat in the Sparse_Vec v . | |
Sparse_Vec< T > | get_col (int c) const |
Returns column c of the Sparse_Mat. | |
void | set_col (int c, const Sparse_Vec< T > &v) |
Set column c of the Sparse_Mat. | |
void | transpose (Sparse_Mat< T > &m) const |
Transpose the sparse matrix, return the result in m . | |
Sparse_Mat< T > | transpose () const |
Returns the transpose of the sparse matrix. | |
void | operator= (const Sparse_Mat< T > &m) |
Assign sparse matrix the value and dimensions of the sparse matrix m . | |
void | operator= (const Mat< T > &m) |
Assign sparse matrix the value and dimensions of the dense matrix m . | |
Sparse_Mat< T > | operator- () const |
Returns the sign inverse of all elements in the sparse matrix. | |
bool | operator== (const Sparse_Mat< T > &m) const |
Compare two sparse matricies. False if wrong sizes or different values. | |
void | operator+= (const Sparse_Mat< T > &v) |
Add sparse matrix v to all non-zero elements of the sparse matrix. | |
void | operator+= (const Mat< T > &v) |
Add matrix v to all non-zero elements of the sparse matrix. | |
void | operator-= (const Sparse_Mat< T > &v) |
Subtract sparse matrix v from all non-zero elements of the sparse matrix. | |
void | operator-= (const Mat< T > &v) |
Subtract matrix v from all non-zero elements of the sparse matrix. | |
void | operator *= (const T &v) |
Multiply all non-zero elements of the sparse matrix with the scalar v . | |
void | operator/= (const T &v) |
Divide all non-zero elements of the sparse matrix with the scalar v . | |
Friends | |
Sparse_Mat< T > | operator+ (const Sparse_Mat< T > &m1, const Sparse_Mat< T > &m2) |
Addition m1+m2 where m1 and m2 are sparse matrices. | |
Sparse_Mat< T > | operator * (const T &c, const Sparse_Mat< T > &m) |
Multiplication c*m where c is a scalar and m is a sparse matrix. | |
Sparse_Mat< T > | operator * (const Sparse_Mat< T > &m1, const Sparse_Mat< T > &m2) |
Multiplication m1*m2 where m1 and m2 are sparse matrices. | |
Sparse_Vec< T > | operator * (const Sparse_Mat< T > &m, const Sparse_Vec< T > &v) |
Multiplication m*v where m is a sparse matrix and v is a sparse vector. | |
Vec< T > | operator * (const Sparse_Mat< T > &m, const Vec< T > &v) |
Multiplication m*v where m is a sparse matrix and v is a full column vector. | |
Vec< T > | operator * (const Vec< T > &v, const Sparse_Mat< T > &m) |
Multiplication v'*m where m is a sparse matrix and v is a full column vector. | |
Mat< T > | trans_mult (const Sparse_Mat< T > &m) |
Multiplication m'*m where m is a sparse matrix. Returns a full, dense matrix. | |
Sparse_Mat< T > | trans_mult_s (const Sparse_Mat< T > &m) |
Multiplication m'*m where m is a sparse matrix, Returns a sparse matrix. | |
Sparse_Mat< T > | trans_mult (const Sparse_Mat< T > &m1, const Sparse_Mat< T > &m2) |
Multiplication m1'*m2 where m1 and m2 are sparse matrices. | |
Vec< T > | trans_mult (const Sparse_Mat< T > &m, const Vec< T > &v) |
Multiplication m'*v where m is a sparse matrix and v is a full column vector. | |
Sparse_Mat< T > | mult_trans (const Sparse_Mat< T > &m1, const Sparse_Mat< T > &m2) |
Multiplication m1*m2' where m1 and m2 are sparse matrices. | |
Related Functions | |
(Note that these are not member functions.) | |
typedef Sparse_Mat< int > | sparse_imat |
Sparse integer matrix. | |
typedef Sparse_Mat< double > | sparse_mat |
Sparse double matrix. | |
typedef Sparse_Mat< std::complex< double > > | sparse_cmat |
Sparse complex<double> matrix. |
A sparse matrix is a matrix where most elements are zero. The maximum number of non-zero elements in each column is a parameter to the constructor.
Definition at line 104 of file smat.h.
itpp::Sparse_Mat< T >::Sparse_Mat | ( | ) | [inline] |
itpp::Sparse_Mat< T >::Sparse_Mat | ( | int | rows, | |
int | cols, | |||
int | row_data_init = 200 | |||
) | [inline] |
Initiate an empty sparse matrix.
A Sparse_Mat consists of colums that have the type Sparse_Vec. The maximum number of non-zero elements is each column is denoted row_data_init
.
rows | Number of rows in the matrix | |
cols | Number of columns in the matrix | |
row_data_init | The maximum number of non-zero elements in each column (default value is 200) |
itpp::Sparse_Mat< T >::Sparse_Mat | ( | const Sparse_Mat< T > & | m | ) | [inline] |
Initiate a new sparse matrix. The elements of m
are copied into the new sparse matrix.
Definition at line 369 of file smat.h.
References itpp::Sparse_Mat< T >::col, itpp::Sparse_Mat< T >::n_cols, and itpp::Sparse_Mat< T >::n_rows.
itpp::Sparse_Mat< T >::Sparse_Mat | ( | const Mat< T > & | m | ) | [inline] |
Initiate a new sparse matrix from a dense matrix. The elements of m
are copied into the new sparse matrix.
Definition at line 381 of file smat.h.
References itpp::Mat< Num_T >::cols(), itpp::Mat< Num_T >::rows(), and itpp::Sparse_Mat< T >::set_new().
itpp::Sparse_Mat< T >::Sparse_Mat | ( | const Mat< T > & | m, | |
T | epsilon | |||
) | [inline] |
Initiate a new sparse matrix from a dense matrix. Elements of m
larger than epsilon
are copied into the new sparse matrix.
m
larger than abs(epsilon)
are copied into the new sparse matrix. Definition at line 399 of file smat.h.
References itpp::abs(), itpp::Mat< Num_T >::cols(), itpp::Mat< Num_T >::rows(), and itpp::Sparse_Mat< T >::set_new().
itpp::Sparse_Mat< T >::~Sparse_Mat | ( | ) | [inline] |
void itpp::Sparse_Mat< T >::set_size | ( | int | rows, | |
int | cols, | |||
int | row_data_init = -1 | |||
) | [inline] |
Set the size of the sparse matrix.
A Sparse_Mat consists of colums that have the type Sparse_Vec. The maximum number of non-zero elements is each column is denoted row_data_init
, with default value =-1 indicating that the number of data elements is not changed.
rows | Number of rows in the matrix | |
cols | Number of columns in the matrix | |
row_data_init | The maximum number of non-zero elements in each column (default value -1 => allocated size for the data is not changed) |
Definition at line 422 of file smat.h.
Referenced by itpp::Sparse_Mat< T >::transpose().
int itpp::Sparse_Mat< T >::rows | ( | ) | const [inline] |
Returns the number of rows of the sparse matrix.
Definition at line 151 of file smat.h.
Referenced by itpp::GF2mat::GF2mat(), itpp::Sparse_Mat< T >::operator+=(), and itpp::Sparse_Mat< T >::operator-=().
int itpp::Sparse_Mat< T >::cols | ( | ) | const [inline] |
Returns the number of columns of the sparse matrix.
Definition at line 154 of file smat.h.
Referenced by itpp::GF2mat::GF2mat(), itpp::Sparse_Mat< T >::operator+=(), and itpp::Sparse_Mat< T >::operator-=().
int itpp::Sparse_Mat< T >::nnz | ( | ) | [inline] |
The number of non-zero elements in the sparse matrix.
Definition at line 435 of file smat.h.
Referenced by itpp::Sparse_Mat< T >::density().
double itpp::Sparse_Mat< T >::density | ( | ) | [inline] |
Returns the density of the sparse matrix: (number of non-zero elements)/(total number of elements).
Definition at line 445 of file smat.h.
References itpp::Sparse_Mat< T >::nnz().
void itpp::Sparse_Mat< T >::compact | ( | ) | [inline] |
Set the maximum number of non-zero elements in each column equal to the actual number of non-zero elements in each column.
Definition at line 452 of file smat.h.
Referenced by itpp::Sparse_Mat< T >::get_submatrix(), itpp::Sparse_Mat< T >::get_submatrix_cols(), and itpp::operator *().
void itpp::Sparse_Mat< T >::full | ( | Mat< T > & | m | ) | const [inline] |
Returns a full, dense matrix in m
.
Definition at line 459 of file smat.h.
References itpp::Mat< Num_T >::set_size().
Referenced by itpp::full().
Mat< T > itpp::Sparse_Mat< T >::full | ( | ) | const [inline] |
T itpp::Sparse_Mat< T >::operator() | ( | int | r, | |
int | c | |||
) | const [inline] |
Returns element of row r
and column c
.
Definition at line 478 of file smat.h.
References it_assert0.
void itpp::Sparse_Mat< T >::set | ( | int | r, | |
int | c, | |||
T | v | |||
) | [inline] |
Set element (r
, c
) equal to v
.
Definition at line 485 of file smat.h.
References it_assert0.
Referenced by itpp::GF2mat::sparsify().
void itpp::Sparse_Mat< T >::set_new | ( | int | r, | |
int | c, | |||
T | v | |||
) | [inline] |
Set a new element with index (r
, c
) equal to v
.
Definition at line 492 of file smat.h.
References it_assert0.
Referenced by itpp::operator *(), itpp::Sparse_Mat< T >::operator=(), and itpp::Sparse_Mat< T >::Sparse_Mat().
void itpp::Sparse_Mat< T >::add_elem | ( | const int | r, | |
const int | c, | |||
const T | v | |||
) | [inline] |
Add the element in row r
and column c
with v
.
Definition at line 499 of file smat.h.
References it_assert0.
void itpp::Sparse_Mat< T >::zeros | ( | ) | [inline] |
void itpp::Sparse_Mat< T >::zero_elem | ( | const int | r, | |
const int | c | |||
) | [inline] |
Set the element in row r
and column c
to zero (i.e. clear that element if it contains a non-zero value).
Definition at line 513 of file smat.h.
References it_assert0.
void itpp::Sparse_Mat< T >::clear | ( | ) | [inline] |
void itpp::Sparse_Mat< T >::clear_elem | ( | const int | r, | |
const int | c | |||
) | [inline] |
Clear the element in row r
and column c
(if it contains a non-zero value).
Definition at line 527 of file smat.h.
References it_assert0.
void itpp::Sparse_Mat< T >::set_submatrix | ( | int | r1, | |
int | r2, | |||
int | c1, | |||
int | c2, | |||
const Mat< T > & | m | |||
) | [inline] |
Set submatrix defined by rows r1,r2 and columns c1,c2 to matrix m.
Definition at line 534 of file smat.h.
References itpp::Mat< Num_T >::cols(), it_assert1, and itpp::Mat< Num_T >::rows().
void itpp::Sparse_Mat< T >::set_submatrix | ( | int | r, | |
int | c, | |||
const Mat< T > & | m | |||
) | [inline] |
Set submatrix defined by upper-left element (r
,c
) and the size of matrix m
to m
.
Definition at line 555 of file smat.h.
References itpp::Mat< Num_T >::cols(), it_assert1, and itpp::Mat< Num_T >::rows().
Sparse_Mat< T > itpp::Sparse_Mat< T >::get_submatrix | ( | int | r1, | |
int | r2, | |||
int | c1, | |||
int | c2 | |||
) | const [inline] |
Returns the sub-matrix from rows r1
to r2
and columns c1
to c2
.
Definition at line 568 of file smat.h.
References itpp::Sparse_Mat< T >::col, itpp::Sparse_Mat< T >::compact(), and it_assert0.
Sparse_Mat< T > itpp::Sparse_Mat< T >::get_submatrix_cols | ( | int | c1, | |
int | c2 | |||
) | const [inline] |
Returns the sub-matrix from columns c1
to c2
(all rows).
Definition at line 583 of file smat.h.
References itpp::Sparse_Mat< T >::col, itpp::Sparse_Mat< T >::compact(), and it_assert0.
void itpp::Sparse_Mat< T >::get_col | ( | int | c, | |
Sparse_Vec< T > & | v | |||
) | const [inline] |
Returns column c
of the Sparse_Mat in the Sparse_Vec v
.
Definition at line 596 of file smat.h.
References it_assert.
Referenced by itpp::GF2mat::GF2mat(), itpp::Sparse_Mat< T >::operator+=(), and itpp::Sparse_Mat< T >::operator-=().
Sparse_Vec< T > itpp::Sparse_Mat< T >::get_col | ( | int | c | ) | const [inline] |
void itpp::Sparse_Mat< T >::set_col | ( | int | c, | |
const Sparse_Vec< T > & | v | |||
) | [inline] |
void itpp::Sparse_Mat< T >::transpose | ( | Sparse_Mat< T > & | m | ) | const [inline] |
Transpose the sparse matrix, return the result in m
.
Definition at line 617 of file smat.h.
References itpp::Sparse_Mat< T >::col, and itpp::Sparse_Mat< T >::set_size().
Referenced by itpp::mult_trans(), and itpp::transpose().
Sparse_Mat< T > itpp::Sparse_Mat< T >::transpose | ( | ) | const [inline] |
void itpp::Sparse_Mat< T >::operator= | ( | const Sparse_Mat< T > & | m | ) | [inline] |
Assign sparse matrix the value and dimensions of the sparse matrix m
.
Definition at line 635 of file smat.h.
References itpp::Sparse_Mat< T >::col, itpp::Sparse_Mat< T >::n_cols, and itpp::Sparse_Mat< T >::n_rows.
void itpp::Sparse_Mat< T >::operator= | ( | const Mat< T > & | m | ) | [inline] |
Assign sparse matrix the value and dimensions of the dense matrix m
.
Definition at line 647 of file smat.h.
References itpp::Mat< Num_T >::cols(), itpp::Mat< Num_T >::rows(), and itpp::Sparse_Mat< T >::set_new().
Sparse_Mat< T > itpp::Sparse_Mat< T >::operator- | ( | ) | const [inline] |
Returns the sign inverse of all elements in the sparse matrix.
Definition at line 664 of file smat.h.
References itpp::Sparse_Mat< T >::col.
bool itpp::Sparse_Mat< T >::operator== | ( | const Sparse_Mat< T > & | m | ) | const [inline] |
Compare two sparse matricies. False if wrong sizes or different values.
Definition at line 678 of file smat.h.
References itpp::Sparse_Mat< T >::col, itpp::Sparse_Mat< T >::n_cols, and itpp::Sparse_Mat< T >::n_rows.
void itpp::Sparse_Mat< T >::operator+= | ( | const Sparse_Mat< T > & | v | ) | [inline] |
Add sparse matrix v
to all non-zero elements of the sparse matrix.
Definition at line 691 of file smat.h.
References itpp::Sparse_Mat< T >::cols(), itpp::Sparse_Mat< T >::get_col(), it_assert0, and itpp::Sparse_Mat< T >::rows().
void itpp::Sparse_Mat< T >::operator+= | ( | const Mat< T > & | v | ) | [inline] |
Add matrix v
to all non-zero elements of the sparse matrix.
Definition at line 703 of file smat.h.
References itpp::Mat< Num_T >::cols(), itpp::Mat< Num_T >::get_col(), it_assert0, and itpp::Mat< Num_T >::rows().
void itpp::Sparse_Mat< T >::operator-= | ( | const Sparse_Mat< T > & | v | ) | [inline] |
Subtract sparse matrix v
from all non-zero elements of the sparse matrix.
Definition at line 712 of file smat.h.
References itpp::Sparse_Mat< T >::cols(), itpp::Sparse_Mat< T >::get_col(), it_assert0, and itpp::Sparse_Mat< T >::rows().
void itpp::Sparse_Mat< T >::operator-= | ( | const Mat< T > & | v | ) | [inline] |
Subtract matrix v
from all non-zero elements of the sparse matrix.
Definition at line 724 of file smat.h.
References itpp::Mat< Num_T >::cols(), itpp::Mat< Num_T >::get_col(), it_assert0, and itpp::Mat< Num_T >::rows().
void itpp::Sparse_Mat< T >::operator *= | ( | const T & | v | ) | [inline] |
void itpp::Sparse_Mat< T >::operator/= | ( | const T & | v | ) | [inline] |
typedef Sparse_Mat<int> sparse_imat [related] |
typedef Sparse_Mat<double> sparse_mat [related] |
typedef Sparse_Mat<std::complex<double> > sparse_cmat [related] |
Sparse_Mat<T> operator+ | ( | const Sparse_Mat< T > & | m1, | |
const Sparse_Mat< T > & | m2 | |||
) | [friend] |
Addition m1+m2 where m1 and m2 are sparse matrices.
Sparse_Mat<T> operator * | ( | const T & | c, | |
const Sparse_Mat< T > & | m | |||
) | [friend] |
Multiplication c*m where c is a scalar and m is a sparse matrix.
Sparse_Mat<T> operator * | ( | const Sparse_Mat< T > & | m1, | |
const Sparse_Mat< T > & | m2 | |||
) | [friend] |
Multiplication m1*m2 where m1 and m2 are sparse matrices.
Sparse_Vec<T> operator * | ( | const Sparse_Mat< T > & | m, | |
const Sparse_Vec< T > & | v | |||
) | [friend] |
Multiplication m*v where m is a sparse matrix and v is a sparse vector.
Vec<T> operator * | ( | const Sparse_Mat< T > & | m, | |
const Vec< T > & | v | |||
) | [friend] |
Multiplication m*v where m is a sparse matrix and v is a full column vector.
Vec<T> operator * | ( | const Vec< T > & | v, | |
const Sparse_Mat< T > & | m | |||
) | [friend] |
Multiplication v'*m where m is a sparse matrix and v is a full column vector.
Mat<T> trans_mult | ( | const Sparse_Mat< T > & | m | ) | [friend] |
Multiplication m'*m where m is a sparse matrix. Returns a full, dense matrix.
Referenced by itpp::mult_trans().
Sparse_Mat<T> trans_mult_s | ( | const Sparse_Mat< T > & | m | ) | [friend] |
Multiplication m'*m where m is a sparse matrix, Returns a sparse matrix.
Sparse_Mat<T> trans_mult | ( | const Sparse_Mat< T > & | m1, | |
const Sparse_Mat< T > & | m2 | |||
) | [friend] |
Multiplication m1'*m2 where m1 and m2 are sparse matrices.
Vec<T> trans_mult | ( | const Sparse_Mat< T > & | m, | |
const Vec< T > & | v | |||
) | [friend] |
Multiplication m'*v where m is a sparse matrix and v is a full column vector.
Sparse_Mat<T> mult_trans | ( | const Sparse_Mat< T > & | m1, | |
const Sparse_Mat< T > & | m2 | |||
) | [friend] |
Multiplication m1*m2' where m1 and m2 are sparse matrices.
Generated on Wed Apr 18 11:45:38 2007 for IT++ by Doxygen 1.5.2