ARTS 2.5.0 (git: 9ee3ac6c)
matpackI.cc File Reference
#include "matpackI.h"
#include <cmath>
#include <cstring>
#include "blas.h"
#include "exceptions.h"

Go to the source code of this file.

Functions

std::ostream & operator<< (std::ostream &os, const Range &r)
 
std::ostream & operator<< (std::ostream &os, const ConstVectorView &v)
 
void copy (ConstIterator1D origin, const ConstIterator1D &end, Iterator1D target)
 
void copy (Numeric x, Iterator1D target, const Iterator1D &end) ARTS_NOEXCEPT
 Copy a scalar to all elements. More...
 
void swap (Vector &v1, Vector &v2)
 
std::ostream & operator<< (std::ostream &os, const ConstMatrixView &v)
 Output operator. More...
 
void copy (ConstIterator2D origin, const ConstIterator2D &end, Iterator2D target)
 Copy data between begin and end to target. More...
 
void copy (Numeric x, Iterator2D target, const Iterator2D &end) ARTS_NOEXCEPT
 Copy a scalar to all elements. More...
 
void swap (Matrix &m1, Matrix &m2)
 Swaps two objects. More...
 
Numeric operator* (const ConstVectorView &a, const ConstVectorView &b) ARTS_NOEXCEPT
 Scalar product. More...
 
void mult (VectorView y, const ConstMatrixView &M, const ConstVectorView &x)
 Matrix-Vector Multiplication. More...
 
void mult_general (VectorView y, const ConstMatrixView &M, const ConstVectorView &x) ARTS_NOEXCEPT
 Matrix Vector multiplication. More...
 
void mult (MatrixView A, const ConstMatrixView &B, const ConstMatrixView &C)
 Matrix-Matrix Multiplication. More...
 
void mult_general (MatrixView A, const ConstMatrixView &B, const ConstMatrixView &C) ARTS_NOEXCEPT
 General matrix multiplication. More...
 
void cross3 (VectorView c, const ConstVectorView &a, const ConstVectorView &b) ARTS_NOEXCEPT
 cross3 More...
 
Numeric vector_angle (ConstVectorView a, ConstVectorView b)
 
void proj (Vector &c, ConstVectorView a, ConstVectorView b) ARTS_NOEXCEPT
 
ConstMatrixView transpose (ConstMatrixView m) ARTS_NOEXCEPT
 Const version of transpose. More...
 
MatrixView transpose (MatrixView m) ARTS_NOEXCEPT
 Returns the transpose. More...
 
void transform (VectorView y, double(&my_func)(double), ConstVectorView x)
 A generic transform function for vectors, which can be used to implement mathematical functions operating on all elements. More...
 
void transform (MatrixView y, double(&my_func)(double), ConstMatrixView x)
 A generic transform function for matrices, which can be used to implement mathematical functions operating on all elements. More...
 
Numeric max (const ConstVectorView &x) ARTS_NOEXCEPT
 Max function, vector version. More...
 
Numeric max (const ConstMatrixView &x) ARTS_NOEXCEPT
 Max function, matrix version. More...
 
Numeric min (const ConstVectorView &x) ARTS_NOEXCEPT
 Min function, vector version. More...
 
Numeric min (const ConstMatrixView &x) ARTS_NOEXCEPT
 Min function, matrix version. More...
 
Numeric mean (const ConstVectorView &x) ARTS_NOEXCEPT
 Mean function, vector version. More...
 
Numeric nanmean (const ConstVectorView &x) ARTS_NOEXCEPT
 Mean function, vector version ignoring nans and infs. More...
 
Numeric mean (const ConstMatrixView &x) ARTS_NOEXCEPT
 Mean function, matrix version. More...
 
ConstMatrixViewMap MapToEigen (const ConstMatrixView &A)
 
ConstMatrixViewMap MapToEigen (const ConstVectorView &A)
 
ConstMatrixViewMap MapToEigenRow (const ConstVectorView &A)
 
ConstMatrixViewMap MapToEigenCol (const ConstVectorView &A)
 
MatrixViewMap MapToEigen (MatrixView &A)
 
MatrixViewMap MapToEigen (VectorView &A)
 
MatrixViewMap MapToEigenRow (VectorView &A)
 
MatrixViewMap MapToEigenCol (VectorView &A)
 
Matrix4x4ViewMap MapToEigen4x4 (MatrixView &A)
 
