/[escript]/trunk/escript/src/DataLazy.h
ViewVC logotype

Diff of /trunk/escript/src/DataLazy.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

branches/schroedinger/escript/src/DataLazy.h revision 1903 by jfenwick, Wed Oct 22 06:11:01 2008 UTC trunk/escript/src/DataLazy.h revision 2497 by jfenwick, Mon Jun 29 00:04:45 2009 UTC
# Line 22  Line 22 
22  #include <functional>  #include <functional>
23    
24  #include "LocalOps.h"       // for tensor_binary_op  #include "LocalOps.h"       // for tensor_binary_op
25    #include "BufferGroup.h"
26    
27  namespace escript {  namespace escript {
28    
29    // For the purposes of unit testing and maintaining sanity, it is important that this enum be contiguous
30  enum ES_optype  enum ES_optype
31  {  {
32      UNKNOWNOP=0,      UNKNOWNOP=0,
# Line 33  enum ES_optype Line 35  enum ES_optype
35      SUB=3,      SUB=3,
36      MUL=4,      MUL=4,
37      DIV=5,      DIV=5,
38      SIN=6,      POW=6,
39      COS=7,      SIN=POW+1,
40      TAN=8,      COS=SIN+1,
41      ASIN=9,      TAN=SIN+2,
42      ACOS=10,      ASIN=SIN+3,
43      ATAN=11,      ACOS=SIN+4,
44      SINH=12,      ATAN=SIN+5,
45      COSH=13,      SINH=SIN+6,
46      TANH=14,      COSH=SIN+7,
47      ERF=15,      TANH=SIN+8,
48      ASINH=16,      ERF=SIN+9,
49      ACOSH=17,      ASINH=SIN+10,
50      ATANH=18,      ACOSH=SIN+11,
51      LOG10=19,      ATANH=SIN+12,
52      LOG=20,      LOG10=ATANH+1,
53      SIGN=21,      LOG=LOG10+1,
54      ABS=22,      SIGN=LOG10+2,
55      NEG=23,      ABS=LOG10+3,
56      POS=24,      NEG=LOG10+4,
57      EXP=25,      POS=LOG10+5,
58      SQRT=26,      EXP=LOG10+6,
59      RECIP=27,      SQRT=LOG10+7,
60      GZ=28,      RECIP=LOG10+8,
61      LZ=29,      GZ=RECIP+1,
62      GEZ=30,      LZ=GZ+1,
63      LEZ=31      GEZ=GZ+2,
64        LEZ=GZ+3,
65        NEZ=GZ+4,
66        EZ=GZ+5,
67        SYM=EZ+1,
68        NSYM=SYM+1,
69        PROD=NSYM+1,
70        TRANS=PROD+1,
71        TRACE=TRANS+1,
72        SWAP=TRACE+1
73  };  };
74    
75    ESCRIPT_DLL_API
76  const std::string&  const std::string&
77  opToString(ES_optype op);  opToString(ES_optype op);
78    
# Line 106  public: Line 118  public:
118    DataLazy(DataAbstract_ptr left, ES_optype op);    DataLazy(DataAbstract_ptr left, ES_optype op);
119    
120    /**    /**
121      \brief Produce a DataLazy for a unary operation.
122      \param left DataAbstract to be operated on.
123      \param op unary operation to perform.
124      \param tol tolerance for operation
125      \throws DataException if op is not a unary operation or if p cannot be converted to a DataLazy.
126      Note that IDENTITY is not considered a unary operation.
127      */
128      ESCRIPT_DLL_API
129      DataLazy(DataAbstract_ptr left, ES_optype op, double tol);
130    
131      /**
132      \brief Produce a DataLazy for a unary operation which requires a parameter.
133      \param left DataAbstract to be operated on.
134      \param op unary operation to perform.
135      \param axis_offset the parameter for the operation
136      \throws DataException if op is not a unary operation or if p cannot be converted to a DataLazy.
137      Note that IDENTITY is not considered a unary operation.
138      */
139      ESCRIPT_DLL_API  
140      DataLazy(DataAbstract_ptr left, ES_optype op, int axis_offset);
141    
142    
143      /**
144    \brief Produce a DataLazy for a binary operation.    \brief Produce a DataLazy for a binary operation.
145    \param left left operand    \param left left operand
146    \param right right operand    \param right right operand
# Line 115  public: Line 150  public:
150    ESCRIPT_DLL_API    ESCRIPT_DLL_API
151    DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op);    DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op);
152    
153      /**
154      \brief Produce a DataLazy for a binary operation with additional paramters.
155      \param left left operand
156      \param right right operand
157      \param op unary operation to perform.
158      \param axis_offset
159      \param transpose  
160      \throws DataException if op is not a binary operation requiring parameters or if left or right cannot be converted to a DataLazy.
161      */
162      ESCRIPT_DLL_API
163      DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op, int axis_offset, int transpose);
164    
165      /**
166      \brief Produce a DataLazy for a unary operation which requires two integer parameters.
167      \param left DataAbstract to be operated on.
168      \param op unary operation to perform.
169      \param axis0 the first parameter for the operation
170      \param axis1 the second parameter for the operation
171      \throws DataException if op is not a unary operation or if p cannot be converted to a DataLazy.
172      Note that IDENTITY is not considered a unary operation.
173      */
174      ESCRIPT_DLL_API
175      DataLazy(DataAbstract_ptr left, ES_optype op, const int axis0, const int axis1);
176    
177    ESCRIPT_DLL_API    ESCRIPT_DLL_API
178    ~DataLazy();    ~DataLazy();
179    
# Line 137  public: Line 196  public:
196    
197    /**    /**
198       \brief       \brief
199       Return the number of doubles that would be stored for this Data object if it were resolved.       This method throws an exception. It does not really make sense to ask this question of lazy data.
200    */    */
201    ESCRIPT_DLL_API    ESCRIPT_DLL_API
202    ValueType::size_type    ValueType::size_type
# Line 153  public: Line 212  public:
212    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
213                   int dataPointNo) const;                   int dataPointNo) const;
214    
215      DataTypes::ValueType::size_type
216      getPointOffset(int sampleNo,
217                     int dataPointNo);
218    
219    
220    /**    /**
221      \return the number of samples which need to be stored to evaluate the expression.      \return the number of samples which need to be stored to evaluate the expression.
# Line 162  public: Line 225  public:
225    getBuffsRequired() const;    getBuffsRequired() const;
226    
227    /**    /**
228        \return the largest samplesize required to evaluate the expression.
229      */
230      ESCRIPT_DLL_API
231      size_t
232      getMaxSampleSize() const;
233    
234      /**
235        \return the size of the buffer required to evaulate a sample for this object
236      */
237      ESCRIPT_DLL_API
238      size_t
239      getSampleBufferSize() const;
240    
241      /**
242      \brief Compute the value of the expression for the given sample.
243      \return Vector which stores the value of the subexpression for the given sample.
244      \param v A vector to store intermediate results.
245      \param offset Index in v to begin storing results.
246      \param sampleNo Sample number to evaluate.
247      \param roffset (output parameter) the offset in the return vector where the result begins.
248    
249      The return value will be an existing vector so do not deallocate it.
250      */
251      ESCRIPT_DLL_API
252      const ValueType*
253      resolveSample(ValueType& v,  size_t offset, int sampleNo, size_t& roffset);
254    
255       /**
256      \brief Compute the value of the expression for the given sample.
257      \return Vector which stores the value of the subexpression for the given sample.
258      \param v A BufferGroup to store intermediate results.
259      \param sampleNo Sample number to evaluate.
260      \param roffset (output parameter) the offset in the return vector where the result begins.
261    
262      The return value will be an existing vector so do not deallocate it.
263      */
264      ESCRIPT_DLL_API
265      const ValueType*
266      resolveSample(BufferGroup& bg, int sampleNo, size_t& roffset);
267    
268      /**
269      \brief if resolve() was called would it produce expanded data.
270      */
271      ESCRIPT_DLL_API
272      bool
273      actsExpanded() const;
274    
275      /**
276       \brief Produces an IDENTITY DataLazy containing zero.       \brief Produces an IDENTITY DataLazy containing zero.
277       The result will have the same shape and functionspace as before.       The result will have the same shape and functionspace as before.
278    */    */
# Line 173  private: Line 284  private:
284    DataReady_ptr m_id;   //  For IDENTITY nodes, stores a wrapped value.    DataReady_ptr m_id;   //  For IDENTITY nodes, stores a wrapped value.
285    DataLazy_ptr m_left, m_right; // operands for operation.    DataLazy_ptr m_left, m_right; // operands for operation.
286    ES_optype m_op;   // operation to perform.    ES_optype m_op;   // operation to perform.
   size_t m_length;  // number of values represented by the operation  
