Xmipp
v3.23.11-Nereus
|
#include <sparse_matrix2d.h>
Public Member Functions | |
int | nrows () const |
Y size of the matrix. More... | |
int | ncols () const |
X size of the matrix. More... | |
SparseMatrix2D (std::vector< SparseElement > &_elements, int _Nelements) | |
void | sparseMatrix2DFromVector (std::vector< SparseElement > &_elements) |
Fill the sparse matrix A with the elements of the vector. More... | |
void | multMv (double *x, double *y) |
void | multMM (const SparseMatrix2D &X, SparseMatrix2D &Y) |
Computes Y=this*X. More... | |
void | multMMDiagonal (const MultidimArray< double > &D, SparseMatrix2D &Y) |
Computes y=SparseMatrixThis*SparseMatrix. More... | |
double | getElemIJ (int row, int col) const |
void | loadMatrix (const FileName &fn) |
Public Attributes | |
int | N =0 |
The matrix is of size NxN. More... | |
MultidimArray< int > | iIdx |
List of i positions. More... | |
MultidimArray< int > | jIdx |
List of j positions. More... | |
MultidimArray< double > | values |
List of values. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &out, const SparseMatrix2D &X) |
Shows the dense Matrix associated. More... | |
Square, sparse matrices.
To create a Sparse Matrix we need a vector with SparseElements that contains a value, its row position and its column position.
We store that information with a Compressed Row Storage (CRS). This method stores a vector with the non-zero values (values), their column position (jIdx) and another vector with the position on values's vector of the element which is the first non-zero elements of each row (iIdx). The value 0 on iIdx vector means that there aren't nonzero values in that row. iIdx and jIdx have the first element in position 1. Value 0 is for no elements on a row.
i.e.:
Vector values 4, 3, 1, 2, 1, 4, 3
Vector jIdX 1, 2, 1, 2, 2, 4, 4
Vector iIdx 1, 3, 5, 7
Matriz A: 4 3 0 0 1 2 0 0 0 1 0 4 0 0 0 3
Definition at line 80 of file sparse_matrix2d.h.
SparseMatrix2D::SparseMatrix2D | ( | std::vector< SparseElement > & | _elements, |
int | _Nelements | ||
) |
Constructor from a set of i,j indexes and their corresponding values. N is the total dimension of the square, sparse matrix.
Definition at line 32 of file sparse_matrix2d.cpp.
double SparseMatrix2D::getElemIJ | ( | int | row, |
int | col | ||
) | const |
Returns the value on position (row,col). The matrix goes from 0 to N-1
Get element
Definition at line 157 of file sparse_matrix2d.cpp.
void SparseMatrix2D::loadMatrix | ( | const FileName & | fn | ) |
Loads a sparse matrix from a file. Loads a SparseMatrix2D from a file which has the following format:
sizeOfMatrix 1 1 value 2 1 value . . . i j value . . . last_i last_j last_value
Definition at line 258 of file sparse_matrix2d.cpp.
void SparseMatrix2D::multMM | ( | const SparseMatrix2D & | X, |
SparseMatrix2D & | Y | ||
) |
Computes Y=this*X.
Computes y=SparseMatrixThis*SparseMatrixX.
Definition at line 175 of file sparse_matrix2d.cpp.
void SparseMatrix2D::multMMDiagonal | ( | const MultidimArray< double > & | D, |
SparseMatrix2D & | Y | ||
) |
Computes y=SparseMatrixThis*SparseMatrix.
Computes Y=this*D where D is a diagonal matrix. It is assumed that the size of this sparse matrix is NxN and that the length of y is N.
Definition at line 227 of file sparse_matrix2d.cpp.
void SparseMatrix2D::multMv | ( | double * | x, |
double * | y | ||
) |
Computes y=this*x y and x are vectors of size Nx1
It computes y <- this*x
Definition at line 113 of file sparse_matrix2d.cpp.
|
inline |
|
inline |
void SparseMatrix2D::sparseMatrix2DFromVector | ( | std::vector< SparseElement > & | _elements | ) |
Fill the sparse matrix A with the elements of the vector.
Definition at line 74 of file sparse_matrix2d.cpp.
|
friend |
Shows the dense Matrix associated.
Definition at line 142 of file sparse_matrix2d.cpp.
MultidimArray<int> SparseMatrix2D::iIdx |
List of i positions.
Definition at line 87 of file sparse_matrix2d.h.
MultidimArray<int> SparseMatrix2D::jIdx |
List of j positions.
Definition at line 89 of file sparse_matrix2d.h.
int SparseMatrix2D::N =0 |
The matrix is of size NxN.
Definition at line 84 of file sparse_matrix2d.h.
MultidimArray<double> SparseMatrix2D::values |
List of values.
Definition at line 91 of file sparse_matrix2d.h.