22 #ifndef fixed_general_matrix_h
23 #define fixed_general_matrix_h
66 Matrix(
Init ini=INIT,
const AT &a=0) { init(a); }
67 Matrix(
Eye ini,
const AT &a=1) { init(ini,a); }
69 Matrix(
int m,
int n,
Init ini=INIT,
const AT &a=0) { init(a); }
70 Matrix(
int m,
int n,
Eye ini,
const AT &a=1) { init(ini,a); }
72 template<
class Row,
class Col>
74 #ifndef FMATVEC_NO_SIZE_CHECK
75 assert(A.
rows() == M);
76 assert(A.
cols() == N);
82 template<
class Type,
class Row,
class Col>
85 #ifndef FMATVEC_NO_SIZE_CHECK
86 assert(A.
rows() == M);
87 assert(A.
cols() == N);
107 template <
class Type,
class Row,
class Col>
121 #ifndef FMATVEC_NO_BOUNDS_CHECK
136 #ifndef FMATVEC_NO_BOUNDS_CHECK
146 AT& e(
int i,
int j) {
154 const AT&
e(
int i,
int j)
const {
207 return CblasRowMajor;
263 template <
int M1,
int M2,
int N1,
int N2>
265 template <
int M1,
int M2>
268 template <
int N1,
int N2>
283 inline Matrix<General,Fixed<M>,Fixed<N>,AT>& init(Eye,
const AT &a=1);
284 inline Matrix<General,Fixed<M>,Fixed<N>,AT>& init(Noinit,
const AT &a=0) {
return *
this; }
290 inline operator std::vector<std::vector<AT> >();
297 Matrix(std::vector<std::vector<AT> > m);
299 inline const Matrix<General,Fixed<N>,Fixed<M>,AT> T()
const;
304 template<
class Row>
inline void set(
int j,
const Vector<Row,AT> &x);
309 template<
class Col>
inline void set(
int i,
const RowVector<Col,AT> &x);
317 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);
322 template<
class Row>
inline void add(
int j,
const Vector<Row,AT> &x);
327 template<
class Col>
inline void add(
int i,
const RowVector<Col,AT> &x);
329 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);
333 template <
int M,
int N,
class AT>
338 std::istringstream iss(strs);
341 if(c==
'[') iss.str(strs);
342 else iss.str(std::string(
"[")+strs+
"]");
371 for(
int i=0; i<M; i++)
372 for(
int j=0; j<N; j++) {
381 template <
int M,
int N,
class AT>
template<
class Type,
class Row,
class Col>
384 #ifndef FMATVEC_NO_SIZE_CHECK
385 assert(A.rows() == M);
386 assert(A.cols() == N);
394 template <
int M,
int N,
class AT>
396 for(
int i=0; i<M; i++)
397 for(
int j=0; j<N; j++)
402 template <
int M,
int N,
class AT>
404 for(
int i=0; i<M; i++)
405 for(
int j=0; j<N; j++)
406 e(i,j) = (i==j) ? val : 0;
410 template <
int M,
int N,
class AT>
412 #ifndef FMATVEC_NO_BOUNDS_CHECK
418 for(
int i=0; i<A.rows(); i++)
419 for(
int j=0; j<A.cols(); j++)
420 A.e(i,j) = e(I.start()+i,J.start()+j);
425 template <
int M,
int N,
class AT>
template <
int M1,
int M2,
int N1,
int N2>
427 #ifndef FMATVEC_NO_BOUNDS_CHECK
433 for(
int i=0; i<A.rows(); i++)
434 for(
int j=0; j<A.cols(); j++)
435 A.e(i,j) = e(M1+i,J.start()+j);
440 template <
int M,
int N,
class AT>
template <
int M1,
int M2>
441 inline const Matrix<General,Fixed<M2-M1+1>,Var,AT> Matrix<General,Fixed<M>,Fixed<N>,AT>::operator()(
const Range<Fixed<M1>,Fixed<M2> > &I,
const Range<Var,Var> &J)
const {
442 #ifndef FMATVEC_NO_BOUNDS_CHECK
446 Matrix<General,Fixed<M2-M1+1>,Var,AT> A(J.end()-J.start()+1,NONINIT);
448 for(
int i=0; i<A.rows(); i++)
449 for(
int j=0; j<A.cols(); j++)
450 A.e(i,j) = e(I.start()+i,J.start()+j);
455 template <
int M,
int N,
class AT>
template <
int N1,
int N2>
456 inline const Matrix<General,Var,Fixed<N2-N1+1>,AT> Matrix<General,Fixed<M>,Fixed<N>,AT>::operator()(
const Range<Var,Var> &I,
const Range<Fixed<N1>,Fixed<N2> > &J)
const {
457 #ifndef FMATVEC_NO_BOUNDS_CHECK
461 Matrix<General,Var,Fixed<N2-N1+1>,AT> A(I.end()-I.start()+1,NONINIT);
463 for(
int i=0; i<A.rows(); i++)
464 for(
int j=0; j<A.cols(); j++)
465 A.e(i,j) = e(I.start()+i,J.start()+j);
470 template <
int M,
int N,
class AT>
471 inline const RowVector<Fixed<N>,AT> Matrix<General,Fixed<M>,Fixed<N>,AT>::row(
int i)
const {
473 #ifndef FMATVEC_NO_BOUNDS_CHECK
478 RowVector<Fixed<N>,AT> x(NONINIT);
480 for(
int j=0; j<N; j++)
487 template <
int M,
int N,
class AT>
488 inline const Vector<Fixed<M>,AT> Matrix<General,Fixed<M>,Fixed<N>,AT>::col(
int j)
const {
490 #ifndef FMATVEC_NO_BOUNDS_CHECK
495 Vector<Fixed<M>,AT> x(NONINIT);
497 for(
int i=0; i<M; i++)
504 template <
int M,
int N,
class AT>
505 inline const Matrix<General,Fixed<N>,Fixed<M>,AT> Matrix<General,Fixed<M>,Fixed<N>,AT>::T()
const {
506 Matrix<General,Fixed<N>,Fixed<M>,AT> A(NONINIT);
507 for(
int i=0; i<N; i++)
508 for(
int j=0; j<M; j++)
513 template <
int M,
int N,
class AT>
template <
class Row>
515 #ifndef FMATVEC_NO_BOUNDS_CHECK
517 assert(rows()==x.size());
519 for(
int i=0; i<rows(); i++)
523 template <
int M,
int N,
class AT>
template <
class Col>
525 #ifndef FMATVEC_NO_BOUNDS_CHECK
527 assert(cols()==x.size());
529 for(
int j=0; j<cols(); j++)
533 template <
int M,
int N,
class AT>
template<
class Type,
class Row,
class Col>
534 inline void Matrix<General,Fixed<M>,
Fixed<N>,AT>::set(
const Range<Var,Var> &I,
const Range<Var,Var> &J,
const Matrix<Type,Row,Col,AT> &A) {
536 #ifndef FMATVEC_NO_BOUNDS_CHECK
537 assert(I.
end()<rows());
538 assert(J.
end()<cols());
543 for(
int i=I.
start(), ii=0; i<=I.
end(); i++, ii++)
544 for(
int j=J.
start(), jj=0; j<=J.
end(); j++, jj++)
548 template <
int M,
int N,
class AT>
template <
class Row>
550 #ifndef FMATVEC_NO_BOUNDS_CHECK
552 assert(rows()==x.size());
554 for(
int i=0; i<rows(); i++)
558 template <
int M,
int N,
class AT>
template <
class Col>
560 #ifndef FMATVEC_NO_BOUNDS_CHECK
562 assert(cols()==x.size());
564 for(
int j=0; j<cols(); j++)
568 template <
int M,
int N,
class AT>
template<
class Type,
class Row,
class Col>
569 inline void Matrix<General,Fixed<M>,
Fixed<N>,AT>::add(
const Range<Var,Var> &I,
const Range<Var,Var> &J,
const Matrix<Type,Row,Col,AT> &A) {
571 #ifndef FMATVEC_NO_BOUNDS_CHECK
572 assert(I.
end()<rows());
573 assert(J.
end()<cols());
578 for(
int i=I.
start(), ii=0; i<=I.
end(); i++, ii++)
579 for(
int j=J.
start(), jj=0; j<=J.
end(); j++, jj++)
580 e(i,j) += A.e(ii,jj);
583 template <
int M,
int N,
class AT>
585 std::vector<std::vector<AT> > ret(rows());
586 for(
int r=0; r<rows(); r++) {
587 ret[r].resize(cols());
588 for(
int c=0; c<cols(); c++)
594 template <
int M,
int N,
class AT>
596 #ifndef FMATVEC_NO_SIZE_CHECK
597 assert(m.size() == M);
598 assert(m[0].size() == N);
600 for(
int r=0; r<rows(); r++) {
601 assert(m[r].size()==cols());
602 for(
int c=0; c<cols(); c++)
609 template <
int M,
int N,
class AT>
template <
class Type,
class Row,
class Col>
611 for(
int i=0; i<M; i++)
612 for(
int j=0; j<N; j++)
616 template<
int M,
int N,
class AT>
template<
class Row>
617 inline void Matrix<General,Fixed<M>,Fixed<N>,AT>::deepCopy(
const Matrix<Symmetric,Row,Row,AT> &A) {
618 for(
int i=0; i<A.size(); i++) {
620 for(
int j=i+1; j<A.size(); j++)
621 e(i,j) = e(j,i) = A.ej(i,j);
640 Matrix(
Init ini=INIT,
const double &a=0) { this->init(a); }
641 Matrix(
Eye ini,
const double &a=1) { this->init(ini,a); }
643 Matrix(
int m,
int n,
Init ini,
const double &a=0) { this->init(a); }
644 Matrix(
int m,
int n,
Eye ini,
const double &a=1) { this->init(ini,a); }
645 explicit Matrix(
const Matrix<General,Fixed<M>,Fixed<M>,
double>& A) { this->deepCopy(A); }
649 #ifndef FMATVEC_NO_SIZE_CHECK
650 assert(A.size() == M);
655 template<
class Type,
class Row,
class Col>
657 #ifndef FMATVEC_NO_SIZE_CHECK
658 assert(A.
rows() == M);
659 assert(A.
cols() == M);
const AT & operator()(int i, int j) const
Element operator.
Definition: fixed_general_matrix.h:135
const AT * operator()() const
Pointer operator.
Definition: fixed_general_matrix.h:169
This is the basic matrix class for arbitrary matrices.
Definition: matrix.h:56
AT * operator()()
Pointer operator.
Definition: fixed_general_matrix.h:163
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
Shape class for rotation matrices.
Definition: types.h:124
int rows() const
Number of rows.
int cols() const
Number of columns.
const CBLAS_ORDER blasOrder() const
Storage convention.
Definition: fixed_general_matrix.h:206
int cols() const
Number of columns.
Definition: fixed_general_matrix.h:181
const AT & e(int i, int j) const
Element operator.
Definition: fixed_general_matrix.h:154
int rows() const
Number of rows.
Definition: fixed_general_matrix.h:175
This is an index class for creating submatrices.
Definition: range.h:35
int size() const
Size.
Definition: range.h:101
const CBLAS_TRANSPOSE blasTrans() const
Transposed status.
Definition: fixed_general_matrix.h:195
int ldim() const
Leading dimension.
Definition: fixed_general_matrix.h:187
AT & operator()(int i, int j)
Element operator.
Definition: fixed_general_matrix.h:120
Basic shape class for matrices.
Definition: types.h:100
int end() const
Last element.
Definition: range.h:95
This is an index class for creating submatrices.
Definition: range.h:44
int start() const
First element.
Definition: range.h:89