ARTS  2.2.66
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 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
 
Numericrw (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< Numericmdata
 The actual data values. More...
 
std::vector< Indexmrowind
 Row indices. More...
 
std::vector< Indexmcolptr
 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...
 

Detailed Description

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.

Author
Stefan Buehler sbueh.nosp@m.ler@.nosp@m.ltu.s.nosp@m.e
Date
Tue Jul 15 15:05:40 2003

Definition at line 55 of file matpackII.h.

Constructor & Destructor Documentation

◆ Sparse() [1/2]

Sparse::Sparse ( )

Default constructor.

Author
Stefan Buehler sbueh.nosp@m.ler@.nosp@m.ltu.s.nosp@m.e
Date
Tue Jul 15 15:05:40 2003

Definition at line 209 of file matpackII.cc.

◆ Sparse() [2/2]

Sparse::Sparse ( Index  r,
Index  c 
)

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.

Parameters
rRow dimension of new sparse matrix.
cColumn dimension of new sparse matrix.
Author
Stefan Buehler sbueh.nosp@m.ler@.nosp@m.ltu.s.nosp@m.e
Date
Tue Jul 15 15:05:40 2003

Definition at line 238 of file matpackII.cc.

Member Function Documentation

◆ colptr()

const std::vector<Index>& Sparse::colptr ( ) const
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().

◆ data()

const std::vector<Numeric>& Sparse::data ( ) const
inline

Definition at line 75 of file matpackII.h.

References mdata.

Referenced by add(), and xml_write_to_stream().

◆ 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
rWhere to insert the row
vVector to be inserted.
Author
Mattias Ekstr?m ekstr.nosp@m.om@r.nosp@m.ss.ch.nosp@m.alme.nosp@m.rs.se
Date
2003-08-11

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_I()

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

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.

Parameters
rNew row dimension.
cNew column dimension.
Author
Mattias Ekstr?m
Date
2003-12-05

Definition at line 430 of file matpackII.cc.

References mcolptr, mcr, mdata, min, mrowind, and mrr.

Referenced by sensor_responseInit(), and test47().

◆ ncols()

◆ nnz()

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

◆ nrows()

◆ operator()()

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

Plain index operator.

This is the same as the .ro index operator.

Parameters
rRow index.
cColumn index.
Returns
The data element with these indices.
Author
Stefan Buehler sbueh.nosp@m.ler@.nosp@m.ltu.s.nosp@m.e
Date
Tue Jul 15 15:05:40 2003

Definition at line 152 of file matpackII.cc.

References ro().

Referenced by colptr().

◆ 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
rNew row dimension.
cNew column dimension.
Author
Stefan Buehler sbueh.nosp@m.ler@.nosp@m.ltu.s.nosp@m.e
Date
Tue Jul 15 15:05:40 2003

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

◆ ro()

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

Read only index operator.

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
rRow index.
cColumn index.
Returns
The data element with these indices, or zero.
Author
Stefan Buehler sbueh.nosp@m.ler@.nosp@m.ltu.s.nosp@m.e
Date
Tue Jul 15 15:05:40 2003

Definition at line 170 of file matpackII.cc.

References mcolptr, mcr, mdata, mrowind, and mrr.

Referenced by colptr(), and operator()().

◆ rowind()

const std::vector<Index>& Sparse::rowind ( ) const
inline

Definition at line 76 of file matpackII.h.

References mrowind.

Referenced by xml_write_to_stream().

◆ rw()

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

Read and write index operator.

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
rRow index.
cColumn index.
Returns
The data element with these indices.
Author
Stefan Buehler sbueh.nosp@m.ler@.nosp@m.ltu.s.nosp@m.e
Date
Tue Jul 15 15:05:40 2003

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

Friends And Related Function Documentation

◆ 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
AOutput: Absolute value matrix.
BOriginal matrix.
Author
Mattias Ekstrom
Date
2005-03-21

Definition at line 537 of file matpackII.cc.

Referenced by colptr().

◆ add

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

Sparse - Sparse addition.

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
AOutput: Result matrix.
BFirst summand matrix.
CSecond summand matrix.
Author
Oliver Lemke
Date
2009-09-03

Definition at line 871 of file matpackII.cc.

Referenced by colptr().

◆ mult [1/3]

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
yOutput: The multiplication result.
MMatrix for multiplication (sparse).
xVector for multiplication.
Author
Stefan Buehler sbueh.nosp@m.ler@.nosp@m.ltu.s.nosp@m.e
Date
Tue Jul 15 15:05:40 2003

Definition at line 579 of file matpackII.cc.

Referenced by colptr().

◆ mult [2/3]

void mult ( MatrixView  A,
const Sparse B,
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
AOutput: Result matrix (full).
BFirst matrix to multiply (sparse).
CSecond matrix to multiply (full).
Author
Stefan Buehler sbueh.nosp@m.ler@.nosp@m.ltu.s.nosp@m.e
Date
Tue Jul 15 15:05:40 2003

Definition at line 633 of file matpackII.cc.

◆ mult [3/3]

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
AOutput: Result matrix.
BFirst product matrix.
CSecond product matrix.
Author
Mattias Ekstroem
Date
2003-08-06

Definition at line 780 of file matpackII.cc.

◆ operator<<

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

Output operator for Sparse.

Parameters
osOutput stream.
vSparse matrix to print.
Returns
Output stream.
Author
Stefan Buehler sbueh.nosp@m.ler@.nosp@m.ltu.s.nosp@m.e
Date
Tue Jul 15 15:05:40 2003

Definition at line 495 of file matpackII.cc.

Referenced by colptr().

◆ 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
AOutput: Result matrix.
BFirst subtrahend matrix.
CSecond subtrahend matrix.
Author
Oliver Lemke
Date
2009-09-03

Definition at line 920 of file matpackII.cc.

Referenced by colptr().

◆ 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
AOutput: Transposed matrix.
BOriginal matrix.
Author
Mattias Ekstroem
Date
2003-08-05

Definition at line 689 of file matpackII.cc.

Referenced by colptr(), and mult().

Member Data Documentation

◆ mcolptr

std::vector<Index> Sparse::mcolptr
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().

◆ mcr

Index Sparse::mcr
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().

◆ mdata

std::vector<Numeric> Sparse::mdata
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().

◆ mrowind

std::vector<Index> Sparse::mrowind
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().

◆ mrr

Index Sparse::mrr
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().


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