A C++ implementation of the Yale Sparse Matrix Format, for templated sparse matrices.
Use:
#include "SparseMatrix.h"
Note: the library is compatible with iostream. Use the following import to use iostream functions:
#include <iostream>
Create a new matrix called matrix_name, which:
- contains objects of type T;
- uses the functor C to compare two objects of type T;
- uses the object D as default value.
Note: the function pointed to by C must return TRUE if two objects of type T are different, FALSE otherwise.
SparseMatrix<T, C> matrix_name(D);
Construct a matrix of objects of type T from a matrix of objects of type Q:
SparseMatrix<T, C> matrix_name_T(matrix_name_Q);
matrix_name.set_dimension(m, n);
matrix_name.add(object, i, j);
Note: the object must be of type T
matrix_name(i, j);
SparseMatrix<T, C>::iterator s, e;
s = matrix_name.begin();
e = matrix_name.end();
while (s != e) {
std::cout << "value: " << s.operator*()._element_value
<< " row: " << s.operator*()._element_row
<< " column: " << s.operator*()._element_column;
std::cout << std::endl;
s++;
}
Iterators that do not allow editing of objects can also be used:
SparseMatrix<T, C>::const_iterator sc, ec;
Please contact me if you have any concerns or can help me improve the documentation. Thanks!