ARTS 2.5.0 (git: 9ee3ac6c)
Sparse Class Reference

The Sparse class. More...

#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...

Numericrw (Index r, Index c)
Read and write index operator. More...

Numeric ro (Index r, Index c) const

Numeric operator() (Index r, Index c) const
Plain index operator. More...

Sparseoperator+= (const Sparse &x)

Sparseoperator-= (const Sparse &x)
Subtract sparse matrix. More...

Sparseoperator*= (Numeric x)
Scale matrix. More...

Sparseoperator/= (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...

Numericget_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)

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...

Detailed Description

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 67 of file matpackII.h.

◆ Sparse() [1/2]

 Sparse::Sparse ( )

Default constructor.

Date
Tue Jul 15 15:05:40 2003

Definition at line 148 of file matpackII.cc.

◆ Sparse() [2/2]

 Sparse::Sparse ( Index r, Index c )

Constructor setting size.

Parameters
 r Row dimension of new sparse matrix. c Column dimension of new sparse matrix.

Definition at line 157 of file matpackII.cc.

◆ diagonal() [1/2]

 Vector Sparse::diagonal ( ) const

Diagonal elements as vector.

Extracts the diagonal elements from the sparse matrix. matrix.

Returns
A vector containing the diagonal elements.

Definition at line 172 of file matpackII.cc.

References matrix, min, ncols(), and nrows().

◆ diagonal() [2/2]

 Sparse Sparse::diagonal ( ConstVectorView v )
static

Create a sparse matrix from a vector.

Parameters
 v vector containing the diagonal elements.
Returns
Sparse matrix with the elements of the given vector on the diagonal.

Definition at line 161 of file matpackII.cc.

References insert_elements(), and v.

◆ empty()

 bool Sparse::empty ( ) const

Returns true if variable size is zero.

Definition at line 61 of file matpackII.cc.

References matrix.

◆ get_column_index_pointer()

 int * Sparse::get_column_index_pointer ( )
inline

Definition at line 130 of file matpackII.h.

References matrix.

Referenced by get_covariance_matrix_block(), and get_variable_value().

◆ get_element_pointer()

 Numeric * Sparse::get_element_pointer ( )
inline

Definition at line 129 of file matpackII.h.

References matrix.

Referenced by get_covariance_matrix_block(), and get_variable_value().

◆ get_row_start_pointer()

 int * Sparse::get_row_start_pointer ( )
inline

Definition at line 131 of file matpackII.h.

References matrix.

Referenced by get_covariance_matrix_block(), and get_variable_value().

◆ insert_elements()

 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.

Parameters
 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.

References data, and matrix.

◆ insert_row()

 void Sparse::insert_row ( Index r, Vector v )

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.

Parameters
 r Where to insert the row v Vector to be inserted.

Definition at line 314 of file matpackII.cc.

References ARTS_ASSERT, matrix, ncols(), nrows(), and v.

◆ list_elements()

 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.

Parameters
 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().

◆ ncols()

 Index Sparse::ncols ( ) const

◆ nnz()

 Index Sparse::nnz ( ) const

Returns the number of nonzero elements.

Definition at line 72 of file matpackII.cc.

References matrix.

◆ nrows()

 Index Sparse::nrows ( ) const

◆ operator Matrix()

 Sparse::operator Matrix ( ) const
explicit

Convert to dense matrix.

Converts a given sparse matrix to a dense matrix. Intended mainly for testing purposes.

Returns
The dense representation of the given sparse matrix.

Definition at line 189 of file matpackII.cc.

References IGRF::matrix(), ncols, and nrows.

◆ operator()()

 Numeric Sparse::operator() ( Index r, Index c ) const

Plain index operator.

This is the same as the .ro index operator.

Parameters
 r Row index. c Column index.
Returns
The data element with these indices.

Definition at line 111 of file matpackII.cc.

References c, and matrix.

◆ operator*=()

 Sparse & Sparse::operator*= ( Numeric x )

Scale matrix.

Parameters
 x Scalar factor to scale the matrix with.
Returns
Reference to the scaled sparse matrix object.

Definition at line 243 of file matpackII.cc.

References matrix.

◆ operator+=()

 Sparse & Sparse::operator+= ( const Sparse & A )

Element-wise, in-situ sum of two sparse matrices. Matrix must have the same dimensions.

Parameters
 A The sparse matrix to add to the Sparse object.
Returns
Reference to the resulting sum.

Definition at line 215 of file matpackII.cc.

References matrix.

◆ operator-=()

 Sparse & Sparse::operator-= ( const Sparse & A )

Subtract sparse matrix.

Element-wise, in-situ difference of two sparse matrices. Matrix must have the same dimensions.

Parameters
 A The sparse matrix to add to the Sparse object.
Returns
Reference to the resulting sum.

Definition at line 231 of file matpackII.cc.

References matrix.

◆ operator/=()

 Sparse & Sparse::operator/= ( Numeric x )

