ARTS 2.5.4 (git: 4c0d3b4d)
MatrixView Class Reference

The MatrixView class. More...

#include <matpackI.h>

Inheritance diagram for MatrixView:
ConstMatrixView Matrix

Public Types

using iterator = Iterator2D
 
- Public Types inherited from ConstMatrixView
using const_iterator = ConstIterator2D
 

Public Member Functions

constexpr MatrixView (const MatrixView &)=default
 
Numericoperator() (Index r, Index c) ARTS_NOEXCEPT
 Plain index operator. More...
 
Numericget (Index r, Index c) ARTS_NOEXCEPT
 Get element implementation without assertions. More...
 
MatrixView operator() (const Range &r, const Range &c) ARTS_NOEXCEPT
 Index operator for subrange. More...
 
VectorView operator() (const Range &r, Index c) ARTS_NOEXCEPT
 Index operator returning a column as an object of type VectorView. More...
 
VectorView operator() (Index r, const Range &c) ARTS_NOEXCEPT
 Index operator returning a row as an object of type VectorView. More...
 
Iterator2D begin () ARTS_NOEXCEPT
 ‍** Return const iterator to first row. Has to be redefined here, since it is More...
 
Iterator2D end () ARTS_NOEXCEPT
 Return iterator behind last row. More...
 
MatrixViewoperator= (const ConstMatrixView &m)
 Assignment operator. More...
 
MatrixViewoperator= (const MatrixView &m)
 Assignment from MatrixView to MatrixView. More...
 
MatrixViewoperator= (const Matrix &m)
 Assignment from a Matrix. More...
 
MatrixViewoperator= (const ConstVectorView &m)
 Assignment from a vector. More...
 
MatrixViewoperator= (Numeric x)
 Assigning a scalar to a MatrixView will set all elements to this value. More...
 
MatrixViewoperator*= (Numeric x) ARTS_NOEXCEPT
 Multiplication by scalar. More...
 
MatrixViewoperator/= (Numeric x) ARTS_NOEXCEPT
 Division by scalar. More...
 
MatrixViewoperator+= (Numeric x) ARTS_NOEXCEPT
 Addition of scalar. More...
 
MatrixViewoperator-= (Numeric x) ARTS_NOEXCEPT
 Subtraction of scalar. More...
 
MatrixViewoperator*= (const ConstMatrixView &x) ARTS_NOEXCEPT
 Element-vise multiplication by another Matrix. More...
 
MatrixViewoperator/= (const ConstMatrixView &x) ARTS_NOEXCEPT
 Element-vise division by another Matrix. More...
 
MatrixViewoperator+= (const ConstMatrixView &x) ARTS_NOEXCEPT
 Element-vise addition of another Matrix. More...
 
MatrixViewoperator-= (const ConstMatrixView &x) ARTS_NOEXCEPT
 Element-vise subtraction of another Matrix. More...
 
MatrixViewoperator*= (const ConstVectorView &x) ARTS_NOEXCEPT
 Element-vise multiplication by a Vector (acting like a 1-column Matrix). More...
 
MatrixViewoperator/= (const ConstVectorView &x) ARTS_NOEXCEPT
 Element-vise division by a Vector (acting like a 1-column Matrix). More...
 
MatrixViewoperator+= (const ConstVectorView &x) ARTS_NOEXCEPT
 Element-vise addition of a Vector (acting like a 1-column Matrix). More...
 
MatrixViewoperator-= (const ConstVectorView &x) ARTS_NOEXCEPT
 Element-vise subtraction of a Vector (acting like a 1-column Matrix). More...
 
const Numericget_c_array () const ARTS_NOEXCEPT
 Conversion to plain C-array. More...
 
Numericget_c_array () ARTS_NOEXCEPT
 Conversion to plain C-array. More...
 
virtual ~MatrixView ()=default
 Destructor. More...
 
ConstIterator2D begin () const ARTS_NOEXCEPT
 Return const iterator to first row. More...
 
ConstIterator2D end () const ARTS_NOEXCEPT
 Return const iterator behind last row. More...
 
Numeric get (Index r, Index c) const ARTS_NOEXCEPT
 Get element implementation without assertions. More...
 
- Public Member Functions inherited from ConstMatrixView
constexpr ConstMatrixView (const ConstMatrixView &)=default
 
