escript Revision_
DataLazy.h
Go to the documentation of this file.
1
2/*****************************************************************************
3*
4* Copyright (c) 2003-2020 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-2017 by Centre for Geoscience Computing (GeoComp)
14* Development from 2019 by School of Earth and Environmental Sciences
15**
16*****************************************************************************/
17
18#ifndef __ESCRIPT_DATALAZY_H__
19#define __ESCRIPT_DATALAZY_H__
20
21#include "system_dep.h"
22#include "DataAbstract.h"
23#include "ArrayOps.h" // for tensor_binary_op
24#include "DataVector.h" // for ElementType
25#include "ES_optype.h"
26
27#include <string>
28
29//#define LAZY_NODE_STORAGE
30
31namespace escript {
32
33
43class DataLazy;
44
47
48class DataLazy : public DataAbstract
49{
50
53
54public:
62
63
73
83 DataLazy(DataAbstract_ptr left, ES_optype op, double tol);
84
94 DataLazy(DataAbstract_ptr left, ES_optype op, int axis_offset);
95
96
106
117 DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op, int axis_offset, int transpose);
118
129 DataLazy(DataAbstract_ptr left, ES_optype op, const int axis0, const int axis1);
130
138 DataLazy(DataAbstract_ptr mask, DataAbstract_ptr left, DataAbstract_ptr right/*, double tol*/);
139
141 ~DataLazy();
142
149 resolve();
150
152 std::string
153 toString() const;
154
157 deepCopy() const;
158
161 zeroedCopy() const;
162
169 getLength() const;
170
171
174 getSlice(const DataTypes::RegionType& region) const;
175
176
178 getPointOffset(int sampleNo,
179 int dataPointNo) const;
180
182 getPointOffset(int sampleNo,
183 int dataPointNo);
184
189 size_t
191
202 resolveSample(int sampleNo, size_t& roffset) const;
203
206 resolveTypedSample(int sampleNo, size_t& roffset, DataTypes::cplx_t dummy) const;
207
210 resolveTypedSample(int sampleNo, size_t& roffset, DataTypes::real_t dummy) const;
211
212
217 bool
218 actsExpanded() const;
219
225 virtual void
226 setToZero();
227
228
230 void
231 resolveGroupWorker(std::vector<DataLazy*>& dats);
232
233
234private:
235 int* m_sampleids; // may be NULL
238
239 mutable DataReady_ptr m_id; // For IDENTITY nodes, stores a wrapped value.
240 mutable DataLazy_ptr m_left, m_right, m_mask; // operands for operation.
241 mutable ES_optype m_op; // operation to perform.
242 mutable ES_opgroup m_opgroup; // type of operation to perform
243
244 size_t m_samplesize; // number of values required to store a sample
245
246 char m_readytype; // E for expanded, T for tagged, C for constant
247
248 int m_axis_offset; // required extra info for general tensor product
249 int m_transpose; // offset and transpose are used for swapaxes as well
250 int m_SL, m_SM, m_SR; // computed properties used in general tensor product
251
252
253 double m_tol; // required extra info for <>0 and ==0
254
255 mutable size_t m_children;
256 mutable size_t m_height;
257
258
259
263 void LazyNodeSetup();
264
265
267 resolveNodeUnary(int tid, int sampleNo, size_t& roffset) const;
268
270 resolveNodeUnaryCplx(int tid, int sampleNo, size_t& roffset) const;
271
272
274 resolveNodeReduction(int tid, int sampleNo, size_t& roffset) const;
275
277 resolveNodeReductionCplx(int tid, int sampleNo, size_t& roffset) const;
278
280 resolveNodeSample(int tid, int sampleNo, size_t& roffset) const;
281
283 resolveNodeSampleCplx(int tid, int sampleNo, size_t& roffset) const;
284
286 resolveNodeBinary(int tid, int sampleNo, size_t& roffset) const;
287
289 resolveNodeBinaryCplx(int tid, int sampleNo, size_t& roffset) const;
290
291
293 resolveNodeNP1OUT(int tid, int sampleNo, size_t& roffset) const;
294
296 resolveNodeNP1OUTCplx(int tid, int sampleNo, size_t& roffset) const;
297
299 resolveNodeNP1OUT_P(int tid, int sampleNo, size_t& roffset) const;
300
302 resolveNodeNP1OUT_PCplx(int tid, int sampleNo, size_t& roffset) const;
303
304
306 resolveNodeTProd(int tid, int sampleNo, size_t& roffset) const;
307
309 resolveNodeTProdCplx(int tid, int sampleNo, size_t& roffset) const;
310
311
313 resolveNodeNP1OUT_2P(int tid, int sampleNo, size_t& roffset) const;
314
316 resolveNodeNP1OUT_2PCplx(int tid, int sampleNo, size_t& roffset) const;
317
319 resolveNodeCondEval(int tid, int sampleNo, size_t& roffset) const;
320
322 resolveNodeCondEvalCplx(int tid, int sampleNo, size_t& roffset) const;
323
324
326 resolveNodeUnary_C(int tid, int sampleNo, size_t& roffset) const;
327
331 void
332 intoString(std::ostringstream& oss) const;
333
337 void
338 intoTreeString(std::ostringstream& oss,std::string indent) const;
339
346 void
347 collapse() const; // converts the node into an IDENTITY node
348
349
356 collapseToReady() const;
357
362 void
364
368 void
369 makeIdentity(const DataReady_ptr& p);
370
371
377
380
381};
382
383// If an expression is already complex, return the same expression.
384// Otherwise, return the old expression with a promote operation
385// above it
387
388}
389
390#endif // __ESCRIPT_DATALAZY_H__
391
#define POINTER_WRAPPER_CLASS(x)
Definition: Pointers.h:33
Definition: DataAbstract.h:63
friend class DataLazy
Definition: DataAbstract.h:550
virtual void transpose(DataAbstract *ev, int axis_offset)
Transpose each data point of this Data object around the given axis.
Definition: DataAbstract.cpp:246
Wraps an expression tree of other DataObjects. The data will be evaluated when required.
Definition: DataLazy.h:49
DataReady_ptr collapseToReady() const
Evaluates the expression using methods on Data. This does the work for the collapse method....
Definition: DataLazy.cpp:931
void makeIdentity(const DataReady_ptr &p)
helper method for resolveToIdentity and the identity constructor
Definition: DataLazy.cpp:2434
const DataTypes::RealVectorType * resolveNodeBinary(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1774
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:2903
DataReady_ptr resolveNodeWorkerCplx()
Definition: DataLazy.cpp:2602
DataLazy_ptr m_right
Definition: DataLazy.h:240
DataAbstract * deepCopy() const
Return a deep copy of the current object.
Definition: DataLazy.cpp:2879
~DataLazy()
Definition: DataLazy.cpp:919
void resolveToIdentity()
resolve the expression can store it in the current node The current node will be converted to an iden...
Definition: DataLazy.cpp:2418
char m_readytype
Definition: DataLazy.h:246
const DataTypes::CplxVectorType * resolveNodeCondEvalCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1729
const DataTypes::CplxVectorType * resolveNodeReductionCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1372
bool actsExpanded() const
if resolve() was called would it produce expanded data.
Definition: DataLazy.cpp:3001
DataTypes::ShapeType ShapeType
Definition: DataLazy.h:52
void intoTreeString(std::ostringstream &oss, std::string indent) const
Definition: DataLazy.cpp:2789
DataLazy_ptr m_left
Definition: DataLazy.h:240
size_t m_height
Definition: DataLazy.h:256
const DataTypes::CplxVectorType * resolveNodeNP1OUT_PCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1574
DataAbstract parent
Definition: DataLazy.h:51
ES_opgroup m_opgroup
Definition: DataLazy.h:242
const DataTypes::CplxVectorType * resolveNodeNP1OUT_2PCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1658
const DataTypes::CplxVectorType * resolveNodeBinaryCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1997
void intoString(std::ostringstream &oss) const
Definition: DataLazy.cpp:2681
const DataTypes::CplxVectorType * resolveNodeUnaryCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1274
const DataTypes::CplxVectorType * resolveNodeSampleCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1175
const DataTypes::CplxVectorType * resolveTypedSample(int sampleNo, size_t &roffset, DataTypes::cplx_t dummy) const
Definition: DataLazy.cpp:2389
DataLazy_ptr m_mask
Definition: DataLazy.h:240
const DataTypes::RealVectorType * resolveNodeCondEval(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1694
const DataTypes::RealVectorType * resolveNodeTProd(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:2224
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:2915
ES_optype m_op
Definition: DataLazy.h:241
void resolveGroupWorker(std::vector< DataLazy * > &dats)
Definition: DataLazy.cpp:2464
double m_tol
Definition: DataLazy.h:253
int * m_sampleids
Definition: DataLazy.h:235
const DataTypes::RealVectorType * resolveNodeSample(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1119
const DataTypes::CplxVectorType * resolveNodeNP1OUTCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1466
void collapse() const
Converts the DataLazy into an IDENTITY storing the value of the expression. This method uses the orig...
Definition: DataLazy.cpp:1100
const DataTypes::RealVectorType * resolveNodeNP1OUT_P(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1527
const DataTypes::RealVectorType * resolveNodeNP1OUT(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1391
int m_transpose
Definition: DataLazy.h:249
const DataTypes::RealVectorType * resolveSample(int sampleNo, size_t &roffset) const
Compute the value of the expression for the given sample.
Definition: DataLazy.cpp:2336
size_t m_samplesize
Definition: DataLazy.h:244
virtual void setToZero()
Produces an IDENTITY DataLazy containing zero. The result will have the same shape and functionspace ...
Definition: DataLazy.cpp:2986
DataReady_ptr m_id
Definition: DataLazy.h:239
int m_axis_offset
Definition: DataLazy.h:248
const DataTypes::CplxVectorType * resolveNodeTProdCplx(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:2278
int m_SM
Definition: DataLazy.h:250
int m_SR
Definition: DataLazy.h:250
const DataTypes::RealVectorType * resolveNodeNP1OUT_2P(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1621
size_t getMaxSampleSize() const
void LazyNodeSetup()
Definition: DataLazy.cpp:408
DataAbstract * getSlice(const DataTypes::RegionType &region) const
Return the given slice from this object.
Definition: DataLazy.cpp:2922
DataTypes::CplxVectorType m_samples_c
Definition: DataLazy.h:237
size_t m_children
Definition: DataLazy.h:255
std::string toString() const
Write the data as a string.
Definition: DataLazy.cpp:2660
int m_SL
Definition: DataLazy.h:250
DataTypes::RealVectorType m_samples_r
Definition: DataLazy.h:236
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:2956
const DataTypes::RealVectorType * resolveNodeUnary(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1225
DataReady_ptr resolve()
Evaluate the lazy expression.
Definition: DataLazy.cpp:2455
const DataTypes::RealVectorType * resolveNodeReduction(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1320
DataReady_ptr resolveNodeWorker()
resolve to a ReadyData object using storage at nodes
Definition: DataLazy.cpp:2544
const DataTypes::CplxVectorType * resolveNodeUnary_C(int tid, int sampleNo, size_t &roffset) const
Definition: DataLazy.cpp:1437
DataTypes::vec_size_type size_type
Definition: DataVectorAlt.h:50
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:30
std::complex< real_t > cplx_t
complex data type
Definition: DataTypes.h:55
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:45
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:52
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:44
Definition: AbstractContinuousDomain.cpp:23
DataLazy_ptr makePromote(DataLazy_ptr p)
Definition: DataLazy.cpp:115
boost::shared_ptr< DataAbstract > DataAbstract_ptr
Definition: DataAbstract.h:54
boost::shared_ptr< DataLazy > DataLazy_ptr
Definition: DataLazy.h:45
ES_optype
Definition: ES_optype.h:30
boost::shared_ptr< const DataLazy > const_DataLazy_ptr
Definition: DataLazy.h:46
ES_opgroup
Definition: ES_optype.h:93
boost::shared_ptr< DataReady > DataReady_ptr
Definition: DataAbstract.h:59