22 #ifndef general_matrix_h
23 #define general_matrix_h
46 friend class Vector<Ref,AT>;
49 friend class Matrix<Symmetric,Ref,Ref,AT>;
66 const AT* elePtr(
int i,
int j)
const {
67 return tp ? ele+i*lda+j : ele+i+j*lda;
70 AT* elePtr(
int i,
int j) {
71 return tp ? ele+i*lda+j : ele+i+j*lda;
74 Matrix(
int m_,
int n_,
int lda_,
bool tp_, Memory<AT> memory_,
const AT* ele_) : memory(memory_), ele((AT*)ele_), m(m_), n(n_), lda(lda_), tp(tp_) {
85 Matrix() : memory(), ele(0), m(0), n(0), lda(0), tp(false) { }
93 Matrix(
int m_,
int n_,
Noinit) : memory(m_*n_), ele((AT*)memory.get()), m(m_), n(n_), lda(m_), tp(false) { }
94 Matrix(
int m_,
int n_, Init ini=INIT,
const AT &a=0) : memory(m_*n_), ele((AT*)memory.get()), m(m_), n(n_), lda(m_), tp(false) { init0(a); }
95 Matrix(
int m_,
int n_, Eye ini,
const AT &a=1) : memory(m_*n_), ele((AT*)memory.get()), m(m_), n(n_), lda(m_), tp(false) { init(ini,a); }
114 Matrix(
int m_,
int n_, AT* ele_) : memory(), ele(ele_), m(m_), n(n_), lda(m_), tp(false) {
136 template<
class Type,
class Row,
class Col>
142 Matrix<General,Ref,Ref,AT>& resize() {
150 Matrix<General,Ref,Ref,AT>& resize(
int m_,
int n_, Noinit) {
151 m = m_; n = n_; lda = m;
154 ele = (AT*)memory.get();
158 Matrix<General,Ref,Ref,AT>& resize(
int m,
int n, Init ini=INIT,
const AT &a=0) {
return resize(m,n,Noinit()).init0(a); }
160 Matrix<General,Ref,Ref,AT>& resize(
int m,
int n, Eye ini,
const AT &a=1) {
return resize(m,n,Noinit()).init(ini,a); }
170 inline Matrix<General,Ref,Ref,AT>& operator=(
const Matrix<General,Ref,Ref,AT> &A);
172 template<
class Type,
class Row,
class Col>
173 Matrix<General,Ref,Ref,AT>& operator=(
const Matrix<Type,Row,Col,AT> &A);
181 template<
class Type,
class Row,
class Col>
182 inline Matrix<General,Ref,Ref,AT>& operator<<(const Matrix<Type,Row,Col,AT> &A);
190 inline Matrix<General,Ref,Ref,AT>&
operator>>(
const Matrix<General,Ref,Ref,AT> &A);
204 #ifndef FMATVEC_NO_BOUNDS_CHECK
219 #ifndef FMATVEC_NO_BOUNDS_CHECK
229 AT& er(
int i,
int j) {
233 const AT& er(
int i,
int j)
const {
237 AT& et(
int i,
int j) {
241 const AT& et(
int i,
int j)
const {
245 AT& e(
int i,
int j) {
246 return tp ? et(i,j) : er(i,j);
249 const AT& e(
int i,
int j)
const {
250 return tp ? et(i,j) : er(i,j);
282 int ldim()
const {
return lda;};
298 return (tp)? CblasTrans : CblasNoTrans;
309 return CblasColMajor;
427 inline Matrix<General,Ref,Ref,AT>& init(Eye,
const AT &a=1);
428 inline Matrix<General,Ref,Ref,AT>& init(Noinit,
const AT &a=0) {
return *
this; }
429 inline Matrix<General,Ref,Ref,AT>& init0(
const AT &a=0);
430 inline Matrix<General,Ref,Ref,AT>& init0(Init,
const AT &a=0) {
return init0(a); }
436 inline operator std::vector<std::vector<AT> >();
443 inline Matrix(std::vector<std::vector<AT> > m);
445 Matrix<General,Ref,Ref,AT> T() {
446 return Matrix<General,Ref,Ref,AT>(n,m,lda,tp?
false:
true,memory,ele);
449 const Matrix<General,Ref,Ref,AT> T()
const {
450 return Matrix<General,Ref,Ref,AT>(n,m,lda,tp?
false:
true,memory,ele);
459 std::istringstream iss(strs);
462 if(c==
'[') iss.str(strs);
463 else iss.str(std::string(
"[")+strs+
"]");
491 ele = (AT*)memory.get();
495 for(
int i=0; i<m; i++)
496 for(
int j=0; j<n; j++) {
525 ele = (AT*)memory.get();
527 #ifndef FMATVEC_NO_SIZE_CHECK
528 assert(m == A.
rows());
529 assert(n == A.
cols());
538 template <
class AT>
template<
class Type,
class Row,
class Col>
547 ele = (AT*)memory.get();
549 #ifndef FMATVEC_NO_SIZE_CHECK
550 assert(m == A.
rows());
551 assert(n == A.
cols());
560 template <
class AT>
template<
class Type,
class Row,
class Col>
569 ele = (AT*)memory.get();
579 for(
int i=0; i<m*n; i++) ele[i]=val;
587 for(
int i=0; i<
rows(); i++)
588 for(
int j=0; j<
cols(); j++)
592 for(
int i=0; i<
rows(); i++)
593 for(
int j=0; j<
cols(); j++)
603 for(
int i=0; i<m; i++)
604 for(
int j=0; j<n; j++)
605 et(i,j) = (i==j) ? val : 0;
607 for(
int i=0; i<m; i++)
608 for(
int j=0; j<n; j++)
609 er(i,j) = (i==j) ? val : 0;
625 #ifndef FMATVEC_NO_BOUNDS_CHECK
634 #ifndef FMATVEC_NO_BOUNDS_CHECK
643 #ifndef FMATVEC_NO_BOUNDS_CHECK
651 #ifndef FMATVEC_NO_BOUNDS_CHECK
660 #ifndef FMATVEC_NO_BOUNDS_CHECK
671 #ifndef FMATVEC_NO_BOUNDS_CHECK
682 #ifndef FMATVEC_NO_BOUNDS_CHECK
693 #ifndef FMATVEC_NO_BOUNDS_CHECK
712 std::vector<std::vector<AT> > ret(rows());
714 for(
int r=0; r<rows(); r++) {
715 ret[r].resize(cols());
716 for(
int c=0; c<cols(); c++)
721 for(
int r=0; r<rows(); r++) {
722 ret[r].resize(cols());
723 for(
int c=0; c<cols(); c++)
731 inline Matrix<General,Ref,Ref,AT>::Matrix(std::vector<std::vector<AT> > m) : memory(m.size()*m[0].size()), ele((AT*)memory.get()), m(m.size()), n(m[0].size()), lda(m.size()), tp(false) {
732 #ifndef FMATVEC_NO_INITIALIZATION
735 for(
int r=0; r<
rows(); r++) {
736 assert(m[r].size()==
cols());
737 for(
int c=0; c<
cols(); c++)
744 template <
class AT>
template <
class Type,
class Row,
class Col>
747 for(
int i=0; i<m; i++)
748 for(
int j=0; j<n; j++)
752 for(
int i=0; i<m; i++)
753 for(
int j=0; j<n; j++)
759 inline void Matrix<General,Ref,Ref,AT>::deepCopy(
const Matrix<General,Ref,Ref,AT> &A) {
762 for(
int i=0; i<m; i++)
763 for(
int j=0; j<n; j++)
767 for(
int i=0; i<m; i++)
768 for(
int j=0; j<n; j++)
773 for(
int i=0; i<m; i++)
774 for(
int j=0; j<n; j++)
778 for(
int i=0; i<m; i++)
779 for(
int j=0; j<n; j++)
786 inline void Matrix<General,Ref,Ref,AT>::deepCopy(
const Matrix<Symmetric,Ref,Ref,AT> &A) {
787 for(
int i=0; i<A.size(); i++) {
789 for(
int j=i+1; j<A.size(); j++)
790 er(i,j) = et(i,j) = A.ej(i,j);
This is the basic matrix class for arbitrary matrices.
Definition: matrix.h:56
int ldim() const
Leading dimension.
Definition: general_matrix.h:282
AT & operator()(int i, int j)
Standard constructor.
Definition: matrix.h:85
int rows() const
Number of rows.
Definition: general_matrix.h:270
AT & operator()(int i, int j)
Element operator.
Definition: general_matrix.h:203
Matrix(const Matrix< General, Ref, Ref, AT > &A)
Copy Constructor.
Definition: general_matrix.h:104
const CBLAS_TRANSPOSE blasTrans() const
Transposed status.
Definition: general_matrix.h:297
int rows() const
Number of rows.
int end() const
Last element.
Definition: index.h:85
int cols() const
Number of columns.
This is a rowvector class of general shape in dense storage format.
Definition: row_vector.h:36
const CBLAS_ORDER blasOrder() const
Storage convention.
Definition: general_matrix.h:308
This is a matrix class for general matrices.
Definition: general_matrix.h:40
const AT & operator()(int i, int j) const
Element operator.
Definition: general_matrix.h:218
std::istream & operator>>(std::istream &is, Matrix< Type, Row, Col, AT > &A)
Matrix input.
Definition: matrix.h:170
AT * operator()()
Pointer operator.
Definition: general_matrix.h:258
This is an index class for creating submatrices.
Definition: index.h:34
Matrix(int m_, int n_, AT *ele_)
Regular Constructor.
Definition: general_matrix.h:114
RowVector< Ref, AT > trans(const Vector< Ref, AT > &x)
Transpose of a vector.
Definition: linear_algebra.h:1470
This is a matrix class for symmetric matrices.
Definition: symmetric_matrix.h:39
bool transposed() const
Transposed status.
Definition: general_matrix.h:289
Basic shape class for matrices.
Definition: types.h:100
This is a vector class of general shape in dense storage format.
Definition: vector.h:39
This is a matrix class of general quadratic matrices.
Definition: square_matrix.h:38
Matrix()
Standard constructor.
Definition: general_matrix.h:85
int start() const
First element.
Definition: index.h:79
~Matrix()
Destructor.
Definition: general_matrix.h:133
const AT * operator()() const
Pointer operator.
Definition: general_matrix.h:264
int cols() const
Number of columns.
Definition: general_matrix.h:276