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_elemop_h
00029 #define _math_scmat_elemop_h
00030
00031 #ifdef __GNUC__
00032 #pragma interface
00033 #endif
00034
00035 #include <util/state/state.h>
00036 #include <util/group/message.h>
00037
00038 class SCMatrixBlock;
00039 class SCMatrixBlockIter;
00040 class SCMatrixRectBlock;
00041 class SCMatrixLTriBlock;
00042 class SCMatrixDiagBlock;
00043 class SCVectorSimpleBlock;
00044 class SCMatrixRectSubBlock;
00045 class SCMatrixLTriSubBlock;
00046 class SCMatrixDiagSubBlock;
00047 class SCVectorSimpleSubBlock;
00048
00049 class SCMatrix;
00050 class SymmSCMatrix;
00051 class DiagSCMatrix;
00052 class SCVector;
00053
00058 class SCElementOp: public SavableState {
00059 public:
00060 SCElementOp();
00061 SCElementOp(StateIn&s): SavableState(s) {}
00062 virtual ~SCElementOp();
00070 virtual int has_collect();
00071 virtual void defer_collect(int);
00072 virtual void collect(const Ref<MessageGrp>&);
00076 virtual int has_side_effects();
00077
00080 virtual void process(SCMatrixBlockIter&) = 0;
00081
00086 void process_base(SCMatrixBlock*block);
00087
00092 virtual void process_spec_rect(SCMatrixRectBlock*);
00093 virtual void process_spec_ltri(SCMatrixLTriBlock*);
00094 virtual void process_spec_diag(SCMatrixDiagBlock*);
00095 virtual void process_spec_vsimp(SCVectorSimpleBlock*);
00096 virtual void process_spec_rectsub(SCMatrixRectSubBlock*);
00097 virtual void process_spec_ltrisub(SCMatrixLTriSubBlock*);
00098 virtual void process_spec_diagsub(SCMatrixDiagSubBlock*);
00099 virtual void process_spec_vsimpsub(SCVectorSimpleSubBlock*);
00100 };
00101
00106 class SCElementOp2: public SavableState {
00107 public:
00108 SCElementOp2();
00109 SCElementOp2(StateIn&s): SavableState(s) {}
00110 virtual ~SCElementOp2();
00111 virtual int has_collect();
00112 virtual void defer_collect(int);
00113 virtual int has_side_effects();
00114 virtual int has_side_effects_in_arg();
00115 virtual void collect(const Ref<MessageGrp>&);
00116 virtual void process(SCMatrixBlockIter&,SCMatrixBlockIter&) = 0;
00117 void process_base(SCMatrixBlock*,SCMatrixBlock*);
00118 virtual void process_spec_rect(SCMatrixRectBlock*,SCMatrixRectBlock*);
00119 virtual void process_spec_ltri(SCMatrixLTriBlock*,SCMatrixLTriBlock*);
00120 virtual void process_spec_diag(SCMatrixDiagBlock*,SCMatrixDiagBlock*);
00121 virtual void process_spec_vsimp(SCVectorSimpleBlock*,SCVectorSimpleBlock*);
00122 };
00123
00128 class SCElementOp3: public SavableState {
00129 public:
00130 SCElementOp3();
00131 SCElementOp3(StateIn&s): SavableState(s) {}
00132 virtual ~SCElementOp3();
00133 virtual int has_collect();
00134 virtual void defer_collect(int);
00135 virtual int has_side_effects();
00136 virtual int has_side_effects_in_arg1();
00137 virtual int has_side_effects_in_arg2();
00138 virtual void collect(const Ref<MessageGrp>&);
00139 virtual void process(SCMatrixBlockIter&,
00140 SCMatrixBlockIter&,
00141 SCMatrixBlockIter&) = 0;
00142 void process_base(SCMatrixBlock*,SCMatrixBlock*,SCMatrixBlock*);
00143 virtual void process_spec_rect(SCMatrixRectBlock*,
00144 SCMatrixRectBlock*,
00145 SCMatrixRectBlock*);
00146 virtual void process_spec_ltri(SCMatrixLTriBlock*,
00147 SCMatrixLTriBlock*,
00148 SCMatrixLTriBlock*);
00149 virtual void process_spec_diag(SCMatrixDiagBlock*,
00150 SCMatrixDiagBlock*,
00151 SCMatrixDiagBlock*);
00152 virtual void process_spec_vsimp(SCVectorSimpleBlock*,
00153 SCVectorSimpleBlock*,
00154 SCVectorSimpleBlock*);
00155 };
00156
00157 class SCElementScalarProduct: public SCElementOp2 {
00158 private:
00159 int deferred_;
00160 double product;
00161 public:
00162 SCElementScalarProduct();
00163 SCElementScalarProduct(StateIn&);
00164 ~SCElementScalarProduct();
00165 void save_data_state(StateOut&);
00166 void process(SCMatrixBlockIter&,SCMatrixBlockIter&);
00167 int has_collect();
00168 void defer_collect(int);
00169 void collect(const Ref<MessageGrp>&);
00170 double result();
00171 void init() { product = 0.0; }
00172 };
00173
00174
00175 class SCDestructiveElementProduct: public SCElementOp2 {
00176 public:
00177 SCDestructiveElementProduct();
00178 SCDestructiveElementProduct(StateIn&);
00179 ~SCDestructiveElementProduct();
00180 int has_side_effects();
00181 void save_data_state(StateOut&);
00182 void process(SCMatrixBlockIter&,SCMatrixBlockIter&);
00183 };
00184
00185 class SCElementScale: public SCElementOp {
00186 private:
00187 double scale;
00188 public:
00189 SCElementScale(double a);
00190 SCElementScale(StateIn&);
00191 ~SCElementScale();
00192 int has_side_effects();
00193 void save_data_state(StateOut&);
00194 void process(SCMatrixBlockIter&);
00195 };
00196
00197 class SCElementRandomize: public SCElementOp {
00198 private:
00199 double assign;
00200 public:
00201 SCElementRandomize();
00202 SCElementRandomize(StateIn&);
00203 ~SCElementRandomize();
00204 int has_side_effects();
00205 void save_data_state(StateOut&);
00206 void process(SCMatrixBlockIter&);
00207 };
00208
00209 class SCElementAssign: public SCElementOp {
00210 private:
00211 double assign;
00212 public:
00213 SCElementAssign(double a);
00214 SCElementAssign(StateIn&);
00215 ~SCElementAssign();
00216 int has_side_effects();
00217 void save_data_state(StateOut&);
00218 void process(SCMatrixBlockIter&);
00219 };
00220
00221 class SCElementSquareRoot: public SCElementOp {
00222 public:
00223 SCElementSquareRoot();
00224 SCElementSquareRoot(double a);
00225 SCElementSquareRoot(StateIn&);
00226 ~SCElementSquareRoot();
00227 int has_side_effects();
00228 void save_data_state(StateOut&);
00229 void process(SCMatrixBlockIter&);
00230 };
00231
00232 class SCElementInvert: public SCElementOp {
00233 private:
00234 double threshold_;
00235 int nbelowthreshold_;
00236 int deferred_;
00237 public:
00238 SCElementInvert(double threshold = 0.0);
00239 SCElementInvert(StateIn&);
00240 ~SCElementInvert();
00241 int has_side_effects();
00242 void save_data_state(StateOut&);
00243 void process(SCMatrixBlockIter&);
00244 int has_collect();
00245 void defer_collect(int);
00246 void collect(const Ref<MessageGrp>&);
00247 int result() { return nbelowthreshold_; }
00248 };
00249
00250
00251 class SCElementScaleDiagonal: public SCElementOp {
00252 private:
00253 double scale_diagonal;
00254 public:
00255 SCElementScaleDiagonal(double a);
00256 SCElementScaleDiagonal(StateIn&);
00257 ~SCElementScaleDiagonal();
00258 int has_side_effects();
00259 void save_data_state(StateOut&);
00260 void process(SCMatrixBlockIter&);
00261 };
00262
00263 class SCElementShiftDiagonal: public SCElementOp {
00264 private:
00265 double shift_diagonal;
00266 public:
00267 SCElementShiftDiagonal(double a);
00268 SCElementShiftDiagonal(StateIn&);
00269 ~SCElementShiftDiagonal();
00270 int has_side_effects();
00271 void save_data_state(StateOut&);
00272 void process(SCMatrixBlockIter&);
00273 };
00274
00275 class SCElementMaxAbs: public SCElementOp {
00276 private:
00277 int deferred_;
00278 double r;
00279 public:
00280 SCElementMaxAbs();
00281 SCElementMaxAbs(StateIn&);
00282 ~SCElementMaxAbs();
00283 void save_data_state(StateOut&);
00284 void process(SCMatrixBlockIter&);
00285 int has_collect();
00286 void defer_collect(int);
00287 void collect(const Ref<MessageGrp>&);
00288 double result();
00289 };
00290
00291
00292 class SCElementMinAbs: public SCElementOp {
00293 private:
00294 int deferred_;
00295 double r;
00296 public:
00297
00298 SCElementMinAbs(double rinit);
00299 SCElementMinAbs(StateIn&);
00300 ~SCElementMinAbs();
00301 void save_data_state(StateOut&);
00302 void process(SCMatrixBlockIter&);
00303 int has_collect();
00304 void defer_collect(int);
00305 void collect(const Ref<MessageGrp>&);
00306 double result();
00307 };
00308
00309
00310 class SCElementSumAbs: public SCElementOp {
00311 private:
00312 int deferred_;
00313 double r;
00314 public:
00315 SCElementSumAbs();
00316 SCElementSumAbs(StateIn&);
00317 ~SCElementSumAbs();
00318 void save_data_state(StateOut&);
00319 void process(SCMatrixBlockIter&);
00320 int has_collect();
00321 void defer_collect(int);
00322 void collect(const Ref<MessageGrp>&);
00323 double result();
00324 void init() { r = 0.0; }
00325 };
00326
00327
00328 class SCElementDot: public SCElementOp {
00329 private:
00330 double** avects;
00331 double** bvects;
00332 int length;
00333 public:
00334 SCElementDot(StateIn&);
00335 void save_data_state(StateOut&);
00336 SCElementDot(double**a, double**b, int length);
00337 void process(SCMatrixBlockIter&);
00338 int has_side_effects();
00339 };
00340
00341 class SCElementAccumulateSCMatrix: public SCElementOp {
00342 private:
00343 SCMatrix *m;
00344 public:
00345 SCElementAccumulateSCMatrix(SCMatrix *);
00346 int has_side_effects();
00347 void process(SCMatrixBlockIter&);
00348 };
00349
00350 class SCElementAccumulateSymmSCMatrix: public SCElementOp {
00351 private:
00352 SymmSCMatrix *m;
00353 public:
00354 SCElementAccumulateSymmSCMatrix(SymmSCMatrix *);
00355 int has_side_effects();
00356 void process(SCMatrixBlockIter&);
00357 };
00358
00359 class SCElementAccumulateDiagSCMatrix: public SCElementOp {
00360 private:
00361 DiagSCMatrix *m;
00362 public:
00363 SCElementAccumulateDiagSCMatrix(DiagSCMatrix *);
00364 int has_side_effects();
00365 void process(SCMatrixBlockIter&);
00366 };
00367
00368 class SCElementAccumulateSCVector: public SCElementOp {
00369 private:
00370 SCVector *m;
00371 public:
00372 SCElementAccumulateSCVector(SCVector *);
00373 int has_side_effects();
00374 void process(SCMatrixBlockIter&);
00375 };
00376
00377 #endif
00378
00379
00380
00381
00382