ARTS 2.5.4 (git: 31ce4f0e)
test_utils.h
Go to the documentation of this file.
1/* Copyright (C) 2001-2012 Stefan Buehler <sbuehler@ltu.se>
2 This program is free software; you can redistribute it and/or modify it
3 under the terms of the GNU General Public License as published by the
4 Free Software Foundation; either version 2, or (at your option) any
5 later version.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
15 USA. */
16
25#ifndef test_utils_h
26#define test_utils_h
27
28#include "matpack_complex.h"
29#include "matpackI.h"
30#include <stdlib.h>
31#include <time.h>
32
40template <class rand_type>
41class Rand {
42 public:
43 Rand(rand_type lo, rand_type hi) : low(lo), range(hi - lo) { srand(rand()); }
44
45 rand_type operator()() const {
46 rand_type r =
47 (rand_type)(((Numeric)rand()) / ((Numeric)RAND_MAX) * (Numeric)range);
48 return low + r;
49 }
50
56 private:
57 rand_type low, range;
58};
59
60template <>
61class Rand<Index> {
62 public:
63 Rand(Index lo, Index hi) : low(lo), range(hi - lo) {
64 // Avoid negative ranges.
65 if (hi <= lo) range = 0;
66 srand(rand());
67 }
68
69 Index operator()() const { return low + rand() % (range + 1); }
70
71 private:
73};
74
75// Add noise to vector.
76void add_noise(VectorView v, Numeric range);
77
78// Fill matrix with random values.
79void random_fill_matrix(MatrixView A, Numeric range, bool positive);
80void random_fill_matrix(ComplexMatrixView A, Numeric range, bool positive);
81
82// Fill sparse matrix with random values.
83void random_fill_matrix(Sparse& A, Numeric range, bool positive);
84
85// Fill a dense and a sparse matrix with the identical, random values.
86void random_fill_matrix(Matrix& A, Sparse& B, Numeric range, bool positive);
87
88// Fill matrix with random values symmetrically.
89void random_fill_matrix_symmetric(MatrixView A, Numeric range, bool positive);
91 Numeric range,
92 bool positive);
93
94// Generate random, positive semi-definite matrix.
95void random_fill_matrix_pos_def(MatrixView A, Numeric range, bool positive);
96
97// Generate random, positive semi-definite matrix.
99 Numeric range,
100 bool positive);
101
102// Fill vector with random values.
103void random_fill_vector(VectorView A, Numeric range, bool positive);
104
105// Pick random submatrix.
107
108// Generate random range in the range [0, n - 1]
110
111// Maximum element-wise error of two matrices.
114 bool relative);
115
118 bool relative);
119
120// Maximum element-wise error of two matrices.
123 bool relative);
124
125#endif // test_utils_h
The ComplexMatrixView class.
A constant view of a ComplexMatrix.
A constant view of a Matrix.
Definition: matpackI.h:1043
A constant view of a Vector.
Definition: matpackI.h:512
The MatrixView class.
Definition: matpackI.h:1164
The Matrix class.
Definition: matpackI.h:1261
Rand(Index lo, Index hi)
Definition: test_utils.h:63
Index operator()() const
Definition: test_utils.h:69
Random number class.
Definition: test_utils.h:41
rand_type low
Random Index class.
Definition: test_utils.h:57
rand_type range
Definition: test_utils.h:57
rand_type operator()() const
Definition: test_utils.h:45
Rand(rand_type lo, rand_type hi)
Definition: test_utils.h:43
The range class.
Definition: matpackI.h:159
The VectorView class.
Definition: matpackI.h:663
Implementation of Matrix, Vector, and such stuff.
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
The Sparse class.
Definition: matpackII.h:75
void random_fill_matrix_pos_semi_def(MatrixView A, Numeric range, bool positive)
Generate random, positive semi-definite matrix.
Definition: test_utils.cc:210
void random_fill_matrix(MatrixView A, Numeric range, bool positive)
Fill matrix with random values.
Definition: test_utils.cc:59
void random_fill_matrix_symmetric(MatrixView A, Numeric range, bool positive)
Generate random, symmetric matrix.
Definition: test_utils.cc:156
void random_fill_matrix_pos_def(MatrixView A, Numeric range, bool positive)
Generate random, positive definite matrix.
Definition: test_utils.cc:181
MatrixView random_submatrix(MatrixView A, Index m, Index n)
Numeric get_maximum_error(ConstMatrixView A1, ConstMatrixView A2, bool relative)
Maximum element-wise error of two matrices.
Definition: test_utils.cc:335
void add_noise(VectorView v, Numeric range)
Add noise to vector.
Definition: test_utils.cc:38
void random_fill_vector(VectorView A, Numeric range, bool positive)
Fill vector with random values.
Definition: test_utils.cc:230
Range random_range(Index n)
Generate random sub-range of the range [0, n-1].
Definition: test_utils.cc:273
#define v