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 BLOCK_DIAGONAL_H
|
|
|
|
#define BLOCK_DIAGONAL_H
|
|
|
|
|
2019-01-15 18:55:09 +01:00
|
|
|
#include <memory>
|
2019-01-25 15:27:20 +01:00
|
|
|
#include <vector>
|
2019-01-15 18:55:09 +01:00
|
|
|
|
2019-01-08 17:12:05 +01:00
|
|
|
#include "QuasiTriangular.hh"
|
2009-09-08 15:55:19 +02:00
|
|
|
|
2017-05-16 16:30:27 +02:00
|
|
|
class BlockDiagonal : public QuasiTriangular
|
|
|
|
{
|
2019-01-25 15:27:20 +01:00
|
|
|
std::vector<int> row_len, col_len;
|
2009-09-08 15:55:19 +02:00
|
|
|
public:
|
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
|
|
|
BlockDiagonal(ConstVector d, int d_size);
|
2019-01-25 15:27:20 +01:00
|
|
|
BlockDiagonal(const BlockDiagonal &b) = default;
|
2019-03-29 15:27:34 +01:00
|
|
|
explicit BlockDiagonal(const QuasiTriangular &t);
|
2019-01-25 15:27:20 +01:00
|
|
|
BlockDiagonal &operator=(const QuasiTriangular &t)
|
2017-05-16 16:30:27 +02:00
|
|
|
{
|
2019-01-25 15:27:20 +01:00
|
|
|
GeneralMatrix::operator=(t);
|
|
|
|
return *this;
|
2017-05-16 16:30:27 +02:00
|
|
|
}
|
2019-01-25 15:27:20 +01:00
|
|
|
BlockDiagonal &operator=(const BlockDiagonal &b) = default;
|
|
|
|
~BlockDiagonal() override = default;
|
2017-05-16 16:30:27 +02:00
|
|
|
void setZeroBlockEdge(diag_iter edge);
|
|
|
|
int getNumZeros() const;
|
|
|
|
int getNumBlocks() const;
|
|
|
|
int getLargestBlock() const;
|
|
|
|
void printInfo() const;
|
|
|
|
|
2019-01-09 16:26:42 +01:00
|
|
|
void multKron(KronVector &x) const override;
|
|
|
|
void multKronTrans(KronVector &x) const override;
|
2017-05-16 16:30:27 +02:00
|
|
|
|
2019-01-09 16:26:42 +01:00
|
|
|
const_col_iter col_begin(const DiagonalBlock &b) const override;
|
|
|
|
col_iter col_begin(const DiagonalBlock &b) override;
|
|
|
|
const_row_iter row_end(const DiagonalBlock &b) const override;
|
|
|
|
row_iter row_end(const DiagonalBlock &b) override;
|
2019-01-15 18:55:09 +01:00
|
|
|
std::unique_ptr<QuasiTriangular>
|
2019-01-09 16:26:42 +01:00
|
|
|
clone() const override
|
2017-05-16 16:30:27 +02:00
|
|
|
{
|
2019-01-15 18:55:09 +01:00
|
|
|
return std::make_unique<BlockDiagonal>(*this);
|
2017-05-16 16:30:27 +02:00
|
|
|
}
|
2009-09-08 15:55:19 +02:00
|
|
|
private:
|
2017-05-16 16:30:27 +02:00
|
|
|
void setZerosToRU(diag_iter edge);
|
|
|
|
const_diag_iter findBlockStart(const_diag_iter from) const;
|
|
|
|
static void savePartOfX(int si, int ei, const KronVector &x, Vector &work);
|
|
|
|
void multKronBlock(const_diag_iter start, const_diag_iter end,
|
|
|
|
KronVector &x, Vector &work) const;
|
|
|
|
void multKronBlockTrans(const_diag_iter start, const_diag_iter end,
|
|
|
|
KronVector &x, Vector &work) const;
|
2009-09-08 15:55:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* BLOCK_DIAGONAL_H */
|