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
|
|
|
*/
|
2009-09-08 15:55:19 +02:00
|
|
|
|
|
|
|
#ifndef GENERAL_SYLVESTER_H
|
|
|
|
#define GENERAL_SYLVESTER_H
|
|
|
|
|
2019-01-08 17:12:05 +01:00
|
|
|
#include "SylvMatrix.hh"
|
|
|
|
#include "SimilarityDecomp.hh"
|
|
|
|
#include "SylvesterSolver.hh"
|
2009-09-08 15:55:19 +02:00
|
|
|
|
2019-01-15 18:55:09 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2017-05-16 16:30:27 +02:00
|
|
|
class GeneralSylvester
|
|
|
|
{
|
|
|
|
SylvParams pars;
|
|
|
|
int order;
|
|
|
|
const SqSylvMatrix a;
|
|
|
|
const SylvMatrix b;
|
|
|
|
const SqSylvMatrix c;
|
|
|
|
SylvMatrix d;
|
|
|
|
bool solved;
|
2019-01-15 18:55:09 +01:00
|
|
|
std::unique_ptr<SchurDecompZero> bdecomp;
|
|
|
|
std::unique_ptr<SimilarityDecomp> cdecomp;
|
|
|
|
std::unique_ptr<SylvesterSolver> sylv;
|
2009-09-08 15:55:19 +02:00
|
|
|
public:
|
2019-03-27 19:22:35 +01:00
|
|
|
// Construct with my copy of d
|
2017-05-16 16:30:27 +02:00
|
|
|
GeneralSylvester(int ord, int n, int m, int zero_cols,
|
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
|
|
|
const ConstVector &da, const ConstVector &db,
|
|
|
|
const ConstVector &dc, const ConstVector &dd,
|
2017-05-16 16:30:27 +02:00
|
|
|
const SylvParams &ps);
|
|
|
|
GeneralSylvester(int ord, int n, int m, int zero_cols,
|
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
|
|
|
const ConstVector &da, const ConstVector &db,
|
|
|
|
const ConstVector &dc, const ConstVector &dd,
|
2017-05-16 16:30:27 +02:00
|
|
|
bool alloc_for_check = false);
|
2019-03-27 19:22:35 +01:00
|
|
|
// Construct with provided storage for d
|
2017-05-16 16:30:27 +02:00
|
|
|
GeneralSylvester(int ord, int n, int m, int zero_cols,
|
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
|
|
|
const ConstVector &da, const ConstVector &db,
|
|
|
|
const ConstVector &dc, Vector &dd,
|
2017-05-16 16:30:27 +02:00
|
|
|
bool alloc_for_check = false);
|
|
|
|
GeneralSylvester(int ord, int n, int m, int zero_cols,
|
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
|
|
|
const ConstVector &da, const ConstVector &db,
|
|
|
|
const ConstVector &dc, Vector &dd,
|
2017-05-16 16:30:27 +02:00
|
|
|
const SylvParams &ps);
|
2019-01-15 18:55:09 +01:00
|
|
|
virtual ~GeneralSylvester() = default;
|
2017-05-16 16:30:27 +02:00
|
|
|
int
|
|
|
|
getM() const
|
|
|
|
{
|
2019-04-16 12:40:50 +02:00
|
|
|
return c.nrows();
|
2017-05-16 16:30:27 +02:00
|
|
|
}
|
|
|
|
int
|
|
|
|
getN() const
|
|
|
|
{
|
2019-04-16 12:40:50 +02:00
|
|
|
return a.nrows();
|
2017-05-16 16:30:27 +02:00
|
|
|
}
|
|
|
|
const double *
|
|
|
|
getResult() const
|
|
|
|
{
|
|
|
|
return d.base();
|
|
|
|
}
|
|
|
|
const SylvParams &
|
|
|
|
getParams() const
|
|
|
|
{
|
|
|
|
return pars;
|
|
|
|
}
|
|
|
|
SylvParams &
|
|
|
|
getParams()
|
|
|
|
{
|
|
|
|
return pars;
|
|
|
|
}
|
|
|
|
void solve();
|
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
|
|
|
void check(const ConstVector &ds);
|
2009-09-08 15:55:19 +02:00
|
|
|
private:
|
2017-05-16 16:30:27 +02:00
|
|
|
void init();
|
2009-09-08 15:55:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GENERAL_SYLVESTER_H */
|