2009-09-08 15:55:19 +02:00
|
|
|
/* $Header: /var/lib/cvs/dynare_cpp/sylv/testing/MMMatrix.h,v 1.1.1.1 2004/06/04 13:01:13 kamenik Exp $ */
|
|
|
|
|
|
|
|
/* Tag $Name: $ */
|
|
|
|
|
|
|
|
#ifndef MM_MATRIX_H
|
|
|
|
#define MM_MATRIX_H
|
|
|
|
|
2019-01-08 17:12:05 +01:00
|
|
|
#include "GeneralMatrix.hh"
|
|
|
|
#include "SylvMemory.hh"
|
2009-09-08 15:55:19 +02:00
|
|
|
|
|
|
|
#include <string>
|
2019-01-09 15:46:04 +01:00
|
|
|
#include <utility>
|
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
|
|
|
#include <memory>
|
2009-09-08 15:55:19 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2017-05-16 16:30:27 +02:00
|
|
|
class MMException : public MallocAllocator
|
|
|
|
{
|
|
|
|
string message;
|
2009-09-08 15:55:19 +02:00
|
|
|
public:
|
2019-01-09 15:46:04 +01:00
|
|
|
MMException(string mes) : message(std::move(mes))
|
2017-05-16 16:30:27 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
MMException(const char *mes) : message(mes)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
const char *
|
|
|
|
getMessage() const
|
|
|
|
{
|
|
|
|
return message.data();
|
|
|
|
}
|
2009-09-08 15:55:19 +02:00
|
|
|
};
|
|
|
|
|
2017-05-16 16:30:27 +02:00
|
|
|
class MMMatrixIn : public MallocAllocator
|
|
|
|
{
|
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
|
|
|
std::shared_ptr<const double> data;
|
2017-05-16 16:30:27 +02:00
|
|
|
int rows;
|
|
|
|
int cols;
|
2009-09-08 15:55:19 +02:00
|
|
|
public:
|
2017-05-16 16:30:27 +02:00
|
|
|
MMMatrixIn(const char *fname);
|
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
|
|
|
~MMMatrixIn() = default;
|
|
|
|
ConstVector
|
2017-05-16 16:30:27 +02:00
|
|
|
getData() const
|
|
|
|
{
|
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
|
|
|
return ConstVector{data, size()};
|
2017-05-16 16:30:27 +02:00
|
|
|
}
|
|
|
|
int
|
|
|
|
size() const
|
|
|
|
{
|
|
|
|
return rows*cols;
|
|
|
|
}
|
|
|
|
int
|
|
|
|
row() const
|
|
|
|
{
|
|
|
|
return rows;
|
|
|
|
}
|
|
|
|
int
|
|
|
|
col() const
|
|
|
|
{
|
|
|
|
return cols;
|
|
|
|
}
|
2009-09-08 15:55:19 +02:00
|
|
|
};
|
|
|
|
|
2017-05-16 16:30:27 +02:00
|
|
|
class MMMatrixOut : public MallocAllocator
|
|
|
|
{
|
2009-09-08 15:55:19 +02:00
|
|
|
public:
|
2017-05-16 16:30:27 +02:00
|
|
|
static void write(const char *fname, int rows, int cols, const double *data);
|
|
|
|
static void write(const char *fname, const GeneralMatrix &m);
|
2009-09-08 15:55:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* MM_MATRIX_H */
|