22 #ifndef var_fixed_general_matrix_h
23 #define var_fixed_general_matrix_h
57 Matrix() : M(0), ele(0) { }
69 Matrix(
int m,
Init ini=INIT,
const AT &a=0) : M(m), ele(
new AT[M*N]) { init(a); }
70 Matrix(
int m,
Eye ini,
const AT &a=1) : M(m), ele(
new AT[M*N]) { init(ini,a); }
71 Matrix(
int m,
int n,
Noinit) : M(m), ele(
new AT[M*N]) { }
72 Matrix(
int m,
int n,
Init ini=INIT,
const AT &a=0) : M(m), ele(
new AT[M*N]) { init(a); }
73 Matrix(
int m,
int n,
Eye ini,
const AT &a=1) : M(m), ele(
new AT[M*N]) { init(ini,a); }
86 template<
class Row,
class Col>
92 template<
class Type,
class Row,
class Col>
93 explicit Matrix(
const Matrix<Type,Row,Col,AT> &A) : M(A.
rows()), ele(new AT[M*N]) {
95 #ifndef FMATVEC_NO_SIZE_CHECK
96 assert(A.cols() == N);
114 Matrix(
const char *str);
129 Matrix<General,Var,Fixed<N>,AT>& resize(
int m, Noinit) {
136 Matrix<General,Var,Fixed<N>,AT>& resize(
int m, Init ini=INIT,
const AT &a=0) {
return resize(m,Noinit()).init(a); }
138 Matrix<General,Var,Fixed<N>,AT>& resize(
int m, Eye ini,
const AT &a=1) {
return resize(m,Noinit()).init(ini,a); }
146 inline Matrix<General,Var,Fixed<N>,AT>& operator=(
const Matrix<General,Var,Fixed<N>,AT> &A);
148 template <
class Type,
class Row,
class Col>
149 inline Matrix<General,Var,Fixed<N>,AT>& operator=(
const Matrix<Type,Row,Col,AT> &A);
151 template <
class Type,
class Row,
class Col>
152 inline Matrix<General,Var,Fixed<N>,AT>& operator<<(const Matrix<Type,Row,Col,AT> &A);
166 #ifndef FMATVEC_NO_BOUNDS_CHECK
181 #ifndef FMATVEC_NO_BOUNDS_CHECK
191 AT& e(
int i,
int j) {
199 const AT&
e(
int i,
int j)
const {
211 const AT&
e(
int i)
const {
264 return CblasColMajor;
281 inline Matrix<General,Var,Fixed<N>,AT>& init(Eye,
const AT &a=1);
282 inline Matrix<General,Var,Fixed<N>,AT>& init(Noinit,
const AT &a=0) {
return *
this; }
288 inline operator std::vector<std::vector<AT> >();
295 inline Matrix(std::vector<std::vector<AT> > m);
297 inline const Matrix<General,Fixed<N>,Var,AT> T()
const;
299 template<
class Row>
inline void set(
int j,
const Vector<Row,AT> &x);
301 template<
class Col>
inline void set(
int i,
const RowVector<Col,AT> &x);
303 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);
305 template<
class Row>
inline void add(
int j,
const Vector<Row,AT> &x);
307 template<
class Col>
inline void add(
int i,
const RowVector<Col,AT> &x);
309 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);
313 template <
int N,
class AT>
318 std::istringstream iss(strs);
321 if(c==
'[') iss.str(strs);
322 else iss.str(std::string(
"[")+strs+
"]");
352 for(
int i=0; i<M; i++)
353 for(
int j=0; j<N; j++) {
361 template <
int N,
class AT>
template<
class Type,
class Row,
class Col>
364 #ifndef FMATVEC_NO_SIZE_CHECK
365 assert(N == A.cols());
372 #ifndef FMATVEC_NO_SIZE_CHECK
373 assert(M == A.rows());
382 template <
int N,
class AT>
390 #ifndef FMATVEC_NO_SIZE_CHECK
391 assert(M == A.rows());
400 template <
int N,
class AT>
template<
class Type,
class Row,
class Col>
403 #ifndef FMATVEC_NO_SIZE_CHECK
404 assert(N == A.cols());
417 template <
int N,
class AT>
419 for(
int i=0; i<M*N; i++)
424 template <
int N,
class AT>
426 for(
int i=0; i<M; i++)
427 for(
int j=0; j<N; j++)
428 e(i,j) = (i==j) ? val : 0;
432 template <
int N,
class AT>
433 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 {
434 #ifndef FMATVEC_NO_BOUNDS_CHECK
438 Matrix<General,Var,Var,AT> A(I.end()-I.start()+1,J.end()-J.start()+1,NONINIT);
440 for(
int i=0; i<A.rows(); i++)
441 for(
int j=0; j<A.cols(); j++)
442 A.e(i,j) = e(I.start()+i,J.start()+j);
447 template <
int N,
class AT>
448 inline const RowVector<Fixed<N>,AT> Matrix<General,Var,Fixed<N>,AT>::row(
int i)
const {
450 #ifndef FMATVEC_NO_BOUNDS_CHECK
455 RowVector<Fixed<N>,AT> x(NONINIT);
457 for(
int j=0; j<N; j++)
464 template <
int N,
class AT>
465 inline const Vector<Var,AT> Matrix<General,Var,Fixed<N>,AT>::col(
int j)
const {
467 #ifndef FMATVEC_NO_BOUNDS_CHECK
472 Vector<Var,AT> x(M,NONINIT);
474 for(
int i=0; i<M; i++)
481 template <
int N,
class AT>
482 inline const Matrix<General,Fixed<N>,Var,AT> Matrix<General,Var,Fixed<N>,AT>::T()
const {
483 Matrix<General,Fixed<N>,Var,AT> A(rows(),NONINIT);
484 for(
int i=0; i<N; i++)
485 for(
int j=0; j<M; j++)
490 template <
int N,
class AT>
template <
class Row>
491 inline void Matrix<General,Var,Fixed<N>,AT>::set(
int j,
const Vector<Row,AT> &x) {
492 #ifndef FMATVEC_NO_BOUNDS_CHECK
494 assert(rows()==x.size());
496 for(
int i=0; i<rows(); i++)
500 template <
int N,
class AT>
template <
class Col>
501 inline void Matrix<General,Var,Fixed<N>,AT>::set(
int i,
const RowVector<Col,AT> &x) {
502 #ifndef FMATVEC_NO_BOUNDS_CHECK
504 assert(cols()==x.size());
506 for(
int j=0; j<cols(); j++)
510 template <
int N,
class AT>
template<
class Type,
class Row,
class Col>
511 inline void Matrix<General,Var,Fixed<N>,AT>::set(
const Index &I,
const Index &J,
const Matrix<Type,Row,Col,AT> &A) {
513 #ifndef FMATVEC_NO_BOUNDS_CHECK
514 assert(I.end()<rows());
515 assert(J.end()<cols());
516 assert(I.size()==A.rows());
517 assert(J.size()==A.cols());
520 for(
int i=I.start(), ii=0; i<=I.end(); i++, ii++)
521 for(
int j=J.start(), jj=0; j<=J.end(); j++, jj++)
525 template <
int N,
class AT>
template <
class Row>
526 inline void Matrix<General,Var,Fixed<N>,AT>::add(
int j,
const Vector<Row,AT> &x) {
527 #ifndef FMATVEC_NO_BOUNDS_CHECK
529 assert(rows()==x.size());
531 for(
int i=0; i<rows(); i++)
535 template <
int N,
class AT>
template <
class Col>
536 inline void Matrix<General,Var,Fixed<N>,AT>::add(
int i,
const RowVector<Col,AT> &x) {
537 #ifndef FMATVEC_NO_BOUNDS_CHECK
539 assert(cols()==x.size());
541 for(
int j=0; j<cols(); j++)
545 template <
int N,
class AT>
template<
class Type,
class Row,
class Col>
546 inline void Matrix<General,Var,Fixed<N>,AT>::add(
const Index &I,
const Index &J,
const Matrix<Type,Row,Col,AT> &A) {
548 #ifndef FMATVEC_NO_BOUNDS_CHECK
549 assert(I.end()<rows());
550 assert(J.end()<cols());
551 assert(I.size()==A.rows());
552 assert(J.size()==A.cols());
555 for(
int i=I.start(), ii=0; i<=I.end(); i++, ii++)
556 for(
int j=J.start(), jj=0; j<=J.end(); j++, jj++)
557 e(i,j) += A.e(ii,jj);
560 template <
int N,
class AT>
562 std::vector<std::vector<AT> > ret(rows());
563 for(
int r=0; r<rows(); r++) {
564 ret[r].resize(cols());
565 for(
int c=0; c<cols(); c++)
571 template <
int N,
class AT>
573 #ifndef FMATVEC_NO_SIZE_CHECK
574 assert(m.size() == M);
575 assert(m[0].size() == N);
577 for(
int r=0; r<rows(); r++) {
578 assert(m[r].size()==cols());
579 for(
int c=0; c<cols(); c++)
586 template <
int N,
class AT>
template <
class Type,
class Row,
class Col>
588 for(
int i=0; i<M; i++)
589 for(
int j=0; j<N; j++)
const AT & operator()(int i, int j) const
Element operator.
Definition: var_fixed_general_matrix.h:180
This is the basic matrix class for arbitrary matrices.
Definition: matrix.h:56
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:82
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
~Matrix()
Destructor.
Definition: var_fixed_general_matrix.h:118
int rows() const
Number of rows.
Definition: var_fixed_general_matrix.h:232
int rows() const
Number of rows.
const AT & e(int i) const
Element operator.
Definition: var_fixed_general_matrix.h:211
const CBLAS_TRANSPOSE blasTrans() const
Transposed status.
Definition: var_fixed_general_matrix.h:252
const AT & e(int i, int j) const
Element operator.
Definition: var_fixed_general_matrix.h:199
int ldim() const
Leading dimension.
Definition: var_fixed_general_matrix.h:244
const CBLAS_ORDER blasOrder() const
Storage convention.
Definition: var_fixed_general_matrix.h:263
AT * operator()()
Pointer operator.
Definition: var_fixed_general_matrix.h:220
Basic shape class for matrices.
Definition: types.h:100
const AT * operator()() const
Pointer operator.
Definition: var_fixed_general_matrix.h:226
int cols() const
Number of columns.
Definition: var_fixed_general_matrix.h:238
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:165