ARTS
2.2.66
|
#include <matpackII.h>
Public Member Functions | |
Sparse () | |
Default constructor. More... | |
Sparse (Index r, Index c) | |
Constructor setting size. More... | |
void | insert_row (Index r, Vector v) |
Insert row function. More... | |
void | make_I (Index r, Index c) |
Make Identity matrix. More... | |
void | resize (Index r, Index c) |
Resize function. 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... | |
const std::vector< Numeric > & | data () const |
const std::vector< Index > & | rowind () const |
const std::vector< Index > & | colptr () const |
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... | |
Private Attributes | |
std::vector< Numeric > | mdata |
The actual data values. More... | |
std::vector< Index > | mrowind |
Row indices. More... | |
std::vector< Index > | mcolptr |
Pointers to first data element for each column. More... | |
Index | mrr |
Number of rows in the sparse matrix. More... | |
Index | mcr |
Number of rows in the sparse 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 | mult (MatrixView A, const Sparse &B, ConstMatrixView C) |
SparseMatrix - Matrix 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... | |
The Sparse class.
The chosen storage format is the `compressed column' format. This is the same format used by Matlab. See Matlab User Guide for a description.
Definition at line 55 of file matpackII.h.
Sparse::Sparse | ( | ) |
Constructor setting size.
Elements *mdata and *mrowind have to grow later on, when we add data elements. But *mcolptr always has the dimension of the number of columns of the matrix plus one, so it is allocated directly. (And properly initialized to zero.)
Why is there an extra element in mcolptr? We store also the index behind the last element of the last column. Or in other words the starting index that the next column would have. This just safes a little time when computing indices. Also, this corresponds to the number of nonzero elements.
r | Row dimension of new sparse matrix. |
c | Column dimension of new sparse matrix. |
Definition at line 238 of file matpackII.cc.
|
inline |
Definition at line 77 of file matpackII.h.
References abs, add, C, M, mcolptr, mult, operator()(), operator<<, ro(), rw(), sub, and transpose.
Referenced by xml_write_to_stream().
|
inline |
Definition at line 75 of file matpackII.h.
References mdata.
Referenced by add(), and xml_write_to_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 264 of file matpackII.cc.
References copy(), mcolptr, mcr, mdata, mrowind, mrr, and ConstVectorView::nelem().
Referenced by antenna1d_matrix(), antenna2d_simplified(), mixer_matrix(), sensor_responseBeamSwitching(), sensor_responseFillFgrid(), sensor_responseFrequencySwitching(), sensor_responseGenericAMSU(), sensor_responseMultiMixerBackend(), spectrometer_matrix(), and test44().
Make Identity matrix.
This functions sets the Sparse matrix to be an identity matrix.
The matrix will be remade to fit the given number of rows and columns.
r | New row dimension. |
c | New column dimension. |
Definition at line 430 of file matpackII.cc.
References mcolptr, mcr, mdata, min, mrowind, and mrr.
Referenced by sensor_responseInit(), and test47().
Index Sparse::ncols | ( | ) | const |
Returns the number of columns.
Definition at line 62 of file matpackII.cc.
References mcr.
Referenced by abs(), add(), antenna1d_matrix(), jacobianCalcFreqShift(), jacobianCalcFreqStretch(), mult(), Select(), sensor_checkedCalc(), sensor_responseAntenna(), sensor_responseBackend(), sensor_responseBeamSwitching(), sensor_responseFillFgrid(), sensor_responseFrequencySwitching(), sensor_responseMixer(), sensor_responsePolarisation(), sensor_responseStokesRotation(), sensor_responseWMRF(), SparseSparseMultiply(), sub(), test44(), test45(), test46(), transpose(), WMRFSelectChannels(), and xml_write_to_stream().
Index Sparse::nnz | ( | ) | const |
Returns the number of nonzero elements.
Definition at line 68 of file matpackII.cc.
References mcolptr.
Referenced by Select(), and xml_write_to_stream().
Index Sparse::nrows | ( | ) | const |
Returns the number of rows.
Definition at line 56 of file matpackII.cc.
References mrr.
Referenced by abs(), add(), get_rowindex_for_mblock(), jacobianCalcAbsSpeciesPerturbations(), jacobianCalcFreqShift(), jacobianCalcFreqStretch(), jacobianCalcPointingZaInterp(), jacobianCalcPointingZaRecalc(), jacobianCalcTemperaturePerturbations(), jacobianClose(), mult(), Select(), sensor_checkedCalc(), sensor_responseAntenna(), sensor_responseBackend(), sensor_responseBeamSwitching(), sensor_responseFillFgrid(), sensor_responseFrequencySwitching(), sensor_responseMixer(), sensor_responseMultiMixerBackend(), sensor_responsePolarisation(), sensor_responseStokesRotation(), sensor_responseWMRF(), SparseSparseMultiply(), sub(), test44(), test45(), test46(), transpose(), WMRFSelectChannels(), xml_write_to_stream(), yCalc(), and ySimpleSpectrometer().
Plain index operator.
This is the same as the .ro index operator.
r | Row index. |
c | Column index. |
Definition at line 152 of file matpackII.cc.
References ro().
Referenced by colptr().
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 469 of file matpackII.cc.
References mcolptr, mcr, mdata, mrowind, and mrr.
Referenced by antenna1d_matrix(), antenna2d_simplified(), mixer_matrix(), sensor_responseAntenna(), sensor_responseBackend(), sensor_responseBeamSwitching(), sensor_responseFillFgrid(), sensor_responseFrequencySwitching(), sensor_responseGenericAMSU(), sensor_responseMixer(), sensor_responseMultiMixerBackend(), sensor_responsePolarisation(), sensor_responseStokesRotation(), sensor_responseWMRF(), spectrometer_matrix(), WMRFSelectChannels(), 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 170 of file matpackII.cc.
References mcolptr, mcr, mdata, mrowind, and mrr.
Referenced by colptr(), and operator()().
|
inline |
Read and write index operator.
This has to correctly handle two cases:
r | Row index. |
c | Column index. |
Definition at line 93 of file matpackII.cc.
References mcolptr, mcr, mdata, mrowind, and mrr.
Referenced by add(), colptr(), mult(), sub(), test3(), test40(), test41(), test42(), test43(), test44(), test48(), test49(), and xml_read_from_stream().
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 537 of file matpackII.cc.
Referenced by colptr().
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 871 of file matpackII.cc.
Referenced by colptr().
|
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 579 of file matpackII.cc.
Referenced by colptr().
|
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 633 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 780 of file matpackII.cc.
|
friend |
Output operator for Sparse.
os | Output stream. |
v | Sparse matrix to print. |
Definition at line 495 of file matpackII.cc.
Referenced by colptr().
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 920 of file matpackII.cc.
Referenced by colptr().
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 689 of file matpackII.cc.
|
private |
Pointers to first data element for each column.
Definition at line 100 of file matpackII.h.
Referenced by abs(), add(), colptr(), insert_row(), make_I(), mult(), nnz(), operator<<(), resize(), ro(), rw(), sub(), and transpose().
|
private |
Number of rows in the sparse matrix.
Definition at line 104 of file matpackII.h.
Referenced by insert_row(), make_I(), mult(), ncols(), resize(), ro(), rw(), and transpose().
|
private |
The actual data values.
Definition at line 96 of file matpackII.h.
Referenced by abs(), data(), insert_row(), make_I(), mult(), operator<<(), resize(), ro(), rw(), sub(), and transpose().
|
private |
Row indices.
Definition at line 98 of file matpackII.h.
Referenced by abs(), insert_row(), make_I(), mult(), operator<<(), resize(), ro(), rowind(), rw(), sub(), and transpose().
|
private |
Number of rows in the sparse matrix.
Definition at line 102 of file matpackII.h.
Referenced by insert_row(), make_I(), nrows(), resize(), ro(), and rw().