ARTS  2.2.66
matpackI.cc File Reference
#include <cstring>
#include <cmath>
#include "matpackI.h"
#include "exceptions.h"

Go to the source code of this file.

Functions

std::ostream & operator<< (std::ostream &os, const ConstVectorView &v)
 Output operator. More...
 
void copy (ConstIterator1D origin, const ConstIterator1D &end, Iterator1D target)
 Copy data between begin and end to target. More...
 
void copy (Numeric x, Iterator1D target, const Iterator1D &end)
 Copy a scalar to all elements. More...
 
void swap (Vector &v1, Vector &v2)
 Swaps two objects. More...
 
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)
 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)
 Scalar product. More...
 
void mult (VectorView y, const ConstMatrixView &M, const ConstVectorView &x)
 Matrix Vector multiplication. More...
 
void mult (MatrixView A, const ConstMatrixView &B, const ConstMatrixView &C)
 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...
 
MatrixView transpose (Vector v)
 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 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 
)

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.

Definition at line 612 of file matpackI.cc.

References Iterator1D::mstride, ConstIterator1D::mstride, Iterator1D::mx, and ConstIterator1D::mx.

Referenced by abs(), Sparse::insert_row(), Matrix::Matrix(), Array< base >::operator=(), MatrixView::operator=(), VectorView::operator=(), Matrix::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 1428 of file matpackI.cc.

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

◆ copy() [3/4]

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

Copy a scalar to all elements.

Definition at line 626 of file matpackI.cc.

◆ copy() [4/4]

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

Copy a scalar to all elements.

Definition at line 1443 of file matpackI.cc.

References VectorView::begin(), and VectorView::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 1743 of file matpackI.cc.

References ConstVectorView::nelem().

Referenced by propmat_clearskyAddZeeman(), 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 2054 of file matpackI.cc.

◆ max() [1/2]

Numeric max ( const ConstMatrixView x)

Max function, matrix version.

Definition at line 1910 of file matpackI.cc.

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

◆ max() [2/2]

Numeric max ( const ConstVectorView x)

Max function, vector version.

Definition at line 1892 of file matpackI.cc.

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

Referenced by max().

◆ mean() [1/2]

◆ mean() [2/2]

Numeric mean ( const ConstVectorView x)

◆ min() [1/2]

Numeric min ( const ConstMatrixView x)

Min function, matrix version.

Definition at line 1950 of file matpackI.cc.

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

◆ min() [2/2]

Numeric min ( const ConstVectorView x)

Min function, vector version.

Definition at line 1932 of file matpackI.cc.

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

Referenced by min().

◆ mult() [1/2]

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

Matrix multiplication.

A = B*C. Note that the order is different from MTL, output comes first! Dimensions of A, B, and C must match. 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!

Definition at line 1693 of file matpackI.cc.

References VectorView::begin(), ConstMatrixView::begin(), MatrixView::begin(), C, VectorView::end(), MatrixView::end(), ConstMatrixView::ncols(), ConstMatrixView::nrows(), and transpose().

◆ mult() [2/2]

