#include <SparseMatrix.h>
Public Member Functions | |
virtual void | append_in_row (int row, int col, const double val) |
virtual void | append_new_cols (int num) |
virtual void | append_new_rows (int num) |
virtual void | apply_givens (int row, int col, double *c_givens=NULL, double *s_givens=NULL) |
virtual void | ensure_num_cols (int num_cols) |
virtual void | ensure_num_rows (int num_rows) |
virtual const SparseVector & | get_row (int row) const |
virtual void | import_rows (int num_rows, int num_cols, SparseVector_p *rows) |
virtual int | max_nz () const |
virtual int | nnz () const |
int | num_cols () const |
int | num_rows () const |
virtual double | operator() (int row, int col) const |
const SparseMatrix & | operator= (const SparseMatrix &mat) |
virtual void | print (std::ostream &out=std::cout) const |
virtual void | print (const std::string &file_name) const |
virtual void | print_pattern () const |
virtual void | print_stats () const |
virtual void | remove_row () |
virtual void | save_pattern_eps (const std::string &file_name) const |
virtual void | set (int row, int col, const double val, bool grow_matrix=false) |
virtual void | set_row (int row, const SparseVector &new_row) |
SparseMatrix (int num_rows, int num_cols) | |
SparseMatrix (const SparseMatrix &mat) | |
SparseMatrix (const SparseMatrix &mat, int num_rows, int num_cols, int first_row=0, int first_col=0) | |
SparseMatrix (int num_rows, int num_cols, SparseVector_p *rows) | |
virtual int | triangulate_with_givens () |
virtual | ~SparseMatrix () |
Private Member Functions | |
void | _allocate_SparseMatrix (int num_rows, int num_cols, int max_num_rows, int max_num_cols, bool init_rows=true) |
void | _copy_from_SparseMatrix (const SparseMatrix &mat) |
void | _dealloc_SparseMatrix () |
Private Attributes | |
int | _max_num_cols |
int | _max_num_rows |
int | _num_cols |
int | _num_rows |
SparseVector_p * | _rows |
Friends | |
class | OrderedSparseMatrix |
Definition at line 39 of file SparseMatrix.h.
isam::SparseMatrix::SparseMatrix | ( | int | num_rows, |
int | num_cols | ||
) |
Constructor.
num_rows | Initial number of rows. |
num_cols | Initial number of columns. |
Definition at line 76 of file SparseMatrix.cpp.
isam::SparseMatrix::SparseMatrix | ( | const SparseMatrix & | mat | ) |
isam::SparseMatrix::SparseMatrix | ( | const SparseMatrix & | mat, |
int | num_rows, | ||
int | num_cols, | ||
int | first_row = 0 , |
||
int | first_col = 0 |
||
) |
Submatrix copy constructor
mat | Matrix to copy. |
num_rows | Number of rows to copy. |
num_cols | Number of columns to copy. |
first_row | Row offset. |
first_col | Column offset. |
Definition at line 86 of file SparseMatrix.cpp.
isam::SparseMatrix::SparseMatrix | ( | int | num_rows, |
int | num_cols, | ||
SparseVector_p * | rows | ||
) |
Definition at line 94 of file SparseMatrix.cpp.
isam::SparseMatrix::~SparseMatrix | ( | ) | [virtual] |
Destructor.
Definition at line 105 of file SparseMatrix.cpp.
void isam::SparseMatrix::_allocate_SparseMatrix | ( | int | num_rows, |
int | num_cols, | ||
int | max_num_rows, | ||
int | max_num_cols, | ||
bool | init_rows = true |
||
) | [private] |
Allocate memory - private.
num_rows | Number of active rows. |
num_cols | Number of active columns. |
max_num_rows | Number of rows to reserve memory for. |
max_num_cols | Number of columns to reserve memory for. |
Definition at line 47 of file SparseMatrix.cpp.
void isam::SparseMatrix::_copy_from_SparseMatrix | ( | const SparseMatrix & | mat | ) | [private] |
Copy data from one sparse matrix to a new one - private.
vec | Existing sparse vector to copy from. |
Definition at line 60 of file SparseMatrix.cpp.
void isam::SparseMatrix::_dealloc_SparseMatrix | ( | ) | [private] |
Deallocate memory - private.
Definition at line 67 of file SparseMatrix.cpp.
void isam::SparseMatrix::append_in_row | ( | int | row, |
int | col, | ||
const double | val | ||
) | [virtual] |
Append a new entry to a row. Allows efficient adding of presorted elements.
row | Row of new entry. |
col | Column of new entry - must be after last existing one in this row. |
val | Value of new entry. |
Definition at line 141 of file SparseMatrix.cpp.
void isam::SparseMatrix::append_new_cols | ( | int | num | ) | [virtual] |
Append new columns to matrix.
num | Number of columns to add. |
Reimplemented in isam::OrderedSparseMatrix.
Definition at line 270 of file SparseMatrix.cpp.
void isam::SparseMatrix::append_new_rows | ( | int | num | ) | [virtual] |
Append new rows to matrix.
num | Number of rows to add. |
Reimplemented in isam::SparseSystem.
Definition at line 252 of file SparseMatrix.cpp.
void isam::SparseMatrix::apply_givens | ( | int | row, |
int | col, | ||
double * | c_givens = NULL , |
||
double * | s_givens = NULL |
||
) | [virtual] |
Zero out an entry by applying a Givens rotation. Note that both sparse rows have to be completely 0 on the left of col.
row | The row from which row_bot is taken. |
col | The column of row_bot that should become 0. |
c_givens | Returns cosine of givens rotation if not NULL. |
s_givens | Returns sine of givens rotation if not NULL. |
Reimplemented in isam::SparseSystem.
Definition at line 301 of file SparseMatrix.cpp.
void isam::SparseMatrix::ensure_num_cols | ( | int | num_cols | ) | [virtual] |
Grow matrix to given number of columns; ignore if already at least as large.
num_cols | Number of columns. |
Definition at line 286 of file SparseMatrix.cpp.
void isam::SparseMatrix::ensure_num_rows | ( | int | num_rows | ) | [virtual] |
Grow matrix to given number of rows; ignore if already at least as large.
num_rows | Number of rows. |
Definition at line 279 of file SparseMatrix.cpp.
const SparseVector & isam::SparseMatrix::get_row | ( | int | row | ) | const [virtual] |
Return a sparse row.
row | Number of row to return. |
Definition at line 230 of file SparseMatrix.cpp.
void isam::SparseMatrix::import_rows | ( | int | num_rows, |
int | num_cols, | ||
SparseVector_p * | rows | ||
) | [virtual] |
Import externally allocated rows.
num_rows | Number of rows of new matrix. |
num_cols | Number of columns of new matrix. |
rows | Array of SparseVector of length num_rows. |
Definition at line 240 of file SparseMatrix.cpp.
int isam::SparseMatrix::max_nz | ( | ) | const [virtual] |
Determine maximum number of non-zero entries in any column.
Definition at line 155 of file SparseMatrix.cpp.
int isam::SparseMatrix::nnz | ( | ) | const [virtual] |
Determine number of non-zero entries in sparse matrix.
Definition at line 147 of file SparseMatrix.cpp.
int isam::SparseMatrix::num_cols | ( | ) | const [inline] |
Definition at line 238 of file SparseMatrix.h.
int isam::SparseMatrix::num_rows | ( | ) | const [inline] |
Definition at line 237 of file SparseMatrix.h.
double isam::SparseMatrix::operator() | ( | int | row, |
int | col | ||
) | const [virtual] |
Read a matrix entry.
row | Row of entry. |
col | Column of entry. |
Definition at line 124 of file SparseMatrix.cpp.
const SparseMatrix & isam::SparseMatrix::operator= | ( | const SparseMatrix & | mat | ) |
Assignment operator.
mat | Right-hand-side matrix in assignment |
Definition at line 109 of file SparseMatrix.cpp.
virtual void isam::SparseMatrix::print | ( | std::ostream & | out = std::cout | ) | const [virtual] |
Print sparse matrix as triples to stream; also readable by Matlab: "load R.txt; S=spconvert(R); spy(S)"
out | Output stream. |
virtual void isam::SparseMatrix::print | ( | const std::string & | file_name | ) | const [virtual] |
Print sparse matrix as triples to file
file_name | File name to write sparse matrix to. |
void isam::SparseMatrix::print_pattern | ( | ) | const [virtual] |
Prints non-zero pattern to stdout.
Definition at line 185 of file SparseMatrix.cpp.
void isam::SparseMatrix::print_stats | ( | ) | const [virtual] |
Print size of matrix and number of entries for debugging.
Definition at line 181 of file SparseMatrix.cpp.
void isam::SparseMatrix::remove_row | ( | ) | [virtual] |
Removes the last row (used in SparseSystem::add_row_givens).
Definition at line 293 of file SparseMatrix.cpp.
void isam::SparseMatrix::save_pattern_eps | ( | const std::string & | file_name | ) | const [virtual] |
Save eps graphics file with sparse matrix patterns.
Definition at line 199 of file SparseMatrix.cpp.
void isam::SparseMatrix::set | ( | int | row, |
int | col, | ||
const double | val, | ||
bool | grow_matrix = false |
||
) | [virtual] |
Set one entry of the matrix. Non-existing entries are created.
row | Row of entry. |
col | Column of entry. |
val | New value of entry. |
grow_matrix | Enlarge matrix if entry outside current size (default: false). |
Definition at line 130 of file SparseMatrix.cpp.
void isam::SparseMatrix::set_row | ( | int | row, |
const SparseVector & | new_row | ||
) | [virtual] |
Replace the given row.
row | Number of row to replace. |
new_row | New row vector. |
Reimplemented in isam::OrderedSparseMatrix.
Definition at line 235 of file SparseMatrix.cpp.
int isam::SparseMatrix::triangulate_with_givens | ( | ) | [virtual] |
Triangulate matrix by applying Givens rotations to all entries below the diagonal.
Definition at line 371 of file SparseMatrix.cpp.
friend class OrderedSparseMatrix [friend] |
Definition at line 240 of file SparseMatrix.h.
int isam::SparseMatrix::_max_num_cols [private] |
Definition at line 43 of file SparseMatrix.h.
int isam::SparseMatrix::_max_num_rows [private] |
Definition at line 42 of file SparseMatrix.h.
int isam::SparseMatrix::_num_cols [private] |
Definition at line 41 of file SparseMatrix.h.
int isam::SparseMatrix::_num_rows [private] |
Definition at line 40 of file SparseMatrix.h.
SparseVector_p* isam::SparseMatrix::_rows [private] |
Definition at line 44 of file SparseMatrix.h.