22 #ifndef fixed_var_general_matrix_h
23 #define fixed_var_general_matrix_h
73 Matrix(
int n, Init ini=INIT,
const AT &a=0) : N(n), ele(new AT[M*N]) { init(a); }
74 Matrix(
int n, Eye ini,
const AT &a=1) : N(n), ele(new AT[M*N]) { init(ini,a); }
75 Matrix(
int m,
int n, Noinit) : N(n), ele(new AT[M*N]) { }
76 Matrix(
int m,
int n, Init ini=INIT,
const AT &a=0) : N(n), ele(new AT[M*N]) { init(a); }
77 Matrix(
int m,
int n, Eye ini,
const AT &a=1) : N(n), ele(new AT[M*N]) { init(ini,a); }
90 template<
class Row,
class Col>
96 template<
class Type,
class Row,
class Col>
97 explicit Matrix(
const Matrix<Type,Row,Col,AT> &A) : N(A.
cols()), ele(new AT[M*N]) {
99 #ifndef FMATVEC_NO_SIZE_CHECK
100 assert(A.rows() == M);
118 Matrix(
const char *str);
133 Matrix<General,Fixed<M>,Var,AT>& resize(
int n, Noinit) {
140 Matrix<General,Fixed<M>,Var,AT>& resize(
int n, Init ini=INIT,
const AT &a=0) {
return resize(n,Noinit()).init(a); }
142 Matrix<General,Fixed<M>,Var,AT>& resize(
int n, Eye ini,
const AT &a=1) {
return resize(n,Noinit()).init(ini,a); }
150 inline Matrix<General,Fixed<M>,Var,AT>& operator=(
const Matrix<General,Fixed<M>,Var,AT> &A);
152 template <
class Type,
class Row,
class Col>
153 inline Matrix<General,Fixed<M>,Var,AT>& operator=(
const Matrix<Type,Row,Col,AT> &A);
155 template<
class Type,
class Row,
class Col>
156 inline Matrix<General,Fixed<M>,Var,AT>& operator<<(const Matrix<Type,Row,Col,AT> &A);
170 #ifndef FMATVEC_NO_BOUNDS_CHECK
185 #ifndef FMATVEC_NO_BOUNDS_CHECK
195 AT& e(
int i,
int j) {
203 const AT&
e(
int i,
int j)
const {
215 const AT&
e(
int i)
const {
268 return CblasColMajor;
305 template <
int M1,
int M2>
320 inline Matrix<General,Fixed<M>,Var,AT>& init(Eye,
const AT &a=1);
321 inline Matrix<General,Fixed<M>,Var,AT>& init(Noinit,
const AT &a=0) {
return *
this; }
327 inline operator std::vector<std::vector<AT> >();
334 inline Matrix(std::vector<std::vector<AT> > m);
336 inline const Matrix<General,Var,Fixed<M>,AT> T()
const;
338 template<
class Row>
inline void set(
int j,
const Vector<Row,AT> &x);
340 template<
class Col>
inline void set(
int i,
const RowVector<Col,AT> &x);
342 template<
class Type,
class Row,
class Col>
inline void set(
const Range<Var,Var> &I,
const Range<Var,Var> &J,
const Matrix<Type,Row,Col,AT> &A);
344 template<
class Row>
inline void add(
int j,
const Vector<Row,AT> &x);
346 template<
class Col>
inline void add(
int i,
const RowVector<Col,AT> &x);
348 template<
class Type,
class Row,
class Col>
inline void add(
const Range<Var,Var> &I,
const Range<Var,Var> &J,
const Matrix<Type,Row,Col,AT> &A);
352 template <
int M,
class AT>
357 std::istringstream iss(strs);
360 if(c==
'[') iss.str(strs);
361 else iss.str(std::string(
"[")+strs+
"]");
391 for(
int i=0; i<M; i++)
392 for(
int j=0; j<N; j++) {
400 template <
int M,
class AT>
template<
class Type,
class Row,
class Col>
403 #ifndef FMATVEC_NO_SIZE_CHECK
404 assert(M == A.rows());
411 #ifndef FMATVEC_NO_SIZE_CHECK
412 assert(N == A.cols());
421 template <
int M,
class AT>
429 #ifndef FMATVEC_NO_SIZE_CHECK
430 assert(N == A.cols());
439 template <
int M,
class AT>
template<
class Type,
class Row,
class Col>
442 #ifndef FMATVEC_NO_SIZE_CHECK
443 assert(M == A.rows());
456 template <
int M,
class AT>
458 for(
int i=0; i<M*N; i++)
463 template <
int M,
class AT>
465 for(
int i=0; i<M; i++)
466 for(
int j=0; j<N; j++)
467 e(i,j) = (i==j) ? val : 0;
471 template <
int M,
class AT>
template <
int M1,
int M2>
472 inline const Matrix<General,Fixed<M2-M1+1>,Var,AT> Matrix<General,Fixed<M>,Var,AT>::operator()(
const Range<Fixed<M1>,Fixed<M2> > &I,
const Range<Var,Var> &J)
const {
473 #ifndef FMATVEC_NO_BOUNDS_CHECK
477 Matrix<General,Fixed<M2-M1+1>,Var,AT> A(J.end()-J.start()+1,NONINIT);
479 for(
int i=0; i<A.rows(); i++)
480 for(
int j=0; j<A.cols(); j++)
481 A.e(i,j) = e(M1+i,J.start()+j);
486 template <
int M,
class AT>
488 #ifndef FMATVEC_NO_BOUNDS_CHECK
494 for(
int i=0; i<A.rows(); i++)
495 for(
int j=0; j<A.cols(); j++)
496 A.e(i,j) = e(I.start()+i,J.start()+j);
501 template <
int M,
class AT>
504 #ifndef FMATVEC_NO_BOUNDS_CHECK
511 for(
int j=0; j<N; j++)
518 template <
int M,
class AT>
519 inline const Vector<Fixed<M>,AT> Matrix<General,Fixed<M>,Var,AT>::col(
int j)
const {
521 #ifndef FMATVEC_NO_BOUNDS_CHECK
526 Vector<Fixed<M>,AT> x(NONINIT);
528 for(
int i=0; i<M; i++)
535 template <
int M,
class AT>
536 inline const Matrix<General,Var,Fixed<M>,AT> Matrix<General,Fixed<M>,Var,AT>::T()
const {
537 Matrix<General,Var,Fixed<M>,AT> A(cols(),NONINIT);
538 for(
int i=0; i<N; i++)
539 for(
int j=0; j<M; j++)
544 template <
int M,
class AT>
template <
class Row>
545 inline void Matrix<General,Fixed<M>,Var,AT>::set(
int j,
const Vector<Row,AT> &x) {
546 #ifndef FMATVEC_NO_BOUNDS_CHECK
548 assert(rows()==x.size());
550 for(
int i=0; i<rows(); i++)
554 template <
int M,
class AT>
template <
class Col>
555 inline void Matrix<General,Fixed<M>,Var,AT>::set(
int i,
const RowVector<Col,AT> &x) {
556 #ifndef FMATVEC_NO_BOUNDS_CHECK
558 assert(cols()==x.size());
560 for(
int j=0; j<cols(); j++)
564 template <
int M,
class AT>
template<
class Type,
class Row,
class Col>
565 inline void Matrix<General,Fixed<M>,Var,AT>::set(
const Range<Var,Var> &I,
const Range<Var,Var> &J,
const Matrix<Type,Row,Col,AT> &A) {
567 #ifndef FMATVEC_NO_BOUNDS_CHECK
568 assert(I.end()<rows());
569 assert(J.end()<cols());
570 assert(I.size()==A.rows());
571 assert(J.size()==A.cols());
574 for(
int i=I.start(), ii=0; i<=I.end(); i++, ii++)
575 for(
int j=J.start(), jj=0; j<=J.end(); j++, jj++)
579 template <
int M,
class AT>
template <
class Row>
580 inline void Matrix<General,Fixed<M>,Var,AT>::add(
int j,
const Vector<Row,AT> &x) {
581 #ifndef FMATVEC_NO_BOUNDS_CHECK
583 assert(rows()==x.size());
585 for(
int i=0; i<rows(); i++)
589 template <
int M,
class AT>
template <
class Col>
590 inline void Matrix<General,Fixed<M>,Var,AT>::add(
int i,
const RowVector<Col,AT> &x) {
591 #ifndef FMATVEC_NO_BOUNDS_CHECK
593 assert(cols()==x.size());
595 for(
int j=0; j<cols(); j++)
599 template <
int M,
class AT>
template<
class Type,
class Row,
class Col>
600 inline void Matrix<General,Fixed<M>,Var,AT>::add(
const Range<Var,Var> &I,
const Range<Var,Var> &J,
const Matrix<Type,Row,Col,AT> &A) {
602 #ifndef FMATVEC_NO_BOUNDS_CHECK
603 assert(I.end()<rows());
604 assert(J.end()<cols());
605 assert(I.size()==A.rows());
606 assert(J.size()==A.cols());
609 for(
int i=I.start(), ii=0; i<=I.end(); i++, ii++)
610 for(
int j=J.start(), jj=0; j<=J.end(); j++, jj++)
611 e(i,j) += A.e(ii,jj);
614 template <
int M,
class AT>
616 std::vector<std::vector<AT> > ret(rows());
617 for(
int r=0; r<rows(); r++) {
618 ret[r].resize(cols());
619 for(
int c=0; c<cols(); c++)
625 template <
int M,
class AT>
627 #ifndef FMATVEC_NO_SIZE_CHECK
628 assert(m.size() == M);
629 assert(m[0].size() == N);
631 for(
int r=0; r<rows(); r++) {
632 assert(m[r].size()==cols());
633 for(
int c=0; c<cols(); c++)
640 template <
int M,
class AT>
template <
class Type,
class Row,
class Col>
642 for(
int i=0; i<M; i++)
643 for(
int j=0; j<N; j++)
AT & operator()(int i, int j)
Element operator.
Definition: fixed_var_general_matrix.h:169
This is the basic matrix class for arbitrary matrices.
Definition: matrix.h:56
Matrix()
Standard constructor.
Definition: fixed_var_general_matrix.h:61
This is a matrix class for general matrices.
Definition: var_general_matrix.h:38
AT & operator()(int i, int j)
Standard constructor.
Definition: matrix.h:85
int rows() const
Number of rows.
Definition: fixed_var_general_matrix.h:236
const AT & operator()(int i, int j) const
Element operator.
Definition: fixed_var_general_matrix.h:184
const CBLAS_ORDER blasOrder() const
Storage convention.
Definition: fixed_var_general_matrix.h:267
const AT & e(int i) const
Element operator.
Definition: fixed_var_general_matrix.h:215
AT * operator()()
Pointer operator.
Definition: fixed_var_general_matrix.h:224
const AT & e(int i, int j) const
Element operator.
Definition: fixed_var_general_matrix.h:203
int cols() const
Number of columns.
This is an index class for creating submatrices.
Definition: range.h:35
int cols() const
Number of columns.
Definition: fixed_var_general_matrix.h:242
~Matrix()
Destructor.
Definition: fixed_var_general_matrix.h:122
int ldim() const
Leading dimension.
Definition: fixed_var_general_matrix.h:248
const CBLAS_TRANSPOSE blasTrans() const
Transposed status.
Definition: fixed_var_general_matrix.h:256
const AT * operator()() const
Pointer operator.
Definition: fixed_var_general_matrix.h:230
Basic shape class for matrices.
Definition: types.h:100
This is an index class for creating submatrices.
Definition: range.h:44
Matrix(const Matrix< General, Fixed< M >, Var, AT > &A)
Copy Constructor.
Definition: fixed_var_general_matrix.h:86
This is a vector class of general shape in dense storage format.
Definition: var_row_vector.h:39