ARTS
2.4.0(git:4fb77825)
|
#include <matpackII.h>
Public Member Functions | |
Sparse () | |
Default constructor. More... | |
Sparse (Index r, Index c) | |
Constructor setting size. More... | |
void | split (Index offset, Index nrows) |
Reduce matrix to the row range [offset, offset + nrows]. More... | |
void | insert_row (Index r, Vector v) |
Insert row function. More... | |
void | insert_elements (Index nnz, const ArrayOfIndex &rowind, const ArrayOfIndex &colind, ConstVectorView data) |
Insert vector of elements with given row and column indices. More... | |
void | resize (Index r, Index c) |
Resize function. More... | |
bool | empty () const |
Returns true if variable size is zero. More... | |
Index | nrows () const |
Returns the number of rows. More... | |
Index | ncols () const |
Returns the number of columns. More... | |
Index | nnz () const |
Returns the number of nonzero elements. More... | |
Vector | diagonal () const |
Diagonal elements as vector. More... | |
Numeric & | rw (Index r, Index c) |
Read and write index operator. More... | |
Numeric | ro (Index r, Index c) const |
Read only index operator. More... | |
Numeric | operator() (Index r, Index c) const |
Plain index operator. More... | |
Sparse & | operator+= (const Sparse &x) |
Add sparse matrix. More... | |
Sparse & | operator-= (const Sparse &x) |
Subtract sparse matrix. More... | |
Sparse & | operator*= (Numeric x) |
Scale matrix. More... | |
Sparse & | operator/= (Numeric x) |
Scale matrix by reciprocal. More... | |
operator Matrix () const | |
Convert to dense matrix. More... | |
void | list_elements (Vector &values, ArrayOfIndex &row_indices, ArrayOfIndex &column_indices) const |
List elements in matrix. More... | |
Numeric * | get_element_pointer () |
int * | get_column_index_pointer () |
int * | get_row_start_pointer () |
Static Public Member Functions | |
static Sparse | diagonal (ConstVectorView v) |
Create a sparse matrix from a vector. More... | |
Private Attributes | |
Eigen::SparseMatrix< Numeric, Eigen::RowMajor > | matrix |
The actual matrix. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Sparse &v) |
Output operator for Sparse. More... | |
void | abs (Sparse &A, const Sparse &B) |
Absolute value of sparse matrix elements. More... | |
void | mult (VectorView y, const Sparse &M, ConstVectorView x) |
Sparse matrix - Vector multiplication. More... | |
void | transpose_mult (VectorView y, const Sparse &M, ConstVectorView x) |
Sparse matrix - Vector multiplication. More... | |
void | mult (MatrixView A, const Sparse &B, const ConstMatrixView &C) |
SparseMatrix - Matrix multiplication. More... | |
void | mult (MatrixView A, const ConstMatrixView &B, const Sparse &C) |
Matrix - SparseMatrix multiplication. More... | |
void | mult (Sparse &A, const Sparse &B, const Sparse &C) |
Sparse - Sparse multiplication. More... | |
void | add (Sparse &A, const Sparse &B, const Sparse &C) |
Sparse - Sparse addition. More... | |
void | sub (Sparse &A, const Sparse &B, const Sparse &C) |
Sparse - Sparse subtraction. More... | |
void | transpose (Sparse &A, const Sparse &B) |
Transpose of sparse matrix. More... | |
void | id_mat (Sparse &A) |
Sparse identity matrix. More... | |
The Sparse class.
Wrapper class for Eigen sparse matrices. The storage format used is compressed row storage. Thus inserting of elements in a single row ordered by column index is performed in constant time, if the rows are themselves inserted in increasing order.
Definition at line 60 of file matpackII.h.
Sparse::Sparse | ( | ) |
Constructor setting size.
r | Row dimension of new sparse matrix. |
c | Column dimension of new sparse matrix. |
Definition at line 157 of file matpackII.cc.
Vector Sparse::diagonal | ( | ) | const |
|
static |
Create a sparse matrix from a vector.
v | vector containing the diagonal elements. |
Definition at line 161 of file matpackII.cc.
References insert_elements(), and ConstVectorView::nelem().
bool Sparse::empty | ( | ) | const |
Returns true if variable size is zero.
Definition at line 61 of file matpackII.cc.
References matrix.
|
inline |
Definition at line 123 of file matpackII.h.
References matrix.
Referenced by get_covariance_matrix_block(), and get_variable_value().
|
inline |
Definition at line 122 of file matpackII.h.
References matrix.
Referenced by get_covariance_matrix_block(), and get_variable_value().
|
inline |
Definition at line 124 of file matpackII.h.
References matrix.
Referenced by get_covariance_matrix_block(), and get_variable_value().
void Sparse::insert_elements | ( | Index | nelems, |
const ArrayOfIndex & | rowind, | ||
const ArrayOfIndex & | colind, | ||
ConstVectorView | data | ||
) |
Insert vector of elements with given row and column indices.
Efficient inserting of a vector of elements into the sparse matrix. Overwrites elements currently in the matrix. The complexity is linear in the number of elements and should therefore be the preferred way of inserting elements into the sparse matrix.
nelems | The number of elements to insert. |
rowind | A vector containing the row indices. |
colind | A vector containing the column indices. |
data | The vector containing the elements. |
Definition at line 337 of file matpackII.cc.
Referenced by diagonal(), DiagonalMatrix(), InteractiveWorkspace::set_sparse_variable(), and xml_read_from_stream().
Insert row function.
Inserts a Vector as row of elements at the given position.
The row index must agree with the size of the matrix. This function can not be used to expand the matrix. Only non-zero values will be stored. If the destination row already exist it will be overwritten.
r | Where to insert the row |
v | Vector to be inserted. |
Definition at line 314 of file matpackII.cc.
References matrix, ncols(), ConstVectorView::nelem(), and nrows().
Referenced by antenna1d_matrix(), antenna2d_interp_response(), met_mm_polarisation_hmatrix(), sensor_responseFrequencySwitching(), sensor_responseMixerBackendPrecalcWeights(), sensor_responsePolarisation(), sensor_responseStokesRotation(), spectrometer_matrix(), and test_insert_row().
void Sparse::list_elements | ( | Vector & | values, |
ArrayOfIndex & | row_indices, | ||
ArrayOfIndex & | column_indices | ||
) | const |
List elements in matrix.
Writes the values in the matrix into the given Vector values and the row and column indices into the given ArrayOfIndex objects.
values | The values contained in the matrix. |
row_indices | The row indices corresponding to the values. |
column_indices | The column indices corresponding to the values. |
Definition at line 270 of file matpackII.cc.
References matrix, ncols(), nnz(), nrows(), and Vector::resize().
Referenced by xml_write_to_stream().
Index Sparse::ncols | ( | ) | const |
Returns the number of columns.
Definition at line 69 of file matpackII.cc.
References matrix.
Referenced by abs(), add(), antenna1d_matrix(), antenna2d_interp_response(), Compare(), diagonal(), get_variable_value(), id_mat(), insert_row(), list_elements(), MatrixCopySparse(), mueller_rotation(), mult(), random_fill_matrix(), Select(), sensor_responseAntenna(), sensor_responseBackend(), sensor_responseFrequencySwitching(), sensor_responseMetMM(), sensor_responseMixer(), sensor_responseMixerBackendPrecalcWeights(), sensor_responsePolarisation(), sensor_responseStokesRotation(), sensor_responseWMRF(), SparseSparseMultiply(), split(), sub(), test_identity(), test_insert_row(), transpose(), WMRFSelectChannels(), and xml_write_to_stream().
Index Sparse::nnz | ( | ) | const |
Returns the number of nonzero elements.
Definition at line 72 of file matpackII.cc.
References matrix.
Referenced by get_covariance_matrix_block(), get_variable_value(), list_elements(), Select(), and xml_write_to_stream().
Index Sparse::nrows | ( | ) | const |
Returns the number of rows.
Definition at line 66 of file matpackII.cc.
References matrix.
Referenced by abs(), add(), Compare(), diagonal(), get_variable_value(), id_mat(), insert_row(), list_elements(), MatrixCopySparse(), mueller_rotation(), mult(), random_fill_matrix(), Select(), sensor_responseAntenna(), sensor_responseBackend(), sensor_responseFrequencySwitching(), sensor_responseMetMM(), sensor_responseMixer(), sensor_responseMixerBackendPrecalcWeights(), sensor_responsePolarisation(), sensor_responseStokesRotation(), SparseSparseMultiply(), sub(), test_identity(), test_insert_row(), transpose(), WMRFSelectChannels(), and xml_write_to_stream().
|
explicit |
Convert to dense matrix.
Converts a given sparse matrix to a dense matrix. Intended mainly for testing purposes.
Definition at line 189 of file matpackII.cc.
References ARTS::Var::ncols(), and ARTS::Var::nrows().
Plain index operator.
This is the same as the .ro index operator.
r | Row index. |
c | Column index. |
Definition at line 111 of file matpackII.cc.
Scale matrix.
x | Scalar factor to scale the matrix with. |
Definition at line 243 of file matpackII.cc.
References matrix, and ARTS::Var::x().
Add sparse matrix.
Element-wise, in-situ sum of two sparse matrices. Matrix must have the same dimensions.
A | The sparse matrix to add to the Sparse object. |
Definition at line 215 of file matpackII.cc.
References matrix.
Subtract sparse matrix.
Element-wise, in-situ difference of two sparse matrices. Matrix must have the same dimensions.
A | The sparse matrix to add to the Sparse object. |
Definition at line 231 of file matpackII.cc.
References matrix.
Scale matrix by reciprocal.
x | Reciprocal of the factor to scale the matrix with. |
Definition at line 255 of file matpackII.cc.
References matrix, and ARTS::Var::x().
Resize function.
If the size is already correct this function does nothing.
All data is lost after resizing! The new Sparse is not initialised so it will be empty.
r | New row dimension. |
c | New column dimension. |
Definition at line 361 of file matpackII.cc.
Referenced by add(), antenna1d_matrix(), antenna2d_interp_response(), DiagonalMatrix(), SparseMatrixIdentity(), spectrometer_matrix(), sub(), test47(), test_identity(), test_insert_row(), test_workspace_methods(), and xml_read_from_stream().
Read only index operator.
This has to correctly handle two cases:
r | Row index. |
c | Column index. |
Definition at line 130 of file matpackII.cc.
Referenced by sensor_responseStokesRotation().
Read and write index operator.
This has to correctly handle two cases:
r | Row index. |
c | Column index. |
Definition at line 91 of file matpackII.cc.
Referenced by mueller_rotation(), random_fill_matrix(), Select(), test40(), and test49().
Reduce matrix to the row range [offset, offset + nrows].
Definition at line 296 of file matpackII.cc.
Absolute value of sparse matrix elements.
Computes the absolute values of the elements in sparse matrix B.
The output matrix A must have been initialized with the correct size.
A | Output: Absolute value matrix. |
B | Original matrix. |
Definition at line 394 of file matpackII.cc.
Calculates A = B+C, where result A is sparse, and B and C are also sparse.
Output comes first!
Dimensions of B, and C must match. A will be resized.
A | Output: Result matrix. |
B | First summand matrix. |
C | Second summand matrix. |
Definition at line 630 of file matpackII.cc.
|
friend |
Sparse identity matrix.
Set the given Sparse matrix object to the identity matrix. The matrix must be square.
A | The matrix to be set to the identity matrix. |
Definition at line 647 of file matpackII.cc.
|
friend |
Matrix - SparseMatrix multiplication.
Calculates the matrix product:
A = B*C, where C is sparse.
Output comes first!
Dimensions of A, B, and C must match. No memory reallocation takes place, only the data is copied.
A | Output: Result matrix (full). |
B | First matrix to multiply (sparse). |
C | Second matrix to multiply (full). |
Definition at line 539 of file matpackII.cc.
|
friend |
SparseMatrix - Matrix multiplication.
Calculates the matrix product:
A = B*C, where B is sparse.
Output comes first!
Dimensions of A, B, and C must match. No memory reallocation takes place, only the data is copied.
A | Output: Result matrix (full). |
B | First matrix to multiply (sparse). |
C | Second matrix to multiply (full). |
Definition at line 490 of file matpackII.cc.
Sparse - Sparse multiplication.
Calculates A = B*C, where result A is sparse, and B and C are also sparse.
Output comes first!
Dimensions of A, B, and C must match. No memory reallocation takes place, only the data is copied.
A | Output: Result matrix. |
B | First product matrix. |
C | Second product matrix. |
Definition at line 606 of file matpackII.cc.
|
friend |
Sparse matrix - Vector multiplication.
This calculates the product
y = M*x, where M is sparse.
Output comes first!
Dimensions of y, M, and x must match. No memory reallocation takes place, only the data is copied.
y | Output: The multiplication result. |
M | Matrix for multiplication (sparse). |
x | Vector for multiplication. |
Definition at line 417 of file matpackII.cc.
|
friend |
Output operator for Sparse.
os | Output stream. |
v | Sparse matrix to print. |
Definition at line 375 of file matpackII.cc.
Calculates A = B-C, where result A is sparse, and B and C are also sparse.
Output comes first!
Dimensions of B, and C must match. A will be resized.
A | Output: Result matrix. |
B | First subtrahend matrix. |
C | Second subtrahend matrix. |
Definition at line 667 of file matpackII.cc.
Transpose of sparse matrix.
Computes the transpose of the sparse matrix B.
The output matrix A must have been initialized with the correct size.
A | Output: Transposed matrix. |
B | Original matrix. |
Definition at line 582 of file matpackII.cc.
|
friend |
Sparse matrix - Vector multiplication.
This calculates the product
y = M*x, where M is sparse.
Output comes first!
Dimensions of y, M, and x must match. No memory reallocation takes place, only the data is copied.
y | Output: The multiplication result. |
M | Matrix for multiplication (sparse). |
x | Vector for multiplication. |
Definition at line 452 of file matpackII.cc.
|
private |
The actual matrix.
Definition at line 141 of file matpackII.h.
Referenced by abs(), add(), diagonal(), empty(), get_column_index_pointer(), get_element_pointer(), get_row_start_pointer(), id_mat(), insert_elements(), insert_row(), list_elements(), mult(), ncols(), nnz(), nrows(), operator*=(), operator+=(), operator-=(), operator/=(), split(), sub(), and transpose().