ConstMatrix4x4ViewMap MapToEigen4x4 (const ConstMatrixView &A)
 
Numeric debug_matrixview_get_elem (MatrixView &mv, Index r, Index c)
 Helper function to access matrix elements. More...
 

Variables

const Joker joker = Joker()
 

Detailed Description

Author
Stefan Buehler
Date
2001-09-15

Definition in file matpackI.cc.

Function Documentation

◆ copy() [1/4]

void copy ( ConstIterator1D  origin,
const ConstIterator1D end,
Iterator1D  target 
)

Target must be a valid area of memory. Note that the strides in the iterators can be different, so that we can for example copy data between different kinds of subvectors.

Definition at line 299 of file matpackI.cc.

Referenced by Matrix::Matrix(), MatrixView::operator=(), VectorView::operator=(), Matrix::operator=(), Vector::operator=(), and Vector::Vector().

◆ copy() [2/4]

void copy ( ConstIterator2D  origin,
const ConstIterator2D end,
Iterator2D  target 
)

Copy data between begin and end to target.

Target must be a valid area of memory. Note that the strides in the iterators can be different, so that we can for example copy data between different kinds of subvectors.

Origin, end, and target are 2D iterators, marking rows in a matrix. For each row the 1D iterator is obtained and used to copy the elements.

Definition at line 919 of file matpackI.cc.

References ConstVectorView::begin(), and Zeeman::end().

◆ copy() [3/4]

void copy ( Numeric  x,
Iterator1D  target,
const Iterator1D end 
)

Copy a scalar to all elements.

Definition at line 310 of file matpackI.cc.

References Zeeman::end().

◆ copy() [4/4]

void copy ( Numeric  x,
Iterator2D  target,
const Iterator2D end 
)

Copy a scalar to all elements.

Definition at line 931 of file matpackI.cc.

References Zeeman::end().

◆ cross3()

void cross3 ( VectorView  c,
const ConstVectorView a,
const ConstVectorView b 
)

cross3

Calculates the cross product between two vectors of length 3.

c = a x b, for 3D vectors. The vector c must have length 3 and can not be the same variable as a or b.

param c Out: The cross product vector

Parameters
aIn: A vector of length 3.
bIn: A vector of length 3.
Author
Patrick Eriksson
Date
2012-02-12

Definition at line 1393 of file matpackI.cc.

References a, ARTS_ASSERT, b, and c.

Referenced by MCAntenna::draw_los(), and specular_losCalc().

◆ debug_matrixview_get_elem()

Numeric debug_matrixview_get_elem ( MatrixView mv,
Index  r,
Index  c 
)

Helper function to access matrix elements.

Because of function inlining the operator() is not accessible from the debuggger. This function helps to access Matrix elements from within the debugger.

Parameters
mvMatrixView
rRow index
cColumn index
Author
Oliver Lemke
Date
2004-05-10

Definition at line 1762 of file matpackI.cc.

References c.

◆ MapToEigen() [1/4]

ConstMatrixViewMap MapToEigen ( const ConstMatrixView A)

Definition at line 1669 of file matpackI.cc.

Referenced by MapToEigenRow().

◆ MapToEigen() [2/4]

ConstMatrixViewMap MapToEigen ( const ConstVectorView A)

Definition at line 1677 of file matpackI.cc.

◆ MapToEigen() [3/4]

MatrixViewMap MapToEigen ( MatrixView A)

Definition at line 1700 of file matpackI.cc.

◆ MapToEigen() [4/4]

MatrixViewMap MapToEigen ( VectorView A)

Definition at line 1708 of file matpackI.cc.

◆ MapToEigen4x4() [1/2]

ConstMatrix4x4ViewMap MapToEigen4x4 ( const ConstMatrixView A)

Definition at line 1737 of file matpackI.cc.

◆ MapToEigen4x4() [2/2]

Matrix4x4ViewMap MapToEigen4x4 ( MatrixView A)

Definition at line 1729 of file matpackI.cc.

◆ MapToEigenCol() [1/2]

ConstMatrixViewMap MapToEigenCol ( const ConstVectorView A)

Definition at line 1690 of file matpackI.cc.

◆ MapToEigenCol() [2/2]

MatrixViewMap MapToEigenCol ( VectorView A)

Definition at line 1719 of file matpackI.cc.