Scale matrix by reciprocal.

Parameters
 x Reciprocal of the factor to scale the matrix with.
Returns
Reference to the scaled sparse matrix object.

Definition at line 255 of file matpackII.cc.

References matrix.

◆ resize()

 void Sparse::resize ( Index r, Index c )

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.

Parameters
 r New row dimension. c New column dimension.

Definition at line 361 of file matpackII.cc.

References ARTS_ASSERT, c, and matrix.

◆ ro()

 Numeric Sparse::ro ( Index r, Index c ) const

This has to correctly handle two cases:

1. The data element exists. In this case the element is returned.
2. The element does not exist. In this case the value 0 is returned.
Parameters
 r Row index. c Column index.
Returns
The data element with these indices, or zero.
Date
Tue Jul 15 15:05:40 2003

Definition at line 130 of file matpackII.cc.

References ARTS_ASSERT, c, and nrows().

Referenced by sensor_responseStokesRotation().

◆ rw()

 Numeric & Sparse::rw ( Index r, Index c )

This has to correctly handle two cases:

1. The data element exists. In this case the operator acts similar to the const index operator in that the element is returned.
2. The element does not exist. In this case it is created.
Parameters
 r Row index. c Column index.
Returns
The data element with these indices.

Definition at line 91 of file matpackII.cc.

References ARTS_ASSERT, c, matrix, ncols(), and nrows().

◆ split()

 void Sparse::split ( Index offset, Index nrows )

Reduce matrix to the row range [offset, offset + nrows].

Definition at line 296 of file matpackII.cc.

References matrix, and ncols().

◆ abs

 void abs ( Sparse & A, const Sparse & B )
friend

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.

Parameters
 A Output: Absolute value matrix. B Original matrix.
Date
2005-03-21

Definition at line 394 of file matpackII.cc.

 void add ( Sparse & A, const Sparse & B, const Sparse & C )
friend

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.

Parameters
 A Output: Result matrix. B First summand matrix. C Second summand matrix.
Date
2009-09-03

Definition at line 630 of file matpackII.cc.

◆ id_mat

 void id_mat ( Sparse & A )
friend

Sparse identity matrix.

Set the given Sparse matrix object to the identity matrix. The matrix must be square.

Parameters
 A The matrix to be set to the identity matrix.

Definition at line 647 of file matpackII.cc.

◆ mult [1/4]

 void mult ( MatrixView A, const ConstMatrixView & B, const Sparse & C )
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.

Parameters
 A Output: Result matrix (full). B First matrix to multiply (sparse). C Second matrix to multiply (full).
Date
Tue Jul 15 15:05:40 2003

Definition at line 539 of file matpackII.cc.

◆ mult [2/4]

 void mult ( MatrixView A, const Sparse & B, const ConstMatrixView & C )
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.

Parameters
 A Output: Result matrix (full). B First matrix to multiply (sparse). C Second matrix to multiply (full).
Date
Tue Jul 15 15:05:40 2003

Definition at line 490 of file matpackII.cc.

◆ mult [3/4]

 void mult ( Sparse & A, const Sparse & B, const Sparse & C )
friend

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.

Parameters
 A Output: Result matrix. B First product matrix. C Second product matrix.
Date
2003-08-06

Definition at line 606 of file matpackII.cc.

◆ mult [4/4]

 void mult ( VectorView y, const Sparse & M, ConstVectorView x )
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.

Parameters
 y Output: The multiplication result. M Matrix for multiplication (sparse). x Vector for multiplication.

Definition at line 417 of file matpackII.cc.

◆ operator<<

 std::ostream & operator<< ( std::ostream & os, const Sparse & v )
friend

Output operator for Sparse.

Parameters
 os Output stream. v Sparse matrix to print.
Returns
Output stream.

Definition at line 375 of file matpackII.cc.

◆ sub

 void sub ( Sparse & A, const Sparse & B, const Sparse & C )
friend

Sparse - Sparse subtraction.

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.

Parameters
 A Output: Result matrix. B First subtrahend matrix. C Second subtrahend matrix.
Date
2009-09-03

Definition at line 667 of file matpackII.cc.

◆ transpose

 void transpose ( Sparse & A, const Sparse & B )
friend

Transpose of sparse matrix.

Computes the transpose of the sparse matrix B.

The output matrix A must have been initialized with the correct size.

Parameters
 A Output: Transposed matrix. B Original matrix.
Date
2003-08-05

Definition at line 582 of file matpackII.cc.

◆ transpose_mult

 void transpose_mult ( VectorView y, const Sparse & M, ConstVectorView x )
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.

Parameters
 y Output: The multiplication result. M Matrix for multiplication (sparse). x Vector for multiplication.

Definition at line 452 of file matpackII.cc.

◆ matrix

 Eigen::SparseMatrix Sparse::matrix
private

The actual matrix.

Definition at line 148 of file matpackII.h.

The documentation for this class was generated from the following files: