escript
Revision_
|
00001 00002 /***************************************************************************** 00003 * 00004 * Copyright (c) 2003-2014 by University of Queensland 00005 * http://www.uq.edu.au 00006 * 00007 * Primary Business: Queensland, Australia 00008 * Licensed under the Open Software License version 3.0 00009 * http://www.opensource.org/licenses/osl-3.0.php 00010 * 00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC) 00012 * Development 2012-2013 by School of Earth Sciences 00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp) 00014 * 00015 *****************************************************************************/ 00016 00017 00018 #if !defined escript_DataLazy_20081008_H 00019 #define escript_DataLazy_20081008_H 00020 #include "system_dep.h" 00021 00022 #include "DataAbstract.h" 00023 00024 #include <string> 00025 #include <functional> 00026 00027 #include "LocalOps.h" // for tensor_binary_op 00028 #include "DataVector.h" // for ElementType 00029 00030 00031 //#define LAZY_NODE_STORAGE 00032 00033 namespace escript { 00034 00035 // For the purposes of unit testing and maintaining sanity, it is important that this enum be contiguous 00036 enum ES_optype 00037 { 00038 UNKNOWNOP=0, 00039 IDENTITY=1, 00040 ADD=2, 00041 SUB=3, 00042 MUL=4, 00043 DIV=5, 00044 POW=6, 00045 SIN=POW+1, 00046 COS=SIN+1, 00047 TAN=SIN+2, 00048 ASIN=SIN+3, 00049 ACOS=SIN+4, 00050 ATAN=SIN+5, 00051 SINH=SIN+6, 00052 COSH=SIN+7, 00053 TANH=SIN+8, 00054 ERF=SIN+9, 00055 ASINH=SIN+10, 00056 ACOSH=SIN+11, 00057 ATANH=SIN+12, 00058 LOG10=ATANH+1, 00059 LOG=LOG10+1, 00060 SIGN=LOG10+2, 00061 ABS=LOG10+3, 00062 NEG=LOG10+4, 00063 POS=LOG10+5, 00064 EXP=LOG10+6, 00065 SQRT=LOG10+7, 00066 RECIP=LOG10+8, 00067 GZ=RECIP+1, 00068 LZ=GZ+1, 00069 GEZ=GZ+2, 00070 LEZ=GZ+3, 00071 NEZ=GZ+4, 00072 EZ=GZ+5, 00073 SYM=EZ+1, 00074 NSYM=SYM+1, 00075 PROD=NSYM+1, 00076 TRANS=PROD+1, 00077 TRACE=TRANS+1, 00078 SWAP=TRACE+1, 00079 MINVAL=SWAP+1, 00080 MAXVAL=MINVAL+1, 00081 CONDEVAL=MAXVAL+1 00082 }; 00083 00084 ESCRIPT_DLL_API 00085 const std::string& 00086 opToString(ES_optype op); 00087 00097 class DataLazy; 00098 00099 typedef POINTER_WRAPPER_CLASS(DataLazy) DataLazy_ptr; 00100 typedef POINTER_WRAPPER_CLASS(const DataLazy) const_DataLazy_ptr; 00101 00102 class DataLazy : public DataAbstract 00103 { 00104 00105 typedef DataAbstract parent; 00106 typedef DataTypes::ValueType ValueType; 00107 typedef DataTypes::ShapeType ShapeType; 00108 00109 public: 00115 ESCRIPT_DLL_API 00116 DataLazy(DataAbstract_ptr p); 00117 00118 00126 ESCRIPT_DLL_API 00127 DataLazy(DataAbstract_ptr left, ES_optype op); 00128 00137 ESCRIPT_DLL_API 00138 DataLazy(DataAbstract_ptr left, ES_optype op, double tol); 00139 00148 ESCRIPT_DLL_API 00149 DataLazy(DataAbstract_ptr left, ES_optype op, int axis_offset); 00150 00151 00159 ESCRIPT_DLL_API 00160 DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op); 00161 00171 ESCRIPT_DLL_API 00172 DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op, int axis_offset, int transpose); 00173 00183 ESCRIPT_DLL_API 00184 DataLazy(DataAbstract_ptr left, ES_optype op, const int axis0, const int axis1); 00185 00192 ESCRIPT_DLL_API 00193 DataLazy(DataAbstract_ptr mask, DataAbstract_ptr left, DataAbstract_ptr right/*, double tol*/); 00194 00195 ESCRIPT_DLL_API 00196 ~DataLazy(); 00197 00202 ESCRIPT_DLL_API 00203 DataReady_ptr 00204 resolve(); 00205 00206 ESCRIPT_DLL_API 00207 std::string 00208 toString() const; 00209 00210 ESCRIPT_DLL_API 00211 DataAbstract* 00212 deepCopy(); 00213 00214 00219 ESCRIPT_DLL_API 00220 ValueType::size_type 00221 getLength() const; 00222 00223 00224 ESCRIPT_DLL_API 00225 DataAbstract* 00226 getSlice(const DataTypes::RegionType& region) const; 00227 00228 00229 DataTypes::ValueType::size_type 00230 getPointOffset(int sampleNo, 00231 int dataPointNo) const; 00232 00233 DataTypes::ValueType::size_type 00234 getPointOffset(int sampleNo, 00235 int dataPointNo); 00236 00240 ESCRIPT_DLL_API 00241 size_t 00242 getMaxSampleSize() const; 00243 00252 ESCRIPT_DLL_API 00253 const ValueType* 00254 resolveSample(int sampleNo, size_t& roffset) const; 00255 00259 ESCRIPT_DLL_API 00260 bool 00261 actsExpanded() const; 00262 00267 ESCRIPT_DLL_API 00268 virtual void 00269 setToZero(); 00270 00271 00272 ESCRIPT_DLL_API 00273 void 00274 resolveGroupWorker(std::vector<DataLazy*>& dats); 00275 00276 00277 private: 00278 mutable DataReady_ptr m_id; // For IDENTITY nodes, stores a wrapped value. 00279 mutable DataLazy_ptr m_left, m_right, m_mask; // operands for operation. 00280 mutable ES_optype m_op; // operation to perform. 00281 00282 size_t m_samplesize; // number of values required to store a sample 00283 00284 char m_readytype; // E for expanded, T for tagged, C for constant 00285 00286 int m_axis_offset; // required extra info for general tensor product 00287 int m_transpose; // offset and transpose are used for swapaxes as well 00288 int m_SL, m_SM, m_SR; // computed properties used in general tensor product 00289 00290 00291 double m_tol; // required extra info for <>0 and ==0 00292 00293 size_t m_children; 00294 size_t m_height; 00295 00296 int* m_sampleids; // may be NULL 00297 mutable DataVector m_samples; 00298 00302 void LazyNodeSetup(); 00303 00304 00305 const DataTypes::ValueType* 00306 resolveNodeUnary(int tid, int sampleNo, size_t& roffset) const; 00307 00308 00309 const DataTypes::ValueType* 00310 resolveNodeReduction(int tid, int sampleNo, size_t& roffset) const; 00311 00312 const DataTypes::ValueType* 00313 resolveNodeSample(int tid, int sampleNo, size_t& roffset) const; 00314 00315 const DataTypes::ValueType* 00316 resolveNodeBinary(int tid, int sampleNo, size_t& roffset) const; 00317 00318 const DataTypes::ValueType* 00319 resolveNodeNP1OUT(int tid, int sampleNo, size_t& roffset) const; 00320 00321 const DataTypes::ValueType* 00322 resolveNodeNP1OUT_P(int tid, int sampleNo, size_t& roffset) const; 00323 00324 const DataTypes::ValueType* 00325 resolveNodeTProd(int tid, int sampleNo, size_t& roffset) const; 00326 00327 const DataTypes::ValueType* 00328 resolveNodeNP1OUT_2P(int tid, int sampleNo, size_t& roffset) const; 00329 00330 const DataTypes::ValueType* 00331 resolveNodeCondEval(int tid, int sampleNo, size_t& roffset) const; 00332 00336 void 00337 intoString(std::ostringstream& oss) const; 00338 00342 void 00343 intoTreeString(std::ostringstream& oss,std::string indent) const; 00344 00351 void 00352 collapse() const; // converts the node into an IDENTITY node 00353 00354 00360 DataReady_ptr 00361 collapseToReady() const; 00362 00367 void 00368 resolveToIdentity(); 00369 00373 void 00374 makeIdentity(const DataReady_ptr& p); 00375 00376 00380 DataReady_ptr 00381 resolveNodeWorker(); 00382 00383 }; 00384 00385 } 00386 #endif