◆ MapToEigenRow() [1/2]

ConstMatrixViewMap MapToEigenRow ( const ConstVectorView A)

Definition at line 1685 of file matpackI.cc.

References MapToEigen().

◆ MapToEigenRow() [2/2]

MatrixViewMap MapToEigenRow ( VectorView A)

Definition at line 1716 of file matpackI.cc.

References MapToEigen().

◆ max() [1/2]

Numeric max ( const ConstMatrixView x)

Max function, matrix version.

Definition at line 1532 of file matpackI.cc.

References ConstVectorView::begin(), ConstVectorView::end(), and max().

◆ max() [2/2]

Numeric max ( const ConstVectorView x)

Max function, vector version.

Definition at line 1517 of file matpackI.cc.

References max().

Referenced by max().

◆ mean() [1/2]

Numeric mean ( const ConstMatrixView x)

Mean function, matrix version.

Definition at line 1621 of file matpackI.cc.

References ConstVectorView::begin(), ConstVectorView::end(), and mean().

◆ mean() [2/2]

Numeric mean ( const ConstVectorView x)

Mean function, vector version.

Definition at line 1585 of file matpackI.cc.

References mean().

Referenced by mean().

◆ min() [1/2]

Numeric min ( const ConstMatrixView x)

Min function, matrix version.

Definition at line 1566 of file matpackI.cc.

References ConstVectorView::begin(), ConstVectorView::end(), and min().

◆ min() [2/2]

Numeric min ( const ConstVectorView x)

Min function, vector version.

Definition at line 1551 of file matpackI.cc.

References min().

Referenced by ConstMatrixView::diagonal(), and min().

◆ mult() [1/2]

void mult ( MatrixView  A,
const ConstMatrixView B,
const ConstMatrixView C 
)

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 1242 of file matpackI.cc.

◆ mult() [2/2]

void mult ( VectorView  y,
const ConstMatrixView M,
const ConstVectorView x 
)

Matrix-Vector Multiplication.

Computes the Matrix-Vector product y = M * x, for a m times n matrix M, a length-m vector y and a length-n vector x.

The product is computed using the dgemv_ routine from the BLAS library if the matrix is contiguous in memory. If this is not the case, the mult_general method is used to compute the product.

No memory is allocated for the computation and the matrix and vector views may not overlap.

Parameters
[out]yThe length-m VectorView where the result is stored.
[in]MReference to the m-times-n ConstMatrixView holding the matrix M.
[in]xReference to the length-n ConstVectorView holding the vector x.

Definition at line 1123 of file matpackI.cc.

◆ mult_general() [1/2]

void mult_general ( MatrixView  A,
const ConstMatrixView B,
const ConstMatrixView C 
)

General matrix multiplication.

This is the fallback matrix multiplication which works for all ConstMatrixView objects.

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 1346 of file matpackI.cc.

◆ mult_general() [2/2]

void mult_general ( VectorView  y,
const ConstMatrixView M,
const ConstVectorView x 
)

Matrix Vector multiplication.

y = M*x. Note that the order is different from MTL, output comes first! Dimensions of y, M, and x must match. No memory reallocation takes place, only the data is copied. Using this function on overlapping Matrix and VectorViews belonging to the same Matrix will lead to unpredictable results.

The implementation here is different from the other multiplication routines. It does not use iterators but a more drastic approach to gain maximum performance.

Definition at line 1181 of file matpackI.cc.

Referenced by benchmark_mult(), and matrix_vector_mult().

◆ nanmean()

Numeric nanmean ( const ConstVectorView x)

Mean function, vector version ignoring nans and infs.

Definition at line 1600 of file matpackI.cc.

References nanmean().

Referenced by Raw::Reduce::nanfocus(), and nanmean().

◆ operator*()

Numeric operator* ( const ConstVectorView a,
const ConstVectorView b 
)

Scalar product.

The two vectors may be identical.

Definition at line 1092 of file matpackI.cc.

References v.

◆ operator<<() [1/3]

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

Output operator.

This demonstrates how iterators can be used to traverse the matrix. The iterators know which part of the matrix is ‘active’, and also the strides in both directions. This function is a bit more complicated than necessary to illustrate the concept, because the formating should look nice. This means that the first row, and the first element in each row, have to be treated individually.

Definition at line 539 of file matpackI.cc.

◆ operator<<() [2/3]

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

