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 #ifdef __GNUC__
00029 #pragma interface
00030 #endif
00031
00032 #ifndef _math_scmat_repl_h
00033 #define _math_scmat_repl_h
00034
00035 #include <util/group/message.h>
00036
00037 #include <math/scmat/block.h>
00038 #include <math/scmat/matrix.h>
00039 #include <math/scmat/abstract.h>
00040
00041 namespace sc {
00042
00046 class ReplSCMatrixKit: public SCMatrixKit {
00047 public:
00048 ReplSCMatrixKit();
00049 ReplSCMatrixKit(const Ref<KeyVal>&);
00050 ~ReplSCMatrixKit();
00051 SCMatrix* matrix(const RefSCDimension&,const RefSCDimension&);
00052 SymmSCMatrix* symmmatrix(const RefSCDimension&);
00053 DiagSCMatrix* diagmatrix(const RefSCDimension&);
00054 SCVector* vector(const RefSCDimension&);
00055 };
00056
00057
00058 class ReplSCMatrixListSubblockIter: public SCMatrixListSubblockIter {
00059 protected:
00060 Ref<MessageGrp> grp_;
00061 double *data_;
00062 int ndata_;
00063 public:
00064 ReplSCMatrixListSubblockIter(Access,
00065 const Ref<SCMatrixBlockList> &list,
00066 const Ref<MessageGrp> &grp,
00067 double *data, int ndata);
00068 ~ReplSCMatrixListSubblockIter();
00069 };
00070
00071 class ReplSCVector: public SCVector {
00072 friend class ReplSCMatrix;
00073 friend class ReplSymmSCMatrix;
00074 friend class ReplDiagSCMatrix;
00075 protected:
00076 Ref<SCMatrixBlockList> blocklist;
00077 double* vector;
00078 void init_blocklist();
00079 void before_elemop();
00080 void after_elemop();
00081 public:
00082 ReplSCVector(const RefSCDimension&,ReplSCMatrixKit*);
00083 ~ReplSCVector();
00084 void assign_val(double);
00085 void assign_v(SCVector*);
00086 void assign_p(const double*);
00087
00088 void set_element(int,double);
00089 void accumulate_element(int,double);
00090 double get_element(int) const;
00091 void accumulate_product_sv(SymmSCMatrix*,SCVector*);
00092 void accumulate_product_rv(SCMatrix*,SCVector*);
00093 void accumulate(const SCVector*);
00094 void accumulate(const SCMatrix*);
00095 double scalar_product(SCVector*);
00096 void element_op(const Ref<SCElementOp>&);
00097 void element_op(const Ref<SCElementOp2>&,
00098 SCVector*);
00099 void element_op(const Ref<SCElementOp3>&,
00100 SCVector*,SCVector*);
00101 void vprint(const char* title=0,
00102 std::ostream& out=ExEnv::out0(), int =10) const;
00103
00104
00105 double *get_data() { return vector; }
00106
00107 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
00108 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
00109
00110 Ref<ReplSCMatrixKit> skit();
00111 };
00112
00113 class ReplSCMatrix: public SCMatrix {
00114 friend class ReplSymmSCMatrix;
00115 friend class ReplDiagSCMatrix;
00116 friend class ReplSCVector;
00117 protected:
00118 Ref<SCMatrixBlockList> blocklist;
00119 double* matrix;
00120 double** rows;
00121 protected:
00122
00123 int compute_offset(int,int) const;
00124 void init_blocklist();
00125
00126 void before_elemop();
00127 void after_elemop();
00128 public:
00129 ReplSCMatrix(const RefSCDimension&,const RefSCDimension&,
00130 ReplSCMatrixKit*);
00131 ~ReplSCMatrix();
00132
00133
00134 void assign_val(double);
00135 double get_element(int,int) const;
00136 void set_element(int,int,double);
00137 void accumulate_element(int,int,double);
00138 SCMatrix * get_subblock(int,int,int,int);
00139 void assign_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
00140 void accumulate_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
00141 SCVector * get_row(int i);
00142 SCVector * get_column(int i);
00143 void assign_row(SCVector *v, int i);
00144 void assign_column(SCVector *v, int i);
00145 void accumulate_row(SCVector *v, int i);
00146 void accumulate_column(SCVector *v, int i);
00147 void assign_p(const double*);
00148 void assign_pp(const double**);
00149 void convert_p(double*) const;
00150 void convert_pp(double**) const;
00151
00152 void accumulate_outer_product(SCVector*,SCVector*);
00153 void accumulate_product_rr(SCMatrix*,SCMatrix*);
00154 void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
00155 void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
00156 void accumulate(const SCMatrix*);
00157 void accumulate(const SymmSCMatrix*);
00158 void accumulate(const DiagSCMatrix*);
00159 void accumulate(const SCVector*);
00160 void transpose_this();
00161 double invert_this();
00162 void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V);
00163 double solve_this(SCVector*);
00164 double determ_this();
00165 double trace();
00166 void schmidt_orthog(SymmSCMatrix*,int);
00167 int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
00168 void element_op(const Ref<SCElementOp>&);
00169 void element_op(const Ref<SCElementOp2>&,
00170 SCMatrix*);
00171 void element_op(const Ref<SCElementOp3>&,
00172 SCMatrix*,SCMatrix*);
00173 void vprint(const char* title=0,
00174 std::ostream& out=ExEnv::out0(), int =10) const;
00175
00176
00177 double *get_data() { return matrix; }
00178 double **get_rows() { return rows; }
00179
00180 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
00181 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
00182
00183 Ref<ReplSCMatrixKit> skit();
00184 };
00185
00186 class ReplSymmSCMatrix: public SymmSCMatrix {
00187 friend class ReplSCMatrix;
00188 friend class ReplDiagSCMatrix;
00189 friend class ReplSCVector;
00190 protected:
00191 Ref<SCMatrixBlockList> blocklist;
00192 double* matrix;
00193 double** rows;
00194 protected:
00195
00196 int compute_offset(int,int) const;
00197 void init_blocklist();
00198
00199 void before_elemop();
00200 void after_elemop();
00201 public:
00202 ReplSymmSCMatrix(const RefSCDimension&, ReplSCMatrixKit*);
00203 ~ReplSymmSCMatrix();
00204
00205
00206 void assign_val(double);
00207 void assign_s(SymmSCMatrix*);
00208 void assign_p(const double*);
00209 void assign_pp(const double**);
00210 void convert_p(double*) const;
00211 void convert_pp(double**) const;
00212 double get_element(int,int) const;
00213 void set_element(int,int,double);
00214 void accumulate_element(int,int,double);
00215 void scale(double);
00216
00217 SCMatrix * get_subblock(int,int,int,int);
00218 SymmSCMatrix * get_subblock(int,int);
00219 void assign_subblock(SCMatrix*, int,int,int,int);
00220 void assign_subblock(SymmSCMatrix*, int,int);
00221 void accumulate_subblock(SCMatrix*, int,int,int,int);
00222 void accumulate_subblock(SymmSCMatrix*, int,int);
00223 SCVector * get_row(int i);
00224 void assign_row(SCVector *v, int i);
00225 void accumulate_row(SCVector *v, int i);
00226
00227 void accumulate_product_rr(SCMatrix*,SCMatrix*);
00228 void accumulate(const SymmSCMatrix*);
00229 double invert_this();
00230 double solve_this(SCVector*);
00231 double trace();
00232 double determ_this();
00233 void gen_invert_this();
00234
00235 double scalar_product(SCVector*);
00236 void diagonalize(DiagSCMatrix*,SCMatrix*);
00237 void accumulate_symmetric_outer_product(SCVector*);
00238 void accumulate_symmetric_product(SCMatrix*);
00239 void accumulate_symmetric_sum(SCMatrix*);
00240 void accumulate_transform(SCMatrix*,SymmSCMatrix*,
00241 SCMatrix::Transform = SCMatrix::NormalTransform);
00242 void accumulate_transform(SCMatrix*,DiagSCMatrix*,
00243 SCMatrix::Transform = SCMatrix::NormalTransform);
00244 void accumulate_transform(SymmSCMatrix*,SymmSCMatrix*);
00245 void element_op(const Ref<SCElementOp>&);
00246 void element_op(const Ref<SCElementOp2>&,
00247 SymmSCMatrix*);
00248 void element_op(const Ref<SCElementOp3>&,
00249 SymmSCMatrix*,SymmSCMatrix*);
00250 void vprint(const char* title=0,
00251 std::ostream& out=ExEnv::out0(), int =10) const;
00252
00253
00254 double *get_data() { return matrix; }
00255 double **get_rows() { return rows; }
00256
00257 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
00258 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
00259
00260 Ref<ReplSCMatrixKit> skit();
00261 };
00262
00263 class ReplDiagSCMatrix: public DiagSCMatrix {
00264 friend class ReplSCMatrix;
00265 friend class ReplSymmSCMatrix;
00266 friend class ReplSCVector;
00267 protected:
00268 Ref<SCMatrixBlockList> blocklist;
00269 void init_blocklist();
00270 double* matrix;
00271
00272 void before_elemop();
00273 void after_elemop();
00274 public:
00275 ReplDiagSCMatrix(const RefSCDimension&, ReplSCMatrixKit*);
00276 ~ReplDiagSCMatrix();
00277
00278
00279 void assign_val(double);
00280 double get_element(int) const;
00281 void set_element(int,double);
00282 void accumulate_element(int,double);
00283 void accumulate(const DiagSCMatrix*);
00284 double invert_this();
00285 double determ_this();
00286 double trace();
00287 void gen_invert_this();
00288
00289 void element_op(const Ref<SCElementOp>&);
00290 void element_op(const Ref<SCElementOp2>&,
00291 DiagSCMatrix*);
00292 void element_op(const Ref<SCElementOp3>&,
00293 DiagSCMatrix*,DiagSCMatrix*);
00294 void vprint(const char* title=0,
00295 std::ostream& out=ExEnv::out0(), int =10) const;
00296
00297
00298 double *get_data() { return matrix; }
00299
00300 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
00301 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
00302
00303 Ref<ReplSCMatrixKit> skit();
00304 };
00305
00306 }
00307
00308 #endif
00309
00310
00311
00312
00313