2019-06-19 14:34:30 +02:00
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2004 Ondra Kamenik
|
|
|
|
|
* Copyright © 2019 Dynare Team
|
|
|
|
|
*
|
|
|
|
|
* This file is part of Dynare.
|
|
|
|
|
*
|
|
|
|
|
* Dynare is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* Dynare is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-06-09 17:33:48 +02:00
|
|
|
|
* along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2019-06-19 14:34:30 +02:00
|
|
|
|
*/
|
2019-01-08 16:09:25 +01:00
|
|
|
|
|
|
|
|
|
#include "t_polynomial.hh"
|
|
|
|
|
#include "kron_prod.hh"
|
|
|
|
|
|
2019-05-06 18:43:54 +02:00
|
|
|
|
// PowerProvider::getNext() unfolded code
|
|
|
|
|
/* This method constructs unfolded ‘ut’ of higher dimension, deleting
|
2019-01-08 16:09:25 +01:00
|
|
|
|
the previous. */
|
|
|
|
|
|
2023-11-29 19:00:21 +01:00
|
|
|
|
const URSingleTensor&
|
2019-02-27 19:07:01 +01:00
|
|
|
|
PowerProvider::getNext(dummy<URSingleTensor>)
|
2019-01-08 16:09:25 +01:00
|
|
|
|
{
|
|
|
|
|
if (ut)
|
|
|
|
|
{
|
2023-11-29 19:00:21 +01:00
|
|
|
|
auto ut_new = std::make_unique<URSingleTensor>(nv, ut->dimen() + 1);
|
2019-01-08 16:09:25 +01:00
|
|
|
|
KronProd::kronMult(ConstVector(origv), ConstVector(ut->getData()), ut_new->getData());
|
2019-02-26 18:57:36 +01:00
|
|
|
|
ut = std::move(ut_new);
|
2019-01-08 16:09:25 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-02-26 18:57:36 +01:00
|
|
|
|
ut = std::make_unique<URSingleTensor>(nv, 1);
|
2019-01-08 16:09:25 +01:00
|
|
|
|
ut->getData() = origv;
|
|
|
|
|
}
|
|
|
|
|
return *ut;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-06 18:43:54 +02:00
|
|
|
|
// PowerProvider::getNext() folded code
|
|
|
|
|
/* This method just constructs next unfolded ‘ut’ and creates folded ‘ft’. */
|
2019-01-08 16:09:25 +01:00
|
|
|
|
|
2023-11-29 19:00:21 +01:00
|
|
|
|
const FRSingleTensor&
|
2019-02-27 19:07:01 +01:00
|
|
|
|
PowerProvider::getNext(dummy<FRSingleTensor>)
|
2019-01-08 16:09:25 +01:00
|
|
|
|
{
|
2019-02-27 19:07:01 +01:00
|
|
|
|
getNext<URSingleTensor>();
|
2019-02-26 18:57:36 +01:00
|
|
|
|
ft = std::make_unique<FRSingleTensor>(*ut);
|
2019-01-08 16:09:25 +01:00
|
|
|
|
return *ft;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 19:00:21 +01:00
|
|
|
|
UTensorPolynomial::UTensorPolynomial(const FTensorPolynomial& fp) :
|
|
|
|
|
TensorPolynomial<UFSTensor, UGSTensor, URSingleTensor>(fp.nrows(), fp.nvars())
|
2019-01-08 16:09:25 +01:00
|
|
|
|
{
|
2023-11-29 19:00:21 +01:00
|
|
|
|
for (const auto& it : fp)
|
2019-02-20 16:50:33 +01:00
|
|
|
|
insert(std::make_unique<UFSTensor>(*(it.second)));
|
2019-01-08 16:09:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-29 19:00:21 +01:00
|
|
|
|
FTensorPolynomial::FTensorPolynomial(const UTensorPolynomial& up) :
|
|
|
|
|
TensorPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(up.nrows(), up.nvars())
|
2019-01-08 16:09:25 +01:00
|
|
|
|
{
|
2023-11-29 19:00:21 +01:00
|
|
|
|
for (const auto& it : up)
|
2019-02-20 16:50:33 +01:00
|
|
|
|
insert(std::make_unique<FFSTensor>(*(it.second)));
|
2019-01-08 16:09:25 +01:00
|
|
|
|
}
|