16 #ifndef __F_MATRIX_H__ 17 #define __F_MATRIX_H__ 21 #if defined(__ia64) || defined(__x68_64) 67 fMat(
int m,
int n,
double* ini = 0) {
77 for(
int i=0;
i<k;
i++) p_data[
i] = ini[
i];
87 fMat(
int m,
int n,
double ini) {
95 for(
int i=0;
i<k;
i++) p_data[
i] = ini;
108 resize(ini.
row(), ini.
col());
109 int k = ini.
row() * ini.
col();
110 for(
int i=0;
i<k;
i++) p_data[
i] = ini.
data()[
i];
121 if(p_data)
delete[] p_data;
134 if(n_row == i && n_col == j)
return 0;
135 if(p_data)
delete[] p_data;
139 if(n_row > 0 && n_col > 0)
141 int nn = n_row * n_col;
142 p_data =
new double[nn];
171 double& operator() (
int i,
int j) {
172 assert(i>=0 && i<n_row && j>=0 && j<n_col);
173 return *(p_data + i + j*n_row);
177 double operator() (
int i,
int j)
const {
178 assert(i>=0 && i<n_row && j>=0 && j<n_col);
179 return *(p_data + i + j*n_row);
185 void operator = (
double d);
187 void set(
double* _d) {
188 int n_elements = n_row * n_col;
197 operator double *() {
204 ost <<
"[" << mat.
row() <<
", " << mat.
col() <<
"]" << endl;
205 for(i=0; i<mat.
row(); i++)
207 for(j=0; j<mat.
col(); j++)
209 ost << *(mat.
data() + i + j*mat.
row());
210 if(j != mat.
col()-1) ost <<
"\t";
212 if(i == mat.
row()-1) ost << flush;
225 void set_submat(
int row_start,
int col_start,
const fMat& subM);
234 void get_submat(
int row_start,
int col_start,
const fMat& allM);
250 int ndata = n_row * n_col;
251 for(
int i=0;
i<ndata;
i++) p_data[
i] = 0.0;
329 int inv_posv(
const fMat&);
331 int lineq_posv(
const fMat& A,
const fMat& b);
333 int inv_porfs(
const fMat&);
335 int lineq_porfs(
const fMat& A,
const fMat& b);
343 void operator += (
const fMat& mat);
344 void operator -= (
const fMat& mat);
345 void operator *= (
double d);
346 void operator /= (
double d);
362 void set(
const fMat& mat);
363 void neg(
const fMat& mat);
364 void add(
const fMat& mat1,
const fMat& mat2);
365 void add(
const fMat& mat);
366 void sub(
const fMat& mat1,
const fMat& mat2);
367 void mul(
const fMat& mat1,
const fMat& mat2);
368 void mul(
double d,
const fMat& mat);
369 void mul(
const fMat& mat,
double d);
370 void mul_tran(
const fMat& mat1,
int trans_first);
371 void div(
const fMat& mat,
double d);
374 void dmul(
const fMat& mat1,
const fMat& mat2);
377 void ddiv(
const fMat& mat1,
const fMat& mat2);
393 void symmetric(
char t =
'U');
401 friend fMat eigs2(
const fMat& mat,
double *w);
512 if(n_row == i)
return;
513 if(p_data)
delete[] p_data;
519 p_data =
new double[n_row];
524 void get_subvec(
int start,
const fVec& allV);
526 void set_subvec(
int start,
const fVec& subV);
529 void operator = (
double d);
533 void set(
double* _d) {
538 double& operator () (
int i) {
539 assert(i >= 0 && i < n_row);
540 return *(p_data +
i);
543 double operator () (
int i)
const {
544 assert(i >= 0 && i < n_row);
545 return *(p_data +
i);
554 return sqrt((*
this) * (*
this));
571 for(
int i=0;
i<n_row;
i++) ret += p_data[
i];
576 for(
int i=0;
i<n_row;
i++) p_data[
i] = 0;
594 int lineq_posv(
const fMat& A,
const fVec& b);
595 int lineq_porfs(
const fMat& A,
const fVec& b);
604 void operator += (
const fVec& vec);
605 void operator -= (
const fVec& vec);
606 void operator *= (
double d);
607 void operator /= (
double d);
622 void set(
const fVec& vec);
623 void neg(
const fVec& vec);
624 void add(
const fVec& vec1,
const fVec& vec2);
625 void add(
const fVec& vec);
626 void sub(
const fVec& vec1,
const fVec& vec2);
627 void div(
const fVec& vec,
double d);
628 void mul(
const fVec& vec,
double d);
629 void mul(
double d,
const fVec& vec);
631 void mul(
const fMat& mat,
const fVec& vec);
633 void mul(
const fVec& vec,
const fMat& mat);
int inv_row_replaced(const fMat &P, const fMat &q, const fMat &m2d, fMat &X, fMat &y)
int resize(int i, int j)
Changes the matrix size.
fMat()
Default constructor.
fEulerPara operator*(double d, const fEulerPara &ep)
int col() const
Returns the number of columns.
fMat eigs(const fMat &mat, double *w)
int row() const
Returns the number of rows.
double sum()
Returns the sum of the elements.
fMat lineq_svd(const fMat &A, const fMat &b, int lwork=-1)
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
int inv_shrink(const fMat &P, const fMat &q, const fMat &r, const fMat &s, fMat &X)
png_bytep png_bytep png_size_t length
Comprehensive wrapper for CLAPACK functions.
fMat lineq_sr(const fMat &A, fVec &w_err, fVec &w_norm, double k, const fMat &b)
friend fVec unit(const fVec &v)
Returns a unit vector with the same direction (no length check!).
double det(const dmatrix &_a)
fMat operator+(const fMat &mat1, const fMat &mat2)
void zero()
Creates a zero matrix.
fMat(int m, int n, double *ini=0)
Constructor with size and initial values (optional).
fMat(const fMat &ini)
Copy constructor.
def j(str, encoding="cp932")
fMat(int m, int n, double ini)
Constructor with size and common initial values.
void unit()
Converts to a unit vector (no length check!).
void resize(int i)
Change the size.
std::ostream & operator<<(std::ostream &ost, const Point &p)
double * data() const
Returns the pointer to the first element.
fMat lineq(const fMat &A, const fMat &b)
fMat sr_inv_svd(const fMat &mat, fVec &w_err, fVec &w_norm, double k, int lwork=-1)
fMat tran(const fMat &mat)
fMat inv(const fMat &mat)
void zero()
Creates a zero vector.
fVec(int m, double *ini=0)
int inv_enlarge(const fMat &m12, const fMat &m21, const fMat &m22, const fMat &P, fMat &X, fMat &y, fMat &z, fMat &w)
double length() const
Length of the vector.
fMat operator/(const fMat &mat, double d)
fMat inv_svd(const fMat &mat, int lwork=-1)
friend double length(const fVec &v)
Length of the vector.
fMat p_inv(const fMat &mat)
int inv_col_replaced(const fMat &P, const fMat &q, const fMat &m2d, fMat &X, fMat &y)
int size() const
Size of the vector (same as row()).
fMat p_inv_svd(const fMat &mat, int lwork=-1)
void setinfo(int _info)
Sets m_info.
int info()
Returns the value of m_info.
fEulerPara operator-(const fEulerPara &_ep)
int dims_copy(double *_x, double *_y, int _n)
Wrappers of BLAS functions.
Matrix of generic size. The elements are stored in a one-dimensional array in row-major order...
fMat sr_inv(const fMat &mat, fVec &w_err, fVec &w_norm, double k)