ARTS
2.4.0(git:4fb77825)
|
Implementation of Matrix, Vector, and such stuff. More...
Go to the source code of this file.
Classes | |
class | Joker |
The Joker class. More... | |
class | Range |
The range class. More... | |
class | Iterator1D |
The iterator class for sub vectors. More... | |
class | ConstIterator1D |
The constant iterator class for sub vectors. More... | |
class | ConstVectorView |
A constant view of a Vector. More... | |
class | VectorView |
The VectorView class. More... | |
class | Iterator2D |
The row iterator class for sub matrices. More... | |
class | ConstIterator2D |
The const row iterator class for sub matrices. More... | |
class | Vector |
The Vector class. More... | |
class | ConstMatrixView |
A constant view of a Matrix. More... | |
class | MatrixView |
The MatrixView class. More... | |
class | Matrix |
The Matrix class. More... | |
Typedefs | |
typedef Eigen::Stride< Eigen::Dynamic, Eigen::Dynamic > | StrideType |
typedef Eigen::Matrix< Numeric, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > | MatrixType |
typedef Eigen::Map< MatrixType, 0, StrideType > | MatrixViewMap |
typedef Eigen::Map< const MatrixType, 0, StrideType > | ConstMatrixViewMap |
typedef Eigen::Matrix< Numeric, 4, 4, Eigen::RowMajor > | Matrix4x4Type |
typedef Eigen::Map< Matrix4x4Type, 0, StrideType > | Matrix4x4ViewMap |
typedef Eigen::Map< const Matrix4x4Type, 0, StrideType > | ConstMatrix4x4ViewMap |
Functions | |
void | copy (ConstIterator1D origin, const ConstIterator1D &end, Iterator1D target) |
void | copy (Numeric x, Iterator1D target, const Iterator1D &end) |
Copy a scalar to all elements. 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) |
Copy a scalar to all elements. More... | |
void | mult (VectorView y, const ConstMatrixView &M, const ConstVectorView &x) |
Matrix-Vector Multiplication. More... | |
void | mult_general (MatrixView A, const ConstMatrixView &B, const ConstMatrixView &C) |
General matrix multiplication. More... | |
void | mult (MatrixView A, const ConstMatrixView &B, const ConstMatrixView &C) |
Matrix-Matrix Multiplication. More... | |
void | cross3 (VectorView c, const ConstVectorView &a, const ConstVectorView &b) |
cross3 More... | |
Numeric | vector_angle (ConstVectorView a, ConstVectorView b) |
void | proj (Vector &c, ConstVectorView a, ConstVectorView b) |
ConstMatrixView | transpose (ConstMatrixView m) |
Const version of transpose. More... | |
MatrixView | transpose (MatrixView m) |
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) |
Max function, vector version. More... | |
Numeric | max (const ConstMatrixView &x) |
Max function, matrix version. More... | |
Numeric | min (const ConstVectorView &x) |
Min function, vector version. More... | |
Numeric | min (const ConstMatrixView &x) |
Min function, matrix version. More... | |
Numeric | mean (const ConstVectorView &x) |
Mean function, vector version. More... | |
Numeric | mean (const ConstMatrixView &x) |
Mean function, matrix version. More... | |
Numeric | operator* (const ConstVectorView &a, const ConstVectorView &b) |
Scalar product. More... | |
std::ostream & | operator<< (std::ostream &os, const ConstVectorView &v) |
std::ostream & | operator<< (std::ostream &os, const ConstMatrixView &v) |
Output operator. More... | |
std::ostream & | operator<< (std::ostream &os, const Range &r) |
ConstMatrixViewMap | MapToEigen (const ConstMatrixView &A) |
ConstMatrix4x4ViewMap | MapToEigen4x4 (const ConstMatrixView &A) |
ConstMatrixViewMap | MapToEigen (const ConstVectorView &A) |
ConstMatrixViewMap | MapToEigenRow (const ConstVectorView &A) |
ConstMatrixViewMap | MapToEigenCol (const ConstVectorView &A) |
MatrixViewMap | MapToEigen (MatrixView &A) |
Matrix4x4ViewMap | MapToEigen4x4 (MatrixView &A) |
MatrixViewMap | MapToEigen (VectorView &A) |
MatrixViewMap | MapToEigenRow (VectorView &A) |
MatrixViewMap | MapToEigenCol (VectorView &A) |
Numeric | debug_matrixview_get_elem (MatrixView &mv, Index r, Index c) |
Helper function to access matrix elements. More... | |
Variables | |
const Joker | joker |
Implementation of Matrix, Vector, and such stuff.
A VectorView consists of the data, which is stored in a continuous piece of memory, and a selection, specified by start, extend, and stride. A Vector is a VectorView which also allocates its memory automatically.
VectorViews can not be generated directly, they only result from operations on Vectors, such as using the index operator with a Range object. However, you can store them, like:
VectorView A = B[Range(0,3)]
A VectorView acts like a reference to the selected region in the parent matrix. Functions that operate on an existing matrix (i.e., they do not use resize) should take VectorView x as arguement, rather than Vector& x. That has the advantage that they can be called either with a VectorView or Vector. E.g., if you have:
void fill_with_junk(VectorView x); Vector v;
then you can call the function in these two ways:
fill_with_junk(v); fill_with_junk(v[Range(1,3)])
Assignment (=) copies the data from one Vector or VectorView to another one. Dimensions must agree. Only exceptions are the copy constructors which automatically set the dimensions to match.
Things work in the same way for the type Matrix.
There exist operators *=, /=, +=, and -= to multiply (divide,...) by a scalar. Plain operators *,... do not exist, because they would result in the creation of temporaries and therefor be inefficient.
However, you can use * to compute the scalar product. This is efficient, since the return value is just a scalar.
There is a constructor for vector filling it with a sequence of values.
Matrices:
You can extract sub matrices (MatrixView) using Range objects. You can also extract rows and columns this way.
transpose(A) Returns a special MatrixView that is the transpose of the original. The original is not changed by this!
mult(A,B,C) computes A = B*C Note that the order is different from MTL (output first)!
A VectorView or Vector can be taken in the place of a nx1 matrix. That means, Vectors are interpreted as column vectors. Hence, you can compute:
Vector a(10),b(20); Matrix M(10,20);
mult(a,M,b); // a = M*b
but also, by using transpose:
mult(transpose(b),transpose(a),M); // b^t = a^t * M
See the section about Matrices and Vectors in the ARTS user guide for more details.
Definition in file matpackI.h.
typedef Eigen::Map<const Matrix4x4Type, 0, StrideType> ConstMatrix4x4ViewMap |
Definition at line 114 of file matpackI.h.
typedef Eigen::Map<const MatrixType, 0, StrideType> ConstMatrixViewMap |
Definition at line 111 of file matpackI.h.
typedef Eigen::Matrix<Numeric, 4, 4, Eigen::RowMajor> Matrix4x4Type |
Definition at line 112 of file matpackI.h.
typedef Eigen::Map<Matrix4x4Type, 0, StrideType> Matrix4x4ViewMap |
Definition at line 113 of file matpackI.h.
typedef Eigen::Matrix<Numeric, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> MatrixType |
Definition at line 109 of file matpackI.h.
typedef Eigen::Map<MatrixType, 0, StrideType> MatrixViewMap |
Definition at line 110 of file matpackI.h.
typedef Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic> StrideType |
Definition at line 107 of file matpackI.h.
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 407 of file matpackI.cc.
References Zeeman::end(), Iterator1D::mstride, ConstIterator1D::mstride, Iterator1D::mx, and ConstIterator1D::mx.
Referenced by Matrix::Matrix(), MatrixView::operator=(), VectorView::operator=(), Vector::operator=(), and Vector::Vector().
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().
void copy | ( | Numeric | x, |
Iterator1D | target, | ||
const Iterator1D & | end | ||
) |
Copy a scalar to all elements.
Definition at line 313 of file matpackI.cc.
References Zeeman::end(), and ARTS::Var::x().
void copy | ( | Numeric | x, |
Iterator2D | target, | ||
const Iterator2D & | end | ||
) |
Copy a scalar to all elements.
Definition at line 931 of file matpackI.cc.
References VectorView::begin(), and Zeeman::end().
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
a | In: A vector of length 3. |
b | In: A vector of length 3. |
Definition at line 1393 of file matpackI.cc.
Referenced by MCAntenna::draw_los(), and specular_losCalc().
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.
mv | MatrixView |
r | Row index |
c | Column index |
Definition at line 1745 of file matpackI.cc.
ConstMatrixViewMap MapToEigen | ( | const ConstMatrixView & | A | ) |
Definition at line 1058 of file matpackI.cc.
References Range::get_start(), Range::get_stride(), ConstMatrixView::mcr, ConstMatrixView::mdata, ConstMatrixView::mrr, ConstMatrixView::ncols(), and ConstMatrixView::nrows().
Referenced by MapToEigenRow().
ConstMatrixViewMap MapToEigen | ( | const ConstVectorView & | A | ) |
Definition at line 562 of file matpackI.cc.
References Range::get_start(), Range::get_stride(), ConstVectorView::mdata, ConstVectorView::mrange, and ConstVectorView::nelem().
MatrixViewMap MapToEigen | ( | MatrixView & | A | ) |
Definition at line 1059 of file matpackI.cc.
References Range::get_start(), Range::get_stride(), ConstMatrixView::mcr, ConstMatrixView::mdata, ConstMatrixView::mrr, ConstMatrixView::ncols(), and ConstMatrixView::nrows().
MatrixViewMap MapToEigen | ( | VectorView & | A | ) |
Definition at line 564 of file matpackI.cc.
References Range::get_start(), Range::get_stride(), ConstVectorView::mdata, ConstVectorView::mrange, and ConstVectorView::nelem().
ConstMatrix4x4ViewMap MapToEigen4x4 | ( | const ConstMatrixView & | A | ) |
Definition at line 1061 of file matpackI.cc.
References Range::get_start(), Range::get_stride(), ConstMatrixView::mcr, ConstMatrixView::mdata, and ConstMatrixView::mrr.
Matrix4x4ViewMap MapToEigen4x4 | ( | MatrixView & | A | ) |
Definition at line 1062 of file matpackI.cc.
References Range::get_start(), Range::get_stride(), ConstMatrixView::mcr, ConstMatrixView::mdata, and ConstMatrixView::mrr.
ConstMatrixViewMap MapToEigenCol | ( | const ConstVectorView & | A | ) |
Definition at line 563 of file matpackI.cc.
References Range::get_start(), Range::get_stride(), ConstVectorView::mdata, ConstVectorView::mrange, and ConstVectorView::nelem().
MatrixViewMap MapToEigenCol | ( | VectorView & | A | ) |
Definition at line 565 of file matpackI.cc.
References Range::get_start(), Range::get_stride(), ConstVectorView::mdata, ConstVectorView::mrange, and ConstVectorView::nelem().
ConstMatrixViewMap MapToEigenRow | ( | const ConstVectorView & | A | ) |
Definition at line 1668 of file matpackI.cc.
References MapToEigen().
MatrixViewMap MapToEigenRow | ( | VectorView & | A | ) |
Definition at line 1699 of file matpackI.cc.
References MapToEigen().
Numeric max | ( | const ConstMatrixView & | x | ) |
Max function, matrix version.
Definition at line 1536 of file matpackI.cc.
References ConstVectorView::begin(), ConstVectorView::end(), max(), and ARTS::Var::x().
Numeric max | ( | const ConstVectorView & | x | ) |
Max function, vector version.
Definition at line 1521 of file matpackI.cc.
References max(), and ARTS::Var::x().
Referenced by max().
Numeric mean | ( | const ConstMatrixView & | x | ) |
Mean function, matrix version.
Definition at line 1604 of file matpackI.cc.
References ConstVectorView::begin(), ConstVectorView::end(), mean(), and ARTS::Var::x().
Numeric mean | ( | const ConstVectorView & | x | ) |
Mean function, vector version.
Definition at line 1589 of file matpackI.cc.
References mean(), and ARTS::Var::x().
Referenced by abs_lookupSetup(), abs_lookupTestAccMC(), mean(), NumericFromVector(), and polynomial_basis_func().
Numeric min | ( | const ConstMatrixView & | x | ) |
Min function, matrix version.
Definition at line 1570 of file matpackI.cc.
References ConstVectorView::begin(), ConstVectorView::end(), min(), and ARTS::Var::x().
Numeric min | ( | const ConstVectorView & | x | ) |
Min function, vector version.
Definition at line 1555 of file matpackI.cc.
References min(), and ARTS::Var::x().
Referenced by ConstMatrixView::diagonal(), and min().
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:
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.
[in,out] | A | The matrix A, that will hold the result of the multiplication. |
[in] | B | The matrix B |
[in] | C | The matrix C |
Definition at line 1041 of file matpackI.cc.
References Range::get_stride(), ConstMatrixView::mcr, ConstMatrixView::mrr, ConstMatrixView::ncols(), and ConstMatrixView::nrows().
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.
[out] | y | The length-m VectorView where the result is stored. |
[in] | M | Reference to the m-times-n ConstMatrixView holding the matrix M. |
[in] | x | Reference to the length-n ConstVectorView holding the vector x. |
Definition at line 550 of file matpackI.cc.
References dgemv_(), M, mult_general(), ARTS::Var::x(), and ARTS::Var::y().
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.
[in,out] | A | The matrix A, that will hold the result of the multiplication. |
[in] | B | The matrix B |
[in] | C | The matrix C |
Definition at line 1047 of file matpackI.cc.
References VectorView::begin(), MatrixView::begin(), ConstMatrixView::begin(), VectorView::end(), MatrixView::end(), ConstMatrixView::ncols(), ConstMatrixView::nrows(), and transpose().
Numeric operator* | ( | const ConstVectorView & | a, |
const ConstVectorView & | b | ||
) |
Scalar product.
The two vectors may be identical.
Definition at line 523 of file matpackI.cc.
References ConstVectorView::begin(), ConstVectorView::end(), and ConstVectorView::nelem().
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 535 of file matpackI.cc.
References ConstVectorView::begin(), ConstMatrixView::begin(), ConstVectorView::end(), and ConstMatrixView::end().
std::ostream& operator<< | ( | std::ostream & | os, |
const ConstVectorView & | v | ||
) |
Definition at line 107 of file matpackI.cc.
References ConstVectorView::begin(), ConstVectorView::end(), and Zeeman::end().
std::ostream& operator<< | ( | std::ostream & | os, |
const Range & | r | ||
) |
Definition at line 40 of file matpackI.cc.
References Range::get_extent(), Range::get_start(), and Range::get_stride().
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.
c | Out: The projection of b on a. |
a | In: A vector of length N. |
b | In: A vector of length N. |
Definition at line 1434 of file matpackI.cc.
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.
y | Output: The results of the function acting on each element of x. |
my_func | A function (e.g., sqrt). |
x | A matrix. |
Definition at line 1504 of file matpackI.cc.
References VectorView::begin(), ConstVectorView::begin(), ConstVectorView::end(), ARTS::Var::x(), and ARTS::Var::y().
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.
y | Output: The results of the function acting on each element of x. |
my_func | A function (e.g., sqrt). |
x | A vector. |
Definition at line 1476 of file matpackI.cc.
References ARTS::Var::x(), and ARTS::Var::y().
Referenced by abs_lookupSetup(), abs_lookupSetupWide(), chk_interpolation_pgrids(), chk_interpolation_pgrids_loose_no_data_check(), itw2p(), TransmissionMatrix::operator*=(), p2gridpos(), p2gridpos_poly(), p_gridRefine(), ppvar_optical_depthFromPpvar_trans_cumulat(), Absorption::split_list_of_external_lines(), linalg::std(), test2(), test6(), test7(), my_basic_string< char >::tolower(), my_basic_string< char >::toupper(), and VectorLogSpace().
ConstMatrixView transpose | ( | ConstMatrixView | m | ) |
Const version of transpose.
Definition at line 1038 of file matpackI.cc.
References ConstMatrixView::mcr, ConstMatrixView::mdata, and ConstMatrixView::mrr.
Referenced by mult_general(), and transpose().
MatrixView transpose | ( | MatrixView | m | ) |
Returns the transpose.
This creates a special MatrixView for the transpose. The original is not changed!
Definition at line 1171 of file matpackI.cc.
References ConstMatrixView::mcr, ConstMatrixView::mdata, and ConstMatrixView::mrr.
Numeric vector_angle | ( | ConstVectorView | a, |
ConstVectorView | b | ||
) |
Returns numeric angle between two vectors in degrees.
a | In: A vector of length N. |
b | In: A vector of length N. |
Definition at line 1412 of file matpackI.cc.
References ConstVectorView::nelem(), and sqrt().
|
extern |
Referenced by Range::operator()().