constexpr ConstMatrixView (ConstMatrixView &&)=default
 
ConstMatrixViewoperator= (const ConstMatrixView &)=default
 
ConstMatrixViewoperator= (ConstMatrixView &&)=default
 
Index nrows () const noexcept
 
Index ncols () const noexcept
 
Index size () const noexcept
 
bool empty () const noexcept
 
Shape< 2 > shape () const
 
Numeric operator() (Index r, Index c) const ARTS_NOEXCEPT
 Plain const index operator. More...
 
Numeric get (Index r, Index c) const ARTS_NOEXCEPT
 Get element implementation without assertions. More...
 
ConstMatrixView operator() (const Range &r, const Range &c) const ARTS_NOEXCEPT
 Const index operator for subrange. More...
 
ConstVectorView operator() (const Range &r, Index c) const ARTS_NOEXCEPT
 Const index operator returning a column as an object of type ConstVectorView. More...
 
ConstVectorView operator() (Index r, const Range &c) const ARTS_NOEXCEPT
 Const index operator returning a row as an object of type ConstVectorView. More...
 
ConstIterator2D begin () const ARTS_NOEXCEPT
 Return const iterator to first row. More...
 
ConstIterator2D end () const ARTS_NOEXCEPT
 Return const iterator behind last row. More...
 
ConstVectorView diagonal () const ARTS_NOEXCEPT
 Matrix diagonal as vector. More...
 
virtual ~ConstMatrixView ()=default
 Destructor. More...
 

Protected Member Functions

 MatrixView ()=default
 
 MatrixView (Numeric *data, const Range &rr, const Range &cr) ARTS_NOEXCEPT
 Explicit constructor. More...
 
 MatrixView (Numeric *data, const Range &pr, const Range &pc, const Range &nr, const Range &nc) ARTS_NOEXCEPT
 Recursive constructor. More...
 
- Protected Member Functions inherited from ConstMatrixView
 ConstMatrixView ()=default
 
 ConstMatrixView (Numeric *data, const Range &r, const Range &c) ARTS_NOEXCEPT
 Explicit constructor. More...
 
 ConstMatrixView (Numeric *data, const Range &pr, const Range &pc, const Range &nr, const Range &nc) ARTS_NOEXCEPT
 Recursive constructor. More...
 

Friends

class VectorView
 
class Iterator3D
 
class Tensor3View
 
class Tensor4View
 
class Tensor5View
 
class Tensor6View
 
class Tensor7View
 
class ComplexMatrixView
 
ConstMatrixView transpose (ConstMatrixView m) ARTS_NOEXCEPT
 Const version of transpose. More...
 
MatrixView transpose (MatrixView m) ARTS_NOEXCEPT
 Returns the transpose. More...
 
void mult (MatrixView, const ConstMatrixView &, const ConstMatrixView &)
 Matrix-Matrix Multiplication. More...
 

Additional Inherited Members

- Protected Attributes inherited from ConstMatrixView
Range mrr {0, 0, 1}
 The row range of mdata that is actually used. More...
 
Range mcr {0, 0, 1}
 The column range of mdata that is actually used. More...
 
Numericmdata {nullptr}
 Pointer to the plain C array that holds the data. More...
 

Detailed Description

The MatrixView class.

This contains the main implementation of a Matrix. It defines the concepts of MatrixView. Plus additionally the recursive subrange operator, which makes it possible to create a MatrixView from a subrange of a MatrixView.

The class Matrix is just a special case of a MatrixView which also allocates storage.

Definition at line 1169 of file matpackI.h.

Member Typedef Documentation

◆ iterator

Definition at line 1180 of file matpackI.h.

Constructor & Destructor Documentation

◆ MatrixView() [1/4]

constexpr MatrixView::MatrixView ( const MatrixView )
constexprdefault

◆ ~MatrixView()

virtual MatrixView::~MatrixView ( )
virtualdefault

Destructor.

◆ MatrixView() [2/4]

MatrixView::MatrixView ( )
protecteddefault

◆ MatrixView() [3/4]

MatrixView::MatrixView ( Numeric data,
const Range rr,
const Range cr 
)
protected

Explicit constructor.