void mult ( 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 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! 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 1648 of file matpackI.cc.

References M, ConstVectorView::mdata, Range::mextent, ConstVectorView::mrange, Range::mstart, and Range::mstride.

Referenced by cloud_RT_surface(), emission_rtstep(), fos(), get_ppath_trans(), get_ppath_trans2(), interpTArray(), iy_transmission_mult(), iyCloudRadar(), iyEmissionStandard(), iyRadioLink(), iyTransmissionStandard(), jacobianCalcAbsSpeciesPerturbations(), jacobianCalcFreqShift(), jacobianCalcFreqStretch(), jacobianCalcPointingZaInterp(), jacobianCalcPointingZaRecalc(), jacobianCalcTemperaturePerturbations(), main(), map_daa(), matrix_exp(), MatrixMatrixMultiply(), MCGeneral(), MCIPA(), mcPathTraceGeneral(), mcPathTraceIPA(), rte_step_doit(), sensor_responseAntenna(), sensor_responseBackend(), sensor_responseBeamSwitching(), sensor_responseFillFgrid(), sensor_responseFrequencySwitching(), sensor_responseMixer(), sensor_responsePolarisation(), sensor_responseStokesRotation(), sensor_responseWMRF(), SparseSparseMultiply(), surface_calc(), surfaceFlatReflectivity(), test32(), test4(), test40(), test42(), test45(), test5(), test_lusolve4D(), VectorMatrixMultiply(), xsec_species_line_mixing_wrapper_with_zeeman(), yCalc(), yCalc_mblock_loop_body(), and ySimpleSpectrometer().

◆ operator*()

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

Scalar product.

The two vectors may be identical.

Definition at line 1623 of file matpackI.cc.

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

◆ operator<<() [1/2]

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

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

◆ operator<<() [2/2]

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

Output operator.

This demonstrates how iterators can be used to traverse the vector. The iterators know which part of the vector is ‘active’, and also the stride.

Definition at line 285 of file matpackI.cc.

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

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

References C, and ConstVectorView::nelem().

Referenced by propmat_clearskyAddZeeman().

◆ swap() [1/2]

void swap ( Matrix m1,
Matrix m2 
)

Swaps two objects.

Definition at line 1602 of file matpackI.cc.

References ConstMatrixView::mcr, ConstMatrixView::mdata, ConstMatrixView::mrr, and swap().

◆ swap() [2/2]

void swap ( Vector v1,
Vector v2 
)

Swaps two objects.

Definition at line 813 of file matpackI.cc.

References ConstVectorView::mdata, and ConstVectorView::mrange.

Referenced by cloud_RT_no_background(), binistream::readFloat(), swap(), and binostream::writeFloat().

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

References ConstVectorView::begin(), VectorView::begin(), ConstMatrixView::begin(), MatrixView::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 1838 of file matpackI.cc.

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

Referenced by abs_lookupSetup(), abs_lookupSetupBatch(), abs_lookupSetupWide(), GasAbsLookup::Adapt(), AtmFieldsRefinePgrid(), chk_interpolation_pgrids(), chk_interpolation_pgrids_loose_no_data_check(), itw2p(), p2gridpos(), p2gridpos_poly(), test2(), test31(), test6(), test7(), my_basic_string< char >::tolower(), my_basic_string< char >::toupper(), and VectorLogSpace().

◆ transpose() [1/3]

◆ transpose() [2/3]

MatrixView transpose ( MatrixView  m)

Returns the transpose.

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

Definition at line 1806 of file matpackI.cc.

References ConstMatrixView::mcr, ConstMatrixView::mdata, ConstMatrixView::mrr, Array< base >::nelem(), VectorView::operator=(), and Vector::resize().

◆ transpose() [3/3]

MatrixView transpose ( Vector  v)

Returns the transpose.

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

Definition at line 1813 of file matpackI.cc.

References transpose().

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

References ConstVectorView::nelem().

Referenced by propmat_clearskyAddZeeman().

Variable Documentation

◆ joker

const Joker joker = Joker()
extern

Referenced by abs_h2oSet(), abs_lookupSetup(), abs_lookupSetupBatch(), abs_lookupSetupWide(), abs_lookupTestAccMC(), abs_lookupTestAccuracy(), abs_n2Set(), abs_o2Set(), abs_vecAddGas(), abs_vecAddPart(), abs_vecTransform(), abs_xsec_per_speciesAddCIA(), abs_xsec_per_speciesAddConts(), AbsInputFromAtmFields(), GasAbsLookup::Adapt(), antenna1d_matrix(), antenna_responseGaussian(), antenna_responseVaryingGaussian(), AntennaMultiBeamsToPencilBeams(), CIARecord::AppendDataset(), atm_fields_compactAddConstant(), atm_fields_compactAddSpecies(), atm_fields_compactExpand(), atm_fields_compactFromMatrix(), AtmFieldsCalc(), AtmFieldsFromCompact(), AtmFieldsRefinePgrid(), atmgeom_checkedCalc(), calc_lookup_error(), calc_ssp_fixed_test(), calc_ssp_random_test(), calcSingleScatteringDataProperties(), cia_interpolation(), clear_rt_vars_at_gp(), cloud_atm_vars_by_gp(), cloud_fieldsCalc(), cloud_ppath_update1D_planeparallel(), cloud_ppath_update3D(), cloud_RT_no_background(), cloud_RT_surface(), cloudbox_checkedCalc(), CloudboxGetIncoming(), CloudboxGetIncoming1DAtm(), CloudboxGetIncoming2(), cloudboxSetAutomatically(), cloudy_rt_vars_at_gp(), complex_n_interp(), complex_refr_indexConstant(), complex_refr_indexWaterLiebe93(), defocusing_general_sub(), diy_from_path_to_rgrids(), doit_i_fieldSetClearsky(), doit_i_fieldSetFromdoit_i_field1D_spectrum(), doit_i_fieldUpdateSeq1D(), doit_i_fieldUpdateSeq3D(), doit_scat_fieldCalc(), doit_scat_fieldCalcLimb(), doit_scat_fieldNormalize(), DoitCloudboxFieldPut(), DoitScatteringDataPrepare(), dtauc_ssalbCalc(), emission_rtstep(), ext_matAddGas(), ext_matAddPart(), ext_matTransform(), Extract(), GasAbsLookup::Extract(), FieldFromGriddedField(), findZ11max(), fos(), get_iy_of_background(), get_ppath_abs(), get_ppath_atmvars(), get_ppath_blackrad(), get_ppath_ext(), get_ppath_f(), get_ppath_trans(), get_ppath_trans2(), get_refr_index_1d(), get_refr_index_2d(), get_refr_index_3d(), GriddedFieldLatLonExpand(), GriddedFieldLatLonRegrid(), GriddedFieldPRegrid(), GriddedFieldZToPRegrid(), interp(), interp_atmfield_by_itw(), interp_atmsurface_by_itw(), interp_cloud_coeff1D(), interp_scat_angle_temperature(), interpolate_scat_angle(), interpolate_scat_angleDOIT(), interpTArray(), iwp_cloud_opt_pathCalc(), iy_auxFillParticleVariables(), iy_interp_cloudbox_field(), iy_transmission_mult(), iyApplyUnit(), iyb_calc_za_loop_body(), iyCloudRadar(), iyEmissionStandard(), iyFOS(), iyInterpCloudboxField2(), iyLoopFrequencies(), iyMC(), iyRadioLink(), iySurfaceRtpropAgenda(), iyTransmissionStandard(), jacobianCalcAbsSpeciesPerturbations(), jacobianCalcPointingZaRecalc(), jacobianCalcTemperaturePerturbations(), main(), Matrix1ColFromVector(), Matrix1RowFromVector(), Matrix2ColFromVectors(), Matrix2RowFromVectors(), Matrix3ColFromVectors(), Matrix3RowFromVectors(), matrix_exp(), MatrixExtractFromTensor3(), mc_IWP_cloud_opt_pathCalc(), MCGeneral(), MCIPA(), mcPathTraceGeneral(), mcPathTraceIPA(), MPM85O2AbsModel(), MPM87O2AbsModel(), MPM89O2AbsModel(), MPM92O2AbsModel(), MPM93_O2_continuum(), MPM93O2AbsModel(), MPM93RainExt(), mult(), opt_prop_sptFromData(), opt_prop_sptFromMonoData(), opt_prop_sum_propmat_clearsky(), opt_propExtract(), p_gridFromZRaw(), pha_mat_singleExtract(), pha_mat_sptFromData(), pha_mat_sptFromDataDOITOpt(), pha_mat_sptFromMonoData(), pha_matTransform(), pmomCalc(), pnd_fieldCalc(), pnd_fieldSetup(), ppath_calc(), ppath_copy(), ppath_start_stepping(), ppath_step_refr_1d(), ppath_step_refr_2d(), ppath_stepGeometric(), ppath_stepRefractionBasic(), ppathFromRtePos2(), propmat_clearsky_fieldCalc(), propmat_clearskyAddFromAbsCoefPerSpecies(), propmat_clearskyAddFromLookup(), propmat_clearskyAddParticles(), propmat_clearskyAddZeeman(), PWR93O2AbsModel(), rte_pos2gridpos(), scat_data_array_monoCalc(), scat_data_arrayCheck(), scat_data_arrayFromMeta(), ScatteringMergeParticles1D(), Select(), sensor_checkedCalc(), sensor_responseAntenna(), sensor_responseGenericAMSU(), sensor_responseSimpleAMSU(), specular_losCalc(), surface_calc(), surface_complex_refr_indexFromGriddedField5(), surface_reflectivityFromGriddedField6(), surface_scalar_reflectivityFromGriddedField4(), surfaceFlatReflectivity(), surfaceFlatRefractiveIndex(), surfaceFlatScalarReflectivity(), test01(), test04(), test06(), test1(), test31(), test36(), test4(), test40(), test42(), test6(), test7(), test9(), TRE05O2AbsModel(), VectorExtractFromMatrix(), xsec_continuum_tag(), xsec_species(), xsec_species_line_mixing_2nd_order(), xsec_species_line_mixing_wrapper_with_zeeman(), yApplyUnit(), ybatchMetProfiles(), ybatchMetProfilesClear(), yCalc_mblock_loop_body(), yCalcAppend(), yCloudRadar(), ySimpleSpectrometer(), z_at_lat_2d(), z_at_latlon(), z_fieldFromHSE(), and za_gridOpt().