2019-06-19 14:34:30 +02:00
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2005 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-04 16:29:57 +01:00
|
|
|
|
|
|
|
|
|
#include "korder_stoch.hh"
|
|
|
|
|
|
2019-06-11 16:45:09 +02:00
|
|
|
|
/* Same as MatrixA constructor, but the submatrix ‘gss_ys’ is passed
|
|
|
|
|
directly. */
|
2019-01-04 16:29:57 +01:00
|
|
|
|
|
|
|
|
|
MatrixAA::MatrixAA(const FSSparseTensor &f, const IntSequence &ss,
|
|
|
|
|
const TwoDMatrix &gss_ys, const PartitionY &ypart)
|
|
|
|
|
: PLUMatrix(ypart.ny())
|
|
|
|
|
{
|
|
|
|
|
zeros();
|
|
|
|
|
|
2019-03-06 18:40:19 +01:00
|
|
|
|
IntSequence c{1};
|
2019-01-04 16:29:57 +01:00
|
|
|
|
FGSTensor f_y(f, ss, c, TensorDimens(ss, c));
|
|
|
|
|
add(1.0, f_y);
|
|
|
|
|
|
|
|
|
|
c[0] = 0;
|
|
|
|
|
FGSTensor f_yss(f, ss, c, TensorDimens(ss, c));
|
|
|
|
|
TwoDMatrix sub(*this, ypart.nstat, ypart.nys());
|
|
|
|
|
sub.multAndAdd(f_yss, gss_ys);
|
|
|
|
|
|
|
|
|
|
calcPLU();
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-11 16:45:09 +02:00
|
|
|
|
// KOrderStoch folded constructor code
|
2019-01-04 16:29:57 +01:00
|
|
|
|
KOrderStoch::KOrderStoch(const PartitionY &yp, int nu,
|
|
|
|
|
const TensorContainer<FSSparseTensor> &fcont,
|
|
|
|
|
const FGSContainer &hh, Journal &jr)
|
2019-02-20 17:00:16 +01:00
|
|
|
|
: nvs{yp.nys(), nu, nu, 1}, ypart(yp), journal(jr),
|
2019-01-04 16:29:57 +01:00
|
|
|
|
_ug(4), _fg(4), _ugs(4), _fgs(4), _uG(4), _fG(4),
|
2019-01-09 16:25:31 +01:00
|
|
|
|
_uh(nullptr), _fh(&hh),
|
2019-01-04 16:29:57 +01:00
|
|
|
|
_uZstack(&_uG, ypart.nyss(), &_ug, ypart.ny(), ypart.nys(), nu),
|
|
|
|
|
_fZstack(&_fG, ypart.nyss(), &_fg, ypart.ny(), ypart.nys(), nu),
|
|
|
|
|
_uGstack(&_ugs, ypart.nys(), nu),
|
|
|
|
|
_fGstack(&_fgs, ypart.nys(), nu),
|
|
|
|
|
f(fcont),
|
2019-02-20 17:51:05 +01:00
|
|
|
|
matA(fcont.get(Symmetry{1}), _uZstack.getStackSizes(), hh.get(Symmetry{1, 0, 0, 0}),
|
2019-01-04 16:29:57 +01:00
|
|
|
|
ypart)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-11 16:45:09 +02:00
|
|
|
|
// KOrderStoch unfolded constructor code
|
2019-01-04 16:29:57 +01:00
|
|
|
|
KOrderStoch::KOrderStoch(const PartitionY &yp, int nu,
|
|
|
|
|
const TensorContainer<FSSparseTensor> &fcont,
|
|
|
|
|
const UGSContainer &hh, Journal &jr)
|
2019-02-20 17:00:16 +01:00
|
|
|
|
: nvs{yp.nys(), nu, nu, 1}, ypart(yp), journal(jr),
|
2019-01-04 16:29:57 +01:00
|
|
|
|
_ug(4), _fg(4), _ugs(4), _fgs(4), _uG(4), _fG(4),
|
2019-01-09 16:25:31 +01:00
|
|
|
|
_uh(&hh), _fh(nullptr),
|
2019-01-04 16:29:57 +01:00
|
|
|
|
_uZstack(&_uG, ypart.nyss(), &_ug, ypart.ny(), ypart.nys(), nu),
|
|
|
|
|
_fZstack(&_fG, ypart.nyss(), &_fg, ypart.ny(), ypart.nys(), nu),
|
|
|
|
|
_uGstack(&_ugs, ypart.nys(), nu),
|
|
|
|
|
_fGstack(&_fgs, ypart.nys(), nu),
|
|
|
|
|
f(fcont),
|
2019-02-20 17:51:05 +01:00
|
|
|
|
matA(fcont.get(Symmetry{1}), _uZstack.getStackSizes(), hh.get(Symmetry{1, 0, 0, 0}),
|
2019-01-04 16:29:57 +01:00
|
|
|
|
ypart)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-11 16:45:09 +02:00
|
|
|
|
// KOrderStoch convenience method specializations
|
2019-01-04 16:29:57 +01:00
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
ctraits<Storage::unfold>::Tg &
|
|
|
|
|
KOrderStoch::g<Storage::unfold>()
|
2019-01-04 16:29:57 +01:00
|
|
|
|
{
|
|
|
|
|
return _ug;
|
|
|
|
|
}
|
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
const ctraits<Storage::unfold>::Tg &
|
|
|
|
|
KOrderStoch::g<Storage::unfold>() const
|
2019-03-06 18:40:19 +01:00
|
|
|
|
{
|
|
|
|
|
return _ug;
|
|
|
|
|
}
|
2019-01-04 16:29:57 +01:00
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
ctraits<Storage::fold>::Tg &
|
|
|
|
|
KOrderStoch::g<Storage::fold>()
|
2019-01-04 16:29:57 +01:00
|
|
|
|
{
|
|
|
|
|
return _fg;
|
|
|
|
|
}
|
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
const ctraits<Storage::fold>::Tg &
|
|
|
|
|
KOrderStoch::g<Storage::fold>() const
|
2019-03-06 18:40:19 +01:00
|
|
|
|
{
|
|
|
|
|
return _fg;
|
|
|
|
|
}
|
2019-01-04 16:29:57 +01:00
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
ctraits<Storage::unfold>::Tgs &
|
|
|
|
|
KOrderStoch::gs<Storage::unfold>()
|
2019-01-04 16:29:57 +01:00
|
|
|
|
{
|
|
|
|
|
return _ugs;
|
|
|
|
|
}
|
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
const ctraits<Storage::unfold>::Tgs &
|
|
|
|
|
KOrderStoch::gs<Storage::unfold>() const
|
2019-03-06 18:40:19 +01:00
|
|
|
|
{
|
|
|
|
|
return _ugs;
|
|
|
|
|
}
|
2019-01-04 16:29:57 +01:00
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
ctraits<Storage::fold>::Tgs &
|
|
|
|
|
KOrderStoch::gs<Storage::fold>()
|
2019-01-04 16:29:57 +01:00
|
|
|
|
{
|
|
|
|
|
return _fgs;
|
|
|
|
|
}
|
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
const ctraits<Storage::fold>::Tgs &
|
|
|
|
|
KOrderStoch::gs<Storage::fold>() const
|
2019-03-06 18:40:19 +01:00
|
|
|
|
{
|
|
|
|
|
return _fgs;
|
|
|
|
|
}
|
2019-01-04 16:29:57 +01:00
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
const ctraits<Storage::unfold>::Tgss &
|
|
|
|
|
KOrderStoch::h<Storage::unfold>() const
|
2019-03-06 18:40:19 +01:00
|
|
|
|
{
|
|
|
|
|
return *_uh;
|
|
|
|
|
}
|
2019-01-04 16:29:57 +01:00
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
const ctraits<Storage::fold>::Tgss &
|
|
|
|
|
KOrderStoch::h<Storage::fold>() const
|
2019-03-06 18:40:19 +01:00
|
|
|
|
{
|
|
|
|
|
return *_fh;
|
|
|
|
|
}
|
2019-01-04 16:29:57 +01:00
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
ctraits<Storage::unfold>::TG &
|
|
|
|
|
KOrderStoch::G<Storage::unfold>()
|
2019-01-04 16:29:57 +01:00
|
|
|
|
{
|
|
|
|
|
return _uG;
|
|
|
|
|
}
|
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
const ctraits<Storage::unfold>::TG &
|
|
|
|
|
KOrderStoch::G<Storage::unfold>() const
|
2019-03-06 18:40:19 +01:00
|
|
|
|
{
|
|
|
|
|
return _uG;
|
|
|
|
|
}
|
2019-01-04 16:29:57 +01:00
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
ctraits<Storage::fold>::TG &
|
|
|
|
|
KOrderStoch::G<Storage::fold>()
|
2019-01-04 16:29:57 +01:00
|
|
|
|
{
|
|
|
|
|
return _fG;
|
|
|
|
|
}
|
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
const ctraits<Storage::fold>::TG &
|
|
|
|
|
KOrderStoch::G<Storage::fold>() const
|
2019-03-06 18:40:19 +01:00
|
|
|
|
{
|
|
|
|
|
return _fG;
|
|
|
|
|
}
|
2019-01-04 16:29:57 +01:00
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
ctraits<Storage::unfold>::TZXstack &
|
|
|
|
|
KOrderStoch::Zstack<Storage::unfold>()
|
2019-01-04 16:29:57 +01:00
|
|
|
|
{
|
|
|
|
|
return _uZstack;
|
|
|
|
|
}
|
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
const ctraits<Storage::unfold>::TZXstack &
|
|
|
|
|
KOrderStoch::Zstack<Storage::unfold>() const
|
2019-03-06 18:40:19 +01:00
|
|
|
|
{
|
|
|
|
|
return _uZstack;
|
|
|
|
|
}
|
2019-01-04 16:29:57 +01:00
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
ctraits<Storage::fold>::TZXstack &
|
|
|
|
|
KOrderStoch::Zstack<Storage::fold>()
|
2019-01-04 16:29:57 +01:00
|
|
|
|
{
|
|
|
|
|
return _fZstack;
|
|
|
|
|
}
|
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
const ctraits<Storage::fold>::TZXstack &
|
|
|
|
|
KOrderStoch::Zstack<Storage::fold>() const
|
2019-03-06 18:40:19 +01:00
|
|
|
|
{
|
|
|
|
|
return _fZstack;
|
|
|
|
|
}
|
2019-01-04 16:29:57 +01:00
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
ctraits<Storage::unfold>::TGXstack &
|
|
|
|
|
KOrderStoch::Gstack<Storage::unfold>()
|
2019-01-04 16:29:57 +01:00
|
|
|
|
{
|
|
|
|
|
return _uGstack;
|
|
|
|
|
}
|
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
const ctraits<Storage::unfold>::TGXstack &
|
|
|
|
|
KOrderStoch::Gstack<Storage::unfold>() const
|
2019-03-06 18:40:19 +01:00
|
|
|
|
{
|
|
|
|
|
return _uGstack;
|
|
|
|
|
}
|
2019-01-04 16:29:57 +01:00
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
ctraits<Storage::fold>::TGXstack &
|
|
|
|
|
KOrderStoch::Gstack<Storage::fold>()
|
2019-01-04 16:29:57 +01:00
|
|
|
|
{
|
|
|
|
|
return _fGstack;
|
|
|
|
|
}
|
|
|
|
|
template<>
|
2019-12-20 14:36:20 +01:00
|
|
|
|
const ctraits<Storage::fold>::TGXstack &
|
|
|
|
|
KOrderStoch::Gstack<Storage::fold>() const
|
2019-03-06 18:40:19 +01:00
|
|
|
|
{
|
|
|
|
|
return _fGstack;
|
|
|
|
|
}
|