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 
50 typedef DataAbstract parent;
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
312  resolveToIdentity();
313 
317  void
318  makeIdentity(const DataReady_ptr& p);
319 
320 
325  resolveNodeWorker();
326 
327 };
328 
329 }
330 
331 #endif // __ESCRIPT_DATALAZY_H__
332 
#define POINTER_WRAPPER_CLASS(x)
Definition: Pointers.h:32
int m_axis_offset
Definition: DataLazy.h:230
ES_optype m_op
Definition: DataLazy.h:224
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
Definition: AbstractContinuousDomain.cpp:22
void transpose(const VEC &in, const DataTypes::ShapeType &inShape, typename VEC::size_type inOffset, VEC &ev, const DataTypes::ShapeType &evShape, typename VEC::size_type evOffset, int axis_offset)
Transpose each data point of this Data object around the given axis.
Definition: DataVectorOps.h:342
char m_readytype
Definition: DataLazy.h:228
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:42
boost::shared_ptr< DataAbstract > DataAbstract_ptr
Definition: DataAbstract.h:51
DataTypes::RealVectorType m_samples
Definition: DataLazy.h:241
DataLazy_ptr m_right
Definition: DataLazy.h:223
DataAbstract parent
Definition: DataLazy.h:50
ES_optype
Definition: ES_optype.h:26
size_t m_children
Definition: DataLazy.h:237
DataTypes::ShapeType ShapeType
Definition: DataLazy.h:51
boost::shared_ptr< const DataLazy > const_DataLazy_ptr
Definition: DataLazy.h:45
int m_transpose
Definition: DataLazy.h:231
size_t m_samplesize
Definition: DataLazy.h:226
Wraps an expression tree of other DataObjects. The data will be evaluated when required.
Definition: DataLazy.h:47
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:29
int m_SR
Definition: DataLazy.h:232
Definition: DataAbstract.h:61
boost::shared_ptr< DataReady > DataReady_ptr
Definition: DataAbstract.h:56
int * m_sampleids
Definition: DataLazy.h:240
boost::shared_ptr< DataLazy > DataLazy_ptr
Definition: DataLazy.h:42
double m_tol
Definition: DataLazy.h:235