ARTS  2.3.1285(git:92a29ea9-dirty)
test_utils.cc File Reference
#include "test_utils.h"
#include <cmath>
#include "arts.h"
#include "lin_alg.h"
#include "matpackII.h"

Go to the source code of this file.

Functions

void add_noise (VectorView v, Numeric scale)
 Add noise to vector. More...
 
void random_fill_matrix (MatrixView A, Numeric range, bool positive)
 Fill matrix with random values. More...
 
void random_fill_matrix (ComplexMatrixView A, Numeric range, bool positive)
 
void random_fill_matrix (Sparse &A, Numeric range, bool positive)
 Generate random sparse matrix. More...
 
void random_fill_matrix (Matrix &A, Sparse &B, Numeric range, bool positive)
 Generate identical, random sparse and dense matrices. More...
 
void random_fill_matrix_symmetric (MatrixView A, Numeric range, bool positive)
 Generate random, symmetric matrix. More...
 
void random_fill_matrix_symmetric (ComplexMatrixView A, Numeric range, bool positive)
 
void random_fill_matrix_pos_def (MatrixView A, Numeric range, bool positive)
 Generate random, positive definite matrix. More...
 
void random_fill_matrix_pos_semi_def (MatrixView A, Numeric range, bool positive)
 Generate random, positive semi-definite matrix. More...
 
void random_fill_vector (VectorView v, Numeric range, bool positive)
 Fill vector with random values. More...
 
MatrixView random_submatrix (MatrixView A, int m, int n)
 Pick random random submatrix of size m times n. More...
 
Range random_range (Index n)
 Generate random sub-range of the range [0, n-1]. More...
 
Numeric get_maximum_error (ConstVectorView v1, ConstVectorView v2, bool relative)
 Maximum element-wise error of two vectors. More...
 
Numeric get_maximum_error (ConstMatrixView A1, ConstMatrixView A2, bool relative)
 Maximum element-wise error of two matrices. More...
 
Numeric get_maximum_error (ConstComplexMatrixView A1, ConstComplexMatrixView A2, bool relative)
 

Detailed Description

Author
Simon Pfreundschuh simon.nosp@m.pf@c.nosp@m.halme.nosp@m.rs.s.nosp@m.e
Date
Sun May 3 21:56:19 2015

Definition in file test_utils.cc.

Function Documentation

◆ add_noise()

void add_noise ( VectorView  v,
Numeric  scale 
)

Add noise to vector.

Parameters
[in,out]vThe vector to add the noise to.
[in]scaleRange for the generated noise given by [0,scale].

Definition at line 38 of file test_utils.cc.

References i, and ConstVectorView::nelem().

Referenced by test_oem_gauss_newton(), test_oem_gauss_newton_sparse(), and test_oem_levenberg_marquardt().

◆ get_maximum_error() [1/3]

Numeric get_maximum_error ( ConstVectorView  v1,
ConstVectorView  v2,
bool  relative 
)

Maximum element-wise error of two vectors.

If relative is true, the maximum element-wise error is computed. Otherwise the absolute error is computed.

Parameters
[in]v1The first vector.
[in]v2The reference vector used to normalize the relative error.
[in]relativeIf true the relative error is computed, otherwise the absolute error is computed.
Returns
The maximum relative or absolute element-wise error.

Definition at line 297 of file test_utils.cc.

References abs, i, max, min, n, and ConstVectorView::nelem().

Referenced by matrix_vector_mult(), test_complex_diagonalize(), test_dense_sparse_multiplication(), test_identity(), test_insert_row(), test_inv(), test_real_diagonalize(), test_solve_linear_system(), test_sparse_arithmetic(), test_sparse_construction(), test_sparse_dense_multiplication(), test_sparse_unary_operations(), and test_xml_io().

◆ get_maximum_error() [2/3]

Numeric get_maximum_error ( ConstMatrixView  A1,
ConstMatrixView  A2,
bool  relative 
)

Maximum element-wise error of two matrices.

If relative is true, the maximum element-wise error is computed. Otherwise the absolute error is computed.

Parameters
[in]A1The first matrix.
[in]A2The reference matrix used to normalize the relative error.
[in]relativeIf true the relative error is computed, otherwise the absolute error is computed.
Returns
The maximum relative or absolute element-wise error.

Definition at line 335 of file test_utils.cc.

References abs, i, max, min, n, ConstMatrixView::ncols(), and ConstMatrixView::nrows().

◆ get_maximum_error() [3/3]

◆ random_fill_matrix() [1/4]

void random_fill_matrix ( MatrixView  A,
Numeric  range,
bool  positive 
)

Fill matrix with random values.

Fills the given matrix with random values of type Numeric in the range [0, range], if positive is set to true, or [-range, range], if positive is set to false.

Parameters
[in,out]AThe matrix to be filled.
[in]rangeThe range of the values to draw the values from.
[in]positiveIf true the matrix is filled with values from the interval [0,range], otherwise the values are taken from the interval [-range, range].

Definition at line 59 of file test_utils.cc.

References i, n, ConstMatrixView::ncols(), and ConstMatrixView::nrows().

Referenced by benchmark_inv(), benchmark_mult(), generate_linear_model(), generate_test_data(), matrix_vector_mult(), QuadraticModel::QuadraticModel(), random_fill_matrix_pos_def(), random_fill_matrix_pos_semi_def(), random_fill_matrix_symmetric(), test_dense_sparse_multiplication(), test_diagonal(), test_sparse_arithmetic(), test_sparse_construction(), test_sparse_dense_multiplication(), test_sparse_unary_operations(), and test_xml_io().

