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_abstract_h
00029 #define _math_scmat_abstract_h
00030
00031 #ifdef __GNUC__
00032 #pragma interface
00033 #endif
00034
00035 #include <util/group/message.h>
00036
00037 #include <util/state/state.h>
00038 #include <math/scmat/dim.h>
00039 #include <math/scmat/block.h>
00040 #include <iostream>
00041
00042 class SCMatrix;
00043 class SymmSCMatrix;
00044 class DiagSCMatrix;
00045 class SCVector;
00046
00047 class SCElementOp;
00048 class SCElementOp2;
00049 class SCElementOp3;
00050
00051 class RefSCDimension;
00052
00056 class SCMatrixKit: public DescribedClass {
00057 protected:
00058 Ref<MessageGrp> grp_;
00059
00060 public:
00061 SCMatrixKit();
00062 SCMatrixKit(const Ref<KeyVal>&);
00063 ~SCMatrixKit();
00064
00065
00068 static SCMatrixKit* default_matrixkit();
00069 static void set_default_matrixkit(const Ref<SCMatrixKit> &);
00070
00071 Ref<MessageGrp> messagegrp() const;
00072
00074 virtual SCMatrix* matrix(const RefSCDimension&,const RefSCDimension&) = 0;
00075 virtual SymmSCMatrix* symmmatrix(const RefSCDimension&) = 0;
00076 virtual DiagSCMatrix* diagmatrix(const RefSCDimension&) = 0;
00077 virtual SCVector* vector(const RefSCDimension&) = 0;
00078
00081 SCMatrix* restore_matrix(StateIn&,
00082 const RefSCDimension&,
00083 const RefSCDimension&);
00084 SymmSCMatrix* restore_symmmatrix(StateIn&,
00085 const RefSCDimension&);
00086 DiagSCMatrix* restore_diagmatrix(StateIn&,
00087 const RefSCDimension&);
00088 SCVector* restore_vector(StateIn&,
00089 const RefSCDimension&);
00090 };
00091
00092
00095 class SCVector: public DescribedClass {
00096 protected:
00097 RefSCDimension d;
00098 Ref<SCMatrixKit> kit_;
00099 public:
00100 SCVector(const RefSCDimension&, SCMatrixKit *);
00101
00103 virtual void save(StateOut&);
00104 virtual void restore(StateIn&);
00105
00107 Ref<SCMatrixKit> kit() const { return kit_; }
00108
00109
00111
00113
00114
00115 virtual ~SCVector();
00117 int n() const { return d->n(); }
00119 virtual double maxabs() const;
00121 virtual void normalize();
00123 virtual void randomize();
00125 void assign(double val) { assign_val(val); }
00127 void assign(const double* v) { assign_p(v); }
00130 void assign(SCVector* v) { assign_v(v); }
00132 virtual void assign_val(double val);
00133 virtual void assign_p(const double* v);
00134 virtual void assign_v(SCVector *v);
00136 virtual void convert(double* v) const;
00139 virtual void convert(SCVector*);
00140 virtual void convert_accumulate(SCVector*);
00142 virtual void scale(double val);
00143
00145 RefSCDimension dim() const { return d; }
00147 virtual void set_element(int i,double val) = 0;
00149 virtual void accumulate_element(int,double) = 0;
00151 virtual double get_element(int i) const = 0;
00153 void accumulate_product(SymmSCMatrix* m, SCVector* v)
00154 { accumulate_product_sv(m,v); }
00155 void accumulate_product(SCMatrix* m, SCVector* v)
00156 { accumulate_product_rv(m,v); }
00157 virtual void accumulate_product_sv(SymmSCMatrix* m, SCVector* v);
00158 virtual void accumulate_product_rv(SCMatrix* m, SCVector* v) = 0;
00160 virtual void accumulate(const SCVector*v) = 0;
00162 virtual void accumulate(const SCMatrix*m) = 0;
00164 virtual double scalar_product(SCVector*) = 0;
00166 virtual void element_op(const Ref<SCElementOp>&) = 0;
00167 virtual void element_op(const Ref<SCElementOp2>&,
00168 SCVector*) = 0;
00169 virtual void element_op(const Ref<SCElementOp3>&,
00170 SCVector*,SCVector*) = 0;
00172 void print(std::ostream&o=ExEnv::out()) const;
00173 void print(const char* title=0,std::ostream&out=ExEnv::out(),int=10) const;
00174 virtual void vprint(const char*title=0,std::ostream&out=ExEnv::out(),
00175 int=10) const = 0;
00176
00178 Ref<MessageGrp> messagegrp() const;
00179
00184 virtual Ref<SCMatrixSubblockIter> local_blocks(
00185 SCMatrixSubblockIter::Access) = 0;
00187 virtual Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access) = 0;
00188 };
00189
00193 class SCMatrix: public DescribedClass {
00194 protected:
00195 RefSCDimension d1,d2;
00196 Ref<SCMatrixKit> kit_;
00197 public:
00198
00199 enum Transform { NormalTransform = 0, TransposeTransform = 1 };
00200
00201
00202 SCMatrix(const RefSCDimension&, const RefSCDimension&, SCMatrixKit *);
00203 virtual ~SCMatrix();
00204
00206 virtual void save(StateOut&);
00207 virtual void restore(StateIn&);
00208
00210 Ref<SCMatrixKit> kit() const { return kit_; }
00211
00213 int nrow() const { return d1->n(); }
00215 int ncol() const { return d2->n(); }
00217 virtual double maxabs() const;
00219 virtual void randomize();
00221 void assign(double val) { assign_val(val); }
00223 void assign(const double* m) { assign_p(m); }
00225 void assign(const double** m) { assign_pp(m); }
00227 void assign(SCMatrix* m) { assign_r(m); }
00229 virtual void assign_val(double val);
00230 virtual void assign_p(const double* m);
00231 virtual void assign_pp(const double** m);
00232 virtual void assign_r(SCMatrix* m);
00235 virtual void convert(double*) const;
00236 virtual void convert(double**) const;
00239 virtual void convert(SCMatrix*);
00240 virtual void convert_accumulate(SCMatrix*);
00242 virtual void scale(double val);
00244 virtual void scale_diagonal(double val);
00246 virtual void shift_diagonal(double val);
00248 virtual void unit();
00250 virtual SCMatrix* copy();
00252 virtual SCMatrix* clone();
00253
00254
00256
00257 RefSCDimension coldim() const { return d2; }
00259 virtual double get_element(int,int) const = 0;
00260 virtual void set_element(int,int,double) = 0;
00261 virtual void accumulate_element(int,int,double) = 0;
00262
00266 virtual SCMatrix * get_subblock(int br, int er, int bc, int ec) =0;
00267
00269 virtual void assign_subblock(SCMatrix *m, int, int, int, int, int=0, int=0) =0;
00270
00272 virtual void accumulate_subblock(SCMatrix *m, int, int, int, int, int=0,int=0) =0;
00273
00275 virtual SCVector * get_row(int i) =0;
00276 virtual SCVector * get_column(int i) =0;
00277
00279 virtual void assign_row(SCVector *v, int i) =0;
00280 virtual void assign_column(SCVector *v, int i) =0;
00281
00283 virtual void accumulate_row(SCVector *v, int i) =0;
00284 virtual void accumulate_column(SCVector *v, int i) =0;
00285
00287 virtual void accumulate(const SCMatrix* m) = 0;
00288 virtual void accumulate(const SymmSCMatrix* m) = 0;
00289 virtual void accumulate(const DiagSCMatrix* m) = 0;
00290 virtual void accumulate(const SCVector*) = 0;
00292 virtual void accumulate_outer_product(SCVector*,SCVector*) = 0;
00293 void accumulate_product(SCMatrix*m1,SCMatrix*m2)
00294 { accumulate_product_rr(m1,m2); }
00295 void accumulate_product(SCMatrix*m1,SymmSCMatrix*m2)
00296 { accumulate_product_rs(m1,m2); }
00297 void accumulate_product(SCMatrix*m1,DiagSCMatrix*m2)
00298 { accumulate_product_rd(m1,m2); }
00299 void accumulate_product(SymmSCMatrix*m1,SCMatrix*m2)
00300 { accumulate_product_sr(m1,m2); }
00301 void accumulate_product(DiagSCMatrix*m1,SCMatrix*m2)
00302 { accumulate_product_dr(m1,m2); }
00303 void accumulate_product(SymmSCMatrix*m1,SymmSCMatrix*m2)
00304 { accumulate_product_ss(m1,m2); }
00305 virtual void accumulate_product_rr(SCMatrix*,SCMatrix*) = 0;
00306 virtual void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
00307 virtual void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
00308 virtual void accumulate_product_sr(SymmSCMatrix*,SCMatrix*);
00309 virtual void accumulate_product_dr(DiagSCMatrix*,SCMatrix*);
00310 virtual void accumulate_product_ss(SymmSCMatrix*,SymmSCMatrix*);
00312 virtual void transpose_this() = 0;
00314 virtual double trace() =0;
00316 virtual double invert_this() = 0;
00318 virtual double determ_this() = 0;
00319
00322 virtual void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V);
00323 virtual double solve_this(SCVector*) = 0;
00324 virtual void gen_invert_this();
00325
00328 virtual void schmidt_orthog(SymmSCMatrix*, int n) =0;
00329
00333 virtual int schmidt_orthog_tol(SymmSCMatrix*, double tol, double*res=0)=0;
00334
00336 virtual void element_op(const Ref<SCElementOp>&) = 0;
00337 virtual void element_op(const Ref<SCElementOp2>&,
00338 SCMatrix*) = 0;
00339 virtual void element_op(const Ref<SCElementOp3>&,
00340 SCMatrix*,SCMatrix*) = 0;
00342 void print(std::ostream&o=ExEnv::out()) const;
00343 void print(const char* title=0,std::ostream& out=ExEnv::out(),
00344 int =10) const;
00345 virtual void vprint(const char*title=0,
00346 std::ostream&out=ExEnv::out(),int =10) const = 0;
00347
00349 Ref<MessageGrp> messagegrp() const;
00350
00353 virtual Ref<SCMatrixSubblockIter> local_blocks(
00354 SCMatrixSubblockIter::Access) = 0;
00356 virtual Ref<SCMatrixSubblockIter> all_blocks(
00357 SCMatrixSubblockIter::Access) = 0;
00358 };
00359
00362 class SymmSCMatrix: public DescribedClass {
00363 protected:
00364 RefSCDimension d;
00365 Ref<SCMatrixKit> kit_;
00366 public:
00367 SymmSCMatrix(const RefSCDimension&, SCMatrixKit *);
00368
00370 Ref<SCMatrixKit> kit() const { return kit_; }
00371
00373 virtual void save(StateOut&);
00374 virtual void restore(StateIn&);
00376 virtual double maxabs() const;
00378 virtual void randomize();
00380 void assign(double val) { assign_val(val); }
00382 void assign(const double* m) { assign_p(m); }
00384 void assign(const double** m) { assign_pp(m); }
00387 void assign(SymmSCMatrix* m) { assign_s(m); }
00389 virtual void assign_val(double val);
00390 virtual void assign_p(const double* m);
00391 virtual void assign_pp(const double** m);
00392 virtual void assign_s(SymmSCMatrix* m);
00394 virtual void convert(double*) const;
00395 virtual void convert(double**) const;
00398 virtual void convert(SymmSCMatrix*);
00399 virtual void convert_accumulate(SymmSCMatrix*);
00401 virtual void scale(double);
00403 virtual void scale_diagonal(double);
00405 virtual void shift_diagonal(double);
00407 virtual void unit();
00409 int n() const { return d->n(); }
00411 virtual SymmSCMatrix* copy();
00413 virtual SymmSCMatrix* clone();
00414
00415
00417
00419
00420 virtual void set_element(int,int,double) = 0;
00421 virtual void accumulate_element(int,int,double) = 0;
00422
00426 virtual SCMatrix * get_subblock(int br, int er, int bc, int ec) =0;
00427 virtual SymmSCMatrix * get_subblock(int br, int er) =0;
00428
00430 virtual void assign_subblock(SCMatrix *m, int, int, int, int) =0;
00431 virtual void assign_subblock(SymmSCMatrix *m, int, int) =0;
00432
00434 virtual void accumulate_subblock(SCMatrix *m, int, int, int, int) =0;
00435 virtual void accumulate_subblock(SymmSCMatrix *m, int, int) =0;
00436
00438 virtual SCVector * get_row(int i) =0;
00439
00441 virtual void assign_row(SCVector *v, int i) =0;
00442
00444 virtual void accumulate_row(SCVector *v, int i) =0;
00445
00448 virtual void diagonalize(DiagSCMatrix*d,SCMatrix*m) = 0;
00450 virtual void accumulate(const SymmSCMatrix* m) = 0;
00452 virtual void accumulate_symmetric_sum(SCMatrix*) = 0;
00453 virtual void accumulate_symmetric_product(SCMatrix*);
00454 virtual void accumulate_transform(SCMatrix*,SymmSCMatrix*,
00455 SCMatrix::Transform = SCMatrix::NormalTransform);
00456 virtual void accumulate_transform(SCMatrix*,DiagSCMatrix*,
00457 SCMatrix::Transform = SCMatrix::NormalTransform);
00458 virtual void accumulate_transform(SymmSCMatrix*,SymmSCMatrix*);
00459 virtual void accumulate_symmetric_outer_product(SCVector*);
00462 virtual double scalar_product(SCVector* v);
00464 virtual double trace() = 0;
00466 virtual double invert_this() = 0;
00468 virtual double determ_this() = 0;
00469
00470 virtual double solve_this(SCVector*) = 0;
00471 virtual void gen_invert_this() = 0;
00472
00474 virtual void element_op(const Ref<SCElementOp>&) = 0;
00475 virtual void element_op(const Ref<SCElementOp2>&,
00476 SymmSCMatrix*) = 0;
00477 virtual void element_op(const Ref<SCElementOp3>&,
00478 SymmSCMatrix*,SymmSCMatrix*) = 0;
00480 void print(std::ostream&o=ExEnv::out()) const;
00481 void print(const char* title=0,std::ostream& out=ExEnv::out(),
00482 int =10) const;
00483 virtual void vprint(const char* title=0,
00484 std::ostream& out=ExEnv::out(), int =10) const;
00485
00487 Ref<MessageGrp> messagegrp() const;
00488
00491 virtual Ref<SCMatrixSubblockIter> local_blocks(
00492 SCMatrixSubblockIter::Access) = 0;
00494 virtual Ref<SCMatrixSubblockIter> all_blocks(
00495 SCMatrixSubblockIter::Access) = 0;
00496 };
00497
00500 class DiagSCMatrix: public DescribedClass {
00501 protected:
00502 RefSCDimension d;
00503 Ref<SCMatrixKit> kit_;
00504 public:
00505 DiagSCMatrix(const RefSCDimension&, SCMatrixKit *);
00506
00508 Ref<SCMatrixKit> kit() const { return kit_; }
00509
00511 virtual void save(StateOut&);
00512 virtual void restore(StateIn&);
00513
00515 virtual double maxabs() const;
00517 virtual void randomize();
00519 void assign(double val) { assign_val(val); }
00521 void assign(const double*p) { assign_p(p); }
00524 void assign(DiagSCMatrix*d_a) { assign_d(d_a); }
00526 virtual void assign_val(double val);
00527 virtual void assign_p(const double*);
00528 virtual void assign_d(DiagSCMatrix*);
00530 virtual void convert(double*) const;
00533 virtual void convert(DiagSCMatrix*);
00534 virtual void convert_accumulate(DiagSCMatrix*);
00536 virtual void scale(double);
00538 int n() const { return d->n(); }
00540 virtual DiagSCMatrix* copy();
00542 virtual DiagSCMatrix* clone();
00543
00544
00546
00548
00549 virtual void set_element(int,double) = 0;
00550 virtual void accumulate_element(int,double) = 0;
00552 virtual void accumulate(const DiagSCMatrix* m) = 0;
00554 virtual double trace() = 0;
00556 virtual double determ_this() = 0;
00558 virtual double invert_this() = 0;
00560 virtual void gen_invert_this() = 0;
00562 virtual void element_op(const Ref<SCElementOp>&) = 0;
00563 virtual void element_op(const Ref<SCElementOp2>&,
00564 DiagSCMatrix*) = 0;
00565 virtual void element_op(const Ref<SCElementOp3>&,
00566 DiagSCMatrix*,DiagSCMatrix*) = 0;
00568 void print(std::ostream&o=ExEnv::out()) const;
00569 void print(const char* title=0,
00570 std::ostream& out=ExEnv::out(), int =10) const;
00571 virtual void vprint(const char* title=0,
00572 std::ostream& out=ExEnv::out(), int =10) const;
00573
00575 Ref<MessageGrp> messagegrp() const;
00576
00579 virtual Ref<SCMatrixSubblockIter> local_blocks(
00580 SCMatrixSubblockIter::Access) = 0;
00582 virtual Ref<SCMatrixSubblockIter> all_blocks(
00583 SCMatrixSubblockIter::Access) = 0;
00584 };
00585
00586 #endif
00587
00588
00589
00590
00591