19#ifndef _GIMLI_MATRIX__H
20#define _GIMLI_MATRIX__H
33 #include <boost/thread.hpp>
39template <
class ValueType >
class DLLEXPORT Matrix3 {
44 : valid_(
false){ clear(); }
46 Matrix3(
const Matrix3 < ValueType > & m ){
47 mat_[0] = m.mat_[0]; mat_[1] = m.mat_[1]; mat_[2] = m.mat_[2];
48 mat_[3] = m.mat_[3]; mat_[4] = m.mat_[4]; mat_[5] = m.mat_[5];
49 mat_[6] = m.mat_[6]; mat_[7] = m.mat_[7]; mat_[8] = m.mat_[8];
52 inline ValueType & operator [](Index i){
return mat_[i];}
53 inline const ValueType & operator [](Index i)
const {
return mat_[i];}
55 #define DEFINE_UNARY_MOD_OPERATOR__(OP, NAME) \
56 inline Matrix3 < ValueType > & operator OP##= (const ValueType & val) { \
57 for (Index i = 0; i < 9; i += 3) {\
58 mat_[i] OP##= val; mat_[i+1] OP##= val; mat_[i+2] OP##= val; } return *this; \
61 DEFINE_UNARY_MOD_OPERATOR__(+, PLUS)
62 DEFINE_UNARY_MOD_OPERATOR__(-, MINUS)
63 DEFINE_UNARY_MOD_OPERATOR__(/, DIVID)
64 DEFINE_UNARY_MOD_OPERATOR__(*, MULT)
66 #undef DEFINE_UNARY_MOD_OPERATOR__
69 mat_[0] = 0.0; mat_[1] = 0.0; mat_[2] = 0.0;
70 mat_[3] = 0.0; mat_[4] = 0.0; mat_[5] = 0.0;
71 mat_[6] = 0.0; mat_[7] = 0.0; mat_[8] = 0.0;
73 inline Index rows()
const {
return 3; }
74 inline Index cols()
const {
return 3; }
76 inline const Vector < ValueType > col(Index i)
const {
77 Vector < ValueType >ret(3);
78 ret[0] = mat_[i]; ret[1] = mat_[3 + i]; ret[2] = mat_[6 + i];
82 inline const Vector < ValueType > row(Index i)
const {
83 Vector < ValueType >ret(3);
84 ret[0] = mat_[i * 3]; ret[1] = mat_[i * 3 + 1]; ret[2] = mat_[i * 3 + 2];
93 inline void setVal(Index i,
const RVector & v){
94 mat_[i * 3] = v[0]; mat_[i * 3 + 1] = v[1]; mat_[i * 3 + 2] = v[2];
97 inline void setValid(
bool v){valid_ = v;}
99 inline bool valid()
const {
return valid_;}
101 inline ValueType det()
const {
102 return mat_[0] * (mat_[4] * mat_[8] - mat_[5] * mat_[7]) -
103 mat_[1] * (mat_[3] * mat_[8] - mat_[5] * mat_[6]) +
104 mat_[2] * (mat_[3] * mat_[7] - mat_[4] * mat_[6]);
112template <
class ValueType >
113std::ostream & operator << (std::ostream & str,
const Matrix3 < ValueType > & vec){
114 for (Index i = 0; i < 3; i ++)
115 str << vec[i] <<
" ";
117 for (Index i = 0; i < 3; i ++)
118 str << vec[3 + i] <<
" ";
120 for (Index i = 0; i < 3; i ++)
121 str << vec[6 + i] <<
" ";
126template <
class ValueType > \
127Pos operator * (
const Matrix3 < ValueType > & A,
const Pos & b) {
128 return Pos (A[0] * b[0] + A[1] * b[1] + A[2] * b[2],
129 A[3] * b[0] + A[4] * b[1] + A[5] * b[2],
130 A[6] * b[0] + A[7] * b[1] + A[8] * b[2]);
147 virtual uint
rtti()
const {
return GIMLI_MATRIXBASE_RTTI; }
149 void setVerbose(
bool verbose){ verbose_ = verbose; }
151 bool verbose()
const {
return verbose_; }
158 log(Warning,
"no rows() implemented for: ",
typeid(*this).name());
164 log(Warning,
"no cols() implemented for: ",
typeid(*this).name());
170 log(Warning,
"no resize(Index rows, Index cols) implemented for: ",
typeid(*this).name());
175 log(Warning,
"no clean() implemented for: ",
typeid(*this).name());
180 log(Warning,
"no clear() implemented for: ",
typeid(*this).name());
184 virtual RVector
dot(
const RVector & a)
const {
189 virtual RVector
mult(
const RVector & a)
const {
190 log(Warning,
"no RVector mult(const RVector & a) implemented for: ",
typeid(*this).name());
191 return RVector(
rows());
195 virtual CVector
mult(
const CVector & a)
const {
196 log(Warning,
"no CVector mult(const CVector & a) implemented for: ",
typeid(*this).name());
197 return CVector(
rows());
200 virtual RVector mult(
const RVector & b, Index startI, Index endI)
const {
201 log(Warning,
"no RVector mult(const RVector & b, Index startI, Index endI) implemented for: ",
typeid(*this).name());
202 return RVector(rows());
204 virtual CVector mult(
const CVector & b, Index startI, Index endI)
const {
205 log(Warning,
"no CVector mult(const CVector & b, Index startI, Index endI) implemented for: ",
typeid(*this).name());
206 return CVector(rows());
211 log(Warning,
"no RVector transMult(const RVector & a) implemented for: ",
typeid(*this).name());
212 return RVector(
cols());
217 log(Warning,
"no CVector transMult(const CVector & a) implemented for: ",
typeid(*this).name());
218 return CVector(
cols());
271 virtual void save(
const std::string & filename)
const {
272 log(Warning,
"no save(const std::string & filename) implemented for: ",
typeid(*this).name());
294 virtual Index
rows()
const {
return nrows_; }
297 virtual Index
cols()
const {
return nrows_; }
300 virtual RVector
mult(
const RVector & a)
const {
301 if (a.size() != nrows_) {
302 throwLengthError(WHERE_AM_I +
" vector/matrix lengths do not match " +
303 str(nrows_) +
" " + str(a.size()));
310 if (a.size() != nrows_) {
311 throwLengthError(WHERE_AM_I +
" matrix/vector lengths do not match " +
312 str(a.size()) +
" " + str(nrows_));
336 Matrix(Index rows, Index cols)
340 Matrix(Index rows, Index cols, ValueType *src)
342 fromData(src, rows, cols);
368 inline void copy(
const Matrix < ValueType > & mat){ copy_(mat); }
371 virtual uint
rtti()
const {
return GIMLI_MATRIX_RTTI; }
373 #define DEFINE_UNARY_MOD_OPERATOR__(OP, NAME) \
374 inline Matrix < ValueType > & operator OP##=(const Matrix < ValueType>&A){\
375 for (Index i = 0; i < mat_.size(); i ++) mat_[i] OP##= A[i]; return *this;}\
376 inline Matrix < ValueType > & operator OP##= (const ValueType & val) { \
377 for (Index i = 0; i < mat_.size(); i ++) mat_[i] OP##= val; return*this;}\
379 DEFINE_UNARY_MOD_OPERATOR__(+, PLUS)
380 DEFINE_UNARY_MOD_OPERATOR__(-, MINUS)
381 DEFINE_UNARY_MOD_OPERATOR__(/, DIVID)
382 DEFINE_UNARY_MOD_OPERATOR__(*, MULT)
384 #undef DEFINE_UNARY_MOD_OPERATOR__
406 for (uint i = 0; i < this->
rows(); i ++){ f[i] = Vector < T >(mat_[i]); }
414 inline void clear() { mat_.clear(); }
418 for (Index i = 0; i < mat_.size(); i ++) mat_[i].
clear();
428 if (mat_.size() > 0)
return mat_[0].size();
438 inline void setRow(Index i,
const Vector < ValueType > & val) {
448 inline void setVal(Index i,
const Vector < ValueType > & val) {
449 return this->
setRow(i, val);
451 inline void setVal(Index i, Index j,
const ValueType & val) {
452 this->rowRef(i).setVal(val, j);
454 inline void addVal(Index i, Index j,
const ValueType & val) {
455 this->rowRef(i).addVal(val, j);
459 inline const Vector < ValueType > &
row(Index i)
const {
465 inline Vector < ValueType > &
rowRef(Index i) {
473 if (i < 0 || i > this->
cols()-1) {
474 throwLengthError(WHERE_AM_I +
" col bounds out of range " +
475 str(i) +
" " + str(this->
cols())) ;
477 Vector < ValueType >
col(this->
rows());
478 for (Index j = 0, jmax =
rows(); j < jmax; j ++)
col[j] = mat_[j][i];
483 inline void push_back(
const Vector < ValueType > & vec) {
493 inline void setCol(Index
col,
const Vector < ValueType > & v){
494 if (col < 0 || col > this->
cols()-1) {
495 throwLengthError(WHERE_AM_I +
" col bounds out of range " +
496 str(
col) +
" " + str(this->
cols())) ;
498 if (v.size() > this->rows()) {
499 throwLengthError(WHERE_AM_I +
" rows bounds out of range " +
500 str(v.size()) +
" " + str(this->
rows())) ;
502 for (Index i = 0; i < v.size(); i ++) mat_[i][
col] = v[i];
506 inline void addCol(Index
col,
const Vector < ValueType > & v){
507 if (col < 0 || col > this->
cols()-1) {
508 throwLengthError(WHERE_AM_I +
" col bounds out of range " +
509 str(
col) +
" " + str(this->
cols())) ;
511 if (v.size() > this->rows()) {
512 throwLengthError(WHERE_AM_I +
" rows bounds out of range " +
513 str(v.size()) +
" " + str(this->
rows())) ;
515 for (Index i = 0; i < v.size(); i ++) mat_[i][
col] += v[i];
522 inline Matrix < ValueType > &
add(
const Matrix < ValueType > & a){
527 Matrix < ValueType > &
transAdd(
const Matrix < ValueType > & a);
531 Vector < ValueType >
mult(
const Vector < ValueType > & b)
const;
550 Vector < ValueType >
mult(
const Vector < ValueType > & b, Index startI, Index endI)
const;
589 virtual void save(
const std::string & filename)
const {
594 void round(
const ValueType & tolerance){
595 for (Index i = 0; i < mat_.size(); i ++) mat_[i].
round(tolerance);
598 std::vector < Vector< ValueType > > mat_;
600 void dumpData(ValueType * target)
const{
602 for (Index i = 0; i < mat_.size(); i ++) {
603 std::memcpy(&target[i*this->cols()], &mat_[i][0],
sizeof(ValueType) * this->cols());
606 void fromData(ValueType * src, Index m, Index n){
608 for (Index i = 0; i < m; i ++) {
609 std::memcpy(&mat_[i][0], &src[i*n],
sizeof(ValueType) * n);
614 void allocate_(Index rows, Index cols){
616 if (mat_.size() != rows) mat_.resize(rows);
617 for (Index i = 0; i < mat_.size(); i ++) {
619 mat_[i].resize(cols);
622 rowFlag_.resize(rows);
625 void copy_(
const Matrix < ValueType > & mat){
626 allocate_(mat.rows(), mat.cols());
627 for (Index i = 0; i < mat_.size(); i ++) mat_[i] = mat[i];
656#define DEFINE_BINARY_OPERATOR__(OP, NAME) \
657template < class ValueType > \
658Matrix < ValueType > operator OP (const Matrix < ValueType > & A, const Matrix < ValueType > & B) { \
659Matrix < ValueType > tmp(A); \
660return tmp OP##= B; } \
661template < class ValueType > \
662Matrix < ValueType > operator OP (const Matrix < ValueType > & A, const ValueType & v) { \
663Matrix < ValueType > tmp(A); \
666DEFINE_BINARY_OPERATOR__(+, PLUS)
667DEFINE_BINARY_OPERATOR__(-, MINUS)
668DEFINE_BINARY_OPERATOR__(/, DIVID)
669DEFINE_BINARY_OPERATOR__(*, MULT)
671#undef DEFINE_BINARY_OPERATOR__
673template<
class ValueType >
class DLLEXPORT Mult{
676 x_(&
x), b_(&b), A_(&A), start_(start), end_(end){
679 for (Index i = start_; i < end_; i++) (*x_)[i] = sum((*A_)[i] * *b_);
689template <
class ValueType >
690Vector < ValueType > multMT(
const Matrix < ValueType > & A,
const Vector < ValueType > & b){
692 Index cols = A.
cols();
693 Index rows = A.
rows();
695 Vector < ValueType > ret(rows);
696 boost::thread_group threads;
698 Index singleCalcCount = Index(ceil((
double)rows / (
double)nThreads));
701 for (Index i = 0; i < nThreads; i ++){
704 Index start = singleCalcCount * i;
705 Index end = singleCalcCount * (i + 1);
706 if (i == nThreads -1) end = A.
rows();
717template <
class ValueType >
719 if (A.rows() != B.rows() || A.cols() != B.cols())
return false;
720 for (Index i = 0; i < A.rows(); i ++){
721 if (A[i] != B[i])
return false;
726template <
class ValueType >
727void scaleMatrix(Matrix < ValueType >& A,
728 const Vector < ValueType > & l,
const Vector < ValueType > & r){
729 Index rows = A.rows();
730 Index cols = A.cols();
731 if (rows != l.size()){
732 throwLengthError(WHERE_AM_I +
" " + str(rows) +
" != " + str(l.size()));
734 if (cols != r.size()){
735 throwLengthError(WHERE_AM_I +
" " + str(cols) +
" != " + str(r.size()));
738 for (Index i = 0 ; i < rows ; i++) {
744template <
class ValueType >
745void rank1Update(Matrix < ValueType > & A,
746 const Vector < ValueType > & u,
const Vector < ValueType > & v) {
747 Index rows = A.rows();
748 Index cols = A.cols();
749 if (rows != u.size()){
750 throwLengthError(WHERE_AM_I +
" " + str(rows) +
" != " + str(u.size()));
753 if (cols != v.size()){
754 throwLengthError(WHERE_AM_I +
" " + str(cols) +
" != " + str(v.size()));
757 for (Index i = 0 ; i < rows ; i++) {
764template <
class ValueType >
766 Matrix < ValueType > n;
767 for (Index i = 0; i < m.rows(); i ++) n.push_back(fliplr(m[i]));
771template <
class ValueType >
772Matrix < ValueType > real(
const Matrix < std::complex< ValueType > > & cv){
773 Matrix < ValueType > v(cv.rows());
774 for (Index i = 0; i < cv.rows(); i ++) v[i] = real(cv[i]);
778template <
class ValueType >
779Matrix < ValueType > imag(
const Matrix < std::complex< ValueType > > & cv){
780 Matrix < ValueType > v(cv.rows());
781 for (Index i = 0; i < cv.rows(); i ++) v[i] = imag(cv[i]);
792template <
class ValueType >
793bool saveMatrix(
const Matrix < ValueType > & A,
const std::string & filename,
IOFormat format = Binary){
795 std::string fname(filename);
796 if (fname.rfind(
'.') == std::string::npos) fname += MATRIXBINSUFFIX;
798 FILE *file; file = fopen(fname.c_str(),
"w+b");
801 std::cerr << fname <<
": " << strerror(errno) <<
" " << errno << std::endl;
805 uint32 rows = A.
rows();
806 uint ret = fwrite(& rows,
sizeof(uint32), 1, file);
811 uint32 cols = A.
cols();
812 ret = fwrite(& cols,
sizeof(uint32), 1, file);
814 for (uint i = 0; i < rows; i ++){
815 for (uint j = 0; j < cols; j ++){
816 ret = fwrite(&A[i][j],
sizeof(ValueType), 1, file);
827template <
class ValueType >
828bool load(Matrix < ValueType > & A,
const std::string & filename){
831 if (filename.rfind(
".matrix") != std::string::npos ||
832 filename.rfind(
".mat") != std::string::npos ||
833 filename.rfind(MATRIXBINSUFFIX) != std::string::npos) {
835 return loadMatrixSingleBin(A, filename);
839 if (fileExist(filename +
".matrix"))
return loadMatrixSingleBin(A, filename +
".matrix");
840 if (fileExist(filename +
".mat"))
return loadMatrixSingleBin(A, filename +
".mat");
841 if (fileExist(filename + MATRIXBINSUFFIX))
843 return loadMatrixSingleBin(A, filename + MATRIXBINSUFFIX);
850DLLEXPORT
bool loadMatrixSingleBin(RMatrix & A,
const std::string & filename);
851DLLEXPORT
bool loadMatrixSingleBin(CMatrix & A,
const std::string & filename);
859DLLEXPORT
bool loadMatrixVectorsBin(RMatrix & A,
const std::string & filenameBody, uint kCount=1);
860DLLEXPORT
bool loadMatrixVectorsBin(CMatrix & A,
const std::string & filenameBody, uint kCount=1);
863template <
class ValueType >
864bool saveMatrixCol(
const Matrix < ValueType > & A,
const std::string & filename){
869template <
class ValueType >
870bool saveMatrixCol(
const Matrix < ValueType > & A,
const std::string & filename,
871 const std::string & comments){
872 std::fstream file; openOutFile(filename, & file,
true);
873 if (comments.length() > 0){
874 file <<
"#" << comments << std::endl;
877 for (uint i = 0; i < A.
cols(); i ++){
878 for (uint j = 0; j < A.
rows(); j ++){
879 file << A[j][i] <<
"\t";
888template <
class ValueType >
890 std::vector < std::string > comments;
895template <
class ValueType >
897 std::vector < std::string > & comments){
899 uint commentCount = 0;
900 uint cols = countColumnsInFile(filename, commentCount);
914 Vector < ValueType > tmp;
915 Vector < ValueType > row(cols);
916 std::fstream file; openInFile(filename, & file,
true);
917 for (uint i = 0; i < commentCount; i ++) {
920 comments = getSubstrings(str.substr(str.find(
'#'), -1));
924 while(file >> val) tmp.push_back(val);
927 Index rows = tmp.size() / cols ;
930 for (uint i = 0; i < rows; i ++){
931 for (uint j = 0; j < cols; j ++){
932 A[j][i] = tmp[i * cols + j];
939template <
class ValueType >
940bool saveMatrixRow(
const Matrix < ValueType > & A,
const std::string & filename){
945template <
class ValueType >
946bool saveMatrixRow(
const Matrix < ValueType > & A,
const std::string & filename,
947 const std::string & comments){
948 std::fstream file; openOutFile(filename, & file,
true);
949 if (comments.length() > 0){
950 file <<
"#" << comments << std::endl;
953 for (uint i = 0; i < A.
rows(); i ++){
954 for (uint j = 0; j < A.
cols(); j ++){
955 file << A[i][j] <<
"\t";
964template <
class ValueType >
967 std::vector < std::string > comments;
972template <
class ValueType >
974 const std::string & filename,
975 std::vector < std::string > & comments){
977 uint commentCount = 0;
978 uint cols = countColumnsInFile(filename, commentCount);
980 Vector < ValueType > row(cols);
981 std::fstream file; openInFile(filename, & file,
true);
982 for (uint i = 0; i < commentCount; i ++) {
985 comments = getSubstrings(str.substr(str.find(
'#'), -1));
989 Vector < ValueType > tmp;
990 while(file >> val) tmp.push_back(val);
993 Index rows = tmp.size() / cols ;
996 for (uint i = 0; i < rows; i ++){
997 for (uint j = 0; j < cols; j ++){
998 A[i][j] = tmp[i * cols + j];
1007DLLEXPORT
void matMultABA(
const RMatrix & A,
const RMatrix & B, RMatrix & C, RMatrix & AtB,
double a=1.0,
double b=0.0);
1010DLLEXPORT
void matMult(
const RMatrix & A,
const RMatrix & B, RMatrix & C,
double a=1.0,
double b=0.0);
1013DLLEXPORT
void matTransMult(
const RMatrix & A,
const RMatrix & B, RMatrix & C,
double a=1.0,
double b=0.0);
1016template <
class T >
inline T
det(
const T & a,
const T & b,
const T & c,
const T & d){
1017 return a * d - b * c;
1030 case 2:
det = A[0][0] * A[1][1] - A[0][1] * A[1][0];
1033 det = A[0][0] * (A[1][1] * A[2][2] - A[1][2] * A[2][1]) -
1034 A[0][1] * (A[1][0] * A[2][2] - A[1][2] * A[2][0]) +
1035 A[0][2] * (A[1][0] * A[2][1] - A[1][1] * A[2][0]);
1044 std::cerr << WHERE_AM_I <<
" matrix determinant of dim not yet implemented -- dim: " << A.rows() << std::endl;
1062 I[0] = (A[4] * A[8] - A[5] * A[7]);
1063 I[3] = -(A[3] * A[8] - A[5] * A[6]);
1064 I[6] = (A[3] * A[7] - A[4] * A[6]);
1065 I[1] = -(A[1] * A[8] - A[2] * A[7]);
1066 I[4] = (A[0] * A[8] - A[2] * A[6]);
1067 I[7] = -(A[0] * A[7] - A[1] * A[6]);
1068 I[2] = (A[1] * A[5] - A[2] * A[4]);
1069 I[5] = -(A[0] * A[5] - A[2] * A[3]);
1070 I[8] = (A[0] * A[4] - A[1] * A[3]);
1074 I /= (A[0] * I[0] + A[1] * I[3] + A[2] * I[6]);
1097 I[0][0] = (A[1][1] * A[2][2] - A[1][2] * A[2][1]);
1098 I[1][0] = -(A[1][0] * A[2][2] - A[1][2] * A[2][0]);
1099 I[2][0] = (A[1][0] * A[2][1] - A[1][1] * A[2][0]);
1100 I[0][1] = -(A[0][1] * A[2][2] - A[0][2] * A[2][1]);
1101 I[1][1] = (A[0][0] * A[2][2] - A[0][2] * A[2][0]);
1102 I[2][1] = -(A[0][0] * A[2][1] - A[0][1] * A[2][0]);
1103 I[0][2] = (A[0][1] * A[1][2] - A[0][2] * A[1][1]);
1104 I[1][2] = -(A[0][0] * A[1][2] - A[0][2] * A[1][0]);
1105 I[2][2] = (A[0][0] * A[1][1] - A[0][1] * A[1][0]);
1108 std::cerr << WHERE_AM_I <<
" matrix determinant of dim not yet implemented -- dim: " << A.
rows() << std::endl;
1114inline void save(
const MatrixBase & A,
const std::string & filename){
1118inline void save(
MatrixBase & A,
const std::string & filename){
1122inline RVector operator * (
const MatrixBase & A,
const RVector & b){
1126inline RVector transMult(
const MatrixBase & A,
const RVector & b){
1127 return A.transMult(b);
1130inline RVector operator * (
const RMatrix & A,
const RVector & b){
1133inline CVector operator * (
const CMatrix & A,
const CVector & b){
1136inline RVector transMult(
const RMatrix & A,
const RVector & b){
1137 return A.transMult(b);
1139inline CVector transMult(
const CMatrix & A,
const CVector & b){
1140 return A.transMult(b);
1143inline RMatrix real(
const CMatrix & A){
1144 RMatrix R(A.rows(), A.cols());
1145 for (Index i = 0; i < A.rows(); i ++) R[i] = real(A[i]);
1148inline RMatrix imag(
const CMatrix & A){
1149 RMatrix R(A.rows(), A.cols());
1150 for (Index i = 0; i < A.rows(); i ++) R[i] = imag(A[i]);
1155std::ostream & operator << (std::ostream & str,
const Matrix < T > & M){
1156 for (Index i = 0; i < M.rows(); i ++) {
1157 str << M[i] << std::endl;
virtual Index cols() const
Definition matrix.h:297
virtual RVector transMult(const RVector &a) const
Definition matrix.h:309
virtual RVector mult(const RVector &a) const
Definition matrix.h:300
IdentityMatrix()
Definition matrix.h:283
virtual Index rows() const
Definition matrix.h:294
virtual ~IdentityMatrix()
Definition matrix.h:291
IdentityMatrix(Index nrows, double val=1.0)
Definition matrix.h:287
Interface class for matrices.
Definition matrix.h:137
virtual CVector mult(const CVector &a) const
Definition matrix.h:195
virtual RVector dot(const RVector &a) const
Definition matrix.h:184
virtual ~MatrixBase()
Definition matrix.h:144
virtual uint rtti() const
Definition matrix.h:147
Index size() const
Definition matrix.h:154
virtual void resize(Index rows, Index cols)
Definition matrix.h:169
virtual void clean()
Definition matrix.h:174
virtual RVector mult(const RVector &a) const
Definition matrix.h:189
virtual void clear()
Definition matrix.h:179
virtual RVector transMult(const RVector &a) const
Definition matrix.h:210
virtual CVector transMult(const CVector &a) const
Definition matrix.h:216
virtual void save(const std::string &filename) const
Definition matrix.h:271
MatrixBase(bool verbose=false)
Definition matrix.h:141
virtual Index cols() const
Definition matrix.h:163
virtual Index rows() const
Definition matrix.h:157
Simple row-based dense matrix based on Vector.
Definition matrix.h:324
virtual uint rtti() const
Definition matrix.h:371
Vector< ValueType > mult(const Vector< ValueType > &b, Index startI, Index endI) const
Vector< ValueType > & back()
Definition matrix.h:490
void addCol(Index col, const Vector< ValueType > &v)
Definition matrix.h:506
Vector< ValueType > mult(const Vector< ValueType > &b) const
Vector< double > & rowRef(Index i)
Definition matrix.h:465
BVector rowFlag_
Definition matrix.h:632
Matrix< ValueType > & add(const Matrix< ValueType > &a)
Definition matrix.h:522
virtual ~Matrix()
Definition matrix.h:365
void setVal(Index i, const Vector< ValueType > &val)
Definition matrix.h:448
Matrix()
Definition matrix.h:327
Vector< ValueType > transMult(const Vector< ValueType > &b) const
virtual void save(const std::string &filename) const
Definition matrix.h:589
BVector & rowFlag()
Definition matrix.h:519
void copy(const Matrix< ValueType > &mat)
Definition matrix.h:368
void setCol(Index col, const Vector< ValueType > &v)
Definition matrix.h:493
void clear()
Definition matrix.h:414
Index rows() const
Definition matrix.h:422
Index cols() const
Definition matrix.h:427
void setRow(Index i, const Vector< ValueType > &val)
Definition matrix.h:438
Matrix(const std::vector< Vector< ValueType > > &mat)
Definition matrix.h:346
void push_back(const Vector< ValueType > &vec)
Definition matrix.h:483
const Vector< double > & row(Index i) const
Definition matrix.h:459
virtual void resize(Index rows, Index cols)
Definition matrix.h:411
virtual const Vector< ValueType > col(Index i) const
Definition matrix.h:471
Matrix(const Matrix< ValueType > &mat)
Definition matrix.h:354
void clean()
Definition matrix.h:417
void round(const ValueType &tolerance)
Definition matrix.h:594
Matrix< ValueType > & transAdd(const Matrix< ValueType > &a)
Matrix(const std::string &filename)
Definition matrix.h:350
One dimensional array aka Vector of limited size.
Definition vector.h:186
GIMLi main namespace for the Geophyiscal Inversion and Modelling Library.
Definition baseentity.h:24
bool saveMatrixRow(const Matrix< ValueType > &A, const std::string &filename)
Definition matrix.h:940
Matrix3< ValueType > inv(const Matrix3< ValueType > &A)
Definition matrix.h:1051
T det(const T &a, const T &b, const T &c, const T &d)
Definition matrix.h:1016
bool saveMatrix(const Matrix< ValueType > &A, const std::string &filename, IOFormat format=Binary)
Definition matrix.h:793
RVector x(const R3Vector &rv)
Definition pos.cpp:107
void matTransMult(const RMatrix &A, const RMatrix &B, RMatrix &C, double a, double b)
Definition matrix.cpp:201
void matMultABA(const RMatrix &A, const RMatrix &B, RMatrix &C, RMatrix &AtB, double a, double b)
Definition matrix.cpp:140
void matMult(const RMatrix &A, const RMatrix &B, RMatrix &C, double a, double b)
Definition matrix.cpp:154
bool loadMatrixCol(Matrix< ValueType > &A, const std::string &filename)
Definition matrix.h:889
bool saveMatrixCol(const Matrix< ValueType > &A, const std::string &filename)
Definition matrix.h:864
bool loadMatrixRow(Matrix< ValueType > &A, const std::string &filename)
Definition matrix.h:965
IOFormat
Definition gimli.h:289
bool loadMatrixVectorsBin(RMatrix &A, const std::string &filenameBody, uint kCount)
Definition matrix.cpp:377
bool load(Matrix< ValueType > &A, const std::string &filename)
Definition matrix.h:828