| 1 |
/* |
| 2 |
* Copyright © 2004 Ondra Kamenik |
| 3 |
* Copyright © 2019-2023 Dynare Team |
| 4 |
* |
| 5 |
* This file is part of Dynare. |
| 6 |
* |
| 7 |
* Dynare is free software: you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation, either version 3 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* Dynare is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "factory.hh" |
| 22 |
|
| 23 |
void |
| 24 |
Factory::init(const Symmetry& s, const IntSequence& nvs) |
| 25 |
{ |
| 26 |
IntSequence sym(s); |
| 27 |
decltype(mtgen)::result_type seed = sym[0]; |
| 28 |
seed = 256 * seed + nvs[0]; |
| 29 |
if (sym.size() > 1) |
| 30 |
seed = 256 * seed + sym[1]; |
| 31 |
if (nvs.size() > 1) |
| 32 |
seed = 256 * seed + nvs[0]; |
| 33 |
mtgen.seed(seed); |
| 34 |
} |
| 35 |
|
| 36 |
void |
| 37 |
Factory::init(int dim, int nv) |
| 38 |
{ |
| 39 |
decltype(mtgen)::result_type seed = dim; |
| 40 |
seed = 256 * seed + nv; |
| 41 |
mtgen.seed(seed); |
| 42 |
} |
| 43 |
|
| 44 |
double |
| 45 |
Factory::get() |
| 46 |
{ |
| 47 |
return dis(mtgen) - 0.5; |
| 48 |
} |
| 49 |
|
| 50 |
void |
| 51 |
Factory::fillMatrix(TwoDMatrix& m) |
| 52 |
{ |
| 53 |
Vector& d = m.getData(); |
| 54 |
for (int i = 0; i < d.length(); i++) |
| 55 |
d[i] = get(); |
| 56 |
} |
| 57 |
|
| 58 |
Vector |
| 59 |
Factory::makeVector(int n) |
| 60 |
{ |
| 61 |
init(n, n * n); |
| 62 |
|
| 63 |
Vector v(n); |
| 64 |
for (int i = 0; i < n; i++) |
| 65 |
v[i] = get(); |
| 66 |
|
| 67 |
return v; |
| 68 |
} |