| 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 |
#ifndef FACTORY_HH |
| 22 |
#define FACTORY_HH |
| 23 |
|
| 24 |
#include <memory> |
| 25 |
#include <random> |
| 26 |
|
| 27 |
#include "equivalence.hh" |
| 28 |
#include "int_sequence.hh" |
| 29 |
#include "rfs_tensor.hh" |
| 30 |
#include "symmetry.hh" |
| 31 |
#include "t_container.hh" |
| 32 |
#include "twod_matrix.hh" |
| 33 |
|
| 34 |
class Factory |
| 35 |
{ |
| 36 |
std::mt19937 mtgen; |
| 37 |
std::uniform_real_distribution<> dis; |
| 38 |
|
| 39 |
void init(const Symmetry& s, const IntSequence& nvs); |
| 40 |
void init(int dim, int nv); |
| 41 |
void fillMatrix(TwoDMatrix& m); |
| 42 |
|
| 43 |
public: |
| 44 |
double get(); |
| 45 |
// This can be used with UGSTensor, FGSTensor |
| 46 |
template<class _Ttype> |
| 47 |
std::unique_ptr<_Ttype> |
| 48 |
make(int r, const Symmetry& s, const IntSequence& nvs) |
| 49 |
{ |
| 50 |
auto res = std::make_unique<_Ttype>(r, TensorDimens(s, nvs)); |
| 51 |
init(s, nvs); |
| 52 |
fillMatrix(*res); |
| 53 |
return res; |
| 54 |
} |
| 55 |
|
| 56 |
// This can be used with FFSTensor, UFSTensor, FRTensor, URTensor |
| 57 |
template<class _Ttype> |
| 58 |
std::unique_ptr<_Ttype> |
| 59 |
make(int r, int nv, int dim) |
| 60 |
{ |
| 61 |
auto res = std::make_unique<_Ttype>(r, nv, dim); |
| 62 |
init(dim, nv); |
| 63 |
fillMatrix(*res); |
| 64 |
return res; |
| 65 |
} |
| 66 |
|
| 67 |
template<class _Ttype, class _Ctype> |
| 68 |
_Ctype |
| 69 |
makeCont(int r, const IntSequence& nvs, int maxdim) |
| 70 |
{ |
| 71 |
int symnum = nvs.size(); |
| 72 |
_Ctype res(symnum); |
| 73 |
for (int dim = 1; dim <= maxdim; dim++) |
| 74 |
if (symnum == 1) |
| 75 |
// Full symmetry |
| 76 |
res.insert(make<_Ttype>(r, Symmetry {dim}, nvs)); |
| 77 |
else |
| 78 |
// General symmetry |
| 79 |
for (int i = 0; i <= dim; i++) |
| 80 |
res.insert(make<_Ttype>(r, Symmetry {i, dim - i}, nvs)); |
| 81 |
return res; |
| 82 |
} |
| 83 |
|
| 84 |
template<class _Ttype, class _Ptype> |
| 85 |
_Ptype |
| 86 |
makePoly(int r, int nv, int maxdim) |
| 87 |
{ |
| 88 |
_Ptype p(r, nv); |
| 89 |
for (int d = 1; d <= maxdim; d++) |
| 90 |
p.insert(make<_Ttype>(r, nv, d)); |
| 91 |
return p; |
| 92 |
} |
| 93 |
|
| 94 |
Vector makeVector(int n); |
| 95 |
}; |
| 96 |
|
| 97 |
#endif |