ARTS
2.0.49
|
#include <matpackII.h>
Public Member Functions | |
Sparse () | |
Default constructor. More... | |
Sparse (Index r, Index c) | |
Constructor setting size. More... | |
Sparse (const Sparse &m) | |
Copy constructor from another Sparse. 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... | |
~Sparse () | |
Destructor for Sparse. 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 vector< Numeric > * | data () const |
const vector< Index > * | rowind () const |
const 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... | |
Sparse & | operator= (const Sparse &m) |
Assignment from another Sparse. More... | |
Private Attributes | |
vector< Numeric > * | mdata |
The actual data values. More... | |
vector< Index > * | mrowind |
Row indices. More... | |
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 | |
ostream & | operator<< (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 235 of file matpackII.cc.
Sparse::Sparse | ( | const Sparse & | m | ) |
Sparse::~Sparse | ( | ) |
|
inline |
|
inline |
Definition at line 79 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 303 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_responseMultiMixerBackend(), sensor_responsePolarisation(), 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 474 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 59 of file matpackII.cc.
References mcr.
Referenced by abs(), add(), antenna1d_matrix(), jacobianCalcFreqShiftAndStretchInterp(), mult(), Select(), sensor_responseAntenna(), sensor_responseBackend(), sensor_responseBeamSwitching(), sensor_responseFillFgrid(), sensor_responseFrequencySwitching(), sensor_responseMixer(), sensor_responsePolarisation(), sensor_responseWMRF(), SparseSparseMultiply(), sub(), test44(), test45(), test46(), transpose(), WMRFSelectChannels(), xml_write_to_stream(), yCalc(), and yCalc2().
Index Sparse::nnz | ( | ) | const |
Returns the number of nonzero elements.
Definition at line 65 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 53 of file matpackII.cc.
References mrr.
Referenced by abs(), add(), get_rowindex_for_mblock(), jacobianCalcAbsSpeciesPerturbations(), jacobianCalcFreqShiftAndStretchInterp(), jacobianCalcPointingZaInterp(), jacobianCalcPointingZaRecalc(), jacobianCalcTemperaturePerturbations(), jacobianClose(), mult(), Select(), sensor_responseAntenna(), sensor_responseBackend(), sensor_responseBeamSwitching(), sensor_responseFillFgrid(), sensor_responseFrequencySwitching(), sensor_responseMixer(), sensor_responseMultiMixerBackend(), sensor_responsePolarisation(), sensor_responseWMRF(), SparseSparseMultiply(), sub(), test44(), test45(), test46(), transpose(), WMRFSelectChannels(), xml_write_to_stream(), yCalc(), and yCalc2().
Plain index operator.
This is the same as the .ro index operator.
r | Row index. |
c | Column index. |
Definition at line 149 of file matpackII.cc.
References ro().
Assignment from another Sparse.
It is crucial that we implement this, otherwise the compiler creates a default assignment operator which does not do the right thing. (It will lead to segmentation faults).
The dimensions of the target sparse matrix are adjusted automatically. This is important, so that structures containing Sparse are copied correctly.
m | The other Sparse to copy to this one. |
Definition at line 551 of file matpackII.cc.
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 516 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_responseMixer(), sensor_responseMultiMixerBackend(), sensor_responsePolarisation(), 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 167 of file matpackII.cc.
References mcr, mdata, and mrr.
Referenced by operator()().
|
inline |
Read and write index operator.
This has to correctly handle two cases:
r | Row index. |
c | Column index. |
Definition at line 90 of file matpackII.cc.
Referenced by add(), mult(), sub(), 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 641 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 974 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 736 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 883 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 683 of file matpackII.cc.
|
friend |
Output operator for Sparse.
os | Output stream. |
v | Sparse matrix to print. |
Definition at line 599 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 1023 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 792 of file matpackII.cc.
|
private |
Pointers to first data element for each column.
Definition at line 107 of file matpackII.h.
Referenced by abs(), add(), colptr(), insert_row(), make_I(), mult(), nnz(), operator<<(), operator=(), resize(), Sparse(), sub(), transpose(), and ~Sparse().
|
private |
Number of rows in the sparse matrix.
Definition at line 111 of file matpackII.h.
Referenced by insert_row(), make_I(), mult(), ncols(), operator=(), resize(), ro(), and transpose().
|
private |
The actual data values.
Definition at line 103 of file matpackII.h.
Referenced by abs(), add(), data(), insert_row(), make_I(), mult(), operator<<(), operator=(), resize(), ro(), Sparse(), sub(), transpose(), and ~Sparse().
|
private |
Row indices.
Definition at line 105 of file matpackII.h.
Referenced by abs(), add(), insert_row(), make_I(), mult(), operator<<(), operator=(), resize(), rowind(), Sparse(), sub(), transpose(), and ~Sparse().
|
private |
Number of rows in the sparse matrix.
Definition at line 109 of file matpackII.h.
Referenced by insert_row(), make_I(), nrows(), operator=(), resize(), and ro().