1 |
|
2 |
/******************************************************* |
3 |
* |
4 |
* Copyright (c) 2003-2008 by University of Queensland |
5 |
* Earth Systems Science Computational Center (ESSCC) |
6 |
* http://www.uq.edu.au/esscc |
7 |
* |
8 |
* Primary Business: Queensland, Australia |
9 |
* Licensed under the Open Software License version 3.0 |
10 |
* http://www.opensource.org/licenses/osl-3.0.php |
11 |
* |
12 |
*******************************************************/ |
13 |
|
14 |
|
15 |
#if !defined escript_DataLazy_20081008_H |
16 |
#define escript_DataLazy_20081008_H |
17 |
#include "system_dep.h" |
18 |
|
19 |
#include "DataAbstract.h" |
20 |
//#include "DataTypes.h" |
21 |
//#include "FunctionSpace.h" |
22 |
|
23 |
#include <string> |
24 |
#include <functional> |
25 |
|
26 |
#include "LocalOps.h" // for tensor_binary_op |
27 |
|
28 |
namespace escript { |
29 |
|
30 |
enum ES_optype |
31 |
{ |
32 |
UNKNOWNOP=0, |
33 |
IDENTITY=1, |
34 |
ADD=2, |
35 |
SUB=3, |
36 |
MUL=4, |
37 |
DIV=5 |
38 |
}; |
39 |
|
40 |
const std::string& |
41 |
opToString(ES_optype op); |
42 |
|
43 |
/** |
44 |
\class escript::DataLazy |
45 |
\brief Wraps an expression tree of other DataObjects. |
46 |
The values of DataPoints are computed when requested rather than all at once. |
47 |
|
48 |
NOTE: This class assumes that the Data being pointed at are immutable. |
49 |
*/ |
50 |
|
51 |
class DataLazy; |
52 |
|
53 |
typedef POINTER_WRAPPER_CLASS(DataLazy) DataLazy_ptr; |
54 |
typedef POINTER_WRAPPER_CLASS(const DataLazy) const_DataLazy_ptr; |
55 |
|
56 |
class DataLazy : public DataAbstract |
57 |
{ |
58 |
|
59 |
typedef DataAbstract parent; |
60 |
typedef DataTypes::ValueType ValueType; |
61 |
typedef DataTypes::ShapeType ShapeType; |
62 |
|
63 |
public: |
64 |
ESCRIPT_DLL_API |
65 |
DataLazy(DataAbstract_ptr p); |
66 |
|
67 |
ESCRIPT_DLL_API |
68 |
DataLazy(DataLazy_ptr left, DataLazy_ptr right, ES_optype op); |
69 |
|
70 |
ESCRIPT_DLL_API |
71 |
DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op); |
72 |
|
73 |
ESCRIPT_DLL_API |
74 |
~DataLazy(); |
75 |
|
76 |
|
77 |
|
78 |
/** |
79 |
\brief Compute all data points in the expression tree |
80 |
*/ |
81 |
ESCRIPT_DLL_API |
82 |
DataReady_ptr |
83 |
resolve(); |
84 |
|
85 |
ESCRIPT_DLL_API |
86 |
std::string |
87 |
toString() const; |
88 |
|
89 |
ESCRIPT_DLL_API |
90 |
DataAbstract* |
91 |
deepCopy(); |
92 |
|
93 |
|
94 |
/** |
95 |
\brief |
96 |
Return the number of doubles that would be stored for this Data object if it were resolved. |
97 |
*/ |
98 |
ESCRIPT_DLL_API |
99 |
ValueType::size_type |
100 |
getLength() const; |
101 |
|
102 |
|
103 |
ESCRIPT_DLL_API |
104 |
DataAbstract* |
105 |
getSlice(const DataTypes::RegionType& region) const; |
106 |
|
107 |
|
108 |
DataTypes::ValueType::size_type |
109 |
getPointOffset(int sampleNo, |
110 |
int dataPointNo) const; |
111 |
|
112 |
|
113 |
// // this is a top level function, the actual searching will be done by helper methods |
114 |
// ESCRIPT_DLL_API |
115 |
// void |
116 |
// getSample(ValueType& v, int sampleNo,size_t offset=0) const; |
117 |
|
118 |
ESCRIPT_DLL_API |
119 |
int |
120 |
getBuffsRequired() const; |
121 |
|
122 |
private: |
123 |
DataReady_ptr m_id; |
124 |
DataLazy_ptr m_left, m_right; |
125 |
ES_optype m_op; |
126 |
size_t m_length; // number of values represented by the operation |
127 |
|
128 |
int m_buffsRequired; // how many buffers are required to evaluate this expression |
129 |
size_t m_samplesize; // number of values required to store a sample |
130 |
|
131 |
const double* |
132 |
resolveSample(ValueType& v,int sampleNo, size_t offset ) const; |
133 |
|
134 |
}; |
135 |
|
136 |
} |
137 |
#endif |