This one is used by Matrix to initialize its own MatrixView part. The row range rr must have a stride to account for the length of one row.

Definition at line 887 of file matpackI.cc.

◆ MatrixView() [4/4]

MatrixView::MatrixView ( Numeric data,
const Range pr,
const Range pc,
const Range nr,
const Range nc 
)
protected

Recursive constructor.

This is used to construct SubMatrices from SubMatrices. That means that the new ranges have to be interpreted relative to the original ranges.

The new ranges may contain -1 for the extent which acts as a joker. However, the used Range constructor converts this to an explicit range, consistent with the original Range.

Parameters
*dataThe actual data.
prPrevious range.
pcPrevious range.
nrNew Range.
ncNew Range.

Definition at line 908 of file matpackI.cc.

Member Function Documentation

◆ begin() [1/2]

Iterator2D MatrixView::begin ( )

‍** Return const iterator to first row. Has to be redefined here, since it is

‍** Return const iterator behind last row. *‍/ Return iterator to first row.

Definition at line 621 of file matpackI.cc.

References ConstMatrixView::mcr, ConstMatrixView::mdata, ConstMatrixView::mrr, Range::mstart, Range::mstride, and VectorView.

Referenced by copy(), Matrix::Matrix(), operator=(), Matrix::operator=(), and transform().

◆ begin() [2/2]

ConstIterator2D ConstMatrixView::begin ( ) const

Return const iterator to first row.

Definition at line 1095 of file matpackI.cc.

◆ end() [1/2]

Iterator2D MatrixView::end ( )

Return iterator behind last row.

Definition at line 626 of file matpackI.cc.

References ConstMatrixView::mcr, ConstMatrixView::mdata, Range::mextent, ConstMatrixView::mrr, Range::mstart, Range::mstride, and VectorView.

Referenced by copy(), and operator=().

◆ end() [2/2]

ConstIterator2D ConstMatrixView::end ( ) const

Return const iterator behind last row.

Definition at line 1096 of file matpackI.cc.

◆ get() [1/2]

Numeric & MatrixView::get ( Index  r,
Index  c 
)
inline

Get element implementation without assertions.

Definition at line 1195 of file matpackI.h.

References c, and ConstVectorView::mdata.

Referenced by interpweights().

◆ get() [2/2]

Numeric ConstMatrixView::get ( Index  r,
Index  c 
) const
inline

Get element implementation without assertions.

Definition at line 1084 of file matpackI.h.

◆ get_c_array() [1/2]

Numeric * MatrixView::get_c_array ( )

Conversion to plain C-array.

This function returns a pointer to the raw data. It fails if the MatrixView is not pointing to the beginning of a Matrix or the stride is not 1 because the caller expects to get a C array with continuous data.

Definition at line 754 of file matpackI.cc.

References ARTS_ASSERT, ConstMatrixView::mcr, ConstMatrixView::mdata, Range::mextent, ConstMatrixView::mrr, Range::mstart, Range::mstride, and ConstMatrixView::size().

◆ get_c_array() [2/2]

const Numeric * MatrixView::get_c_array ( ) const

Conversion to plain C-array.

This function returns a pointer to the raw data. It fails if the MatrixView is not pointing to the beginning of a Matrix or the stride is not 1 because the caller expects to get a C array with continuous data.

Definition at line 738 of file matpackI.cc.

References ARTS_ASSERT, ConstMatrixView::mcr, ConstMatrixView::mdata, Range::mextent, ConstMatrixView::mrr, Range::mstart, Range::mstride, and ConstMatrixView::size().

Referenced by nca_get_data_Matrix(), nca_put_var_Matrix(), nca_read_from_file(), nca_write_to_file(), Reduce(), and test38().

◆ operator()() [1/4]

MatrixView MatrixView::operator() ( const Range r,
const Range c 
)

Index operator for subrange.

We have to also account for the case, that *this is already a subrange of a Matrix. This allows correct recursive behavior.

Definition at line 578 of file matpackI.cc.

◆ operator()() [2/4]

VectorView MatrixView::operator() ( const Range r,
Index  c 
)

Index operator returning a column as an object of type VectorView.

Parameters
rA range of rows.
cIndex of selected column

Definition at line 587 of file matpackI.cc.

References ARTS_ASSERT, and c.

