escript  Revision_
DataLazy.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 #ifndef __ESCRIPT_DATALAZY_H__
18 #define __ESCRIPT_DATALAZY_H__
19 
20 #include "system_dep.h"
21 #include "DataAbstract.h"
22 #include "ArrayOps.h" // for tensor_binary_op
23 #include "DataVector.h" // for ElementType
24 #include "ES_optype.h"
25 
26 #include <string>
27 
28 //#define LAZY_NODE_STORAGE
29 
30 namespace escript {
31 
32 
42 class DataLazy;
43 
46 
47 class DataLazy : public DataAbstract
48 {
49 
52 
53 public:
61 
62 
72 
82  DataLazy(DataAbstract_ptr left, ES_optype op, double tol);
83 
93  DataLazy(DataAbstract_ptr left, ES_optype op, int axis_offset);
94 
95 
105 
116  DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op, int axis_offset, int transpose);
117 
128  DataLazy(DataAbstract_ptr left, ES_optype op, const int axis0, const int axis1);
129 
137  DataLazy(DataAbstract_ptr mask, DataAbstract_ptr left, DataAbstract_ptr right/*, double tol*/);
138 
140  ~DataLazy();
141 
148  resolve();
149 
151  std::string
152  toString() const;
153 
155  DataAbstract*
156  deepCopy() const;
157 
158 
165  getLength() const;
166 
167 
169  DataAbstract*
170  getSlice(const DataTypes::RegionType& region) const;
171 
172 
174  getPointOffset(int sampleNo,
175  int dataPointNo) const;
176 
178  getPointOffset(int sampleNo,
179  int dataPointNo);
180 
185  size_t
186  getMaxSampleSize() const;
187 
198  resolveSample(int sampleNo, size_t& roffset) const;
199 
204  bool
205  actsExpanded() const;
206 
212  virtual void
213  setToZero();
214 
215 
217  void
218  resolveGroupWorker(std::vector<DataLazy*>& dats);
219 
220 
221 private:
222  mutable DataReady_ptr m_id; // For IDENTITY nodes, stores a wrapped value.
223  mutable DataLazy_ptr m_left, m_right, m_mask; // operands for operation.
224  mutable ES_optype m_op; // operation to perform.
225 
226  size_t m_samplesize; // number of values required to store a sample
227 
228  char m_readytype; // E for expanded, T for tagged, C for constant
229 
230  int m_axis_offset; // required extra info for general tensor product
231  int m_transpose; // offset and transpose are used for swapaxes as well
232  int m_SL, m_SM, m_SR; // computed properties used in general tensor product
233 
234 
235  double m_tol; // required extra info for <>0 and ==0
236 
237  size_t m_children;
238  size_t m_height;
239 
240  int* m_sampleids; // may be NULL
242 
246  void LazyNodeSetup();
247 
248 
250  resolveNodeUnary(int tid, int sampleNo, size_t& roffset) const;
251 
252 
254  resolveNodeReduction(int tid, int sampleNo, size_t& roffset) const;
255 
257  resolveNodeSample(int tid, int sampleNo, size_t& roffset) const;
258 
260  resolveNodeBinary(int tid, int sampleNo, size_t& roffset) const;
261 
263  resolveNodeNP1OUT(int tid, int sampleNo, size_t& roffset) const;
264 
266  resolveNodeNP1OUT_P(int tid, int sampleNo, size_t& roffset) const;
267 
269  resolveNodeTProd(int tid, int sampleNo, size_t& roffset) const;
270 
272  resolveNodeNP1OUT_2P(int tid, int sampleNo, size_t& roffset) const;
273 
275  resolveNodeCondEval(int tid, int sampleNo, size_t& roffset) const;
276 
280  void
281  intoString(std::ostringstream& oss) const;
282 
286  void
287  intoTreeString(std::ostringstream& oss,std::string indent) const;
288 
295  void
296  collapse() const; // converts the node into an IDENTITY node
297 
298 
305  collapseToReady() const;
306 
311  void
313 
317  void
318  makeIdentity(const DataReady_ptr& p);
319 
320 
326 
327 };
328 
329 }
330 
331 #endif // __ESCRIPT_DATALAZY_H__
332 
void LazyNodeSetup()
Definition: DataLazy.cpp:388
void resolveToIdentity()
resolve the expression can store it in the current node The current node will be converted to an iden...
Definition: DataLazy.cpp:1560
#define POINTER_WRAPPER_CLASS(x)
Definition: Pointers.h:32
std::string toString() const
Write the data as a string.
Definition: DataLazy.cpp:1733
const DataTypes::RealVectorType * resolveNodeCondEval(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1202
int m_axis_offset
Definition: DataLazy.h:230
ES_optype m_op
Definition: DataLazy.h:224
DataLazy_ptr m_left
Definition: DataLazy.h:223
size_t m_height
Definition: DataLazy.h:238
DataReady_ptr m_id
Definition: DataLazy.h:222
DataTypes::vec_size_type size_type
Definition: DataVectorAlt.h:49
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:43
size_t getMaxSampleSize() const
Definition: AbstractContinuousDomain.cpp:22
const DataTypes::RealVectorType * resolveNodeSample(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:938
int m_SM
Definition: DataLazy.h:232
DataTypes::RealVectorType::size_type getPointOffset(int sampleNo, int dataPointNo) const
Return the offset for the given sample. This returns the offset for the given point into the containe...
Definition: DataLazy.cpp:1948
DataReady_ptr resolve()
Evaluate the lazy expression.
Definition: DataLazy.cpp:1587
char m_readytype
Definition: DataLazy.h:228
DataTypes::RealVectorType::size_type getLength() const
This method throws an exception. It does not really make sense to ask this question of lazy data...
Definition: DataLazy.cpp:1907
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:42
boost::shared_ptr< DataAbstract > DataAbstract_ptr
Definition: DataAbstract.h:51
DataAbstract * deepCopy() const
Return a deep copy of the current object.
Definition: DataLazy.cpp:1880
DataReady_ptr resolveNodeWorker()
resolve to a ReadyData object using storage at nodes
Definition: DataLazy.cpp:1676
DataTypes::RealVectorType m_samples
Definition: DataLazy.h:241
const DataTypes::RealVectorType * resolveNodeBinary(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1246
~DataLazy()
Definition: DataLazy.cpp:751
void collapse() const
Converts the DataLazy into an IDENTITY storing the value of the expression. This method uses the orig...
Definition: DataLazy.cpp:921
DataLazy_ptr m_right
Definition: DataLazy.h:223
void makeIdentity(const DataReady_ptr &p)
helper method for resolveToIdentity and the identity constructor
Definition: DataLazy.cpp:1568
void intoString(std::ostringstream &oss) const
Definition: DataLazy.cpp:1754
DataReady_ptr collapseToReady() const
Evaluates the expression using methods on Data. This does the work for the collapse method...
Definition: DataLazy.cpp:763
DataAbstract parent
Definition: DataLazy.h:50
ES_optype
Definition: ES_optype.h:26
const DataTypes::RealVectorType * resolveSample(int sampleNo, size_t &roffset) const
Compute the value of the expression for the given sample.
Definition: DataLazy.cpp:1532
const DataTypes::RealVectorType * resolveNodeNP1OUT_P(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1118
int m_SL
Definition: DataLazy.h:232
size_t m_children
Definition: DataLazy.h:237
const DataTypes::RealVectorType * resolveNodeUnary(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:987
DataTypes::ShapeType ShapeType
Definition: DataLazy.h:51
void intoTreeString(std::ostringstream &oss, std::string indent) const
Definition: DataLazy.cpp:1823
const DataTypes::RealVectorType * resolveNodeTProd(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1473
boost::shared_ptr< const DataLazy > const_DataLazy_ptr
Definition: DataLazy.h:45
const DataTypes::RealVectorType * resolveNodeNP1OUT(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1073
const DataTypes::RealVectorType * resolveNodeReduction(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1021
int m_transpose
Definition: DataLazy.h:231
size_t m_samplesize
Definition: DataLazy.h:226
virtual void transpose(DataAbstract *ev, int axis_offset)
Transpose each data point of this Data object around the given axis.
Definition: DataAbstract.cpp:245
Wraps an expression tree of other DataObjects. The data will be evaluated when required.
Definition: DataLazy.h:47
bool actsExpanded() const
if resolve() was called would it produce expanded data.
Definition: DataLazy.cpp:1993
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:29
int m_SR
Definition: DataLazy.h:232
virtual void setToZero()
Produces an IDENTITY DataLazy containing zero. The result will have the same shape and functionspace ...
Definition: DataLazy.cpp:1978
const DataTypes::RealVectorType * resolveNodeNP1OUT_2P(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1166
Definition: DataAbstract.h:61
void resolveGroupWorker(std::vector< DataLazy *> &dats)
Definition: DataLazy.cpp:1596
boost::shared_ptr< DataReady > DataReady_ptr
Definition: DataAbstract.h:56
int * m_sampleids
Definition: DataLazy.h:240
DataLazy(DataAbstract_ptr p)
Create an IDENTITY DataLazy for the given DataAbstract.
Definition: DataLazy.cpp:407
DataLazy_ptr m_mask
Definition: DataLazy.h:223
DataAbstract * getSlice(const DataTypes::RegionType &region) const
Return the given slice from this object.
Definition: DataLazy.cpp:1914
boost::shared_ptr< DataLazy > DataLazy_ptr
Definition: DataLazy.h:42
double m_tol
Definition: DataLazy.h:235