22 #ifndef diagonal_matrix_h 23 #define diagonal_matrix_h 51 const AT* elePtr(
int i)
const {
63 typedef AT value_type;
69 explicit Matrix() : memory(), ele(0) { }
76 explicit Matrix(
int n_,
Noinit) : memory(n_), ele((AT*)memory.get()), n(n_) { }
77 explicit Matrix(
int n_, Init ini=INIT,
const AT &a=AT()) : memory(n_), ele((AT*)memory.get()), n(n_) { init(a); }
78 explicit Matrix(
int n_, Eye ini,
const AT &a=1) : memory(n_), ele((AT*)memory.get()), n(n_) { init(ini,a); }
79 explicit Matrix(
int m_,
int n_, Noinit) : memory(n_), ele((AT*)memory.get()), n(n_) { }
95 template<
class Type,
class Row,
class Col>
97 FMATVEC_ASSERT(A.
rows() == A.
cols(), AT);
108 ele = (AT*)memory.get();
112 Matrix<Diagonal,Ref,Ref,AT>& resize(
int n, Init ini=INIT,
const AT &a=AT()) { resize(n,Noinit()).
init(a); }
113 Matrix<Diagonal,Ref,Ref,AT>& resize(
int n, Eye ini,
const AT &a=1) { resize(n,Noinit()).
init(ini,a); }
122 FMATVEC_ASSERT(n == A.n, AT);
132 template<
class Type,
class Row,
class Col>
134 FMATVEC_ASSERT(n == A.
rows(), AT);
135 FMATVEC_ASSERT(n == A.
cols(), AT);
158 template<
class Type,
class Row,
class Col>
160 if(n!=A.n) resize(A.
rows(),NONINIT);
175 FMATVEC_ASSERT(i>=0, AT);
176 FMATVEC_ASSERT(j>=0, AT);
177 FMATVEC_ASSERT(i<n, AT);
178 FMATVEC_ASSERT(j<n, AT);
189 FMATVEC_ASSERT(i>=0, AT);
190 FMATVEC_ASSERT(i<n, AT);
205 FMATVEC_ASSERT(i>=0, AT);
206 FMATVEC_ASSERT(i<n, AT);
211 const AT& e(
int i,
int j)
const {
213 return i==j ? ele[i] : zero;
216 const AT& e(
int i)
const {
267 return CblasColMajor;
279 inline Matrix<Diagonal,Ref,Ref,AT>& init(Eye,
const AT &a=1) {
return init(a); }
280 inline Matrix<Diagonal,Ref,Ref,AT>& init(Noinit,
const AT &a=AT()) {
return *
this; }
287 explicit Matrix<Diagonal,Ref,Ref,AT>(
const std::vector<std::vector<AT>> &m);
293 explicit operator std::vector<std::vector<AT>>()
const;
313 for(
size_t r=0; r<m.size(); ++r) {
314 if(n!=static_cast<int>(m[r].size()))
315 throw std::runtime_error(
"The rows of the input have different lenght.");
316 for(
size_t c=0; c<m[r].size(); ++c) {
319 if(r!=c && (fabs(m[r][c])>1e-13 || fabs(m[r][c])>1e-13))
320 throw std::runtime_error(
"The input is not diagonal.");
328 for(
int i=0; i<
rows(); i++)
335 for(
int i=0; i<n; i++)
342 std::vector<std::vector<AT>> ret(rows());
343 for(
int r=0; r<rows(); r++) {
344 ret[r].resize(cols());
345 for(
int c=0; c<cols(); c++)
AT & operator()(int i)
Element operator.
Definition: diagonal_matrix.h:203
Matrix(const Matrix< Diagonal, Ref, Ref, AT > &A)
Copy Constructor.
Definition: diagonal_matrix.h:86
Matrix< Diagonal, Ref, Ref, AT > & operator=(const Matrix< Type, Row, Col, AT > &A)
Assignment operator.
Definition: diagonal_matrix.h:133
Matrix(const Matrix< Type, Row, Col, AT > &A)
Copy Constructor.
Definition: diagonal_matrix.h:96
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
Matrix()
Standard constructor.
Definition: diagonal_matrix.h:69
AT * operator()()
Pointer operator.
Definition: diagonal_matrix.h:237
const AT & operator()(int i, int j) const
Element operator.
Definition: diagonal_matrix.h:173
int cols() const
Number of columns.
Definition: diagonal_matrix.h:251
const AT * operator()() const
Pointer operator.
Definition: diagonal_matrix.h:228
int size() const
Number of rows and columns.
Definition: diagonal_matrix.h:257
Matrix< Diagonal, Ref, Ref, AT > & operator=(const Matrix< Diagonal, Ref, Ref, AT > &A)
Assignment operator.
Definition: diagonal_matrix.h:121
Matrix< Diagonal, Ref, Ref, AT > & operator&=(Matrix< Diagonal, Ref, Ref, AT > &A)
Reference operator.
Definition: diagonal_matrix.h:145
int cols() const
Number of columns.
const AT & operator()(int i) const
Element operator.
Definition: diagonal_matrix.h:187
Namespace fmatvec.
Definition: _memory.cc:28
const CBLAS_ORDER blasOrder() const
Storage convention.
Definition: diagonal_matrix.h:266
Shape class for diagonal matrices.
Definition: types.h:164
Matrix< Diagonal, Ref, Ref, AT > & init(const AT &val=AT())
Initialization.
Definition: diagonal_matrix.h:327
int rows() const
Number of rows.
Definition: diagonal_matrix.h:245
int rows() const
Number of rows.
This is a matrix class for diagonal matrices.
Definition: diagonal_matrix.h:39