00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #if !defined escript_DataLazy_20081008_H
00016 #define escript_DataLazy_20081008_H
00017 #include "system_dep.h"
00018
00019 #include "DataAbstract.h"
00020
00021 #include <string>
00022 #include <functional>
00023
00024 #include "LocalOps.h"
00025 #include "BufferGroup.h"
00026 #include "DataVector.h"
00027
00028
00029 #define LAZY_NODE_STORAGE
00030
00031 namespace escript {
00032
00033
00034 enum ES_optype
00035 {
00036 UNKNOWNOP=0,
00037 IDENTITY=1,
00038 ADD=2,
00039 SUB=3,
00040 MUL=4,
00041 DIV=5,
00042 POW=6,
00043 SIN=POW+1,
00044 COS=SIN+1,
00045 TAN=SIN+2,
00046 ASIN=SIN+3,
00047 ACOS=SIN+4,
00048 ATAN=SIN+5,
00049 SINH=SIN+6,
00050 COSH=SIN+7,
00051 TANH=SIN+8,
00052 ERF=SIN+9,
00053 ASINH=SIN+10,
00054 ACOSH=SIN+11,
00055 ATANH=SIN+12,
00056 LOG10=ATANH+1,
00057 LOG=LOG10+1,
00058 SIGN=LOG10+2,
00059 ABS=LOG10+3,
00060 NEG=LOG10+4,
00061 POS=LOG10+5,
00062 EXP=LOG10+6,
00063 SQRT=LOG10+7,
00064 RECIP=LOG10+8,
00065 GZ=RECIP+1,
00066 LZ=GZ+1,
00067 GEZ=GZ+2,
00068 LEZ=GZ+3,
00069 NEZ=GZ+4,
00070 EZ=GZ+5,
00071 SYM=EZ+1,
00072 NSYM=SYM+1,
00073 PROD=NSYM+1,
00074 TRANS=PROD+1,
00075 TRACE=TRANS+1,
00076 SWAP=TRACE+1
00077 };
00078
00079 ESCRIPT_DLL_API
00080 const std::string&
00081 opToString(ES_optype op);
00082
00092 class DataLazy;
00093
00094 typedef POINTER_WRAPPER_CLASS(DataLazy) DataLazy_ptr;
00095 typedef POINTER_WRAPPER_CLASS(const DataLazy) const_DataLazy_ptr;
00096
00097 class DataLazy : public DataAbstract
00098 {
00099
00100 typedef DataAbstract parent;
00101 typedef DataTypes::ValueType ValueType;
00102 typedef DataTypes::ShapeType ShapeType;
00103
00104 public:
00110 ESCRIPT_DLL_API
00111 DataLazy(DataAbstract_ptr p);
00112
00113
00121 ESCRIPT_DLL_API
00122 DataLazy(DataAbstract_ptr left, ES_optype op);
00123
00132 ESCRIPT_DLL_API
00133 DataLazy(DataAbstract_ptr left, ES_optype op, double tol);
00134
00143 ESCRIPT_DLL_API
00144 DataLazy(DataAbstract_ptr left, ES_optype op, int axis_offset);
00145
00146
00154 ESCRIPT_DLL_API
00155 DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op);
00156
00166 ESCRIPT_DLL_API
00167 DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op, int axis_offset, int transpose);
00168
00178 ESCRIPT_DLL_API
00179 DataLazy(DataAbstract_ptr left, ES_optype op, const int axis0, const int axis1);
00180
00181 ESCRIPT_DLL_API
00182 ~DataLazy();
00183
00188 ESCRIPT_DLL_API
00189 DataReady_ptr
00190 resolve();
00191
00192 ESCRIPT_DLL_API
00193 std::string
00194 toString() const;
00195
00196 ESCRIPT_DLL_API
00197 DataAbstract*
00198 deepCopy();
00199
00200
00205 ESCRIPT_DLL_API
00206 ValueType::size_type
00207 getLength() const;
00208
00209
00210 ESCRIPT_DLL_API
00211 DataAbstract*
00212 getSlice(const DataTypes::RegionType& region) const;
00213
00214
00215 DataTypes::ValueType::size_type
00216 getPointOffset(int sampleNo,
00217 int dataPointNo) const;
00218
00219 DataTypes::ValueType::size_type
00220 getPointOffset(int sampleNo,
00221 int dataPointNo);
00222
00223
00227 ESCRIPT_DLL_API
00228 int
00229 getBuffsRequired() const;
00230
00234 ESCRIPT_DLL_API
00235 size_t
00236 getMaxSampleSize() const;
00237
00241 ESCRIPT_DLL_API
00242 size_t
00243 getSampleBufferSize() const;
00244
00254 ESCRIPT_DLL_API
00255 const ValueType*
00256 resolveSample(BufferGroup& bg, int sampleNo, size_t& roffset);
00257
00261 ESCRIPT_DLL_API
00262 bool
00263 actsExpanded() const;
00264
00269 ESCRIPT_DLL_API
00270 virtual void
00271 setToZero();
00272
00273 private:
00274 DataReady_ptr m_id;
00275 DataLazy_ptr m_left, m_right;
00276 ES_optype m_op;
00277
00278 int m_buffsRequired;
00279 size_t m_samplesize;
00280
00281 char m_readytype;
00282
00283 int m_axis_offset;
00284 int m_transpose;
00285 int m_SL, m_SM, m_SR;
00286
00287
00288 double m_tol;
00289
00290 size_t m_maxsamplesize;
00291 size_t m_children;
00292 size_t m_height;
00293
00294 #ifdef LAZY_NODE_STORAGE
00295
00296 int* m_sampleids;
00297 DataVector m_samples;
00298
00299 #endif // LAZY_NODE_STORAGE
00300
00301
00302 #ifdef LAZY_NODE_STORAGE
00303
00306 void LazyNodeSetup();
00307
00308
00309 const DataTypes::ValueType*
00310 resolveNodeUnary(int tid, int sampleNo, size_t& roffset);
00311
00312 const DataTypes::ValueType*
00313 resolveNodeSample(int tid, int sampleNo, size_t& roffset);
00314
00315 const DataTypes::ValueType*
00316 resolveNodeBinary(int tid, int sampleNo, size_t& roffset);
00317
00318 const DataTypes::ValueType*
00319 resolveNodeNP1OUT(int tid, int sampleNo, size_t& roffset);
00320
00321 const DataTypes::ValueType*
00322 resolveNodeNP1OUT_P(int tid, int sampleNo, size_t& roffset);
00323
00324 const DataTypes::ValueType*
00325 resolveNodeTProd(int tid, int sampleNo, size_t& roffset);
00326
00327 const DataTypes::ValueType*
00328 resolveNodeNP1OUT_2P(int tid, int sampleNo, size_t& roffset);
00329
00330 #endif
00331
00335 void
00336 intoString(std::ostringstream& oss) const;
00337
00344 void
00345 collapse();
00346
00347
00353 DataReady_ptr
00354 collapseToReady();
00355
00360 void
00361 resolveToIdentity();
00362
00366 void
00367 makeIdentity(const DataReady_ptr& p);
00368
00372 DataReady_ptr
00373 resolveVectorWorker();
00374
00375 #ifdef LAZY_NODE_STORAGE
00376
00379 DataReady_ptr
00380 resolveNodeWorker();
00381 #endif
00382
00393 ESCRIPT_DLL_API
00394 const ValueType*
00395 resolveVectorSample(ValueType& v, size_t offset, int sampleNo, size_t& roffset);
00396
00397
00410 ValueType*
00411 resolveUnary(ValueType& v, size_t offset,int sampleNo, size_t& roffset) const;
00412
00430 ValueType*
00431 resolveNP1OUT(ValueType& v, size_t offset, int sampleNo, size_t& roffset) const;
00432
00445 DataTypes::ValueType*
00446 resolveNP1OUT_P(ValueType& v, size_t offset, int sampleNo, size_t& roffset) const;
00447
00460 DataTypes::ValueType*
00461 resolveNP1OUT_2P(ValueType& v, size_t offset, int sampleNo, size_t& roffset) const;
00462
00463
00476 ValueType*
00477 resolveBinary(ValueType& v, size_t offset,int sampleNo, size_t& roffset) const;
00478
00491 DataTypes::ValueType*
00492 resolveTProd(ValueType& v, size_t offset, int sampleNo, size_t& roffset) const;
00493
00494 };
00495
00496 }
00497 #endif