# elemop.h

    00001 //
    00002 // elemop.h
    00003 //
    00004 // Copyright (C) 1996 Limit Point Systems, Inc.
    00005 //
    00006 // Author: Curtis Janssen <cljanss@limitpt.com>
    00007 // Maintainer: LPS
    00008 //
    00009 // This file is part of the SC Toolkit.
    00010 //
    00011 // The SC Toolkit is free software; you can redistribute it and/or modify
    00012 // it under the terms of the GNU Library General Public License as published by
    00013 // the Free Software Foundation; either version 2, or (at your option)
    00014 // any later version.
    00015 //
    00016 // The SC Toolkit is distributed in the hope that it will be useful,
    00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00019 // GNU Library General Public License for more details.
    00020 //
    00021 // You should have received a copy of the GNU Library General Public License
    00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
    00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
    00024 //
    00025 // The U.S. Government is granted a limited license as per AL 91-7.
    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 namespace sc {
    00039
    00040 class SCMatrixBlock;
    00041 class SCMatrixBlockIter;
    00042 class SCMatrixRectBlock;
    00043 class SCMatrixLTriBlock;
    00044 class SCMatrixDiagBlock;
    00045 class SCVectorSimpleBlock;
    00046 class SCMatrixRectSubBlock;
    00047 class SCMatrixLTriSubBlock;
    00048 class SCMatrixDiagSubBlock;
    00049 class SCVectorSimpleSubBlock;
    00050
    00051 class SCMatrix;
    00052 class SymmSCMatrix;
    00053 class DiagSCMatrix;
    00054 class SCVector;
    00055
    00060 class SCElementOp: public SavableState {
    00061   public:
    00062     SCElementOp();
    00063     SCElementOp(StateIn&s): SavableState(s) {}
    00064     virtual ~SCElementOp();
    00072     virtual int has_collect();
    00073     virtual void defer_collect(int);
    00074     virtual void collect(const Ref<MessageGrp>&);
    00078     virtual void collect(const Ref<SCElementOp>&);
    00082     virtual int has_side_effects();
    00083
    00086     virtual bool threadsafe();
    00087
    00090     virtual bool cloneable();
    00091
    00095     virtual Ref<SCElementOp> clone();
    00096
    00099     virtual void process(SCMatrixBlockIter&) = 0;
    00100
    00105     void process_base(SCMatrixBlock*block);
    00106
    00111     virtual void process_spec_rect(SCMatrixRectBlock*);
    00112     virtual void process_spec_ltri(SCMatrixLTriBlock*);
    00113     virtual void process_spec_diag(SCMatrixDiagBlock*);
    00114     virtual void process_spec_vsimp(SCVectorSimpleBlock*);
    00115     virtual void process_spec_rectsub(SCMatrixRectSubBlock*);
    00116     virtual void process_spec_ltrisub(SCMatrixLTriSubBlock*);
    00117     virtual void process_spec_diagsub(SCMatrixDiagSubBlock*);
    00118     virtual void process_spec_vsimpsub(SCVectorSimpleSubBlock*);
    00119 };
    00120
    00125 class SCElementOp2: public SavableState {
    00126   public:
    00127     SCElementOp2();
    00128     SCElementOp2(StateIn&s): SavableState(s) {}
    00129     virtual ~SCElementOp2();
    00130     virtual int has_collect();
    00131     virtual void defer_collect(int);
    00132     virtual int has_side_effects();
    00133     virtual int has_side_effects_in_arg();
    00134     virtual void collect(const Ref<MessageGrp>&);
    00135     virtual void process(SCMatrixBlockIter&,SCMatrixBlockIter&) = 0;
    00136     void process_base(SCMatrixBlock*,SCMatrixBlock*);
    00137     virtual void process_spec_rect(SCMatrixRectBlock*,SCMatrixRectBlock*);
    00138     virtual void process_spec_ltri(SCMatrixLTriBlock*,SCMatrixLTriBlock*);
    00139     virtual void process_spec_diag(SCMatrixDiagBlock*,SCMatrixDiagBlock*);
    00140     virtual void process_spec_vsimp(SCVectorSimpleBlock*,SCVectorSimpleBlock*);
    00141 };
    00142
    00147 class SCElementOp3: public SavableState {
    00148   public:
    00149     SCElementOp3();
    00150     SCElementOp3(StateIn&s): SavableState(s) {}
    00151     virtual ~SCElementOp3();
    00152     virtual int has_collect();
    00153     virtual void defer_collect(int);
    00154     virtual int has_side_effects();
    00155     virtual int has_side_effects_in_arg1();
    00156     virtual int has_side_effects_in_arg2();
    00157     virtual void collect(const Ref<MessageGrp>&);
    00158     virtual void process(SCMatrixBlockIter&,
    00159                          SCMatrixBlockIter&,
    00160                          SCMatrixBlockIter&) = 0;
    00161     void process_base(SCMatrixBlock*,SCMatrixBlock*,SCMatrixBlock*);
    00162     virtual void process_spec_rect(SCMatrixRectBlock*,
    00163                                    SCMatrixRectBlock*,
    00164                                    SCMatrixRectBlock*);
    00165     virtual void process_spec_ltri(SCMatrixLTriBlock*,
    00166                                    SCMatrixLTriBlock*,
    00167                                    SCMatrixLTriBlock*);
    00168     virtual void process_spec_diag(SCMatrixDiagBlock*,
    00169                                    SCMatrixDiagBlock*,
    00170                                    SCMatrixDiagBlock*);
    00171     virtual void process_spec_vsimp(SCVectorSimpleBlock*,
    00172                                     SCVectorSimpleBlock*,
    00173                                     SCVectorSimpleBlock*);
    00174 };
    00175
    00176 class SCElementScalarProduct: public SCElementOp2 {
    00177   private:
    00178     int deferred_;
    00179     double product;
    00180   public:
    00181     SCElementScalarProduct();
    00182     SCElementScalarProduct(StateIn&);
    00183     ~SCElementScalarProduct();
    00184     void save_data_state(StateOut&);
    00185     void process(SCMatrixBlockIter&,SCMatrixBlockIter&);
    00186     int has_collect();
    00187     void defer_collect(int);
    00188     void collect(const Ref<MessageGrp>&);
    00189     double result();
    00190     void init() { product = 0.0; }
    00191 };
    00192
    00193
    00194 class SCDestructiveElementProduct: public SCElementOp2 {
    00195   public:
    00196     SCDestructiveElementProduct();
    00197     SCDestructiveElementProduct(StateIn&);
    00198     ~SCDestructiveElementProduct();
    00199     int has_side_effects();
    00200     void save_data_state(StateOut&);
    00201     void process(SCMatrixBlockIter&,SCMatrixBlockIter&);
    00202 };
    00203
    00204 class SCElementScale: public SCElementOp {
    00205   private:
    00206     double scale;
    00207   public:
    00208     SCElementScale(double a);
    00209     SCElementScale(StateIn&);
    00210     ~SCElementScale();
    00211     int has_side_effects();
    00212     void save_data_state(StateOut&);
    00213     void process(SCMatrixBlockIter&);
    00214 };
    00215
    00216 class SCElementRandomize: public SCElementOp {
    00217   private:
    00218     double assign;
    00219   public:
    00220     SCElementRandomize();
    00221     SCElementRandomize(StateIn&);
    00222     ~SCElementRandomize();
    00223     int has_side_effects();
    00224     void save_data_state(StateOut&);
    00225     void process(SCMatrixBlockIter&);
    00226 };
    00227
    00228 class SCElementAssign: public SCElementOp {
    00229   private:
    00230     double assign;
    00231   public:
    00232     SCElementAssign(double a);
    00233     SCElementAssign(StateIn&);
    00234     ~SCElementAssign();
    00235     int has_side_effects();
    00236     void save_data_state(StateOut&);
    00237     void process(SCMatrixBlockIter&);
    00238 };
    00239
    00240 class SCElementSquareRoot: public SCElementOp {
    00241   public:
    00242     SCElementSquareRoot();
    00243     SCElementSquareRoot(double a);
    00244     SCElementSquareRoot(StateIn&);
    00245     ~SCElementSquareRoot();
    00246     int has_side_effects();
    00247     void save_data_state(StateOut&);
    00248     void process(SCMatrixBlockIter&);
    00249 };
    00250
    00251 class SCElementInvert: public SCElementOp {
    00252   private:
    00253     double threshold_;
    00254     int nbelowthreshold_;
    00255     int deferred_;
    00256   public:
    00257     SCElementInvert(double threshold = 0.0);
    00258     SCElementInvert(StateIn&);
    00259     ~SCElementInvert();
    00260     int has_side_effects();
    00261     void save_data_state(StateOut&);
    00262     void process(SCMatrixBlockIter&);
    00263     int has_collect();
    00264     void defer_collect(int);
    00265     void collect(const Ref<MessageGrp>&);
    00266     void collect(const Ref<SCElementOp>&);
    00267     int result() { return nbelowthreshold_; }
    00268 };
    00269
    00270
    00271 class SCElementScaleDiagonal: public SCElementOp {
    00272   private:
    00273     double scale_diagonal;
    00274   public:
    00275     SCElementScaleDiagonal(double a);
    00276     SCElementScaleDiagonal(StateIn&);
    00277     ~SCElementScaleDiagonal();
    00278     int has_side_effects();
    00279     void save_data_state(StateOut&);
    00280     void process(SCMatrixBlockIter&);
    00281 };
    00282
    00283 class SCElementShiftDiagonal: public SCElementOp {
    00284   private:
    00285     double shift_diagonal;
    00286   public:
    00287     SCElementShiftDiagonal(double a);
    00288     SCElementShiftDiagonal(StateIn&);
    00289     ~SCElementShiftDiagonal();
    00290     int has_side_effects();
    00291     void save_data_state(StateOut&);
    00292     void process(SCMatrixBlockIter&);
    00293 };
    00294
    00295 class SCElementMaxAbs: public SCElementOp {
    00296   private:
    00297     int deferred_;
    00298     double r;
    00299   public:
    00300     SCElementMaxAbs();
    00301     SCElementMaxAbs(StateIn&);
    00302     ~SCElementMaxAbs();
    00303     void save_data_state(StateOut&);
    00304     void process(SCMatrixBlockIter&);
    00305     int has_collect();
    00306     void defer_collect(int);
    00307     void collect(const Ref<MessageGrp>&);
    00308     void collect(const Ref<SCElementOp>&);
    00309     double result();
    00310 };
    00311
    00312
    00313 class SCElementMinAbs: public SCElementOp {
    00314   private:
    00315     int deferred_;
    00316     double r;
    00317   public:
    00318     // rinit must be greater than the magnitude of the smallest element
    00319     SCElementMinAbs(double rinit);
    00320     SCElementMinAbs(StateIn&);
    00321     ~SCElementMinAbs();
    00322     void save_data_state(StateOut&);
    00323     void process(SCMatrixBlockIter&);
    00324     int has_collect();
    00325     void defer_collect(int);
    00326     void collect(const Ref<MessageGrp>&);
    00327     void collect(const Ref<SCElementOp>&);
    00328     double result();
    00329 };
    00330
    00331
    00332 class SCElementSumAbs: public SCElementOp {
    00333   private:
    00334     int deferred_;
    00335     double r;
    00336   public:
    00337     SCElementSumAbs();
    00338     SCElementSumAbs(StateIn&);
    00339     ~SCElementSumAbs();
    00340     void save_data_state(StateOut&);
    00341     void process(SCMatrixBlockIter&);
    00342     int has_collect();
    00343     void defer_collect(int);
    00344     void collect(const Ref<MessageGrp>&);
    00345     void collect(const Ref<SCElementOp>&);
    00346     double result();
    00347     void init() { r = 0.0; }
    00348 };
    00349
    00351 class SCElementKNorm: public SCElementOp {
    00352   private:
    00353     int deferred_;
    00354     double r_;  // result
    00355     double k_;  // norm parameter
    00356   public:
    00358     SCElementKNorm(double k = 2.0);
    00359     SCElementKNorm(StateIn&);
    00360     ~SCElementKNorm();
    00361     void save_data_state(StateOut&);
    00362     void process(SCMatrixBlockIter&);
    00363     int has_collect();
    00364     void defer_collect(int);
    00365     void collect(const Ref<MessageGrp>&);
    00366     void collect(const Ref<SCElementOp>&);
    00367     double result();
    00368     void init() { r_ = 0.0; }
    00369 };
    00370
    00371 class SCElementDot: public SCElementOp {
    00372   private:
    00373     double** avects;
    00374     double** bvects;
    00375     int length;
    00376   public:
    00377     SCElementDot(StateIn&);
    00378     void save_data_state(StateOut&);
    00379     SCElementDot(double**a, double**b, int length);
    00380     void process(SCMatrixBlockIter&);
    00381     int has_side_effects();
    00382 };
    00383
    00384 class SCElementAccumulateSCMatrix: public SCElementOp {
    00385   private:
    00386     SCMatrix *m;
    00387   public:
    00388     SCElementAccumulateSCMatrix(SCMatrix *);
    00389     int has_side_effects();
    00390     void process(SCMatrixBlockIter&);
    00391 };
    00392
    00393 class SCElementAccumulateSymmSCMatrix: public SCElementOp {
    00394   private:
    00395     SymmSCMatrix *m;
    00396   public:
    00397     SCElementAccumulateSymmSCMatrix(SymmSCMatrix *);
    00398     int has_side_effects();
    00399     void process(SCMatrixBlockIter&);
    00400 };
    00401
    00402 class SCElementAccumulateDiagSCMatrix: public SCElementOp {
    00403   private:
    00404     DiagSCMatrix *m;
    00405   public:
    00406     SCElementAccumulateDiagSCMatrix(DiagSCMatrix *);
    00407     int has_side_effects();
    00408     void process(SCMatrixBlockIter&);
    00409 };
    00410
    00411 class SCElementAccumulateSCVector: public SCElementOp {
    00412   private:
    00413     SCVector *m;
    00414   public:
    00415     SCElementAccumulateSCVector(SCVector *);
    00416     int has_side_effects();
    00417     void process(SCMatrixBlockIter&);
    00418 };
    00419
    00420 }
    00421
    00422 #endif
    00423
    00424 // Local Variables:
    00425 // mode: c++
    00426 // c-file-style: "CLJ"
    00427 // End: