1 /* 2 * Copyright © 2004 Ondra Kamenik 3 * Copyright © 2019 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 <http://www.gnu.org/licenses/>. 19 */ 20 21 #include "tl_static.hh" 22 #include "pascal_triangle.hh" 23 #include "tl_exception.hh" 24 25 #include <mutex> 26 #include <limits> 27 #include <cmath> 28 29 /* Note that we allow for repeated calls of init(). This is not normal 30 and the only purpose of allowing this is the test suite. */ 31 32 namespace TLStatic 33 { 34 EquivalenceBundle ebundle(1); 35 PermutationBundle pbundle(1); 36 std::mutex mut; 37 38 const EquivalenceSet & getEquiv(int n)39 getEquiv(int n) 40 { 41 return ebundle.get(n); 42 } 43 44 const PermutationSet & getPerm(int n)45 getPerm(int n) 46 { 47 return pbundle.get(n); 48 } 49 50 void init(int dim,int nvar)51 init(int dim, int nvar) 52 { 53 // Check that tensor indices will not overflow (they are stored as signed int, hence on 31 bits) 54 if (std::log2(nvar)*dim > std::numeric_limits<int>::digits) 55 throw TLException(__FILE__, __LINE__, "Problem too large, you should decrease the approximation order"); 56 57 std::lock_guard<std::mutex>{mut}; 58 ebundle.generateUpTo(dim); 59 pbundle.generateUpTo(dim); 60 61 PascalTriangle::ensure(nvar, dim); 62 } 63 } 64