◆ operator()() [3/4]

VectorView MatrixView::operator() ( Index  r,
const Range c 
)

Index operator returning a row as an object of type VectorView.

Parameters
rIndex of selected row.
cRange of columns

Definition at line 599 of file matpackI.cc.

References ARTS_ASSERT, and c.

◆ operator()() [4/4]

Numeric & MatrixView::operator() ( Index  r,
Index  c 
)
inline

Plain index operator.

Definition at line 1184 of file matpackI.h.

References ARTS_ASSERT, c, and VectorView::get().

◆ operator*=() [1/3]

MatrixView & MatrixView::operator*= ( const ConstMatrixView x)

Element-vise multiplication by another Matrix.

Definition at line 765 of file matpackI.cc.

References ARTS_ASSERT, VectorView::begin(), ConstVectorView::begin(), c, VectorView::end(), and Zeeman::end().

◆ operator*=() [2/3]

MatrixView & MatrixView::operator*= ( const ConstVectorView x)

Element-vise multiplication by a Vector (acting like a 1-column Matrix).

Definition at line 829 of file matpackI.cc.

References ARTS_ASSERT, VectorView::begin(), c, and Zeeman::end().

◆ operator*=() [3/3]

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

Multiplication by scalar.

Definition at line 693 of file matpackI.cc.

References c, and Zeeman::end().

◆ operator+=() [1/3]

MatrixView & MatrixView::operator+= ( const ConstMatrixView x)

Element-vise addition of another Matrix.

Definition at line 797 of file matpackI.cc.

References ARTS_ASSERT, VectorView::begin(), ConstVectorView::begin(), c, VectorView::end(), and Zeeman::end().

◆ operator+=() [2/3]

MatrixView & MatrixView::operator+= ( const ConstVectorView x)

Element-vise addition of a Vector (acting like a 1-column Matrix).

Definition at line 857 of file matpackI.cc.

References ARTS_ASSERT, VectorView::begin(), c, and Zeeman::end().

◆ operator+=() [3/3]

MatrixView & MatrixView::operator+= ( Numeric  x)

Addition of scalar.

Definition at line 713 of file matpackI.cc.

References c, and Zeeman::end().

◆ operator-=() [1/3]

MatrixView & MatrixView::operator-= ( const ConstMatrixView x)

Element-vise subtraction of another Matrix.

Definition at line 813 of file matpackI.cc.

References ARTS_ASSERT, VectorView::begin(), ConstVectorView::begin(), c, VectorView::end(), and Zeeman::end().

◆ operator-=() [2/3]

MatrixView & MatrixView::operator-= ( const ConstVectorView x)

Element-vise subtraction of a Vector (acting like a 1-column Matrix).

Definition at line 871 of file matpackI.cc.

References ARTS_ASSERT, VectorView::begin(), c, and Zeeman::end().

◆ operator-=() [3/3]

MatrixView & MatrixView::operator-= ( Numeric  x)

Subtraction of scalar.

Definition at line 723 of file matpackI.cc.

References c, and Zeeman::end().

◆ operator/=() [1/3]

MatrixView & MatrixView::operator/= ( const ConstMatrixView x)

Element-vise division by another Matrix.

Definition at line 781 of file matpackI.cc.

References ARTS_ASSERT, VectorView::begin(), ConstVectorView::begin(), c, VectorView::end(), and Zeeman::end().

◆ operator/=() [2/3]

MatrixView & MatrixView::operator/= ( const ConstVectorView x)

Element-vise division by a Vector (acting like a 1-column Matrix).

Definition at line 843 of file matpackI.cc.

References ARTS_ASSERT, VectorView::begin(), c, and Zeeman::end().

◆ operator/=() [3/3]

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

Division by scalar.

Definition at line 703 of file matpackI.cc.

References c, and Zeeman::end().

◆ operator=() [1/5]

MatrixView & MatrixView::operator= ( const ConstMatrixView m)

Assignment operator.

This copies the data from another MatrixView to this MatrixView. Dimensions must agree! Resizing would destroy the selection that we might have done in this MatrixView by setting its range.

Definition at line 636 of file matpackI.cc.

References ARTS_ASSERT, begin(), ConstMatrixView::begin(), copy(), ConstMatrixView::end(), ConstMatrixView::mcr, Range::mextent, and ConstMatrixView::mrr.

