/[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 2271 by jfenwick, Mon Feb 16 05:08:29 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  };  };
73    
74    ESCRIPT_DLL_API
75  const std::string&  const std::string&
76  opToString(ES_optype op);  opToString(ES_optype op);
77    
# Line 106  public: Line 117  public:
117    DataLazy(DataAbstract_ptr left, ES_optype op);    DataLazy(DataAbstract_ptr left, ES_optype op);
118    
119    /**    /**
120      \brief Produce a DataLazy for a unary operation.
121      \param left DataAbstract to be operated on.
122      \param op unary operation to perform.
123      \param tol tolerance for operation
124      \throws DataException if op is not a unary operation or if p cannot be converted to a DataLazy.
125      Note that IDENTITY is not considered a unary operation.
126      */
127      ESCRIPT_DLL_API
128      DataLazy(DataAbstract_ptr left, ES_optype op, double tol);
129    
130      /**
131      \brief Produce a DataLazy for a unary operation which requires a parameter.
132      \param left DataAbstract to be operated on.
133      \param op unary operation to perform.
134      \param axis_offset the parameter for the operation
135      \throws DataException if op is not a unary operation or if p cannot be converted to a DataLazy.
136      Note that IDENTITY is not considered a unary operation.
137      */
138      ESCRIPT_DLL_API  
139      DataLazy(DataAbstract_ptr left, ES_optype op, int axis_offset);
140    
141    
142      /**
143    \brief Produce a DataLazy for a binary operation.    \brief Produce a DataLazy for a binary operation.
144    \param left left operand    \param left left operand
145    \param right right operand    \param right right operand
# Line 115  public: Line 149  public:
149    ESCRIPT_DLL_API    ESCRIPT_DLL_API
150    DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op);    DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op);
151    
152      /**
153      \brief Produce a DataLazy for a binary operation with additional paramters.
154      \param left left operand
155      \param right right operand
156      \param op unary operation to perform.
157      \param axis_offset
158      \param transpose  
159      \throws DataException if op is not a binary operation requiring parameters or if left or right cannot be converted to a DataLazy.
160      */
161      ESCRIPT_DLL_API
162      DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op, int axis_offset, int transpose);
163    
164    ESCRIPT_DLL_API    ESCRIPT_DLL_API
165    ~DataLazy();    ~DataLazy();
166    
# Line 137  public: Line 183  public:
183    
184    /**    /**
185       \brief       \brief
186       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.
187    */    */
188    ESCRIPT_DLL_API    ESCRIPT_DLL_API
189    ValueType::size_type    ValueType::size_type
# Line 153  public: Line 199  public:
199    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
200                   int dataPointNo) const;                   int dataPointNo) const;
201    
202      DataTypes::ValueType::size_type
203      getPointOffset(int sampleNo,
204                     int dataPointNo);
205    
206    
207    /**    /**
208      \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 212  public:
212    getBuffsRequired() const;    getBuffsRequired() const;
213    
214    /**    /**
215        \return the largest samplesize required to evaluate the expression.
216      */
217      ESCRIPT_DLL_API
218      size_t
219      getMaxSampleSize() const;
220    
221      /**
222        \return the size of the buffer required to evaulate a sample for this object
223      */
224      ESCRIPT_DLL_API
225      size_t
226      getSampleBufferSize() const;
227    
228      /**
229      \brief Compute the value of the expression for the given sample.
230      \return Vector which stores the value of the subexpression for the given sample.
231      \param v A vector to store intermediate results.
232      \param offset Index in v to begin storing results.
233      \param sampleNo Sample number to evaluate.
234      \param roffset (output parameter) the offset in the return vector where the result begins.
235    
236      The return value will be an existing vector so do not deallocate it.
237      */
238      ESCRIPT_DLL_API
239      const ValueType*
240      resolveSample(ValueType& v,  size_t offset, int sampleNo, size_t& roffset);
241    
242       /**
243      \brief Compute the value of the expression for the given sample.
244      \return Vector which stores the value of the subexpression for the given sample.
245      \param v A BufferGroup to store intermediate 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(BufferGroup& bg, int sampleNo, size_t& roffset);
254    
255      /**
256      \brief if resolve() was called would it produce expanded data.
257      */
258      ESCRIPT_DLL_API
259      bool
260      actsExpanded() const;
261    
262      /**
263       \brief Produces an IDENTITY DataLazy containing zero.       \brief Produces an IDENTITY DataLazy containing zero.
264       The result will have the same shape and functionspace as before.       The result will have the same shape and functionspace as before.
265    */    */
# Line 173  private: Line 271  private:
271    DataReady_ptr m_id;   //  For IDENTITY nodes, stores a wrapped value.    DataReady_ptr m_id;   //  For IDENTITY nodes, stores a wrapped value.
272    DataLazy_ptr m_left, m_right; // operands for operation.    DataLazy_ptr m_left, m_right; // operands for operation.
273    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  
274    
275    int m_buffsRequired;  // how many samples are required to evaluate this expression    int m_buffsRequired;  // how many samples are required to evaluate this expression
276    size_t m_samplesize;  // number of values required to store a sample    size_t m_samplesize;  // number of values required to store a sample
277    
278    char m_readytype; // E for expanded, T for tagged, C for constant    char m_readytype; // E for expanded, T for tagged, C for constant
279    
280      int m_axis_offset;    // required extra info for general tensor product
281      int m_transpose;
282      int m_SL, m_SM, m_SR; // computed properties used in general tensor product
283    
284      double m_tol;     // required extra info for <>0 and ==0
285    
286      size_t m_maxsamplesize;   // largest samplesize required by any node in the expression
287      size_t m_children;
288      size_t m_height;
289    
290    
291    /**    /**
292    Does the work for toString.    Does the work for toString.
# Line 206  private: Line 313  private:
313    collapseToReady();    collapseToReady();
314    
315    /**    /**
316    \brief Compute the value of the expression for the given sample.    \brief resolve the expression can store it in the current node
317      The current node will be converted to an identity node.
318      */
319      void
320      resolveToIdentity();
321    
322      /**
323      \brief helper method for resolveToIdentity and the identity constructor
324      */
325      void
326      makeIdentity(const DataReady_ptr& p);
327    
328      /**
329      \brief Compute the value of the expression (unary operation) for the given sample.
330    \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.
331    \param v A vector to store intermediate results.    \param v A vector to store intermediate results.
332    \param offset Index in v to begin storing results.    \param offset Index in v to begin storing results.
# Line 214  private: Line 334  private:
334    \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.
335    
336    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.
337      If the result is stored in v it should be stored at the offset given.
338      Everything from offset to the end of v should be considered available for this method to use.
339    */    */
340    const ValueType*    ValueType*
341    resolveSample(ValueType& v,  size_t offset ,int sampleNo, size_t& roffset);    resolveUnary(ValueType& v,  size_t offset,int sampleNo,  size_t& roffset) const;
342    
343    /**    /**
344    \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.
345    \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.
346    \param v A vector to store intermediate results.    \param v A vector to store intermediate results.
347    \param offset Index in v to begin storing results.    \param offset Index in v to begin storing results.
# Line 229  private: Line 351  private:
351    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.
352    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.
353    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.
354    
355      This method differs from the one above in that deals with operations that are not
356      point-wise. That is, the answer cannot just be written on top of the input.
357      Extra buffers are required for these operations.
358    */    */
359    
360    ValueType*    ValueType*
361    resolveUnary(ValueType& v,  size_t offset,int sampleNo,  size_t& roffset) const;    resolveNP1OUT(ValueType& v, size_t offset, int sampleNo, size_t& roffset) const;
362    
363    /**
364      \brief Compute the value of the expression (unary operation) for the given sample.
365      \return Vector which stores the value of the subexpression for the given sample.
366      \param v A vector to store intermediate results.
367      \param offset Index in v to begin storing results.
368      \param sampleNo Sample number to evaluate.
369      \param roffset (output parameter) the offset in the return vector where the result begins.
370    
371      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.
373      Everything from offset to the end of v should be considered available for this method to use.
374    */
375    DataTypes::ValueType*
376    resolveNP1OUT_P(ValueType& v, size_t offset, int sampleNo, size_t& roffset) const;
377    
378    
379    /**    /**
380    \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 391  private:
391    ValueType*    ValueType*
392    resolveBinary(ValueType& v,  size_t offset,int sampleNo,  size_t& roffset) const;    resolveBinary(ValueType& v,  size_t offset,int sampleNo,  size_t& roffset) const;
393    
394      /**
395      \brief Compute the value of the expression (tensor product) for the given sample.
396      \return Vector which stores the value of the subexpression for the given sample.
397      \param v A vector to store intermediate results.
398      \param offset Index in v to begin storing results.
399      \param sampleNo Sample number to evaluate.
400      \param roffset (output parameter) the offset in the return vector where the result begins.
401    
402      The return value will be an existing vector so do not deallocate it.
403      If the result is stored in v it should be stored at the offset given.
404      Everything from offset to the end of v should be considered available for this method to use.
405      */
406      DataTypes::ValueType*
407      resolveTProd(ValueType& v,  size_t offset, int sampleNo, size_t& roffset) const;
408    
409  };  };
410    
411  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26