escript  Revision_
DataLazy.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2018 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 
159  DataAbstract*
160  zeroedCopy() const;
161 
168  getLength() const;
169 
170 
172  DataAbstract*
173  getSlice(const DataTypes::RegionType& region) const;
174 
175 
177  getPointOffset(int sampleNo,
178  int dataPointNo) const;
179 
181  getPointOffset(int sampleNo,
182  int dataPointNo);
183 
188  size_t
189  getMaxSampleSize() const;
190 
201  resolveSample(int sampleNo, size_t& roffset) const;
202 
205  resolveTypedSample(int sampleNo, size_t& roffset, DataTypes::cplx_t dummy) const;
206 
209  resolveTypedSample(int sampleNo, size_t& roffset, DataTypes::real_t dummy) const;
210 
211 
216  bool
217  actsExpanded() const;
218 
224  virtual void
225  setToZero();
226 
227 
229  void
230  resolveGroupWorker(std::vector<DataLazy*>& dats);
231 
232 
233 private:
234  int* m_sampleids; // may be NULL
237 
238  mutable DataReady_ptr m_id; // For IDENTITY nodes, stores a wrapped value.
239  mutable DataLazy_ptr m_left, m_right, m_mask; // operands for operation.
240  mutable ES_optype m_op; // operation to perform.
241  mutable ES_opgroup m_opgroup; // type of operation to perform
242 
243  size_t m_samplesize; // number of values required to store a sample
244 
245  char m_readytype; // E for expanded, T for tagged, C for constant
246 
247  int m_axis_offset; // required extra info for general tensor product
248  int m_transpose; // offset and transpose are used for swapaxes as well
249  int m_SL, m_SM, m_SR; // computed properties used in general tensor product
250 
251 
252  double m_tol; // required extra info for <>0 and ==0
253 
254  mutable size_t m_children;
255  mutable size_t m_height;
256 
257 
258 
262  void LazyNodeSetup();
263 
264 
266  resolveNodeUnary(int tid, int sampleNo, size_t& roffset) const;
267 
269  resolveNodeUnaryCplx(int tid, int sampleNo, size_t& roffset) const;
270 
271 
273  resolveNodeReduction(int tid, int sampleNo, size_t& roffset) const;
274 
276  resolveNodeReductionCplx(int tid, int sampleNo, size_t& roffset) const;
277 
279  resolveNodeSample(int tid, int sampleNo, size_t& roffset) const;
280 
282  resolveNodeSampleCplx(int tid, int sampleNo, size_t& roffset) const;
283 
285  resolveNodeBinary(int tid, int sampleNo, size_t& roffset) const;
286 
288  resolveNodeBinaryCplx(int tid, int sampleNo, size_t& roffset) const;
289 
290 
292  resolveNodeNP1OUT(int tid, int sampleNo, size_t& roffset) const;
293 
295  resolveNodeNP1OUTCplx(int tid, int sampleNo, size_t& roffset) const;
296 
298  resolveNodeNP1OUT_P(int tid, int sampleNo, size_t& roffset) const;
299 
301  resolveNodeNP1OUT_PCplx(int tid, int sampleNo, size_t& roffset) const;
302 
303 
305  resolveNodeTProd(int tid, int sampleNo, size_t& roffset) const;
306 
308  resolveNodeTProdCplx(int tid, int sampleNo, size_t& roffset) const;
309 
310 
312  resolveNodeNP1OUT_2P(int tid, int sampleNo, size_t& roffset) const;
313 
315  resolveNodeNP1OUT_2PCplx(int tid, int sampleNo, size_t& roffset) const;
316 
318  resolveNodeCondEval(int tid, int sampleNo, size_t& roffset) const;
319 
321  resolveNodeCondEvalCplx(int tid, int sampleNo, size_t& roffset) const;
322 
323 
325  resolveNodeUnary_C(int tid, int sampleNo, size_t& roffset) const;
326 
330  void
331  intoString(std::ostringstream& oss) const;
332 
336  void
337  intoTreeString(std::ostringstream& oss,std::string indent) const;
338 
345  void
346  collapse() const; // converts the node into an IDENTITY node
347 
348 
355  collapseToReady() const;
356 
361  void
363 
367  void
368  makeIdentity(const DataReady_ptr& p);
369 
370 
376 
379 
380 };
381 
382 // If an expression is already complex, return the same expression.
383 // Otherwise, return the old expression with a promote operation
384 // above it
385 DataLazy_ptr makePromote(DataLazy_ptr p);
386 
387 }
388 
389 #endif // __ESCRIPT_DATALAZY_H__
390 
void LazyNodeSetup()
Definition: DataLazy.cpp:407
const DataTypes::CplxVectorType * resolveNodeTProdCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:2277
void resolveToIdentity()
resolve the expression can store it in the current node The current node will be converted to an iden...
Definition: DataLazy.cpp:2417
const DataTypes::CplxVectorType * resolveNodeNP1OUT_PCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1573
#define POINTER_WRAPPER_CLASS(x)
Definition: Pointers.h:32
std::string toString() const
Write the data as a string.
Definition: DataLazy.cpp:2659
const DataTypes::CplxVectorType * resolveNodeReductionCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1371
const DataTypes::RealVectorType * resolveNodeCondEval(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1693
int m_axis_offset
Definition: DataLazy.h:247
DataReady_ptr resolveNodeWorkerCplx()
Definition: DataLazy.cpp:2601
ES_optype m_op
Definition: DataLazy.h:240
DataLazy_ptr m_left
Definition: DataLazy.h:239
size_t m_height
Definition: DataLazy.h:255
DataReady_ptr m_id
Definition: DataLazy.h:238
const DataTypes::CplxVectorType * resolveNodeNP1OUTCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1465
DataLazy_ptr makePromote(DataLazy_ptr p)
Definition: DataLazy.cpp:114
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:1118
int m_SM
Definition: DataLazy.h:249
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:2955
DataReady_ptr resolve()
Evaluate the lazy expression.
Definition: DataLazy.cpp:2454
char m_readytype
Definition: DataLazy.h:245
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:2914
DataTypes::RealVectorType m_samples_r
Definition: DataLazy.h:235
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:2878
DataReady_ptr resolveNodeWorker()
resolve to a ReadyData object using storage at nodes
Definition: DataLazy.cpp:2543
const DataTypes::CplxVectorType * resolveNodeUnaryCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1273
const DataTypes::RealVectorType * resolveNodeBinary(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1773
~DataLazy()
Definition: DataLazy.cpp:918
void collapse() const
Converts the DataLazy into an IDENTITY storing the value of the expression. This method uses the orig...
Definition: DataLazy.cpp:1099
DataLazy_ptr m_right
Definition: DataLazy.h:239
const DataTypes::CplxVectorType * resolveNodeUnary_C(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1436
const DataTypes::CplxVectorType * resolveNodeCondEvalCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1728
void makeIdentity(const DataReady_ptr &p)
helper method for resolveToIdentity and the identity constructor
Definition: DataLazy.cpp:2433
void intoString(std::ostringstream &oss) const
Definition: DataLazy.cpp:2680
ES_opgroup m_opgroup
Definition: DataLazy.h:241
DataReady_ptr collapseToReady() const
Evaluates the expression using methods on Data. This does the work for the collapse method...
Definition: DataLazy.cpp:930
const DataTypes::CplxVectorType * resolveTypedSample(int sampleNo, size_t &roffset, DataTypes::cplx_t dummy) const
Definition: DataLazy.cpp:2388
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:2335
const DataTypes::RealVectorType * resolveNodeNP1OUT_P(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1526
int m_SL
Definition: DataLazy.h:249
size_t m_children
Definition: DataLazy.h:254
const DataTypes::RealVectorType * resolveNodeUnary(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1224
DataTypes::ShapeType ShapeType
Definition: DataLazy.h:51
const DataTypes::CplxVectorType * resolveNodeBinaryCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1996
DataAbstract * zeroedCopy() const
Return an object with the same type, domain (and tags if appropriate) as this, but all values are zer...
Definition: DataLazy.cpp:2902
void intoTreeString(std::ostringstream &oss, std::string indent) const
Definition: DataLazy.cpp:2788
const DataTypes::RealVectorType * resolveNodeTProd(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:2223
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:1390
const DataTypes::RealVectorType * resolveNodeReduction(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1319
int m_transpose
Definition: DataLazy.h:248
size_t m_samplesize
Definition: DataLazy.h:243
ES_opgroup
Definition: ES_optype.h:88
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
std::complex< real_t > cplx_t
complex data type
Definition: DataTypes.h:53
bool actsExpanded() const
if resolve() was called would it produce expanded data.
Definition: DataLazy.cpp:3000
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:29
int m_SR
Definition: DataLazy.h:249
virtual void setToZero()
Produces an IDENTITY DataLazy containing zero. The result will have the same shape and functionspace ...
Definition: DataLazy.cpp:2985
const DataTypes::RealVectorType * resolveNodeNP1OUT_2P(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1620
Definition: DataAbstract.h:61
void resolveGroupWorker(std::vector< DataLazy *> &dats)
Definition: DataLazy.cpp:2463
boost::shared_ptr< DataReady > DataReady_ptr
Definition: DataAbstract.h:56
int * m_sampleids
Definition: DataLazy.h:234
DataLazy(DataAbstract_ptr p)
Create an IDENTITY DataLazy for the given DataAbstract.
Definition: DataLazy.cpp:440
DataLazy_ptr m_mask
Definition: DataLazy.h:239
const DataTypes::CplxVectorType * resolveNodeNP1OUT_2PCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1657
DataAbstract * getSlice(const DataTypes::RegionType &region) const
Return the given slice from this object.
Definition: DataLazy.cpp:2921
DataTypes::CplxVectorType m_samples_c
Definition: DataLazy.h:236
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:50
boost::shared_ptr< DataLazy > DataLazy_ptr
Definition: DataLazy.h:42
double m_tol
Definition: DataLazy.h:252
const DataTypes::CplxVectorType * resolveNodeSampleCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1174