ESScript  Revision_4488
DataLazy.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15 
16 
17 #if !defined escript_DataLazy_20081008_H
18 #define escript_DataLazy_20081008_H
19 #include "system_dep.h"
20 
21 #include "DataAbstract.h"
22 
23 #include <string>
24 #include <functional>
25 
26 #include "LocalOps.h" // for tensor_binary_op
27 #include "DataVector.h" // for ElementType
28 
29 
30 //#define LAZY_NODE_STORAGE
31 
32 namespace escript {
33 
34 // For the purposes of unit testing and maintaining sanity, it is important that this enum be contiguous
36 {
39  ADD=2,
40  SUB=3,
41  MUL=4,
42  DIV=5,
43  POW=6,
44  SIN=POW+1,
45  COS=SIN+1,
46  TAN=SIN+2,
47  ASIN=SIN+3,
48  ACOS=SIN+4,
49  ATAN=SIN+5,
50  SINH=SIN+6,
51  COSH=SIN+7,
52  TANH=SIN+8,
53  ERF=SIN+9,
54  ASINH=SIN+10,
55  ACOSH=SIN+11,
56  ATANH=SIN+12,
66  GZ=RECIP+1,
67  LZ=GZ+1,
68  GEZ=GZ+2,
69  LEZ=GZ+3,
70  NEZ=GZ+4,
71  EZ=GZ+5,
72  SYM=EZ+1,
73  NSYM=SYM+1,
81 };
82 
84 const std::string&
86 
96 class DataLazy;
97 
100 
101 class DataLazy : public DataAbstract
102 {
103 
104 typedef DataAbstract parent;
107 
108 public:
116 
117 
127 
137  DataLazy(DataAbstract_ptr left, ES_optype op, double tol);
138 
148  DataLazy(DataAbstract_ptr left, ES_optype op, int axis_offset);
149 
150 
160 
171  DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op, int axis_offset, int transpose);
172 
183  DataLazy(DataAbstract_ptr left, ES_optype op, const int axis0, const int axis1);
184 
192  DataLazy(DataAbstract_ptr mask, DataAbstract_ptr left, DataAbstract_ptr right/*, double tol*/);
193 
195  ~DataLazy();
196 
203  resolve();
204 
206  std::string
207  toString() const;
208 
210  DataAbstract*
211  deepCopy();
212 
213 
220  getLength() const;
221 
222 
224  DataAbstract*
225  getSlice(const DataTypes::RegionType& region) const;
226 
227 
229  getPointOffset(int sampleNo,
230  int dataPointNo) const;
231 
233  getPointOffset(int sampleNo,
234  int dataPointNo);
235 
240  size_t
241  getMaxSampleSize() const;
242 
252  const ValueType*
253  resolveSample(int sampleNo, size_t& roffset);
254 
259  bool
260  actsExpanded() const;
261 
267  virtual void
268  setToZero();
269 
270 
272  void
273  resolveGroupWorker(std::vector<DataLazy*>& dats);
274 
275 
276 private:
277  DataReady_ptr m_id; // For IDENTITY nodes, stores a wrapped value.
278  DataLazy_ptr m_left, m_right, m_mask; // operands for operation.
279  ES_optype m_op; // operation to perform.
280 
281  size_t m_samplesize; // number of values required to store a sample
282 
283  char m_readytype; // E for expanded, T for tagged, C for constant
284 
285  int m_axis_offset; // required extra info for general tensor product
286  int m_transpose; // offset and transpose are used for swapaxes as well
287  int m_SL, m_SM, m_SR; // computed properties used in general tensor product
288 
289 
290  double m_tol; // required extra info for <>0 and ==0
291 
292  size_t m_children;
293  size_t m_height;
294 
295  int* m_sampleids; // may be NULL
297 
301  void LazyNodeSetup();
302 
303 
304  const DataTypes::ValueType*
305  resolveNodeUnary(int tid, int sampleNo, size_t& roffset);
306 
307 
308  const DataTypes::ValueType*
309  resolveNodeReduction(int tid, int sampleNo, size_t& roffset);
310 
311  const DataTypes::ValueType*
312  resolveNodeSample(int tid, int sampleNo, size_t& roffset);
313 
314  const DataTypes::ValueType*
315  resolveNodeBinary(int tid, int sampleNo, size_t& roffset);
316 
317  const DataTypes::ValueType*
318  resolveNodeNP1OUT(int tid, int sampleNo, size_t& roffset);
319 
320  const DataTypes::ValueType*
321  resolveNodeNP1OUT_P(int tid, int sampleNo, size_t& roffset);
322 
323  const DataTypes::ValueType*
324  resolveNodeTProd(int tid, int sampleNo, size_t& roffset);
325 
326  const DataTypes::ValueType*
327  resolveNodeNP1OUT_2P(int tid, int sampleNo, size_t& roffset);
328 
329  const DataTypes::ValueType*
330  resolveNodeCondEval(int tid, int sampleNo, size_t& roffset);
331 
335  void
336  intoString(std::ostringstream& oss) const;
337 
341  void
342  intoTreeString(std::ostringstream& oss,std::string indent) const;
343 
350  void
351  collapse(); // converts the node into an IDENTITY node
352 
353 
360  collapseToReady();
361 
366  void
367  resolveToIdentity();
368 
372  void
373  makeIdentity(const DataReady_ptr& p);
374 
375 
380  resolveNodeWorker();
381 
382 };
383 
384 }
385 #endif