287    
288    int m_buffsRequired;  // how many samples are required to evaluate this expression    int m_buffsRequired;  // how many samples are required to evaluate this expression
289    size_t m_samplesize;  // number of values required to store a sample    size_t m_samplesize;  // number of values required to store a sample
290    
291    char m_readytype; // E for expanded, T for tagged, C for constant    char m_readytype; // E for expanded, T for tagged, C for constant
292    
293      int m_axis_offset;    // required extra info for general tensor product
294      int m_transpose;  // offset and transpose are used for swapaxes as well
295      int m_SL, m_SM, m_SR; // computed properties used in general tensor product
296    
297    
298      double m_tol;     // required extra info for <>0 and ==0
299    
300      size_t m_maxsamplesize;   // largest samplesize required by any node in the expression
301      size_t m_children;
302      size_t m_height;
303    
304    
305    /**    /**
306    Does the work for toString.    Does the work for toString.
# Line 206  private: Line 327  private:
327    collapseToReady();    collapseToReady();
328    
329    /**    /**
330    \brief Compute the value of the expression for the given sample.    \brief resolve the expression can store it in the current node
331      The current node will be converted to an identity node.
332      */
333      void
334      resolveToIdentity();
335    
336      /**
337      \brief helper method for resolveToIdentity and the identity constructor
338      */
339      void
340      makeIdentity(const DataReady_ptr& p);
341    
342      /**
343      \brief resolve to a ReadyData object using a vector buffer.
344      */
345      DataReady_ptr
346      resolveVectorWorker();
347    
348      /**
349      \brief Compute the value of the expression (unary operation) for the given sample.
350    \return Vector which stores the value of the subexpression for the given sample.    \return Vector which stores the value of the subexpression for the given sample.
351    \param v A vector to store intermediate results.    \param v A vector to store intermediate results.
352    \param offset Index in v to begin storing results.    \param offset Index in v to begin storing results.
# Line 214  private: Line 354  private:
354    \param roffset (output parameter) the offset in the return vector where the result begins.    \param roffset (output parameter) the offset in the return vector where the result begins.
355    
356    The return value will be an existing vector so do not deallocate it.    The return value will be an existing vector so do not deallocate it.
357      If the result is stored in v it should be stored at the offset given.
358      Everything from offset to the end of v should be considered available for this method to use.
359    */    */
360    const ValueType*    ValueType*
361    resolveSample(ValueType& v,  size_t offset ,int sampleNo, size_t& roffset);    resolveUnary(ValueType& v,  size_t offset,int sampleNo,  size_t& roffset) const;
362    
363    /**    /**
364    \brief Compute the value of the expression (binary operation) for the given sample.    \brief Compute the value of the expression (unary non-pointwise operation) for the given sample.
365    \return Vector which stores the value of the subexpression for the given sample.    \return Vector which stores the value of the subexpression for the given sample.
366    \param v A vector to store intermediate results.    \param v A vector to store intermediate results.
367    \param offset Index in v to begin storing results.    \param offset Index in v to begin storing results.
# Line 229  private: Line 371  private:
371    The return value will be an existing vector so do not deallocate it.    The return value will be an existing vector so do not deallocate it.
372    If the result is stored in v it should be stored at the offset given.    If the result is stored in v it should be stored at the offset given.
373    Everything from offset to the end of v should be considered available for this method to use.    Everything from offset to the end of v should be considered available for this method to use.
374    
375      This method differs from the one above in that deals with operations that are not
376      point-wise. That is, the answer cannot just be written on top of the input.
377      Extra buffers are required for these operations.
378    */    */
379    
380    ValueType*    ValueType*
381    resolveUnary(ValueType& v,  size_t offset,int sampleNo,  size_t& roffset) const;    resolveNP1OUT(ValueType& v, size_t offset, int sampleNo, size_t& roffset) const;
382    
383    /**
384      \brief Compute the value of the expression (unary operation) for the given sample.
385      \return Vector which stores the value of the subexpression for the given sample.
386      \param v A vector to store intermediate results.
387      \param offset Index in v to begin storing results.
388      \param sampleNo Sample number to evaluate.
389      \param roffset (output parameter) the offset in the return vector where the result begins.
390    
391      The return value will be an existing vector so do not deallocate it.
392      If the result is stored in v it should be stored at the offset given.
393      Everything from offset to the end of v should be considered available for this method to use.
394    */
395    DataTypes::ValueType*
396    resolveNP1OUT_P(ValueType& v, size_t offset, int sampleNo, size_t& roffset) const;
397    
398    /**
399      \brief Compute the value of the expression (unary operation with int params) for the given sample.
400      \return Vector which stores the value of the subexpression for the given sample.
401      \param v A vector to store intermediate results.
402      \param offset Index in v to begin storing results.
403      \param sampleNo Sample number to evaluate.
404      \param roffset (output parameter) the offset in the return vector where the result begins.
405    
406      The return value will be an existing vector so do not deallocate it.
407      If the result is stored in v it should be stored at the offset given.
408      Everything from offset to the end of v should be considered available for this method to use.
409    */
410    DataTypes::ValueType*
411    resolveNP1OUT_2P(ValueType& v, size_t offset, int sampleNo, size_t& roffset) const;
412    
413    
414    /**    /**
415    \brief Compute the value of the expression (binary operation) for the given sample.    \brief Compute the value of the expression (binary operation) for the given sample.
# Line 248  private: Line 426  private:
426    ValueType*    ValueType*
427    resolveBinary(ValueType& v,  size_t offset,int sampleNo,  size_t& roffset) const;    resolveBinary(ValueType& v,  size_t offset,int sampleNo,  size_t& roffset) const;
428    
429      /**
430      \brief Compute the value of the expression (tensor product) for the given sample.
431      \return Vector which stores the value of the subexpression for the given sample.
432      \param v A vector to store intermediate results.
433      \param offset Index in v to begin storing results.
434      \param sampleNo Sample number to evaluate.
435      \param roffset (output parameter) the offset in the return vector where the result begins.
436    
437      The return value will be an existing vector so do not deallocate it.
438      If the result is stored in v it should be stored at the offset given.
439      Everything from offset to the end of v should be considered available for this method to use.
440      */
441      DataTypes::ValueType*
442      resolveTProd(ValueType& v,  size_t offset, int sampleNo, size_t& roffset) const;
443    
444  };  };
445    
446  }  }

Legend:
Removed from v.1903  
changed lines
  Added in v.2497

  ViewVC Help
Powered by ViewVC 1.1.26