Definition at line 106 of file matpackI.cc.

References Zeeman::end(), and v.

◆ operator<<() [3/3]

std::ostream & operator<< ( std::ostream &  os,
const Range r 
)

Definition at line 37 of file matpackI.cc.

References Range::get_extent(), Range::get_start(), and Range::get_stride().

◆ proj()

void proj ( Vector c,
ConstVectorView  a,
ConstVectorView  b 
)

Calculates the projection of two vectors of equal length.

c = proj_a(b). Projecting b on a. The vector c must have the same length but can not be the same variable as a or b.

Parameters
cOut: The projection of b on a.
aIn: A vector of length N.
bIn: A vector of length N.
Author
Richard Larsson
Date
2012-07-10

Definition at line 1434 of file matpackI.cc.

References a, ARTS_ASSERT, b, and c.

◆ swap() [1/2]

void swap ( Matrix m1,
Matrix m2 
)

Swaps two objects.

Definition at line 1075 of file matpackI.cc.

◆ swap() [2/2]

void swap ( Vector v1,
Vector v2 
)

Definition at line 419 of file matpackI.cc.

◆ transform() [1/2]

void transform ( MatrixView  y,
double(&)(double)  my_func,
ConstMatrixView  x 
)

A generic transform function for matrices, which can be used to implement mathematical functions operating on all elements.

Because we have this, we don't need explicit functions like sqrt for matrices! The type of the mathematical function is double (&my_func)(double). Numeric would not work here, since mathematical functions for float do not exist!

transform(y,sin,x) computes y = sin(x)

This function can also be used for Vectors, because there is a conversion to MatrixView.

The two Matrix views may be the same one, in which case the conversion happens in place.

Parameters
yOutput: The results of the function acting on each element of x.
my_funcA function (e.g., sqrt).
xA matrix.

Definition at line 1500 of file matpackI.cc.

References ARTS_ASSERT, VectorView::begin(), MatrixView::begin(), ConstVectorView::begin(), ConstMatrixView::begin(), ConstVectorView::end(), ConstMatrixView::end(), ConstMatrixView::ncols(), and ConstMatrixView::nrows().

◆ transform() [2/2]

void transform ( VectorView  y,
double(&)(double)  my_func,
ConstVectorView  x 
)

A generic transform function for vectors, which can be used to implement mathematical functions operating on all elements.

Because we have this, we don't need explicit functions like sqrt for matrices! The type of the mathematical function is double (&my_func)(double). Numeric would not work here, since mathematical functions for float do not exist!

transform(y,sin,x) computes y = sin(x)

Although the matrix version of this can also be used for vectors, thanks to the automatic interpretation of a vector as a one column matrix, this one is slightly more efficient. However, the difference is very small (only a few percent).

The two views may be the same one, in which case the conversion happens in place.

Parameters
yOutput: The results of the function acting on each element of x.
my_funcA function (e.g., sqrt).
xA vector.

Definition at line 1472 of file matpackI.cc.

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

Referenced by abs_lookupSetup(), abs_lookupSetupWide(), GasAbsLookup::Adapt(), chk_interpolation_pgrids(), chk_interpolation_pgrids_loose_no_data_check(), itw2p(), Raw::Average::nanstd(), TransmissionMatrix::operator*=(), p2gridpos(), ppvar_optical_depthFromPpvar_trans_cumulat(), Absorption::split_list_of_external_lines(), Raw::Average::std(), test2(), test6(), test7(), my_basic_string< charT >::tolower(), my_basic_string< charT >::toupper(), and VectorLogSpace().

◆ transpose() [1/2]

ConstMatrixView transpose ( ConstMatrixView  m)

Const version of transpose.

Definition at line 1444 of file matpackI.cc.

◆ transpose() [2/2]

MatrixView transpose ( MatrixView  m)

Returns the transpose.

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

Definition at line 1450 of file matpackI.cc.

References M.

◆ vector_angle()

Numeric vector_angle ( ConstVectorView  a,
ConstVectorView  b 
)

Returns numeric angle between two vectors in degrees.

Parameters
aIn: A vector of length N.
bIn: A vector of length N.
Author
Richard Larsson
Date
2012-07-10

Definition at line 1412 of file matpackI.cc.

References a, ARTS_ASSERT, b, and sqrt().

Variable Documentation

◆ joker

const Joker joker = Joker()
extern