◆ operator=() [2/5]

MatrixView & MatrixView::operator= ( const ConstVectorView v)

Assignment from a vector.

This copies the data from a VectorView to this MatrixView. Dimensions must agree! Resizing would destroy the selection that we might have done in this MatrixView by setting its range.

Definition at line 675 of file matpackI.cc.

References ARTS_ASSERT, begin(), ConstMatrixView::begin(), copy(), ConstMatrixView::end(), ConstMatrixView::mcr, Range::mextent, ConstMatrixView::mrr, and v.

◆ operator=() [3/5]

MatrixView & MatrixView::operator= ( const Matrix m)

Assignment from a Matrix.

This must exist to overide the automatically generated assignment operators, which don't copy the contents!

Definition at line 662 of file matpackI.cc.

References ARTS_ASSERT, begin(), copy(), end(), ConstMatrixView::mcr, Range::mextent, and ConstMatrixView::mrr.

◆ operator=() [4/5]

MatrixView & MatrixView::operator= ( const MatrixView m)

Assignment from MatrixView to MatrixView.

This is a tricky one. The problem is that since MatrixView is derived from ConstMatrixView, a default = operator is generated by the compiler, which does not do what we want. So we need this one to override the default.

Definition at line 650 of file matpackI.cc.

References ARTS_ASSERT, begin(), copy(), end(), ConstMatrixView::mcr, Range::mextent, and ConstMatrixView::mrr.

◆ operator=() [5/5]

MatrixView & MatrixView::operator= ( Numeric  x)

Assigning a scalar to a MatrixView will set all elements to this value.

Definition at line 687 of file matpackI.cc.

References begin(), copy(), and end().

Friends And Related Function Documentation

◆ ComplexMatrixView

friend class ComplexMatrixView
friend

Definition at line 1246 of file matpackI.h.

◆ Iterator3D

friend class Iterator3D
friend

Definition at line 1240 of file matpackI.h.

◆ mult

void mult ( MatrixView  ,
const ConstMatrixView ,
const ConstMatrixView  
)
friend

Matrix-Matrix Multiplication.

Performs the matrix multiplication A = B * C. The dimensions must match, i.e. A must be a m times n matrix, B a m times k matrix and C a k times c matrix. No memory reallocation takes place, only the data is copied. Using this function on overlapping MatrixViews belonging to the same Matrix will lead to unpredictable results. In particular, this means that A and B must not be the same matrix!

If the memory layout allows it, the multiplication is performed using BLAS' _dgemm, which leads to a significant speed up of the operation. To be compatible with BLAS the matrix views A, B and C must satisfy:

  • A must have column or row stride 1
  • B must have column or row stride 1
  • C must have column stride 1

That means that A and B can be ConstMatrixView objects corresponding to transposed/non-transposed submatrices of a matrix, that are continuous along their first/second dimension. C must correspond to a non-transposed submatrix of a matrix, that is continuous along its second dimension.

Parameters
[in,out]AThe matrix A, that will hold the result of the multiplication.
[in]BThe matrix B
[in]CThe matrix C

Definition at line 1250 of file matpackI.cc.

◆ Tensor3View

friend class Tensor3View
friend

Definition at line 1241 of file matpackI.h.

◆ Tensor4View

friend class Tensor4View
friend

Definition at line 1242 of file matpackI.h.

◆ Tensor5View

friend class Tensor5View
friend

Definition at line 1243 of file matpackI.h.

◆ Tensor6View

friend class Tensor6View
friend

Definition at line 1244 of file matpackI.h.

◆ Tensor7View

friend class Tensor7View
friend

Definition at line 1245 of file matpackI.h.

◆ transpose [1/2]

ConstMatrixView transpose ( ConstMatrixView  m)
friend

Const version of transpose.

Definition at line 1454 of file matpackI.cc.

◆ transpose [2/2]

MatrixView transpose ( MatrixView  m)
friend

Returns the transpose.

This creates a special MatrixView for the transpose. The original is not changed!

Definition at line 1460 of file matpackI.cc.

◆ VectorView

friend class VectorView
friend

Definition at line 1239 of file matpackI.h.

Referenced by begin(), and end().


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