19 #include "../config.h" 20 #ifdef __MATRIXWRAPPER_LTI__ 25 #include <ltilib/ltiMatrixInversion.h> 26 #include <ltilib/ltiMatrixDecomposition.h> 27 #include <ltilib/ltiSymmetricMatrixInversion.h> 35 MyMatrix::Matrix() : ltiMatrix() {}
36 MyMatrix::Matrix(
int num_rows,
int num_cols) : ltiMatrix(num_rows,
43 MyMatrix::Matrix(
const MyMatrix& a) : ltiMatrix(a){}
47 MyMatrix::Matrix(
const ltiMatrix & a) : ltiMatrix(a){}
50 unsigned int MyMatrix::rows()
const {
return ((ltiMatrix)(*
this)).rows();}
51 unsigned int MyMatrix::columns()
const {
return ((ltiMatrix)(*
this)).columns();}
56 ltiMatrix temp = (ltiMatrix) *
this;
62 ltiMatrix temp = (ltiMatrix) *
this;
66 double& MyMatrix::operator()(
unsigned int a,
unsigned int b)
69 return this->at(a-1,b-1);
72 const double MyMatrix::operator()(
unsigned int a,
unsigned int b)
const 75 return this->at(a-1,b-1);
78 const bool MyMatrix::operator==(
const MyMatrix& a)
const 80 const ltiMatrix& op1 = *
this;
81 const ltiMatrix& op2 = a;
87 MyMatrix& MyMatrix::operator+= (
double a)
89 ltiMatrix & op1 = (*this);
94 MyMatrix& MyMatrix::operator-= (
double a)
96 ltiMatrix & op1 = (*this);
101 MyMatrix& MyMatrix::operator*= (
double a)
103 ltiMatrix & op1 = (*this);
108 MyMatrix MyMatrix::operator+ (
double a)
const 110 ltiMatrix op1(*
this);
115 MyMatrix MyMatrix::operator- (
double a)
const 117 ltiMatrix op1(*
this);
122 MyMatrix MyMatrix::operator* (
double a)
const 124 ltiMatrix op1(*
this);
130 MyMatrix& MyMatrix::operator/= (
double a)
132 ltiMatrix & op1 = (*this);
141 ltiMatrix op1 = (*this);
142 return (
MyMatrix) (op1.subtract(a));
147 ltiMatrix op1 = (*this);
153 ltiMatrix op1 = (*this);
154 return (
MyMatrix) (op1.multiply(a));
157 MyMatrix MyMatrix::operator/ (
double b)
const 159 ltiMatrix op1(*
this);
167 ltiMatrix & op1 = (*this);
174 ltiMatrix & op1 = (*this);
183 const ltiMatrix& op1 = *
this;
184 ltiColumnVector op2(b);
189 MyMatrix &MyMatrix::operator=(
const double a)
191 ltiMatrix & op1 = (*this);
192 op1.fill(a,0,0,(*this).rows(),(*this).columns());
198 MyMatrix MyMatrix::transpose()
const 200 ltiMatrix base(*
this);
205 double MyMatrix::determinant()
const 207 ltiMatrix & base = (ltiMatrix &) *
this;
208 lti::matrix<double> tmp;
209 tmp.resize(base.size());
210 for (
int i=0;i<tmp.rows();i++)
211 for (
int j=0;j<tmp.columns();j++) {
212 tmp.at(i,j)=(double)(base.at(i,j));
214 lti::luDecomposition<double> lu;
221 lti::matrixInversion<double> inv;
222 ltiMatrix base(*
this);
232 assert(this->rows() == this->columns() );
236 if ( sym.rows() != this->rows() )
237 sym.resize(this->rows());
240 for (
unsigned int i=0; i<this->rows(); i++ )
241 for (
unsigned int j=0; j<=i; j++ )
243 sym[i][j] = (*this)[i][j];
244 sym[j][i] = (*this)[i][j];
250 MyMatrix MyMatrix::sub(
int i_start,
int i_end,
int j_start ,
int j_end)
const 252 ltiMatrix m(*
this,i_start-1,i_end-1, j_start-1,j_end-1);
258 MyMatrix::resize(
unsigned int i,
unsigned int j,
bool copy,
bool initialize)
260 ltiMatrix& base = (ltiMatrix &) *
this;
261 base.resize(i,j, copy, initialize);
268 MySymmetricMatrix::SymmetricMatrix() : ltiSymmetricMatrix() {}
269 MySymmetricMatrix::SymmetricMatrix(
int n) : ltiSymmetricMatrix(n,n) {}
272 MySymmetricMatrix::SymmetricMatrix(
const SymmetricMatrix& a) : ltiSymmetricMatrix(a){}
273 MySymmetricMatrix::SymmetricMatrix(
const ltiSymmetricMatrix & a) : ltiSymmetricMatrix(a){}
276 MySymmetricMatrix::~SymmetricMatrix(){}
279 unsigned int MySymmetricMatrix::rows()
const {
return (((ltiSymmetricMatrix)(*
this)).rows());}
280 unsigned int MySymmetricMatrix::columns()
const {
return (((ltiSymmetricMatrix)(*
this)).rows());}
287 lti::matrixInversion<double> inv;
288 ltiSymmetricMatrix base(*
this);
293 double MySymmetricMatrix::determinant()
const 295 ltiSymmetricMatrix & base = (ltiSymmetricMatrix &) *
this;
296 lti::matrix<double> tmp;
297 tmp.resize(base.size());
298 for (
int i=0;i<tmp.rows();i++)
299 for (
int j=0;j<tmp.columns();j++) {
300 tmp.at(i,j)=(double)(base.at(i,j));
302 lti::luDecomposition<double> lu;
307 double& MySymmetricMatrix::operator()(
unsigned int a,
unsigned int b)
309 ltiSymmetricMatrix & op1 = (*this);
312 return op1.at(b-1,a-1);
314 return op1.at(a-1,b-1);
316 const double MySymmetricMatrix::operator()(
unsigned int a,
unsigned int b)
const 318 ltiSymmetricMatrix op1(*
this);
321 return op1.at(b-1,a-1);
323 return op1.at(a-1,b-1);
329 const ltiSymmetricMatrix& op1 = *
this;
330 const ltiSymmetricMatrix& op2 = a;
337 ltiSymmetricMatrix temp = (ltiSymmetricMatrix) *
this;
338 temp.fill(a,0,0,temp.rows(),temp.columns());
346 MySymmetricMatrix::operator +=(
double a)
348 ltiSymmetricMatrix & op1 = (*this);
354 MySymmetricMatrix::operator -=(
double a)
356 ltiSymmetricMatrix & op1 = (*this);
362 MySymmetricMatrix::operator *=(
double b)
364 ltiSymmetricMatrix & op1 = (*this);
370 MySymmetricMatrix::operator /=(
double b)
372 ltiSymmetricMatrix & op1 = (*this);
378 MySymmetricMatrix::operator+ (
double a)
const 380 ltiSymmetricMatrix op1(*
this);
386 MySymmetricMatrix::operator- (
double a)
const 388 ltiSymmetricMatrix op1(*
this);
395 ltiSymmetricMatrix op1(*
this);
402 ltiSymmetricMatrix op1(*
this);
414 ltiSymmetricMatrix & op1 = (*this);
415 const ltiMatrix & op2 = a;
421 MySymmetricMatrix::operator -=(
const MyMatrix& a)
423 ltiSymmetricMatrix & op1 = (*this);
424 const ltiMatrix & op2 = a;
431 MySymmetricMatrix::operator+ (
const MyMatrix &a)
const 433 ltiMatrix op1(*
this);
438 MySymmetricMatrix::operator- (
const MyMatrix &a)
const 441 ltiMatrix op1(*
this);
442 return (
MyMatrix) (op1.subtract(a));
446 MySymmetricMatrix::operator* (
const MyMatrix &a)
const 448 ltiMatrix op1(*
this);
449 return (
MyMatrix) (op1.multiply(a));
463 ltiSymmetricMatrix & op1 = (*this);
464 const ltiSymmetricMatrix & op2 = a;
472 ltiSymmetricMatrix & op1 = (*this);
473 const ltiSymmetricMatrix & op2 = a;
482 ltiSymmetricMatrix op1 = (*this);
490 ltiSymmetricMatrix op1 = (*this);
498 ltiSymmetricMatrix op1 = (*this);
499 return (
MyMatrix) (op1.multiply(a));
509 const ltiSymmetricMatrix& op1 = (
const ltiSymmetricMatrix&) *
this;
510 ltiColumnVector op2 = b;
516 const ltiSymmetricMatrix& op1 = (
const ltiSymmetricMatrix&) *
this;
517 ltiColumnVector op2 = b;
521 MyMatrix MySymmetricMatrix::sub(
int i_start,
int i_end,
int j_start ,
int j_end)
const 524 unsigned int r = this->rows();
525 unsigned int c = this->columns();
526 ltiMatrix copy = *
this;
527 for (
unsigned int i=0; i<r; i++)
528 for (
unsigned int j=0; j<=i; j++)
529 copy.at(j,i) = copy.at(i,j);
530 ltiMatrix m(copy,i_start-1,i_end-1, j_start-1,j_end-1);
536 MySymmetricMatrix::resize(
unsigned int i,
bool copy,
bool initialize)
538 ltiSymmetricMatrix& base = (ltiSymmetricMatrix &) *
this;
539 base.resize(i, i, copy, initialize);
#define MySymmetricMatrix