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_blocked_h
00033 #define _math_scmat_blocked_h
00034
00035 #include <math/scmat/block.h>
00036 #include <math/scmat/elemop.h>
00037 #include <math/scmat/matrix.h>
00038 #include <math/scmat/abstract.h>
00039
00040 class BlockedSCMatrixKit;
00041 class BlockedSCVector;
00042 class BlockedSCMatrix;
00043 class BlockedSymmSCMatrix;
00044 class BlockedDiagSCMatrix;
00045
00046 class BlockedSCMatrixKit: public SCMatrixKit {
00047 private:
00048 Ref<SCMatrixKit> subkit_;
00049 public:
00050 BlockedSCMatrixKit(const Ref<SCMatrixKit>& subkit);
00051 BlockedSCMatrixKit(const Ref<KeyVal>&);
00052 ~BlockedSCMatrixKit();
00053 SCMatrix* matrix(const RefSCDimension&,const RefSCDimension&);
00054 SymmSCMatrix* symmmatrix(const RefSCDimension&);
00055 DiagSCMatrix* diagmatrix(const RefSCDimension&);
00056 SCVector* vector(const RefSCDimension&);
00057
00058 Ref<SCMatrixKit> subkit() { return subkit_; }
00059 };
00060
00061
00062 class BlockedSCVector: public SCVector {
00063 friend class BlockedSCMatrix;
00064 friend class BlockedSymmSCMatrix;
00065 friend class BlockedDiagSCMatrix;
00066 private:
00067 Ref<SCMatrixKit> subkit;
00068 RefSCVector *vecs_;
00069
00070 void resize(SCDimension*);
00071
00072 public:
00073 BlockedSCVector(const RefSCDimension&, BlockedSCMatrixKit*);
00074 ~BlockedSCVector();
00075
00076
00077 void save(StateOut&);
00078 void restore(StateIn&);
00079
00080 void assign_val(double);
00081 void assign_v(SCVector*);
00082 void assign_p(const double*);
00083
00084 double get_element(int) const;
00085 void set_element(int,double);
00086 void accumulate_element(int,double);
00087
00088 void accumulate_product_rv(SCMatrix*,SCVector*);
00089 void accumulate_product_sv(SymmSCMatrix*,SCVector*);
00090
00091 void accumulate(const SCVector*);
00092 void accumulate(const SCMatrix*);
00093 double scalar_product(SCVector*);
00094
00095 void element_op(const Ref<SCElementOp>&);
00096 void element_op(const Ref<SCElementOp2>&,
00097 SCVector*);
00098 void element_op(const Ref<SCElementOp3>&,
00099 SCVector*,SCVector*);
00100 void vprint(const char* title=0,
00101 std::ostream& out=ExEnv::out(), int =10) const;
00102
00103
00104 RefSCDimension dim() const { return d; }
00105 RefSCDimension dim(int) const;
00106 int nblocks() const;
00107 RefSCVector block(int);
00108
00109 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
00110 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
00111 };
00112
00113 class BlockedSCMatrix: public SCMatrix {
00114 friend class BlockedSymmSCMatrix;
00115 friend class BlockedDiagSCMatrix;
00116 friend class BlockedSCVector;
00117 private:
00118 Ref<SCMatrixKit> subkit;
00119 RefSCMatrix *mats_;
00120 int nblocks_;
00121
00122 void resize(SCDimension*, SCDimension*);
00123
00124 public:
00125 BlockedSCMatrix(const RefSCDimension&, const RefSCDimension&,
00126 BlockedSCMatrixKit*);
00127 ~BlockedSCMatrix();
00128
00129
00130 void save(StateOut&);
00131 void restore(StateIn&);
00132
00133 void assign_val(double);
00134 double get_element(int,int) const;
00135 void set_element(int,int,double);
00136 void accumulate_element(int,int,double);
00137
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
00142 SCVector * get_row(int i);
00143 SCVector * get_column(int i);
00144 void assign_row(SCVector *v, int i);
00145 void assign_column(SCVector *v, int i);
00146 void accumulate_row(SCVector *v, int i);
00147 void accumulate_column(SCVector *v, int i);
00148
00149 void accumulate_outer_product(SCVector*,SCVector*);
00150 void accumulate_product_rr(SCMatrix*,SCMatrix*);
00151 void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
00152 void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
00153 void accumulate(const SCMatrix*);
00154 void accumulate(const SymmSCMatrix*);
00155 void accumulate(const DiagSCMatrix*);
00156 void accumulate(const SCVector*);
00157
00158 void transpose_this();
00159 double invert_this();
00160 void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V);
00161 double solve_this(SCVector*);
00162 double determ_this();
00163 double trace();
00164 void gen_invert_this();
00165 void schmidt_orthog(SymmSCMatrix*,int);
00166 int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
00167
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
00174 void vprint(const char* title=0,
00175 std::ostream& out=ExEnv::out(), int =10) const;
00176
00177
00178 RefSCDimension rowdim() const { return d1; }
00179 RefSCDimension coldim() const { return d2; }
00180 RefSCDimension rowdim(int) const;
00181 RefSCDimension coldim(int) const;
00182 int nblocks() const;
00183 RefSCMatrix block(int);
00184
00185 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
00186 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
00187 };
00188
00189 class BlockedSymmSCMatrix: public SymmSCMatrix {
00190 friend class BlockedSCMatrix;
00191 friend class BlockedDiagSCMatrix;
00192 friend class BlockedSCVector;
00193 private:
00194 Ref<SCMatrixKit> subkit;
00195 RefSymmSCMatrix *mats_;
00196
00197 void resize(SCDimension*);
00198
00199 public:
00200 BlockedSymmSCMatrix(const RefSCDimension&,BlockedSCMatrixKit*);
00201 ~BlockedSymmSCMatrix();
00202
00203
00204 void save(StateOut&);
00205 void restore(StateIn&);
00206
00207 double get_element(int,int) const;
00208 void set_element(int,int,double);
00209 void accumulate_element(int,int,double);
00210 void scale(double);
00211 void assign_val(double);
00212 void assign_s(SymmSCMatrix*m);
00213
00214 SCMatrix * get_subblock(int,int,int,int);
00215 SymmSCMatrix * get_subblock(int,int);
00216 void assign_subblock(SCMatrix*, int,int,int,int);
00217 void assign_subblock(SymmSCMatrix*, int,int);
00218 void accumulate_subblock(SCMatrix*, int,int,int,int);
00219 void accumulate_subblock(SymmSCMatrix*, int,int);
00220 SCVector * get_row(int i);
00221 void assign_row(SCVector *v, int i);
00222 void accumulate_row(SCVector *v, int i);
00223
00224 double invert_this();
00225 double determ_this();
00226 double trace();
00227 double solve_this(SCVector*);
00228 void gen_invert_this();
00229
00230 double scalar_product(SCVector*);
00231 void diagonalize(DiagSCMatrix*,SCMatrix*);
00232
00233 void accumulate(const SymmSCMatrix*);
00234 void accumulate_symmetric_outer_product(SCVector*);
00235 void accumulate_symmetric_product(SCMatrix*);
00236 void accumulate_symmetric_sum(SCMatrix*);
00237 void accumulate_transform(SCMatrix*,SymmSCMatrix*,
00238 SCMatrix::Transform = SCMatrix::NormalTransform);
00239 void accumulate_transform(SCMatrix*,DiagSCMatrix*,
00240 SCMatrix::Transform = SCMatrix::NormalTransform);
00241 void accumulate_transform(SymmSCMatrix*,SymmSCMatrix*);
00242
00243 void convert_accumulate(SymmSCMatrix*a);
00244
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
00251 void vprint(const char* title=0,
00252 std::ostream& out=ExEnv::out(), int =10) const;
00253
00254
00255 RefSCDimension dim() const { return d; }
00256 RefSCDimension dim(int) const;
00257 int nblocks() const;
00258 RefSymmSCMatrix block(int);
00259
00260 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
00261 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
00262 };
00263
00264 class BlockedDiagSCMatrix: public DiagSCMatrix {
00265 friend class BlockedSCMatrix;
00266 friend class BlockedSymmSCMatrix;
00267 friend class BlockedSCVector;
00268 private:
00269 Ref<SCMatrixKit> subkit;
00270 RefDiagSCMatrix *mats_;
00271
00272 void resize(SCDimension*);
00273
00274 public:
00275 BlockedDiagSCMatrix(const RefSCDimension&,BlockedSCMatrixKit*);
00276 ~BlockedDiagSCMatrix();
00277
00278
00279 void save(StateOut&);
00280 void restore(StateIn&);
00281
00282 double get_element(int) const;
00283 void set_element(int,double);
00284 void accumulate_element(int,double);
00285 void accumulate(const DiagSCMatrix*);
00286
00287 double invert_this();
00288 double determ_this();
00289 double trace();
00290 void gen_invert_this();
00291
00292 void element_op(const Ref<SCElementOp>&);
00293 void element_op(const Ref<SCElementOp2>&,
00294 DiagSCMatrix*);
00295 void element_op(const Ref<SCElementOp3>&,
00296 DiagSCMatrix*,DiagSCMatrix*);
00297 void vprint(const char* title=0,
00298 std::ostream& out=ExEnv::out(), int =10) const;
00299
00300
00301 RefSCDimension dim() const { return d; }
00302 RefSCDimension dim(int) const;
00303 int nblocks() const;
00304 RefDiagSCMatrix block(int);
00305
00306 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
00307 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
00308 };
00309
00310 class BlockedSCElementOp : public SCElementOp {
00311 private:
00312 int current_block_;
00313
00314 public:
00315 BlockedSCElementOp();
00316 void working_on(int);
00317 int current_block() const;
00318 };
00319
00320 class BlockedSCElementOp2 : public SCElementOp2 {
00321 private:
00322 int current_block_;
00323
00324 public:
00325 BlockedSCElementOp2();
00326 void working_on(int);
00327 int current_block() const;
00328 };
00329
00330 class BlockedSCElementOp3 : public SCElementOp3 {
00331 private:
00332 int current_block_;
00333
00334 public:
00335 BlockedSCElementOp3();
00336 void working_on(int);
00337 int current_block() const;
00338 };
00339
00340 #endif
00341
00342
00343
00344
00345