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_block_h
00029 #define _math_scmat_block_h
00030
00031 #ifdef __GNUC__
00032 #pragma interface
00033 #endif
00034
00035 #include <util/state/state.h>
00036
00037 class SCElementOp;
00038 class SCElementOp2;
00039 class SCElementOp3;
00040
00043 class SCMatrixBlock: public SavableState {
00044 public:
00045 int blocki, blockj;
00046 public:
00047 SCMatrixBlock();
00048 SCMatrixBlock(StateIn&s);
00049 virtual ~SCMatrixBlock();
00050 void save_data_state(StateOut&s);
00051
00055 virtual SCMatrixBlock *deepcopy() const;
00056
00061 virtual double *dat();
00062 virtual int ndat() const;
00063
00064
00065 virtual void process(SCElementOp*) = 0;
00066 virtual void process(SCElementOp2*, SCMatrixBlock*) = 0;
00067 virtual void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*) = 0;
00068 };
00069
00070
00071 class SCMatrixBlockListLink {
00072 private:
00073 void operator = (const SCMatrixBlockListLink&) {}
00074 SCMatrixBlock* _block;
00075 SCMatrixBlockListLink* _next;
00076 public:
00077 SCMatrixBlockListLink(SCMatrixBlock*, SCMatrixBlockListLink* = 0);
00078 ~SCMatrixBlockListLink();
00079 void block(SCMatrixBlock*);
00080 void next(SCMatrixBlockListLink* link) { _next = link; }
00081 SCMatrixBlock* block() { return _block; }
00082 SCMatrixBlockListLink* next() { return _next; }
00083 };
00084
00085 class SCMatrixBlockListIter {
00086 private:
00087 SCMatrixBlockListLink* link;
00088 public:
00089 SCMatrixBlockListIter(): link(0) {}
00090 SCMatrixBlockListIter(SCMatrixBlockListLink*l): link(l) {}
00091 int operator !=(const SCMatrixBlockListIter p) const {
00092 return link != p.link;
00093 }
00094 void operator ++() { link = link->next(); }
00095 void operator ++(int) { link = link->next(); }
00096 SCMatrixBlock* block() const { return link->block(); }
00097 };
00098
00099 class SCMatrixBlockList: public SavableState {
00100 private:
00101 SCMatrixBlockListLink* _begin;
00102 public:
00103 SCMatrixBlockList();
00104 SCMatrixBlockList(StateIn&);
00105 ~SCMatrixBlockList();
00106 void save_data_state(StateOut&);
00107 void insert(SCMatrixBlock*);
00108 void append(SCMatrixBlock*);
00109 SCMatrixBlockListIter begin() { return _begin; }
00110 SCMatrixBlockListIter end() { return 0; }
00111 SCMatrixBlockList *deepcopy();
00112 };
00113
00114
00125 class SCVectorSimpleBlock: public SCMatrixBlock {
00126 public:
00127 SCVectorSimpleBlock(int istart,int iend);
00128 SCVectorSimpleBlock(StateIn&);
00129 virtual ~SCVectorSimpleBlock();
00130 void save_data_state(StateOut&);
00131 int istart;
00132 int iend;
00133 double* data;
00134
00135 SCMatrixBlock *deepcopy() const;
00136
00137 void process(SCElementOp*);
00138 void process(SCElementOp2*, SCMatrixBlock*);
00139 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00140
00141 double *dat();
00142 int ndat() const;
00143 };
00144
00145
00156 class SCVectorSimpleSubBlock: public SCMatrixBlock {
00157 public:
00158 SCVectorSimpleSubBlock(int istart,int iend, int offset, double* data);
00159 SCVectorSimpleSubBlock(StateIn&);
00160 virtual ~SCVectorSimpleSubBlock();
00161 void save_data_state(StateOut&);
00162 int istart;
00163 int iend;
00164 int offset;
00165 double* data;
00166
00167 void process(SCElementOp*);
00168 void process(SCElementOp2*, SCMatrixBlock*);
00169 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00170 };
00171
00172
00185 class SCMatrixRectBlock: public SCMatrixBlock {
00186 public:
00187 SCMatrixRectBlock(int is, int ie, int js, int je);
00188 SCMatrixRectBlock(StateIn&);
00189 virtual ~SCMatrixRectBlock();
00190 void save_data_state(StateOut&);
00191 int istart;
00192 int jstart;
00193 int iend;
00194 int jend;
00195 double* data;
00196
00197 SCMatrixBlock *deepcopy() const;
00198
00199 void process(SCElementOp*);
00200 void process(SCElementOp2*, SCMatrixBlock*);
00201 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00202
00203 double *dat();
00204 int ndat() const;
00205 };
00206
00207
00221 class SCMatrixRectSubBlock: public SCMatrixBlock {
00222 public:
00223 SCMatrixRectSubBlock(int is, int ie, int istride, int js, int je,
00224 double* data);
00225 SCMatrixRectSubBlock(StateIn&);
00226
00227 virtual ~SCMatrixRectSubBlock();
00228
00229 void save_data_state(StateOut&);
00230 int istart;
00231 int jstart;
00232 int iend;
00233 int jend;
00234 int istride;
00235 double* data;
00236
00237 void process(SCElementOp*);
00238 void process(SCElementOp2*, SCMatrixBlock*);
00239 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00240 };
00241
00242
00255 class SCMatrixLTriBlock: public SCMatrixBlock {
00256 public:
00257 SCMatrixLTriBlock(int s,int e);
00258 SCMatrixLTriBlock(StateIn&);
00259 virtual ~SCMatrixLTriBlock();
00260 void save_data_state(StateOut&);
00261 int start;
00262 int end;
00263 double* data;
00264
00265 SCMatrixBlock *deepcopy() const;
00266
00267 void process(SCElementOp*);
00268 void process(SCElementOp2*, SCMatrixBlock*);
00269 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00270
00271 double *dat();
00272 int ndat() const;
00273 };
00274
00275
00290 class SCMatrixLTriSubBlock: public SCMatrixBlock {
00291 public:
00292 SCMatrixLTriSubBlock(int is,int ie,int js,int je,double*data);
00293 SCMatrixLTriSubBlock(StateIn&);
00294
00295 virtual ~SCMatrixLTriSubBlock();
00296
00297 void save_data_state(StateOut&);
00298 int istart;
00299 int iend;
00300 int jstart;
00301 int jend;
00302 double* data;
00303
00304 void process(SCElementOp*);
00305 void process(SCElementOp2*, SCMatrixBlock*);
00306 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00307 };
00308
00309
00320 class SCMatrixDiagBlock: public SCMatrixBlock {
00321 public:
00322 SCMatrixDiagBlock(int istart,int iend,int jstart);
00323 SCMatrixDiagBlock(int istart,int iend);
00324 SCMatrixDiagBlock(StateIn&);
00325 virtual ~SCMatrixDiagBlock();
00326 void save_data_state(StateOut&);
00327 int istart;
00328 int jstart;
00329 int iend;
00330 double* data;
00331
00332 SCMatrixBlock *deepcopy() const;
00333
00334 void process(SCElementOp*);
00335 void process(SCElementOp2*, SCMatrixBlock*);
00336 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00337
00338 double *dat();
00339 int ndat() const;
00340 };
00341
00342
00353 class SCMatrixDiagSubBlock: public SCMatrixBlock {
00354 public:
00355 SCMatrixDiagSubBlock(int istart,int iend,int jstart, int offset,
00356 double*data);
00357 SCMatrixDiagSubBlock(int istart,int iend, int offset, double*data);
00358 SCMatrixDiagSubBlock(StateIn&);
00359
00360 virtual ~SCMatrixDiagSubBlock();
00361
00362 void save_data_state(StateOut&);
00363 int istart;
00364 int jstart;
00365 int iend;
00366 int offset;
00367 double* data;
00368
00369 void process(SCElementOp*);
00370 void process(SCElementOp2*, SCMatrixBlock*);
00371 void process(SCElementOp3*, SCMatrixBlock*, SCMatrixBlock*);
00372 };
00373
00374
00375
00376
00377
00381 class SCMatrixSubblockIter: public RefCount {
00382 public:
00383 enum Access { Read, Write, Accum, None };
00384 protected:
00385 Access access_;
00386 public:
00389 SCMatrixSubblockIter(Access access): access_(access) {}
00391 virtual void begin() = 0;
00393 virtual int ready() = 0;
00395 virtual void next() = 0;
00397 virtual SCMatrixBlock *block() = 0;
00399 Access access() const { return access_; }
00400 };
00401
00402
00403 class SCMatrixSimpleSubblockIter: public SCMatrixSubblockIter {
00404 protected:
00405 Ref<SCMatrixBlock> block_;
00406 int ready_;
00407 public:
00408 SCMatrixSimpleSubblockIter(Access, const Ref<SCMatrixBlock> &b);
00409 void begin();
00410 int ready();
00411 void next();
00412 SCMatrixBlock *block();
00413 };
00414
00415 class SCMatrixListSubblockIter: public SCMatrixSubblockIter {
00416 protected:
00417 Ref<SCMatrixBlockList> list_;
00418 SCMatrixBlockListIter iter_;
00419 public:
00420 SCMatrixListSubblockIter(Access, const Ref<SCMatrixBlockList> &list);
00421 void begin();
00422 int ready();
00423 void next();
00424 SCMatrixBlock *block();
00425 };
00426
00427 class SCMatrixNullSubblockIter: public SCMatrixSubblockIter {
00428 public:
00429 SCMatrixNullSubblockIter();
00430 SCMatrixNullSubblockIter(Access);
00431 void begin();
00432 int ready();
00433 void next();
00434 SCMatrixBlock *block();
00435 };
00436
00437 class SCMatrixCompositeSubblockIter: public SCMatrixSubblockIter {
00438 protected:
00439 int niters_;
00440 Ref<SCMatrixSubblockIter> *iters_;
00441 int iiter_;
00442 public:
00443 SCMatrixCompositeSubblockIter(Access, int niter);
00444 SCMatrixCompositeSubblockIter(Ref<SCMatrixSubblockIter>&,
00445 Ref<SCMatrixSubblockIter>&);
00446 ~SCMatrixCompositeSubblockIter();
00447 void set_iter(int i, const Ref<SCMatrixSubblockIter> &);
00448 void begin();
00449 int ready();
00450 void next();
00451 SCMatrixBlock *block();
00452 int current_block() const { return iiter_; }
00453 };
00454
00455
00456 class SCMatrixJointSubblockIter: public SCMatrixSubblockIter {
00457 protected:
00458 int niters_;
00459 Ref<SCMatrixSubblockIter> *iters_;
00460 public:
00461 SCMatrixJointSubblockIter(const Ref<SCMatrixSubblockIter>&,
00462 const Ref<SCMatrixSubblockIter>&,
00463 const Ref<SCMatrixSubblockIter>& = 0,
00464 const Ref<SCMatrixSubblockIter>& = 0,
00465 const Ref<SCMatrixSubblockIter>& = 0);
00466 ~SCMatrixJointSubblockIter();
00467 void begin();
00468 int ready();
00469 void next();
00470 SCMatrixBlock *block();
00471 SCMatrixBlock *block(int i);
00472 };
00473
00474
00475 #endif
00476
00477
00478
00479
00480