00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _math_scmat_matrix_h
00029 #define _math_scmat_matrix_h
00030 #ifdef __GNUC__
00031 #pragma interface
00032 #endif
00033
00034 #include <iostream>
00035 #include <util/container/array.h>
00036
00037 #include <math/scmat/abstract.h>
00038
00039 class SCVectordouble;
00040 class SCMatrixdouble;
00041 class SymmSCMatrixdouble;
00042 class DiagSCMatrixdouble;
00043
00044 class SCMatrixBlockIter;
00045 class SCMatrixRectBlock;
00046 class SCMatrixLTriBlock;
00047 class SCMatrixDiagBlock;
00048 class SCVectorSimpleBlock;
00049
00050 class RefSCMatrix;
00051 class RefSymmSCMatrix;
00054 class RefSCVector: public Ref<SCVector> {
00055
00056 public:
00059 RefSCVector();
00061 RefSCVector(const RefSCVector& v);
00063 RefSCVector(SCVector *v);
00064
00065
00066 ~RefSCVector();
00068 RefSCVector& operator=(SCVector* v);
00070 RefSCVector& operator=(const RefSCVector& v);
00071
00072
00073 public:
00076 RefSCVector(const RefSCDimension& dim,const Ref<SCMatrixKit>&);
00077
00079 SCVectordouble operator()(int) const;
00081 SCVectordouble operator[](int) const;
00083 RefSCVector operator+(const RefSCVector&a) const;
00085 RefSCVector operator-(const RefSCVector&a) const;
00087 RefSCVector operator*(double) const;
00089 RefSCMatrix outer_product(const RefSCVector& v) const;
00091 RefSymmSCMatrix symmetric_outer_product() const;
00092
00093 void set_element(int i,double val) const;
00094 void accumulate_element(int i,double val) const;
00095 double get_element(int) const;
00096 int n() const;
00097 RefSCDimension dim() const;
00098 Ref<SCMatrixKit> kit() const;
00099 RefSCVector clone() const;
00100 RefSCVector copy() const;
00101 double maxabs() const;
00102 double scalar_product(const RefSCVector&) const;
00103 double dot(const RefSCVector&) const;
00104 void normalize() const;
00105 void randomize() const;
00106 void assign(const RefSCVector& v) const;
00107 void assign(double val) const;
00108 void assign(const double* v) const;
00109 void convert(double*) const;
00110 void scale(double val) const;
00111 void accumulate(const RefSCVector& v) const;
00112 void accumulate_product(const RefSymmSCMatrix&, const RefSCVector&);
00113 void accumulate_product(const RefSCMatrix&, const RefSCVector&);
00114 void element_op(const Ref<SCElementOp>& op) const;
00115 void element_op(const Ref<SCElementOp2>&,
00116 const RefSCVector&) const;
00117 void element_op(const Ref<SCElementOp3>&,
00118 const RefSCVector&,
00119 const RefSCVector&) const;
00120 void print(std::ostream&out) const;
00121 void print(const char*title=0,
00122 std::ostream&out=ExEnv::out(), int precision=10) const;
00123 void save(StateOut&);
00124 void restore(StateIn&);
00125 };
00126 RefSCVector operator*(double,const RefSCVector&);
00127
00128 class RefSymmSCMatrix;
00129 class RefDiagSCMatrix;
00133 class RefSCMatrix: public Ref<SCMatrix> {
00134
00135 public:
00138 RefSCMatrix();
00140 RefSCMatrix(const RefSCMatrix& m);
00142 RefSCMatrix(SCMatrix* m);
00143 ~RefSCMatrix();
00145 RefSCMatrix& operator=(SCMatrix* m);
00147 RefSCMatrix& operator=(const RefSCMatrix& m);
00148
00149
00150 public:
00153 RefSCMatrix(const RefSCDimension& d1,const RefSCDimension& d2,
00154 const Ref<SCMatrixKit>&);
00155
00157 RefSCVector operator*(const RefSCVector&) const;
00158
00160 RefSCMatrix operator*(const RefSCMatrix&) const;
00161 RefSCMatrix operator*(const RefSymmSCMatrix&) const;
00162 RefSCMatrix operator*(const RefDiagSCMatrix&) const;
00163
00165 RefSCMatrix operator*(double) const;
00166
00168 RefSCMatrix operator+(const RefSCMatrix&) const;
00170 RefSCMatrix operator-(const RefSCMatrix&) const;
00171
00173 RefSCMatrix t() const;
00175 RefSCMatrix i() const;
00177 RefSCMatrix gi() const;
00178
00181 RefSCMatrix clone() const;
00182 RefSCMatrix copy() const;
00183
00184 RefSCMatrix get_subblock(int br, int er, int bc, int ec);
00185 void assign_subblock(const RefSCMatrix&, int br, int er, int bc, int ec,
00186 int source_br = 0, int source_bc = 0);
00187 void accumulate_subblock(const RefSCMatrix&, int, int, int, int,
00188 int source_br = 0, int source_bc = 0);
00189 RefSCVector get_row(int) const;
00190 RefSCVector get_column(int) const;
00191 void assign_row(const RefSCVector&, int) const;
00192 void assign_column(const RefSCVector&, int) const;
00193 void accumulate_row(const RefSCVector&, int) const;
00194 void accumulate_column(const RefSCVector&, int) const;
00195
00196 void accumulate_outer_product(const RefSCVector&,const RefSCVector&) const;
00197 void accumulate_product(const RefSCMatrix&,const RefSCMatrix&) const;
00198 void assign(const RefSCMatrix&) const;
00199 void scale(double) const;
00200 void randomize() const;
00201 void assign(double) const;
00202 void assign(const double*) const;
00203 void assign(const double**) const;
00204 void convert(double*) const;
00205 void convert(double**) const;
00206 void accumulate(const RefSCMatrix&) const;
00207 void accumulate(const RefSymmSCMatrix&) const;
00208 void accumulate(const RefDiagSCMatrix&) const;
00209 void element_op(const Ref<SCElementOp>&) const;
00210 void element_op(const Ref<SCElementOp2>&,
00211 const RefSCMatrix&) const;
00212 void element_op(const Ref<SCElementOp3>&,
00213 const RefSCMatrix&,
00214 const RefSCMatrix&) const;
00215 int nrow() const;
00216 int ncol() const;
00217 RefSCDimension rowdim() const;
00218 RefSCDimension coldim() const;
00219 Ref<SCMatrixKit> kit() const;
00220 void set_element(int,int,double) const;
00221 void accumulate_element(int,int,double) const;
00222 double get_element(int,int) const;
00223 void print(std::ostream&) const;
00224 void print(const char*title=0,
00225 std::ostream&out=ExEnv::out(), int =10) const;
00226 double trace() const;
00227 void save(StateOut&);
00228 void restore(StateIn&);
00229
00234 void svd(const RefSCMatrix &U,
00235 const RefDiagSCMatrix &sigma,
00236 const RefSCMatrix &V);
00238 double solve_lin(const RefSCVector& v) const;
00240 double determ() const;
00242 SCMatrixdouble operator()(int i,int j) const;
00243 };
00245 RefSCMatrix operator*(double,const RefSCMatrix&);
00246
00249 class RefSymmSCMatrix: public Ref<SymmSCMatrix> {
00250
00251 public:
00254 RefSymmSCMatrix();
00256 RefSymmSCMatrix(const RefSymmSCMatrix& m);
00258 RefSymmSCMatrix(SymmSCMatrix *m);
00259 ~RefSymmSCMatrix();
00261 RefSymmSCMatrix& operator=(SymmSCMatrix* m);
00263 RefSymmSCMatrix& operator=(const RefSymmSCMatrix& m);
00264
00265
00266 public:
00269 RefSymmSCMatrix(const RefSCDimension& d,const Ref<SCMatrixKit>&);
00271 RefSCMatrix operator*(const RefSCMatrix&) const;
00272 RefSCMatrix operator*(const RefSymmSCMatrix&) const;
00274 RefSCVector operator*(const RefSCVector&a) const;
00275 RefSymmSCMatrix operator*(double) const;
00277 RefSymmSCMatrix operator+(const RefSymmSCMatrix&) const;
00278 RefSymmSCMatrix operator-(const RefSymmSCMatrix&) const;
00280 RefSymmSCMatrix i() const;
00282 RefSymmSCMatrix gi() const;
00285 RefSymmSCMatrix clone() const;
00286 RefSymmSCMatrix copy() const;
00287 void set_element(int,int,double) const;
00288 void accumulate_element(int,int,double) const;
00289 double get_element(int,int) const;
00290
00291 RefSCMatrix get_subblock(int br, int er, int bc, int ec);
00292 RefSymmSCMatrix get_subblock(int br, int er);
00293 void assign_subblock(const RefSCMatrix&, int br, int er, int bc, int ec);
00294 void assign_subblock(const RefSymmSCMatrix&, int br, int er);
00295 void accumulate_subblock(const RefSCMatrix&, int, int, int, int);
00296 void accumulate_subblock(const RefSymmSCMatrix&, int, int);
00297 RefSCVector get_row(int);
00298 void assign_row(const RefSCVector&, int);
00299 void accumulate_row(const RefSCVector&, int);
00300
00301 void accumulate_symmetric_outer_product(const RefSCVector&) const;
00302 double scalar_product(const RefSCVector&) const;
00303 void accumulate_symmetric_product(const RefSCMatrix&) const;
00304 void accumulate_symmetric_sum(const RefSCMatrix&) const;
00306 void accumulate_transform(const RefSCMatrix&a,const RefSymmSCMatrix&b,
00307 SCMatrix::Transform = SCMatrix::NormalTransform) const;
00308 void accumulate_transform(const RefSCMatrix&a,const RefDiagSCMatrix&b,
00309 SCMatrix::Transform = SCMatrix::NormalTransform) const;
00310 void accumulate_transform(const RefSymmSCMatrix&a,
00311 const RefSymmSCMatrix&b) const;
00312
00313 void randomize() const;
00314 void assign(const RefSymmSCMatrix&) const;
00315 void scale(double) const;
00316 void assign(double) const;
00317 void assign(const double*) const;
00318 void assign(const double**) const;
00319 void convert(double*) const;
00320 void convert(double**) const;
00321 void accumulate(const RefSymmSCMatrix&) const;
00322 void element_op(const Ref<SCElementOp>&) const;
00323 void element_op(const Ref<SCElementOp2>&,
00324 const RefSymmSCMatrix&) const;
00325 void element_op(const Ref<SCElementOp3>&,
00326 const RefSymmSCMatrix&,
00327 const RefSymmSCMatrix&) const;
00328 double trace() const;
00329 int n() const;
00330 RefSCDimension dim() const;
00331 Ref<SCMatrixKit> kit() const;
00332 void print(std::ostream&) const;
00333 void print(const char*title=0,
00334 std::ostream&out=ExEnv::out(), int =10) const;
00335 void save(StateOut&);
00336 void restore(StateIn&);
00337
00339 double solve_lin(const RefSCVector&) const;
00341 double determ() const;
00343 RefDiagSCMatrix eigvals() const;
00345 RefSCMatrix eigvecs() const;
00348 void diagonalize(const RefDiagSCMatrix& eigvals,
00349 const RefSCMatrix& eigvecs) const;
00351 SymmSCMatrixdouble operator()(int i,int j) const;
00352 };
00354 RefSymmSCMatrix operator*(double,const RefSymmSCMatrix&);
00355
00358 class RefDiagSCMatrix: public Ref<DiagSCMatrix> {
00359
00360 public:
00363 RefDiagSCMatrix();
00365 RefDiagSCMatrix(const RefDiagSCMatrix& m);
00367 RefDiagSCMatrix(DiagSCMatrix *m);
00368 ~RefDiagSCMatrix();
00370 RefDiagSCMatrix& operator=(DiagSCMatrix* m);
00372 RefDiagSCMatrix& operator=(const RefDiagSCMatrix & m);
00373
00374
00375 public:
00378 RefDiagSCMatrix(const RefSCDimension&,const Ref<SCMatrixKit>&);
00380 RefSCMatrix operator*(const RefSCMatrix&) const;
00381 RefDiagSCMatrix operator*(double) const;
00383 RefDiagSCMatrix operator+(const RefDiagSCMatrix&) const;
00384 RefDiagSCMatrix operator-(const RefDiagSCMatrix&) const;
00386 RefDiagSCMatrix i() const;
00388 RefDiagSCMatrix gi() const;
00391 RefDiagSCMatrix clone() const;
00392 RefDiagSCMatrix copy() const;
00393 void set_element(int,double) const;
00394 void accumulate_element(int,double) const;
00395 double get_element(int) const;
00396 void randomize() const;
00397 void assign(const RefDiagSCMatrix&) const;
00398 void scale(double) const;
00399 void assign(double) const;
00400 void assign(const double*) const;
00401 void convert(double*) const;
00402 void accumulate(const RefDiagSCMatrix&) const;
00403 void element_op(const Ref<SCElementOp>&) const;
00404 void element_op(const Ref<SCElementOp2>&,
00405 const RefDiagSCMatrix&) const;
00406 void element_op(const Ref<SCElementOp3>&,
00407 const RefDiagSCMatrix&,
00408 const RefDiagSCMatrix&) const;
00409 int n() const;
00410 RefSCDimension dim() const;
00411 Ref<SCMatrixKit> kit() const;
00412 double trace() const;
00413 void print(std::ostream&) const;
00414 void print(const char*title=0,
00415 std::ostream&out=ExEnv::out(), int =10) const;
00416 void save(StateOut&);
00417 void restore(StateIn&);
00419 double determ() const;
00421 DiagSCMatrixdouble operator()(int i) const;
00422 };
00424 RefDiagSCMatrix operator*(double,const RefDiagSCMatrix&);
00425
00426 class SCVectordouble {
00427 friend class RefSCVector;
00428 private:
00429 RefSCVector vector;
00430 int i;
00431
00432 SCVectordouble(SCVector*,int);
00433 public:
00434 SCVectordouble(const SCVectordouble&);
00435 ~SCVectordouble();
00436 double operator=(double a);
00437 double operator=(const SCVectordouble&);
00438 operator double();
00439 double val() const;
00440 };
00441
00442 class SCMatrixdouble {
00443 friend class RefSCMatrix;
00444 private:
00445 RefSCMatrix matrix;
00446 int i;
00447 int j;
00448
00449 SCMatrixdouble(SCMatrix*,int,int);
00450 public:
00451 SCMatrixdouble(const SCMatrixdouble&);
00452 ~SCMatrixdouble();
00453 double operator=(double a);
00454 double operator=(const SCMatrixdouble&);
00455 operator double();
00456 double val() const;
00457 };
00458
00459 class SymmSCMatrixdouble {
00460 friend class RefSymmSCMatrix;
00461 private:
00462 RefSymmSCMatrix matrix;
00463 int i;
00464 int j;
00465
00466 SymmSCMatrixdouble(SymmSCMatrix*,int,int);
00467 public:
00468 SymmSCMatrixdouble(const SCMatrixdouble&);
00469 ~SymmSCMatrixdouble();
00470 double operator=(double a);
00471 double operator=(const SymmSCMatrixdouble&);
00472 operator double();
00473 double val() const;
00474 };
00475
00476 class DiagSCMatrixdouble {
00477 friend class RefDiagSCMatrix;
00478 private:
00479 RefDiagSCMatrix matrix;
00480 int i;
00481 int j;
00482
00483 DiagSCMatrixdouble(DiagSCMatrix*,int,int);
00484 public:
00485 DiagSCMatrixdouble(const SCMatrixdouble&);
00486 ~DiagSCMatrixdouble();
00487 double operator=(double a);
00488 double operator=(const DiagSCMatrixdouble&);
00489 operator double();
00490 double val() const;
00491 };
00492
00493 #ifdef INLINE_FUNCTIONS
00494 #include <math/scmat/matrix_i.h>
00495 #endif
00496
00497 #endif
00498
00499
00500
00501
00502