ARTS  2.3.1285(git:92a29ea9-dirty)
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 <stdlib.h>
29 #include <time.h>
30 #include "complex.h"
31 #include "matpackI.h"
32 
40 template <class rand_type>
41 class 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 
60 template <>
61 class 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.
77 
78 // Fill matrix with random values.
79 void random_fill_matrix(MatrixView A, Numeric range, bool positive);
80 void random_fill_matrix(ComplexMatrixView A, Numeric range, bool positive);
81 
82 // Fill sparse matrix with random values.
83 void random_fill_matrix(Sparse& A, Numeric range, bool positive);
84 
85 // Fill a dense and a sparse matrix with the identical, random values.
86 void random_fill_matrix(Matrix& A, Sparse& B, Numeric range, bool positive);
87 
88 // Fill matrix with random values symmetrically.
91  Numeric range,
92  bool positive);
93 
94 // Generate random, positive semi-definite matrix.
95 void 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.
103 void 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.
113  ConstMatrixView A2,
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
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
The VectorView class.
Definition: matpackI.h:610
void random_fill_matrix_pos_def(MatrixView A, Numeric range, bool positive)
Generate random, positive definite matrix.
Definition: test_utils.cc:181
void add_noise(VectorView v, Numeric range)
Add noise to vector.
Definition: test_utils.cc:38
A class implementing complex numbers for ARTS.
Random number class.
Definition: test_utils.h:41
The MatrixView class.
Definition: matpackI.h:1093
The Sparse class.
Definition: matpackII.h:60
The range class.
Definition: matpackI.h:160
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
Index operator()() const
Definition: test_utils.h:69
MatrixView random_submatrix(MatrixView A, Index m, Index n)
rand_type range
Definition: test_utils.h:57
Rand(rand_type lo, rand_type hi)
Definition: test_utils.h:43
Rand(Index lo, Index hi)
Definition: test_utils.h:63
void random_fill_matrix_symmetric(MatrixView A, Numeric range, bool positive)
Generate random, symmetric matrix.
Definition: test_utils.cc:156
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
The Matrix class.
Definition: matpackI.h:1193
void random_fill_matrix_pos_semi_def(MatrixView A, Numeric range, bool positive)
Generate random, positive semi-definite matrix.
Definition: test_utils.cc:210
Implementation of Matrix, Vector, and such stuff.
A constant view of a Vector.
Definition: matpackI.h:476
rand_type operator()() const
Definition: test_utils.h:45
A constant view of a Matrix.
Definition: matpackI.h:982
rand_type low
Random Index class.
Definition: test_utils.h:57
A constant view of a ComplexMatrix.
Definition: complex.h:618
Numeric get_maximum_error(ConstMatrixView A1, ConstMatrixView A2, bool relative)
Maximum element-wise error of two matrices.
Definition: test_utils.cc:335
void random_fill_matrix(MatrixView A, Numeric range, bool positive)
Fill matrix with random values.
Definition: test_utils.cc:59
The ComplexMatrixView class.
Definition: complex.h:731