2019-06-19 14:34:30 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2004-2011 Ondra Kamenik
|
2023-12-06 15:34:02 +01:00
|
|
|
* Copyright © 2019-2023 Dynare Team
|
2019-06-19 14:34:30 +02:00
|
|
|
*
|
|
|
|
* 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 "SchurDecomp.hh"
|
|
|
|
|
2019-04-30 12:58:21 +02:00
|
|
|
#include <memory>
|
2023-12-06 15:34:02 +01:00
|
|
|
#include <vector>
|
2019-01-16 17:52:16 +01:00
|
|
|
|
2019-01-08 17:12:05 +01:00
|
|
|
#include <dynlapack.h>
|
|
|
|
|
2023-11-29 19:00:21 +01:00
|
|
|
SchurDecomp::SchurDecomp(const SqSylvMatrix& m) : q(m.nrows())
|
2019-01-08 17:12:05 +01:00
|
|
|
{
|
2019-04-16 12:40:50 +02:00
|
|
|
lapack_int rows = m.nrows();
|
2019-01-08 17:12:05 +01:00
|
|
|
SqSylvMatrix auxt(m);
|
2019-01-24 13:08:05 +01:00
|
|
|
lapack_int lda = auxt.getLD(), ldvs = q.getLD();
|
2019-01-08 17:12:05 +01:00
|
|
|
lapack_int sdim;
|
2023-12-06 15:34:02 +01:00
|
|
|
std::vector<double> wr(rows), wi(rows);
|
2023-11-29 19:00:21 +01:00
|
|
|
lapack_int lwork = 6 * rows;
|
2023-12-06 15:34:02 +01:00
|
|
|
std::vector<double> work(lwork);
|
2019-01-08 17:12:05 +01:00
|
|
|
lapack_int info;
|
2023-12-06 15:34:02 +01:00
|
|
|
dgees("V", "N", nullptr, &rows, auxt.base(), &lda, &sdim, wr.data(), wi.data(), q.base(), &ldvs,
|
|
|
|
work.data(), &lwork, nullptr, &info);
|
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
|
|
|
t_storage = std::make_unique<QuasiTriangular>(auxt.getData(), rows);
|
2019-01-15 18:55:09 +01:00
|
|
|
t = t_storage.get();
|
2019-01-08 17:12:05 +01:00
|
|
|
}
|
|
|
|
|
2023-11-29 19:00:21 +01:00
|
|
|
SchurDecomp::SchurDecomp(const QuasiTriangular& tr) :
|
|
|
|
q(tr.nrows()), t_storage {std::make_unique<QuasiTriangular>(tr)}, t {t_storage.get()}
|
2019-01-08 17:12:05 +01:00
|
|
|
{
|
2019-01-15 18:55:09 +01:00
|
|
|
q.setUnit();
|
2019-01-08 17:12:05 +01:00
|
|
|
}
|
|
|
|
|
2023-11-29 19:00:21 +01:00
|
|
|
SchurDecomp::SchurDecomp(QuasiTriangular& tr) : q(tr.nrows()), t {&tr}
|
2019-01-08 17:12:05 +01:00
|
|
|
{
|
2019-01-15 18:55:09 +01:00
|
|
|
q.setUnit();
|
2019-01-08 17:12:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SchurDecomp::getDim() const
|
|
|
|
{
|
2019-04-16 12:40:50 +02:00
|
|
|
return t->nrows();
|
2019-01-08 17:12:05 +01:00
|
|
|
}
|
|
|
|
|
2023-11-29 19:00:21 +01:00
|
|
|
SchurDecompZero::SchurDecompZero(const GeneralMatrix& m) :
|
|
|
|
SchurDecomp(SqSylvMatrix(m, m.nrows() - m.ncols(), 0, m.ncols())),
|
|
|
|
ru(m, 0, 0, m.nrows() - m.ncols(), m.ncols())
|
2019-01-08 17:12:05 +01:00
|
|
|
{
|
|
|
|
ru.multRight(getQ());
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SchurDecompZero::getDim() const
|
|
|
|
{
|
2023-11-29 19:00:21 +01:00
|
|
|
return getT().nrows() + ru.nrows();
|
2019-01-08 17:12:05 +01:00
|
|
|
}
|