◆ random_fill_matrix() [2/4]

void random_fill_matrix ( ComplexMatrixView  A,
Numeric  range,
bool  positive 
)

Definition at line 71 of file test_utils.cc.

References i, n, ConstComplexMatrixView::ncols(), and ConstComplexMatrixView::nrows().

◆ random_fill_matrix() [3/4]

void random_fill_matrix ( Sparse A,
Numeric  range,
bool  positive 
)

Generate random sparse matrix.

Fills a sparse m-times-n matrix A with max{m,n} random values at random positions.

Parameters
[out]AThe matrix to be filled.
[in]rangeThe range from which values are genereated. If positive = true the values are generated from the range [0,range], otherwise from the range [-range, range]
[in]positiveSee above.

Definition at line 96 of file test_utils.cc.

References i, max, n, Sparse::ncols(), Absorption::nelem(), Sparse::nrows(), and Sparse::rw().

◆ random_fill_matrix() [4/4]

void random_fill_matrix ( Matrix A,
Sparse B,
Numeric  range,
bool  positive 
)

Generate identical, random sparse and dense matrices.

Fills a dense and a sparse m-times-n matrix A with max{m,n} random values at random positions.

Parameters
[out]AThe dense matrix to be filled.
[out]BThe sparse matrix to be filled.
[in]rangeThe range from which values are genereated. If positive = true the values are generated from the range [0,range], otherwise from the range [-range, range]
[in]positiveSee above.

Definition at line 126 of file test_utils.cc.

References i, max, n, Sparse::ncols(), ConstMatrixView::ncols(), Absorption::nelem(), Sparse::nrows(), ConstMatrixView::nrows(), and Sparse::rw().

◆ random_fill_matrix_pos_def()

void random_fill_matrix_pos_def ( MatrixView  A,
Numeric  range,
bool  positive 
)

Generate random, positive definite matrix.

Generate a random, positive definite matrix by generating a positive semi-definite matrix and adding the identity matrix.

Parameters
[out]AThe random, positive definite matrix.
[in]rangeThe range from which the random values are picked. If positive == true, the values are taken from the range [0,range], otherwise the are taken from the range [-range, range].
[in]positiveSee above.

Definition at line 181 of file test_utils.cc.

References i, M, mult(), n, ConstMatrixView::ncols(), ConstMatrixView::nrows(), random_fill_matrix(), and transpose().

Referenced by test_inv(), and test_solve_linear_system().

◆ random_fill_matrix_pos_semi_def()

void random_fill_matrix_pos_semi_def ( MatrixView  A,
Numeric  range,
bool  positive 
)

Generate random, positive semi-definite matrix.

Generate a random, positive semi-definite matrix by randomly generating a matrix and multiplying it by its transpose.

Parameters
[out]AThe random, positive semi-definite matrix.
[in]rangeThe range from which the random values are picked. If positive == true, the values are taken from the range [0,range], otherwise the are taken from the range [-range, range].
[in]positiveSee above.

Definition at line 210 of file test_utils.cc.

References M, mult(), random_fill_matrix(), and transpose().

◆ random_fill_matrix_symmetric() [1/2]

void random_fill_matrix_symmetric ( MatrixView  A,
Numeric  range,
bool  positive 
)

Generate random, symmetric matrix.

Parameters
[out]AThe matrix to be filled.
[in]rangeThe range from which values are genereated. If positive = true the values are generated from the range [0,range], otherwise from the range [-range, range]
[in]positiveSee above.

Definition at line 156 of file test_utils.cc.

References M, random_fill_matrix(), and transpose().

Referenced by generate_test_data(), QuadraticModel::QuadraticModel(), test_complex_diagonalize(), and test_real_diagonalize().

◆ random_fill_matrix_symmetric() [2/2]

void random_fill_matrix_symmetric ( ComplexMatrixView  A,
Numeric  range,
bool  positive 
)

Definition at line 161 of file test_utils.cc.

References M, random_fill_matrix(), and transpose().

◆ random_fill_vector()

void random_fill_vector ( VectorView  v,
Numeric  range,
bool  positive 
)

Fill vector with random values.

Fills the given vector with random values of type Numeric drawn from the range [0, range], if positive is set to true, or from the range [-range, range], if positive == false.

Parameters
[in,out]vThe vector to be filled.
[in]rangeThe range from which the values are taken.
[in]positiveIf true, the values are taken from the interval [0, range], otherwise from the range [-range, range].

Definition at line 230 of file test_utils.cc.

References i, n, and ConstVectorView::nelem().

Referenced by generate_test_data(), matrix_vector_mult(), test_insert_row(), test_oem_gauss_newton_sparse(), and test_solve_linear_system().

◆ random_range()

Range random_range ( Index  n)

Generate random sub-range of the range [0, n-1].

Generate random Range object such that 0 <= extent <= n and 0 <= start < n - extent.

Parameters
nThe range [0, n-1] to pick the sub-range from.
Returns
Random sub-range.

Definition at line 273 of file test_utils.cc.

◆ random_submatrix()

MatrixView random_submatrix ( MatrixView  A,
int  m,
int  n 
)

Pick random random submatrix of size m times n.

Randomly chooses a submatrix of the given matrix A and returns the corresponding MatrixView.

Parameters
[in]AThe matrix to choose the submatrix from.
[in]mNumber of rows of the submatrix.
[in]nNumber of columns of the submatrix.
Returns
ConstMatrixView corresponding to a randomly chosen m-by-n submatrix.

Definition at line 251 of file test_utils.cc.

References ConstMatrixView::ncols(), and ConstMatrixView::nrows().