ARTS  2.4.0(git:4fb77825)
test_utils.h File Reference

Utility functions for testing. More...

#include <stdlib.h>
#include <time.h>
#include "complex.h"
#include "matpackI.h"

Go to the source code of this file.

Classes

class  Rand< rand_type >
 Random number class. More...
 
class  Rand< Index >
 

Functions

void add_noise (VectorView v, Numeric range)
 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 A, Numeric range, bool positive)
 Fill vector with random values. More...
 
MatrixView random_submatrix (MatrixView A, Index m, Index n)
 
Range random_range (Index n)
 Generate random sub-range of the range [0, n-1]. 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)
 
Numeric get_maximum_error (ConstVectorView v1, ConstVectorView v2, bool relative)
 Maximum element-wise error of two vectors. More...
 

Detailed Description

Utility functions for testing.

Author
Simon Pfreundschuh simon.nosp@m.pf@c.nosp@m.hlame.nosp@m.rs.s.nosp@m.e
Date
Sun May 3 20:47:42 2015

Definition in file test_utils.h.

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 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 ( ConstComplexMatrixView  A1,
ConstComplexMatrixView  A2,
bool  relative 
)

◆ 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, max, min, ConstMatrixView::ncols(), and ConstMatrixView::nrows().

◆ get_maximum_error() [3/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, max, min, 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().

◆ random_fill_matrix() [1/4]

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

◆ random_fill_matrix() [2/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 max, ConstMatrixView::ncols(), Sparse::ncols(), Absorption::nelem(), ConstMatrixView::nrows(), Sparse::nrows(), and Sparse::rw().

◆ random_fill_matrix() [3/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 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() [4/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 max, Sparse::ncols(), Absorption::nelem(), Sparse::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 M, mult(), 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 ( ComplexMatrixView  A,
Numeric  range,
bool  positive 
)

Definition at line 161 of file test_utils.cc.

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

◆ random_fill_matrix_symmetric() [2/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_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 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,
Index  m,
Index  n 
)