/[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

revision 1865 by jfenwick, Thu Oct 9 03:53:57 2008 UTC revision 1926 by jfenwick, Fri Oct 24 05:54:08 2008 UTC
# Line 17  Line 17 
17  #include "system_dep.h"  #include "system_dep.h"
18    
19  #include "DataAbstract.h"  #include "DataAbstract.h"
 //#include "DataTypes.h"  
 //#include "FunctionSpace.h"  
20    
21  #include <string>  #include <string>
22    #include <functional>
23    
24    #include "LocalOps.h"       // for tensor_binary_op
25    
26  namespace escript {  namespace escript {
27    
28    // For the purposes of unit testing and maintaining sanity, it is important that this enum be contiguous
29  enum ES_optype  enum ES_optype
30  {  {
31      UNKNOWNOP=0,      UNKNOWNOP=0,
32      IDENTITY=1      IDENTITY=1,
33        ADD=2,
34        SUB=3,
35        MUL=4,
36        DIV=5,
37        POW=6,
38        SIN=POW+1,
39        COS=SIN+1,
40        TAN=SIN+2,
41        ASIN=SIN+3,
42        ACOS=SIN+4,
43        ATAN=SIN+5,
44        SINH=SIN+6,
45        COSH=SIN+7,
46        TANH=SIN+8,
47        ERF=SIN+9,
48        ASINH=SIN+10,
49        ACOSH=SIN+11,
50        ATANH=SIN+12,
51        LOG10=ATANH+1,
52        LOG=LOG10+1,
53        SIGN=LOG10+2,
54        ABS=LOG10+3,
55        NEG=LOG10+4,
56        POS=LOG10+5,
57        EXP=LOG10+6,
58        SQRT=LOG10+7,
59        RECIP=LOG10+8,
60        GZ=RECIP+1,
61        LZ=GZ+1,
62        GEZ=GZ+2,
63        LEZ=GZ+3
64  };  };
65    
66  const std::string&  const std::string&
# Line 36  opToString(ES_optype op); Line 69  opToString(ES_optype op);
69  /**  /**
70  \class escript::DataLazy  \class escript::DataLazy
71  \brief Wraps an expression tree of other DataObjects.  \brief Wraps an expression tree of other DataObjects.
72  The values of DataPoints are computed when requested rather than all at once.  The data will be evaluated when required.
73    
74    
75    NOTE: This class assumes that the Data being pointed at are immutable.
76  */  */
77    
78    class DataLazy;
79    
80    typedef POINTER_WRAPPER_CLASS(DataLazy) DataLazy_ptr;
81    typedef POINTER_WRAPPER_CLASS(const DataLazy) const_DataLazy_ptr;
82    
83  class DataLazy : public DataAbstract  class DataLazy : public DataAbstract
84  {  {
85    
# Line 47  typedef DataTypes::ValueType ValueType; Line 88  typedef DataTypes::ValueType ValueType;
88  typedef DataTypes::ShapeType ShapeType;  typedef DataTypes::ShapeType ShapeType;
89    
90  public:  public:
91      /**
92      \brief Create an IDENTITY DataLazy for the given DataAbstract.
93      \param p DataAbstract to be wrapped.
94      \throws DataException if p is lazy data or it is not constant, tagged or expanded.
95      */
96    ESCRIPT_DLL_API    ESCRIPT_DLL_API
97    DataLazy(DataAbstract_ptr p);    DataLazy(DataAbstract_ptr p);
98    
99    
100      /**
101      \brief Produce a DataLazy for a unary operation.
102      \param left DataAbstract to be operated on.
103      \param op unary operation to perform.
104      \throws DataException if op is not a unary operation or if p cannot be converted to a DataLazy.
105      Note that IDENTITY is not considered a unary operation.
106      */
107      ESCRIPT_DLL_API
108      DataLazy(DataAbstract_ptr left, ES_optype op);
109    
110      /**
111      \brief Produce a DataLazy for a binary operation.
112      \param left left operand
113      \param right right operand
114      \param op unary operation to perform.
115      \throws DataException if op is not a binary operation or if left or right cannot be converted to a DataLazy.
116      */
117    ESCRIPT_DLL_API    ESCRIPT_DLL_API
118    DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op);    DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op);
119    
120    ESCRIPT_DLL_API    ESCRIPT_DLL_API
121    ~DataLazy();    ~DataLazy();
122    
   
   
123    /**    /**
124    \brief Compute all data points in the expression tree    \brief Evaluate the lazy expression.
125      \return A DataReady with the value of the lazy expresion.
126    */    */
127    ESCRIPT_DLL_API    ESCRIPT_DLL_API
128    DataReady_ptr resolve();    DataReady_ptr
129      resolve();
130    
131    ESCRIPT_DLL_API    ESCRIPT_DLL_API
132    std::string    std::string
# Line 91  public: Line 155  public:
155    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
156                   int dataPointNo) const;                   int dataPointNo) const;
157    
158    
159      /**
160        \return the number of samples which need to be stored to evaluate the expression.
161      */
162      ESCRIPT_DLL_API
163      int
164      getBuffsRequired() const;
165    
166      /**
167         \brief Produces an IDENTITY DataLazy containing zero.
168         The result will have the same shape and functionspace as before.
169      */
170      ESCRIPT_DLL_API
171      virtual void
172      setToZero();
173    
174  private:  private:
175    DataAbstract_ptr m_left, m_right;    DataReady_ptr m_id;   //  For IDENTITY nodes, stores a wrapped value.
176    ES_optype m_op;    DataLazy_ptr m_left, m_right; // operands for operation.
177    size_t length;    // number of values represented by the operation    ES_optype m_op;   // operation to perform.
178      size_t m_length;  // number of values represented by the operation
179    
180      int m_buffsRequired;  // how many samples are required to evaluate this expression
181      size_t m_samplesize;  // number of values required to store a sample
182    
183      char m_readytype; // E for expanded, T for tagged, C for constant
184    
185    
186      /**
187      Does the work for toString.
188      */
189      void
190      intoString(std::ostringstream& oss) const;
191    
192      /**
193       \brief Converts the DataLazy into an IDENTITY storing the value of the expression.
194       This method uses the original methods on the Data class to evaluate the expressions.
195       For this reason, it should not be used on DataExpanded instances. (To do so would defeat
196       the purpose of using DataLazy in the first place).
197      */
198      void
199      collapse();       // converts the node into an IDENTITY node
200    
201    
202      /**
203      \brief Evaluates the expression using methods on Data.
204      This does the work for the collapse method.
205      For reasons of efficiency do not call this method on DataExpanded nodes.
206      */
207      DataReady_ptr
208      collapseToReady();
209    
210      /**
211      \brief Compute the value of the expression for the given sample.
212      \return Vector which stores the value of the subexpression for the given sample.
213      \param v A vector to store intermediate results.
214      \param offset Index in v to begin storing results.
215      \param sampleNo Sample number to evaluate.
216      \param roffset (output parameter) the offset in the return vector where the result begins.
217    
218      The return value will be an existing vector so do not deallocate it.
219      */
220      const ValueType*
221      resolveSample(ValueType& v,  size_t offset ,int sampleNo, size_t& roffset);
222    
223      /**
224      \brief Compute the value of the expression (binary operation) for the given sample.
225      \return Vector which stores the value of the subexpression for the given sample.
226      \param v A vector to store intermediate results.
227      \param offset Index in v to begin storing results.
228      \param sampleNo Sample number to evaluate.
229      \param roffset (output parameter) the offset in the return vector where the result begins.
230    
231      The return value will be an existing vector so do not deallocate it.
232      If the result is stored in v it should be stored at the offset given.
233      Everything from offset to the end of v should be considered available for this method to use.
234      */
235      ValueType*
236      resolveUnary(ValueType& v,  size_t offset,int sampleNo,  size_t& roffset) const;
237    
238      /**
239      \brief Compute the value of the expression (binary operation) for the given sample.
240      \return Vector which stores the value of the subexpression for the given sample.
241      \param v A vector to store intermediate results.
242      \param offset Index in v to begin storing results.
243      \param sampleNo Sample number to evaluate.
244      \param roffset (output parameter) the offset in the return vector where the result begins.
245    
246      The return value will be an existing vector so do not deallocate it.
247      If the result is stored in v it should be stored at the offset given.
248      Everything from offset to the end of v should be considered available for this method to use.
249      */
250      ValueType*
251      resolveBinary(ValueType& v,  size_t offset,int sampleNo,  size_t& roffset) const;
252    
253  };  };
254    
255  }  }

Legend:
Removed from v.1865  
changed lines
  Added in v.1926

  ViewVC Help
Powered by ViewVC 1.1.26