Simple sparse matrix. More...
#include <vnl_sparse_matrix.h>

Public Types | |
| typedef vnl_sparse_matrix_pair< T > | pair_t |
| typedef std::vector< pair_t > | row |
| typedef std::vector< row > | vnl_sparse_matrix_elements |
Public Member Functions | |
| vnl_sparse_matrix () | |
| Construct an empty matrix. More... | |
| vnl_sparse_matrix (unsigned int m, unsigned int n) | |
| Construct an empty m*n matrix. More... | |
| vnl_sparse_matrix (vnl_sparse_matrix< T > const &rhs) | |
| Construct an m*n Matrix and copy rhs into it. More... | |
| vnl_sparse_matrix< T > & | operator= (vnl_sparse_matrix< T > const &rhs) |
| Copy another vnl_sparse_matrix<T> into this. More... | |
| void | mult (vnl_vector< T > const &rhs, vnl_vector< T > &result) const |
| Multiply this*rhs, where rhs is a vector. More... | |
| void | mult (unsigned int n, unsigned int m, T const *p, T *q) const |
| Multiply this*p, a fortran order matrix. More... | |
| void | pre_mult (const vnl_vector< T > &lhs, vnl_vector< T > &result) const |
| Multiplies lhs*this, where lhs is a vector. More... | |
| T & | operator() (unsigned int row, unsigned int column) |
| Get a reference to an entry in the matrix. More... | |
| T | operator() (unsigned int row, unsigned int column) const |
| Get the value of an entry in the matrix. More... | |
| T | get (unsigned int row, unsigned int column) const |
| Get an entry in the matrix. More... | |
| void | put (unsigned int row, unsigned int column, T value) |
| Put (i.e., add or overwrite) an entry into the matrix. More... | |
| void | diag_AtA (vnl_vector< T > &result) const |
| Get diag(A_transpose * A). More... | |
| vnl_sparse_matrix & | set_row (unsigned int r, std::vector< int > const &cols, std::vector< T > const &vals) |
| Set a whole row at once. Much faster. Returns *this. More... | |
| row & | get_row (unsigned int r) |
| Return row as vector of pairs. More... | |
| vnl_sparse_matrix< T > & | vcat (vnl_sparse_matrix< T > const &A) |
| Laminate matrix A onto the bottom of this one. More... | |
| unsigned int | rows () const |
| Get the number of rows in the matrix. More... | |
| unsigned int | columns () const |
| Get the number of columns in the matrix. More... | |
| unsigned int | cols () const |
| Get the number of columns in the matrix. More... | |
| bool | empty_row (unsigned int r) const |
| Return whether a given row is empty. More... | |
| T | sum_row (unsigned int r) |
| This is occasionally useful. More... | |
| vnl_sparse_matrix & | scale_row (unsigned int r, T scale) |
| Useful for normalizing row sums in convolution operators. More... | |
| void | clear () |
| Set all elements to null. More... | |
| void | set_size (int r, int c) |
| Resizes the array to have r rows and c cols – sets elements to null. More... | |
| void | resize (int r, int c) |
| Resizes the array to have r rows and c cols. More... | |
| void | reset () const |
| Resets the internal iterator. More... | |
| bool | next () const |
| Moves the internal iterator to next non-zero entry in matrix. More... | |
| int | getrow () const |
| Returns the row of the entry pointed to by internal iterator. More... | |
| int | getcolumn () const |
| Returns the column of the entry pointed to by internal iterator. More... | |
| T | value () const |
| Returns the value pointed to by the internal iterator. More... | |
| bool | operator== (vnl_sparse_matrix< T > const &rhs) const |
| Comparison. More... | |
| bool | operator!= (vnl_sparse_matrix< T > const &rhs) const |
| Inequality. More... | |
| vnl_sparse_matrix< T > | operator- () const |
| Unary minus. More... | |
| vnl_sparse_matrix< T > | operator+ (vnl_sparse_matrix< T > const &rhs) const |
| addition. More... | |
| vnl_sparse_matrix< T > | operator- (vnl_sparse_matrix< T > const &rhs) const |
| subtraction. More... | |
| vnl_sparse_matrix< T > | operator * (vnl_sparse_matrix< T > const &rhs) const |
| multiplication. More... | |
| vnl_sparse_matrix< T > & | operator+= (vnl_sparse_matrix< T > const &rhs) |
| in-place addition. More... | |
| vnl_sparse_matrix< T > & | operator-= (vnl_sparse_matrix< T > const &rhs) |
| in-place subtraction. More... | |
| vnl_sparse_matrix< T > & | operator *= (vnl_sparse_matrix< T > const &rhs) |
| in-place multiplication. More... | |
| vnl_sparse_matrix< T > | operator * (T const &rhs) const |
| scalar multiplication. More... | |
| vnl_sparse_matrix< T > & | operator *= (T const &rhs) |
| in-place scalar multiplication. More... | |
| vnl_sparse_matrix< T > | operator/ (T const &rhs) const |
| scalar division. More... | |
| vnl_sparse_matrix< T > & | operator/= (T const &rhs) |
| in-place scalar division. More... | |
| vnl_sparse_matrix< T > | transpose () const |
| returns a new sparse matrix, viz. the transpose of this. More... | |
| vnl_sparse_matrix< T > | conjugate_transpose () const |
| returns a new sparse matrix, viz. the conjugate (or Hermitian) transpose of this. More... | |
| vnl_sparse_matrix & | set_identity () |
| Sets this matrix to an identity matrix, then returns "*this". More... | |
| vnl_sparse_matrix & | normalize_rows () |
| Normalizes each row so it is a unit vector, and returns "*this". More... | |
| void | add (const vnl_sparse_matrix< T > &rhs, vnl_sparse_matrix< T > &result) const |
| Add rhs to this. More... | |
| void | subtract (const vnl_sparse_matrix< T > &rhs, vnl_sparse_matrix< T > &result) const |
| Subtract rhs from this. More... | |
| void | mult (vnl_sparse_matrix< T > const &rhs, vnl_sparse_matrix< T > &result) const |
| Multiply this*rhs, another sparse matrix. More... | |
Protected Attributes | |
| vnl_sparse_matrix_elements | elements |
| unsigned int | rs_ |
| unsigned int | cs_ |
| unsigned int | itr_row |
| row::const_iterator | itr_cur |
| bool | itr_isreset |
Related Functions | |
(Note that these are not member functions.) | |
| template<class T > | |
| void | vsl_b_write (vsl_b_ostream &os, const vnl_sparse_matrix< T > &v) |
| Binary save vnl_sparse_matrix to stream. More... | |
| template<class T > | |
| void | vsl_b_read (vsl_b_istream &is, vnl_sparse_matrix< T > &v) |
| Binary load vnl_sparse_matrix from stream. More... | |
| template<class T > | |
| void | vsl_print_summary (std::ostream &os, const vnl_sparse_matrix< T > &b) |
| Print human readable summary of object to a stream. More... | |
Simple sparse matrix.
Stores non-zero elements as a sparse_matrix_pair
Definition at line 108 of file vnl_sparse_matrix.h.
| typedef vnl_sparse_matrix_pair<T> vnl_sparse_matrix< T >::pair_t |
Definition at line 111 of file vnl_sparse_matrix.h.
| typedef std::vector< pair_t > vnl_sparse_matrix< T >::row |
Definition at line 112 of file vnl_sparse_matrix.h.
| typedef std::vector< row > vnl_sparse_matrix< T >::vnl_sparse_matrix_elements |
Definition at line 113 of file vnl_sparse_matrix.h.
| vnl_sparse_matrix< T >::vnl_sparse_matrix | ( | ) |
Construct an empty matrix.
Definition at line 28 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T >::vnl_sparse_matrix | ( | unsigned int | m, |
| unsigned int | n | ||
| ) |
Construct an empty m*n matrix.
Construct an empty m*n matrix. There are m rows and n columns.
Definition at line 36 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T >::vnl_sparse_matrix | ( | vnl_sparse_matrix< T > const & | rhs | ) |
Construct an m*n Matrix and copy rhs into it.
Definition at line 44 of file vnl_sparse_matrix.hxx.
| void vnl_sparse_matrix< T >::add | ( | const vnl_sparse_matrix< T > & | rhs, |
| vnl_sparse_matrix< T > & | result | ||
| ) | const |
Add rhs to this.
Deprecated for direct use: please use operator "+" instead.
Definition at line 306 of file vnl_sparse_matrix.hxx.
|
inline |
Set all elements to null.
Definition at line 184 of file vnl_sparse_matrix.h.
|
inline |
Get the number of columns in the matrix.
Definition at line 172 of file vnl_sparse_matrix.h.
|
inline |
Get the number of columns in the matrix.
Definition at line 169 of file vnl_sparse_matrix.h.
| vnl_sparse_matrix< T > vnl_sparse_matrix< T >::conjugate_transpose | ( | ) | const |
returns a new sparse matrix, viz. the conjugate (or Hermitian) transpose of this.
Definition at line 957 of file vnl_sparse_matrix.hxx.
| void vnl_sparse_matrix< T >::diag_AtA | ( | vnl_vector< T > & | result | ) | const |
Get diag(A_transpose * A).
Useful for forming Jacobi preconditioners for linear solvers.
Definition at line 481 of file vnl_sparse_matrix.hxx.
|
inline |
Return whether a given row is empty.
Definition at line 175 of file vnl_sparse_matrix.h.
| T vnl_sparse_matrix< T >::get | ( | unsigned int | r, |
| unsigned int | c | ||
| ) | const |
Get an entry in the matrix.
This is the "const" version of operator().
Definition at line 448 of file vnl_sparse_matrix.hxx.
|
inline |
Return row as vector of pairs.
Added to aid binary I/O
Definition at line 160 of file vnl_sparse_matrix.h.
| int vnl_sparse_matrix< T >::getcolumn | ( | ) | const |
Returns the column of the entry pointed to by internal iterator.
Definition at line 667 of file vnl_sparse_matrix.hxx.
| int vnl_sparse_matrix< T >::getrow | ( | ) | const |
Returns the row of the entry pointed to by internal iterator.
Definition at line 658 of file vnl_sparse_matrix.hxx.
| void vnl_sparse_matrix< T >::mult | ( | vnl_vector< T > const & | rhs, |
| vnl_vector< T > & | result | ||
| ) | const |
Multiply this*rhs, where rhs is a vector.
Multiply this*rhs, a vector.
Definition at line 243 of file vnl_sparse_matrix.hxx.
| void vnl_sparse_matrix< T >::mult | ( | unsigned int | prows, |
| unsigned int | pcols, | ||
| T const * | p, | ||
| T * | q | ||
| ) | const |
Multiply this*p, a fortran order matrix.
The matrix p has n rows and m columns, and is in fortran order, ie. columns first.
Definition at line 157 of file vnl_sparse_matrix.hxx.
| void vnl_sparse_matrix< T >::mult | ( | vnl_sparse_matrix< T > const & | rhs, |
| vnl_sparse_matrix< T > & | result | ||
| ) | const |
Multiply this*rhs, another sparse matrix.
Deprecated for direct use: please use operator "*" instead.
Definition at line 67 of file vnl_sparse_matrix.hxx.
| bool vnl_sparse_matrix< T >::next | ( | ) | const |
Moves the internal iterator to next non-zero entry in matrix.
Returns true if there is another value, false otherwise. Use in combination with methods reset, getrow, getcolumn, and value.
Definition at line 622 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > & vnl_sparse_matrix< T >::normalize_rows | ( | ) |
Normalizes each row so it is a unit vector, and returns "*this".
Make each row of the matrix have unit norm.
Zero rows are not modified Returning "*this" allows "chaining" two or more operations:
Note that there is no method normalize_columns() since its implementation would be much more inefficient than normalize_rows()!
All-zero rows are ignored.
Definition at line 873 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > vnl_sparse_matrix< T >::operator * | ( | vnl_sparse_matrix< T > const & | rhs | ) | const |
multiplication.
Definition at line 778 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > vnl_sparse_matrix< T >::operator * | ( | T const & | rhs | ) | const |
scalar multiplication.
Definition at line 835 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > & vnl_sparse_matrix< T >::operator *= | ( | vnl_sparse_matrix< T > const & | rhs | ) |
in-place multiplication.
Definition at line 865 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > & vnl_sparse_matrix< T >::operator *= | ( | T const & | rhs | ) |
in-place scalar multiplication.
Definition at line 787 of file vnl_sparse_matrix.hxx.
|
inline |
Inequality.
Definition at line 213 of file vnl_sparse_matrix.h.
| T & vnl_sparse_matrix< T >::operator() | ( | unsigned int | row, |
| unsigned int | column | ||
| ) |
Get a reference to an entry in the matrix.
Definition at line 412 of file vnl_sparse_matrix.hxx.
| T vnl_sparse_matrix< T >::operator() | ( | unsigned int | row, |
| unsigned int | column | ||
| ) | const |
Get the value of an entry in the matrix.
Definition at line 431 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > vnl_sparse_matrix< T >::operator+ | ( | vnl_sparse_matrix< T > const & | rhs | ) | const |
addition.
Definition at line 760 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > & vnl_sparse_matrix< T >::operator+= | ( | vnl_sparse_matrix< T > const & | rhs | ) |
in-place addition.
Definition at line 851 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > vnl_sparse_matrix< T >::operator- | ( | ) | const |
Unary minus.
Definition at line 731 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > vnl_sparse_matrix< T >::operator- | ( | vnl_sparse_matrix< T > const & | rhs | ) | const |
subtraction.
Definition at line 769 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > & vnl_sparse_matrix< T >::operator-= | ( | vnl_sparse_matrix< T > const & | rhs | ) |
in-place subtraction.
Definition at line 858 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > vnl_sparse_matrix< T >::operator/ | ( | T const & | rhs | ) | const |
scalar division.
Definition at line 843 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > & vnl_sparse_matrix< T >::operator/= | ( | T const & | rhs | ) |
in-place scalar division.
Definition at line 811 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > & vnl_sparse_matrix< T >::operator= | ( | vnl_sparse_matrix< T > const & | rhs | ) |
Copy another vnl_sparse_matrix<T> into this.
Definition at line 52 of file vnl_sparse_matrix.hxx.
| bool vnl_sparse_matrix< T >::operator== | ( | vnl_sparse_matrix< T > const & | rhs | ) | const |
Comparison.
Definition at line 685 of file vnl_sparse_matrix.hxx.
| void vnl_sparse_matrix< T >::pre_mult | ( | const vnl_vector< T > & | lhs, |
| vnl_vector< T > & | result | ||
| ) | const |
Multiplies lhs*this, where lhs is a vector.
Multiply lhs*this, where lhs is a vector.
Definition at line 269 of file vnl_sparse_matrix.hxx.
| void vnl_sparse_matrix< T >::put | ( | unsigned int | row, |
| unsigned int | column, | ||
| T | value | ||
| ) |
Put (i.e., add or overwrite) an entry into the matrix.
Definition at line 464 of file vnl_sparse_matrix.hxx.
| void vnl_sparse_matrix< T >::reset | ( | ) | const |
Resets the internal iterator.
Definition at line 610 of file vnl_sparse_matrix.hxx.
| void vnl_sparse_matrix< T >::resize | ( | int | r, |
| int | c | ||
| ) |
Resizes the array to have r rows and c cols.
Resizes the matrix so that it has r rows and c columns, leaving the current contents.
This is more wasteful of resources than set_size, but it preserves the contents.
Definition at line 585 of file vnl_sparse_matrix.hxx.
|
inline |
Get the number of rows in the matrix.
Definition at line 166 of file vnl_sparse_matrix.h.
| vnl_sparse_matrix< T > & vnl_sparse_matrix< T >::scale_row | ( | unsigned int | r, |
| T | scale | ||
| ) |
Useful for normalizing row sums in convolution operators.
Definition at line 553 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > & vnl_sparse_matrix< T >::set_identity | ( | ) |
Sets this matrix to an identity matrix, then returns "*this".
Fill this matrix with 1s on the main diagonal and 0s elsewhere.
Returning "*this" allows e.g. passing an identity matrix as argument to a function f, without having to name the constructed matrix:
Returning "*this" also allows "chaining" two or more operations: e.g., to set a matrix to identity, then add an other matrix to it:
If the matrix is not square, anyhow set main diagonal to 1, the rest to 0.
Definition at line 914 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > & vnl_sparse_matrix< T >::set_row | ( | unsigned int | r, |
| std::vector< int > const & | cols, | ||
| std::vector< T > const & | vals | ||
| ) |
Set a whole row at once. Much faster. Returns *this.
Set row in the matrix.
Definition at line 503 of file vnl_sparse_matrix.hxx.
| void vnl_sparse_matrix< T >::set_size | ( | int | r, |
| int | c | ||
| ) |
Resizes the array to have r rows and c cols – sets elements to null.
Resizes the matrix so that it has r rows and c columns, clearing the current contents.
Definition at line 566 of file vnl_sparse_matrix.hxx.
| void vnl_sparse_matrix< T >::subtract | ( | const vnl_sparse_matrix< T > & | rhs, |
| vnl_sparse_matrix< T > & | result | ||
| ) | const |
Subtract rhs from this.
Deprecated for direct use: please use operator "-" instead.
Definition at line 359 of file vnl_sparse_matrix.hxx.
| T vnl_sparse_matrix< T >::sum_row | ( | unsigned int | r | ) |
This is occasionally useful.
This is occasionally useful. Sums a row of the matrix efficiently.
Definition at line 540 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > vnl_sparse_matrix< T >::transpose | ( | ) | const |
returns a new sparse matrix, viz. the transpose of this.
Definition at line 931 of file vnl_sparse_matrix.hxx.
| T vnl_sparse_matrix< T >::value | ( | ) | const |
Returns the value pointed to by the internal iterator.
Definition at line 676 of file vnl_sparse_matrix.hxx.
| vnl_sparse_matrix< T > & vnl_sparse_matrix< T >::vcat | ( | vnl_sparse_matrix< T > const & | A | ) |
Laminate matrix A onto the bottom of this one.
Definition at line 521 of file vnl_sparse_matrix.hxx.
|
related |
Binary load vnl_sparse_matrix from stream.
|
related |
Binary save vnl_sparse_matrix to stream.
|
related |
Print human readable summary of object to a stream.
|
protected |
Definition at line 297 of file vnl_sparse_matrix.h.
|
protected |
Definition at line 296 of file vnl_sparse_matrix.h.
|
mutableprotected |
Definition at line 301 of file vnl_sparse_matrix.h.
|
mutableprotected |
Definition at line 302 of file vnl_sparse_matrix.h.
|
mutableprotected |
Definition at line 300 of file vnl_sparse_matrix.h.
|
protected |
Definition at line 297 of file vnl_sparse_matrix.h.
1.8.15