|
elemop.h00001 // 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 int has_side_effects(); 00079 00082 virtual void process(SCMatrixBlockIter&) = 0; 00083 00088 void process_base(SCMatrixBlock*block); 00089 00094 virtual void process_spec_rect(SCMatrixRectBlock*); 00095 virtual void process_spec_ltri(SCMatrixLTriBlock*); 00096 virtual void process_spec_diag(SCMatrixDiagBlock*); 00097 virtual void process_spec_vsimp(SCVectorSimpleBlock*); 00098 virtual void process_spec_rectsub(SCMatrixRectSubBlock*); 00099 virtual void process_spec_ltrisub(SCMatrixLTriSubBlock*); 00100 virtual void process_spec_diagsub(SCMatrixDiagSubBlock*); 00101 virtual void process_spec_vsimpsub(SCVectorSimpleSubBlock*); 00102 }; 00103 00108 class SCElementOp2: public SavableState { 00109 public: 00110 SCElementOp2(); 00111 SCElementOp2(StateIn&s): SavableState(s) {} 00112 virtual ~SCElementOp2(); 00113 virtual int has_collect(); 00114 virtual void defer_collect(int); 00115 virtual int has_side_effects(); 00116 virtual int has_side_effects_in_arg(); 00117 virtual void collect(const Ref<MessageGrp>&); 00118 virtual void process(SCMatrixBlockIter&,SCMatrixBlockIter&) = 0; 00119 void process_base(SCMatrixBlock*,SCMatrixBlock*); 00120 virtual void process_spec_rect(SCMatrixRectBlock*,SCMatrixRectBlock*); 00121 virtual void process_spec_ltri(SCMatrixLTriBlock*,SCMatrixLTriBlock*); 00122 virtual void process_spec_diag(SCMatrixDiagBlock*,SCMatrixDiagBlock*); 00123 virtual void process_spec_vsimp(SCVectorSimpleBlock*,SCVectorSimpleBlock*); 00124 }; 00125 00130 class SCElementOp3: public SavableState { 00131 public: 00132 SCElementOp3(); 00133 SCElementOp3(StateIn&s): SavableState(s) {} 00134 virtual ~SCElementOp3(); 00135 virtual int has_collect(); 00136 virtual void defer_collect(int); 00137 virtual int has_side_effects(); 00138 virtual int has_side_effects_in_arg1(); 00139 virtual int has_side_effects_in_arg2(); 00140 virtual void collect(const Ref<MessageGrp>&); 00141 virtual void process(SCMatrixBlockIter&, 00142 SCMatrixBlockIter&, 00143 SCMatrixBlockIter&) = 0; 00144 void process_base(SCMatrixBlock*,SCMatrixBlock*,SCMatrixBlock*); 00145 virtual void process_spec_rect(SCMatrixRectBlock*, 00146 SCMatrixRectBlock*, 00147 SCMatrixRectBlock*); 00148 virtual void process_spec_ltri(SCMatrixLTriBlock*, 00149 SCMatrixLTriBlock*, 00150 SCMatrixLTriBlock*); 00151 virtual void process_spec_diag(SCMatrixDiagBlock*, 00152 SCMatrixDiagBlock*, 00153 SCMatrixDiagBlock*); 00154 virtual void process_spec_vsimp(SCVectorSimpleBlock*, 00155 SCVectorSimpleBlock*, 00156 SCVectorSimpleBlock*); 00157 }; 00158 00159 class SCElementScalarProduct: public SCElementOp2 { 00160 private: 00161 int deferred_; 00162 double product; 00163 public: 00164 SCElementScalarProduct(); 00165 SCElementScalarProduct(StateIn&); 00166 ~SCElementScalarProduct(); 00167 void save_data_state(StateOut&); 00168 void process(SCMatrixBlockIter&,SCMatrixBlockIter&); 00169 int has_collect(); 00170 void defer_collect(int); 00171 void collect(const Ref<MessageGrp>&); 00172 double result(); 00173 void init() { product = 0.0; } 00174 }; 00175 00176 00177 class SCDestructiveElementProduct: public SCElementOp2 { 00178 public: 00179 SCDestructiveElementProduct(); 00180 SCDestructiveElementProduct(StateIn&); 00181 ~SCDestructiveElementProduct(); 00182 int has_side_effects(); 00183 void save_data_state(StateOut&); 00184 void process(SCMatrixBlockIter&,SCMatrixBlockIter&); 00185 }; 00186 00187 class SCElementScale: public SCElementOp { 00188 private: 00189 double scale; 00190 public: 00191 SCElementScale(double a); 00192 SCElementScale(StateIn&); 00193 ~SCElementScale(); 00194 int has_side_effects(); 00195 void save_data_state(StateOut&); 00196 void process(SCMatrixBlockIter&); 00197 }; 00198 00199 class SCElementRandomize: public SCElementOp { 00200 private: 00201 double assign; 00202 public: 00203 SCElementRandomize(); 00204 SCElementRandomize(StateIn&); 00205 ~SCElementRandomize(); 00206 int has_side_effects(); 00207 void save_data_state(StateOut&); 00208 void process(SCMatrixBlockIter&); 00209 }; 00210 00211 class SCElementAssign: public SCElementOp { 00212 private: 00213 double assign; 00214 public: 00215 SCElementAssign(double a); 00216 SCElementAssign(StateIn&); 00217 ~SCElementAssign(); 00218 int has_side_effects(); 00219 void save_data_state(StateOut&); 00220 void process(SCMatrixBlockIter&); 00221 }; 00222 00223 class SCElementSquareRoot: public SCElementOp { 00224 public: 00225 SCElementSquareRoot(); 00226 SCElementSquareRoot(double a); 00227 SCElementSquareRoot(StateIn&); 00228 ~SCElementSquareRoot(); 00229 int has_side_effects(); 00230 void save_data_state(StateOut&); 00231 void process(SCMatrixBlockIter&); 00232 }; 00233 00234 class SCElementInvert: public SCElementOp { 00235 private: 00236 double threshold_; 00237 int nbelowthreshold_; 00238 int deferred_; 00239 public: 00240 SCElementInvert(double threshold = 0.0); 00241 SCElementInvert(StateIn&); 00242 ~SCElementInvert(); 00243 int has_side_effects(); 00244 void save_data_state(StateOut&); 00245 void process(SCMatrixBlockIter&); 00246 int has_collect(); 00247 void defer_collect(int); 00248 void collect(const Ref<MessageGrp>&); 00249 int result() { return nbelowthreshold_; } 00250 }; 00251 00252 00253 class SCElementScaleDiagonal: public SCElementOp { 00254 private: 00255 double scale_diagonal; 00256 public: 00257 SCElementScaleDiagonal(double a); 00258 SCElementScaleDiagonal(StateIn&); 00259 ~SCElementScaleDiagonal(); 00260 int has_side_effects(); 00261 void save_data_state(StateOut&); 00262 void process(SCMatrixBlockIter&); 00263 }; 00264 00265 class SCElementShiftDiagonal: public SCElementOp { 00266 private: 00267 double shift_diagonal; 00268 public: 00269 SCElementShiftDiagonal(double a); 00270 SCElementShiftDiagonal(StateIn&); 00271 ~SCElementShiftDiagonal(); 00272 int has_side_effects(); 00273 void save_data_state(StateOut&); 00274 void process(SCMatrixBlockIter&); 00275 }; 00276 00277 class SCElementMaxAbs: public SCElementOp { 00278 private: 00279 int deferred_; 00280 double r; 00281 public: 00282 SCElementMaxAbs(); 00283 SCElementMaxAbs(StateIn&); 00284 ~SCElementMaxAbs(); 00285 void save_data_state(StateOut&); 00286 void process(SCMatrixBlockIter&); 00287 int has_collect(); 00288 void defer_collect(int); 00289 void collect(const Ref<MessageGrp>&); 00290 double result(); 00291 }; 00292 00293 00294 class SCElementMinAbs: public SCElementOp { 00295 private: 00296 int deferred_; 00297 double r; 00298 public: 00299 // rinit must be greater than the magnitude of the smallest element 00300 SCElementMinAbs(double rinit); 00301 SCElementMinAbs(StateIn&); 00302 ~SCElementMinAbs(); 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 double result(); 00309 }; 00310 00311 00312 class SCElementSumAbs: public SCElementOp { 00313 private: 00314 int deferred_; 00315 double r; 00316 public: 00317 SCElementSumAbs(); 00318 SCElementSumAbs(StateIn&); 00319 ~SCElementSumAbs(); 00320 void save_data_state(StateOut&); 00321 void process(SCMatrixBlockIter&); 00322 int has_collect(); 00323 void defer_collect(int); 00324 void collect(const Ref<MessageGrp>&); 00325 double result(); 00326 void init() { r = 0.0; } 00327 }; 00328 00329 00330 class SCElementDot: public SCElementOp { 00331 private: 00332 double** avects; 00333 double** bvects; 00334 int length; 00335 public: 00336 SCElementDot(StateIn&); 00337 void save_data_state(StateOut&); 00338 SCElementDot(double**a, double**b, int length); 00339 void process(SCMatrixBlockIter&); 00340 int has_side_effects(); 00341 }; 00342 00343 class SCElementAccumulateSCMatrix: public SCElementOp { 00344 private: 00345 SCMatrix *m; 00346 public: 00347 SCElementAccumulateSCMatrix(SCMatrix *); 00348 int has_side_effects(); 00349 void process(SCMatrixBlockIter&); 00350 }; 00351 00352 class SCElementAccumulateSymmSCMatrix: public SCElementOp { 00353 private: 00354 SymmSCMatrix *m; 00355 public: 00356 SCElementAccumulateSymmSCMatrix(SymmSCMatrix *); 00357 int has_side_effects(); 00358 void process(SCMatrixBlockIter&); 00359 }; 00360 00361 class SCElementAccumulateDiagSCMatrix: public SCElementOp { 00362 private: 00363 DiagSCMatrix *m; 00364 public: 00365 SCElementAccumulateDiagSCMatrix(DiagSCMatrix *); 00366 int has_side_effects(); 00367 void process(SCMatrixBlockIter&); 00368 }; 00369 00370 class SCElementAccumulateSCVector: public SCElementOp { 00371 private: 00372 SCVector *m; 00373 public: 00374 SCElementAccumulateSCVector(SCVector *); 00375 int has_side_effects(); 00376 void process(SCMatrixBlockIter&); 00377 }; 00378 00379 } 00380 00381 #endif 00382 00383 // Local Variables: 00384 // mode: c++ 00385 // c-file-style: "CLJ" 00386 // End: Generated at Fri Jan 10 08:14:08 2003 for MPQC 2.1.3 using the documentation package Doxygen 1.2.14. |