22 #ifndef fixed_general_matrix_h
23 #define fixed_general_matrix_h
43 typedef AT AtomicType;
69 Matrix(
Init ini=INIT,
const AT &a=0) { init(a); }
70 Matrix(
Eye ini,
const AT &a=1) { init(ini,a); }
72 Matrix(
int m,
int n,
Init ini=INIT,
const AT &a=0) { init(a); }
73 Matrix(
int m,
int n,
Eye ini,
const AT &a=1) { init(ini,a); }
75 template<
class Row,
class Col>
77 #ifndef FMATVEC_NO_SIZE_CHECK
78 assert(A.
rows() == M);
79 assert(A.
cols() == N);
85 template<
class Type,
class Row,
class Col>
88 #ifndef FMATVEC_NO_SIZE_CHECK
89 assert(A.
rows() == M);
90 assert(A.
cols() == N);
110 template <
class Type,
class Row,
class Col>
124 #ifndef FMATVEC_NO_BOUNDS_CHECK
139 #ifndef FMATVEC_NO_BOUNDS_CHECK
149 AT& e(
int i,
int j) {
157 const AT&
e(
int i,
int j)
const {
201 throw std::runtime_error(
"A fixed matrix cannot be resized.");
222 return CblasRowMajor;
278 template <
int M1,
int M2,
int N1,
int N2>
280 template <
int M1,
int M2>
283 template <
int N1,
int N2>
298 inline Matrix<General,Fixed<M>,Fixed<N>,AT>& init(Eye,
const AT &a=1);
299 inline Matrix<General,Fixed<M>,Fixed<N>,AT>& init(Noinit,
const AT &a=0) {
return *
this; }
305 inline operator std::vector<std::vector<AT> >();
312 Matrix(std::vector<std::vector<AT> > m);
314 inline const Matrix<General,Fixed<N>,Fixed<M>,AT> T()
const;
319 template<
class Row>
inline void set(
int j,
const Vector<Row,AT> &x);
324 template<
class Col>
inline void set(
int i,
const RowVector<Col,AT> &x);
332 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);
337 template<
class Row>
inline void add(
int j,
const Vector<Row,AT> &x);
342 template<
class Col>
inline void add(
int i,
const RowVector<Col,AT> &x);
344 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);
348 template <
int M,
int N,
class AT>
353 std::istringstream iss(strs);
356 if(c==
'[') iss.str(strs);
357 else iss.str(std::string(
"[")+strs+
"]");
386 for(
int i=0; i<M; i++)
387 for(
int j=0; j<N; j++) {
396 template <
int M,
int N,
class AT>
template<
class Type,
class Row,
class Col>
399 #ifndef FMATVEC_NO_SIZE_CHECK
400 assert(A.rows() == M);
401 assert(A.cols() == N);
409 template <
int M,
int N,
class AT>
411 for(
int i=0; i<M; i++)
412 for(
int j=0; j<N; j++)
417 template <
int M,
int N,
class AT>
419 for(
int i=0; i<M; i++)
420 for(
int j=0; j<N; j++)
421 e(i,j) = (i==j) ? val : 0;
425 template <
int M,
int N,
class AT>
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(I.start()+i,J.start()+j);
440 template <
int M,
int N,
class AT>
template <
int M1,
int M2,
int N1,
int N2>
442 #ifndef FMATVEC_NO_BOUNDS_CHECK
448 for(
int i=0; i<A.rows(); i++)
449 for(
int j=0; j<A.cols(); j++)
450 A.e(i,j) = e(M1+i,J.start()+j);
455 template <
int M,
int N,
class AT>
template <
int M1,
int M2>
456 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 {
457 #ifndef FMATVEC_NO_BOUNDS_CHECK
461 Matrix<General,Fixed<M2-M1+1>,Var,AT> A(J.end()-J.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>
template <
int N1,
int N2>
471 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 {
472 #ifndef FMATVEC_NO_BOUNDS_CHECK
476 Matrix<General,Var,Fixed<N2-N1+1>,AT> A(I.end()-I.start()+1,NONINIT);
478 for(
int i=0; i<A.rows(); i++)
479 for(
int j=0; j<A.cols(); j++)
480 A.e(i,j) = e(I.start()+i,J.start()+j);
485 template <
int M,
int N,
class AT>
486 inline const RowVector<Fixed<N>,AT> Matrix<General,Fixed<M>,Fixed<N>,AT>::row(
int i)
const {
488 #ifndef FMATVEC_NO_BOUNDS_CHECK
493 RowVector<Fixed<N>,AT> x(NONINIT);
495 for(
int j=0; j<N; j++)
502 template <
int M,
int N,
class AT>
503 inline const Vector<Fixed<M>,AT> Matrix<General,Fixed<M>,Fixed<N>,AT>::col(
int j)
const {
505 #ifndef FMATVEC_NO_BOUNDS_CHECK
510 Vector<Fixed<M>,AT> x(NONINIT);
512 for(
int i=0; i<M; i++)
519 template <
int M,
int N,
class AT>
520 inline const Matrix<General,Fixed<N>,Fixed<M>,AT> Matrix<General,Fixed<M>,Fixed<N>,AT>::T()
const {
521 Matrix<General,Fixed<N>,Fixed<M>,AT> A(NONINIT);
522 for(
int i=0; i<N; i++)
523 for(
int j=0; j<M; j++)
528 template <
int M,
int N,
class AT>
template <
class Row>
530 #ifndef FMATVEC_NO_BOUNDS_CHECK
532 assert(rows()==x.size());
534 for(
int i=0; i<rows(); i++)
538 template <
int M,
int N,
class AT>
template <
class Col>
540 #ifndef FMATVEC_NO_BOUNDS_CHECK
542 assert(cols()==x.size());
544 for(
int j=0; j<cols(); j++)
548 template <
int M,
int N,
class AT>
template<
class Type,
class Row,
class Col>
549 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) {
551 #ifndef FMATVEC_NO_BOUNDS_CHECK
552 assert(I.
end()<rows());
553 assert(J.
end()<cols());
558 for(
int i=I.
start(), ii=0; i<=I.
end(); i++, ii++)
559 for(
int j=J.
start(), jj=0; j<=J.
end(); j++, jj++)
563 template <
int M,
int N,
class AT>
template <
class Row>
565 #ifndef FMATVEC_NO_BOUNDS_CHECK
567 assert(rows()==x.size());
569 for(
int i=0; i<rows(); i++)
573 template <
int M,
int N,
class AT>
template <
class Col>
575 #ifndef FMATVEC_NO_BOUNDS_CHECK
577 assert(cols()==x.size());
579 for(
int j=0; j<cols(); j++)
583 template <
int M,
int N,
class AT>
template<
class Type,
class Row,
class Col>
584 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) {
586 #ifndef FMATVEC_NO_BOUNDS_CHECK
587 assert(I.
end()<rows());
588 assert(J.
end()<cols());
593 for(
int i=I.
start(), ii=0; i<=I.
end(); i++, ii++)
594 for(
int j=J.
start(), jj=0; j<=J.
end(); j++, jj++)
595 e(i,j) += A.e(ii,jj);
598 template <
int M,
int N,
class AT>
600 std::vector<std::vector<AT> > ret(rows());
601 for(
int r=0; r<rows(); r++) {
602 ret[r].resize(cols());
603 for(
int c=0; c<cols(); c++)
609 template <
int M,
int N,
class AT>
611 #ifndef FMATVEC_NO_SIZE_CHECK
612 assert(m.size() == M);
613 assert(m[0].size() == N);
615 for(
int r=0; r<rows(); r++) {
616 assert(m[r].size()==cols());
617 for(
int c=0; c<cols(); c++)
624 template <
int M,
int N,
class AT>
template <
class Type,
class Row,
class Col>
626 for(
int i=0; i<M; i++)
627 for(
int j=0; j<N; j++)
631 template<
int M,
int N,
class AT>
template<
class Row>
632 inline void Matrix<General,Fixed<M>,Fixed<N>,AT>::deepCopy(
const Matrix<Symmetric,Row,Row,AT> &A) {
633 for(
int i=0; i<A.size(); i++) {
635 for(
int j=i+1; j<A.size(); j++)
636 e(i,j) = e(j,i) = A.ej(i,j);
652 typedef double AtomicType;
656 Matrix(
Init ini=INIT,
const double &a=0) { this->init(a); }
657 Matrix(
Eye ini,
const double &a=1) { this->init(ini,a); }
659 Matrix(
int m,
int n,
Init ini,
const double &a=0) { this->init(a); }
660 Matrix(
int m,
int n,
Eye ini,
const double &a=1) { this->init(ini,a); }
661 explicit Matrix(
const Matrix<General,Fixed<M>,Fixed<M>,
double>& A) { this->deepCopy(A); }
665 #ifndef FMATVEC_NO_SIZE_CHECK
666 assert(A.size() == M);
671 template<
class Type,
class Row,
class Col>
673 #ifndef FMATVEC_NO_SIZE_CHECK
674 assert(A.
rows() == M);
675 assert(A.
cols() == M);
const AT & operator()(int i, int j) const
Element operator.
Definition: fixed_general_matrix.h:138
bool transposed() const
A fixed matrix is stored in c-storage order -> transposed is always true.
Definition: fixed_general_matrix.h:193
const AT * operator()() const
Pointer operator.
Definition: fixed_general_matrix.h:172
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
AT * operator()()
Pointer operator.
Definition: fixed_general_matrix.h:166
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:86
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:221
int cols() const
Number of columns.
Definition: fixed_general_matrix.h:184
const AT & e(int i, int j) const
Element operator.
Definition: fixed_general_matrix.h:157
int rows() const
Number of rows.
Definition: fixed_general_matrix.h:178
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:210
int ldim() const
Leading dimension.
Definition: fixed_general_matrix.h:190
AT & operator()(int i, int j)
Element operator.
Definition: fixed_general_matrix.h:123
Basic shape class for matrices.
Definition: types.h:100
void resize(int m, int n)
Definition: fixed_general_matrix.h:199
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