22 #ifndef var_fixed_general_matrix_h
23 #define var_fixed_general_matrix_h
41 typedef AT AtomicType;
58 Matrix() : M(0), ele(0) { }
70 Matrix(
int m,
Init ini=INIT,
const AT &a=0) : M(m), ele(
new AT[M*N]) { init(a); }
71 Matrix(
int m,
Eye ini,
const AT &a=1) : M(m), ele(
new AT[M*N]) { init(ini,a); }
72 Matrix(
int m,
int n,
Noinit) : M(m), ele(
new AT[M*N]) { }
73 Matrix(
int m,
int n,
Init ini=INIT,
const AT &a=0) : M(m), ele(
new AT[M*N]) { init(a); }
74 Matrix(
int m,
int n,
Eye ini,
const AT &a=1) : M(m), ele(
new AT[M*N]) { init(ini,a); }
87 template<
class Row,
class Col>
93 template<
class Type,
class Row,
class Col>
94 explicit Matrix(
const Matrix<Type,Row,Col,AT> &A) : M(A.
rows()), ele(new AT[M*N]) {
96 #ifndef FMATVEC_NO_SIZE_CHECK
97 assert(A.cols() == N);
115 Matrix(
const char *str);
130 Matrix<General,Var,Fixed<N>,AT>& resize(
int m, Noinit) {
137 Matrix<General,Var,Fixed<N>,AT>& resize(
int m, Init ini=INIT,
const AT &a=0) {
return resize(m,Noinit()).init(a); }
139 Matrix<General,Var,Fixed<N>,AT>& resize(
int m, Eye ini,
const AT &a=1) {
return resize(m,Noinit()).init(ini,a); }
145 throw std::runtime_error(
"A var-fixed matrix can only be resized in the first dimension.");
157 template <
class Type,
class Row,
class Col>
160 template <
class Type,
class Row,
class Col>
175 #ifndef FMATVEC_NO_BOUNDS_CHECK
190 #ifndef FMATVEC_NO_BOUNDS_CHECK
200 AT& e(
int i,
int j) {
208 const AT&
e(
int i,
int j)
const {
220 const AT&
e(
int i)
const {
278 return CblasColMajor;
295 inline Matrix<General,Var,Fixed<N>,AT>& init(Eye,
const AT &a=1);
296 inline Matrix<General,Var,Fixed<N>,AT>& init(Noinit,
const AT &a=0) {
return *
this; }
302 inline operator std::vector<std::vector<AT> >();
309 inline Matrix(std::vector<std::vector<AT> > m);
311 inline const Matrix<General,Fixed<N>,Var,AT> T()
const;
313 template<
class Row>
inline void set(
int j,
const Vector<Row,AT> &x);
315 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);
319 template<
class Row>
inline void add(
int j,
const Vector<Row,AT> &x);
321 template<
class Col>
inline void add(
int i,
const RowVector<Col,AT> &x);
323 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);
327 template <
int N,
class AT>
332 std::istringstream iss(strs);
335 if(c==
'[') iss.str(strs);
336 else iss.str(std::string(
"[")+strs+
"]");
366 for(
int i=0; i<M; i++)
367 for(
int j=0; j<N; j++) {
375 template <
int N,
class AT>
template<
class Type,
class Row,
class Col>
378 #ifndef FMATVEC_NO_SIZE_CHECK
379 assert(N == A.cols());
386 #ifndef FMATVEC_NO_SIZE_CHECK
387 assert(M == A.rows());
396 template <
int N,
class AT>
404 #ifndef FMATVEC_NO_SIZE_CHECK
405 assert(M == A.rows());
414 template <
int N,
class AT>
template<
class Type,
class Row,
class Col>
417 #ifndef FMATVEC_NO_SIZE_CHECK
418 assert(N == A.cols());
431 template <
int N,
class AT>
433 for(
int i=0; i<M*N; i++)
438 template <
int N,
class AT>
440 for(
int i=0; i<M; i++)
441 for(
int j=0; j<N; j++)
442 e(i,j) = (i==j) ? val : 0;
446 template <
int N,
class AT>
447 inline const Matrix<General,Var,Var,AT> Matrix<General,Var,Fixed<N>,AT>::operator()(
const Range<Var,Var> &I,
const Range<Var,Var> &J)
const {
448 #ifndef FMATVEC_NO_BOUNDS_CHECK
452 Matrix<General,Var,Var,AT> A(I.end()-I.start()+1,J.end()-J.start()+1,NONINIT);
454 for(
int i=0; i<A.rows(); i++)
455 for(
int j=0; j<A.cols(); j++)
456 A.e(i,j) = e(I.start()+i,J.start()+j);
461 template <
int N,
class AT>
462 inline const RowVector<Fixed<N>,AT> Matrix<General,Var,Fixed<N>,AT>::row(
int i)
const {
464 #ifndef FMATVEC_NO_BOUNDS_CHECK
469 RowVector<Fixed<N>,AT> x(NONINIT);
471 for(
int j=0; j<N; j++)
478 template <
int N,
class AT>
479 inline const Vector<Var,AT> Matrix<General,Var,Fixed<N>,AT>::col(
int j)
const {
481 #ifndef FMATVEC_NO_BOUNDS_CHECK
486 Vector<Var,AT> x(M,NONINIT);
488 for(
int i=0; i<M; i++)
495 template <
int N,
class AT>
496 inline const Matrix<General,Fixed<N>,Var,AT> Matrix<General,Var,Fixed<N>,AT>::T()
const {
497 Matrix<General,Fixed<N>,Var,AT> A(rows(),NONINIT);
498 for(
int i=0; i<N; i++)
499 for(
int j=0; j<M; j++)
504 template <
int N,
class AT>
template <
class Row>
505 inline void Matrix<General,Var,Fixed<N>,AT>::set(
int j,
const Vector<Row,AT> &x) {
506 #ifndef FMATVEC_NO_BOUNDS_CHECK
508 assert(rows()==x.size());
510 for(
int i=0; i<rows(); i++)
514 template <
int N,
class AT>
template <
class Col>
515 inline void Matrix<General,Var,Fixed<N>,AT>::set(
int i,
const RowVector<Col,AT> &x) {
516 #ifndef FMATVEC_NO_BOUNDS_CHECK
518 assert(cols()==x.size());
520 for(
int j=0; j<cols(); j++)
524 template <
int N,
class AT>
template<
class Type,
class Row,
class Col>
525 inline void Matrix<General,Var,Fixed<N>,AT>::set(
const Range<Var,Var> &I,
const Range<Var,Var> &J,
const Matrix<Type,Row,Col,AT> &A) {
527 #ifndef FMATVEC_NO_BOUNDS_CHECK
528 assert(I.end()<rows());
529 assert(J.end()<cols());
530 assert(I.size()==A.rows());
531 assert(J.size()==A.cols());
534 for(
int i=I.start(), ii=0; i<=I.end(); i++, ii++)
535 for(
int j=J.start(), jj=0; j<=J.end(); j++, jj++)
539 template <
int N,
class AT>
template <
class Row>
540 inline void Matrix<General,Var,Fixed<N>,AT>::add(
int j,
const Vector<Row,AT> &x) {
541 #ifndef FMATVEC_NO_BOUNDS_CHECK
543 assert(rows()==x.size());
545 for(
int i=0; i<rows(); i++)
549 template <
int N,
class AT>
template <
class Col>
550 inline void Matrix<General,Var,Fixed<N>,AT>::add(
int i,
const RowVector<Col,AT> &x) {
551 #ifndef FMATVEC_NO_BOUNDS_CHECK
553 assert(cols()==x.size());
555 for(
int j=0; j<cols(); j++)
559 template <
int N,
class AT>
template<
class Type,
class Row,
class Col>
560 inline void Matrix<General,Var,Fixed<N>,AT>::add(
const Range<Var,Var> &I,
const Range<Var,Var> &J,
const Matrix<Type,Row,Col,AT> &A) {
562 #ifndef FMATVEC_NO_BOUNDS_CHECK
563 assert(I.end()<rows());
564 assert(J.end()<cols());
565 assert(I.size()==A.rows());
566 assert(J.size()==A.cols());
569 for(
int i=I.start(), ii=0; i<=I.end(); i++, ii++)
570 for(
int j=J.start(), jj=0; j<=J.end(); j++, jj++)
571 e(i,j) += A.e(ii,jj);
574 template <
int N,
class AT>
576 std::vector<std::vector<AT> > ret(rows());
577 for(
int r=0; r<rows(); r++) {
578 ret[r].resize(cols());
579 for(
int c=0; c<cols(); c++)
585 template <
int N,
class AT>
587 #ifndef FMATVEC_NO_SIZE_CHECK
588 assert(m.size() == M);
589 assert(m[0].size() == N);
591 for(
int r=0; r<rows(); r++) {
592 assert(m[r].size()==cols());
593 for(
int c=0; c<cols(); c++)
600 template <
int N,
class AT>
template <
class Type,
class Row,
class Col>
602 for(
int i=0; i<M; i++)
603 for(
int j=0; j<N; j++)
const AT & operator()(int i, int j) const
Element operator.
Definition: var_fixed_general_matrix.h:189
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
This is a vector class of general shape in dense storage format.
Definition: var_vector.h:39
Matrix(const Matrix< General, Var, Fixed< N >, AT > &A)
Copy Constructor.
Definition: var_fixed_general_matrix.h:83
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
~Matrix()
Destructor.
Definition: var_fixed_general_matrix.h:119
int rows() const
Number of rows.
Definition: var_fixed_general_matrix.h:241
void resize(int m, int n)
Definition: var_fixed_general_matrix.h:143
bool transposed() const
A var-fixed matrix is stored in fortran-storage order -> return always false.
Definition: var_fixed_general_matrix.h:256
int rows() const
Number of rows.
const AT & e(int i) const
Element operator.
Definition: var_fixed_general_matrix.h:220
const CBLAS_TRANSPOSE blasTrans() const
Transposed status.
Definition: var_fixed_general_matrix.h:266
const AT & e(int i, int j) const
Element operator.
Definition: var_fixed_general_matrix.h:208
int ldim() const
Leading dimension.
Definition: var_fixed_general_matrix.h:253
const CBLAS_ORDER blasOrder() const
Storage convention.
Definition: var_fixed_general_matrix.h:277
AT * operator()()
Pointer operator.
Definition: var_fixed_general_matrix.h:229
Basic shape class for matrices.
Definition: types.h:100
const AT * operator()() const
Pointer operator.
Definition: var_fixed_general_matrix.h:235
int cols() const
Number of columns.
Definition: var_fixed_general_matrix.h:247
This is an index class for creating submatrices.
Definition: range.h:44
AT & operator()(int i, int j)
Element operator.
Definition: var_fixed_general_matrix.h:174