2019-06-19 14:34:30 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2004-2011 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 17:12:05 +01:00
|
|
|
|
|
|
|
#include "KronUtils.hh"
|
2019-02-19 14:50:00 +01:00
|
|
|
#include "int_power.hh"
|
2019-01-08 17:12:05 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
KronUtils::multAtLevel(int level, const QuasiTriangular &t,
|
|
|
|
KronVector &x)
|
|
|
|
{
|
|
|
|
if (0 < level && level < x.getDepth())
|
2019-03-27 19:22:35 +01:00
|
|
|
for (int i = 0; i < x.getM(); i++)
|
|
|
|
{
|
|
|
|
KronVector xi(x, i);
|
|
|
|
multAtLevel(level, t, xi);
|
|
|
|
}
|
2019-01-08 17:12:05 +01:00
|
|
|
else if (0 == level && 0 < x.getDepth())
|
|
|
|
{
|
Dynare++ / sylvester equation solver: refactor Vector and ConstVector classes
- these classes now encapsulate a std::shared_ptr<{const, }double>, so that
they do not perform memory management, and several {Const,}Vector instances
can transparently share the same underlying data
- make converting constructor from ConstVector to Vector explicit, since that
entails memory allocation (but the reverse conversion is almost costless, so
keep it implicit); do the same for GeneralMatrix/ConstGeneralMatrix,
TwoDMatrix/ConstTwoDMatrix
- remove the constructors that were extracting a row/column from a matrix, and
replace them by getRow() and getCol() methods on {Const,}GeneralMatrix
- rename and change the API of the complex version Vector::add(), so that it is
explicit that it deals with complex numbers
- add constructors that take a MATLAB mxArray
2019-01-22 16:07:44 +01:00
|
|
|
GeneralMatrix tmp(x, x.getN(), power(x.getM(), x.getDepth()));
|
2019-01-08 17:12:05 +01:00
|
|
|
t.multLeftOther(tmp);
|
|
|
|
}
|
|
|
|
else if (0 == level && 0 == x.getDepth())
|
|
|
|
{
|
2019-03-08 15:32:13 +01:00
|
|
|
Vector b(const_cast<const KronVector &>(x));
|
2019-01-08 17:12:05 +01:00
|
|
|
t.multVec(x, b);
|
|
|
|
}
|
|
|
|
else // 0 < level == depth
|
2019-01-25 15:27:20 +01:00
|
|
|
t.multKron(x);
|
2019-01-08 17:12:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
KronUtils::multAtLevelTrans(int level, const QuasiTriangular &t,
|
|
|
|
KronVector &x)
|
|
|
|
{
|
|
|
|
if (0 < level && level < x.getDepth())
|
2019-03-08 15:32:13 +01:00
|
|
|
for (int i = 0; i < x.getM(); i++)
|
|
|
|
{
|
|
|
|
KronVector xi(x, i);
|
|
|
|
multAtLevelTrans(level, t, xi);
|
|
|
|
}
|
2019-01-08 17:12:05 +01:00
|
|
|
else if (0 == level && 0 < x.getDepth())
|
|
|
|
{
|
Dynare++ / sylvester equation solver: refactor Vector and ConstVector classes
- these classes now encapsulate a std::shared_ptr<{const, }double>, so that
they do not perform memory management, and several {Const,}Vector instances
can transparently share the same underlying data
- make converting constructor from ConstVector to Vector explicit, since that
entails memory allocation (but the reverse conversion is almost costless, so
keep it implicit); do the same for GeneralMatrix/ConstGeneralMatrix,
TwoDMatrix/ConstTwoDMatrix
- remove the constructors that were extracting a row/column from a matrix, and
replace them by getRow() and getCol() methods on {Const,}GeneralMatrix
- rename and change the API of the complex version Vector::add(), so that it is
explicit that it deals with complex numbers
- add constructors that take a MATLAB mxArray
2019-01-22 16:07:44 +01:00
|
|
|
GeneralMatrix tmp(x, x.getN(), power(x.getM(), x.getDepth()));
|
2019-01-08 17:12:05 +01:00
|
|
|
t.multLeftOtherTrans(tmp);
|
|
|
|
}
|
|
|
|
else if (level == 0 && 0 == x.getDepth())
|
|
|
|
{
|
2019-03-08 15:32:13 +01:00
|
|
|
Vector b(const_cast<const KronVector &>(x));
|
2019-01-08 17:12:05 +01:00
|
|
|
t.multVecTrans(x, b);
|
|
|
|
}
|
|
|
|
else // 0 < level == depth
|
2019-01-25 15:27:20 +01:00
|
|
|
t.multKronTrans(x);
|
2019-01-08 17:12:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
KronUtils::multKron(const QuasiTriangular &f, const QuasiTriangular &k,
|
|
|
|
KronVector &x)
|
|
|
|
{
|
|
|
|
multAtLevel(0, k, x);
|
|
|
|
if (x.getDepth() > 0)
|
2019-03-27 19:22:35 +01:00
|
|
|
for (int level = 1; level <= x.getDepth(); level++)
|
|
|
|
multAtLevelTrans(level, f, x);
|
2019-01-08 17:12:05 +01:00
|
|
|
}
|