/[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 1935 by jfenwick, Mon Oct 27 06:06:39 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      DataTypes::ValueType::size_type
159      getPointOffset(int sampleNo,
160                     int dataPointNo);
161    
162    
163      /**
164        \return the number of samples which need to be stored to evaluate the expression.
165      */
166      ESCRIPT_DLL_API
167      int
168      getBuffsRequired() const;
169    
170      /**
171         \brief Produces an IDENTITY DataLazy containing zero.
172         The result will have the same shape and functionspace as before.
173      */
174      ESCRIPT_DLL_API
175      virtual void
176      setToZero();
177    
178  private:  private:
179    DataAbstract_ptr m_left, m_right;    DataReady_ptr m_id;   //  For IDENTITY nodes, stores a wrapped value.
180    ES_optype m_op;    DataLazy_ptr m_left, m_right; // operands for operation.
181    size_t length;    // number of values represented by the operation    ES_optype m_op;   // operation to perform.
182      size_t m_length;  // number of values represented by the operation
183    
184      int m_buffsRequired;  // how many samples are required to evaluate this expression
185      size_t m_samplesize;  // number of values required to store a sample
186    
187      char m_readytype; // E for expanded, T for tagged, C for constant
188    
189    
190      /**
191      Does the work for toString.
192      */
193      void
194      intoString(std::ostringstream& oss) const;
195    
196      /**
197       \brief Converts the DataLazy into an IDENTITY storing the value of the expression.
198       This method uses the original methods on the Data class to evaluate the expressions.
199       For this reason, it should not be used on DataExpanded instances. (To do so would defeat
200       the purpose of using DataLazy in the first place).
201      */
202      void
203      collapse();       // converts the node into an IDENTITY node
204    
205    
206      /**
207      \brief Evaluates the expression using methods on Data.
208      This does the work for the collapse method.
209      For reasons of efficiency do not call this method on DataExpanded nodes.
210      */
211      DataReady_ptr
212      collapseToReady();
213    
214      /**
215      \brief Compute the value of the expression for the given sample.
216      \return Vector which stores the value of the subexpression for the given sample.
217      \param v A vector to store intermediate results.
218      \param offset Index in v to begin storing results.
219      \param sampleNo Sample number to evaluate.
220      \param roffset (output parameter) the offset in the return vector where the result begins.
221    
222      The return value will be an existing vector so do not deallocate it.
223      */
224      const ValueType*
225      resolveSample(ValueType& v,  size_t offset ,int sampleNo, size_t& roffset);
226    
227      /**
228      \brief Compute the value of the expression (binary operation) for the given sample.
229      \return Vector which stores the value of the subexpression for the given sample.
230      \param v A vector to store intermediate results.
231      \param offset Index in v to begin storing results.
232      \param sampleNo Sample number to evaluate.
233      \param roffset (output parameter) the offset in the return vector where the result begins.
234    
235      The return value will be an existing vector so do not deallocate it.
236      If the result is stored in v it should be stored at the offset given.
237      Everything from offset to the end of v should be considered available for this method to use.
238      */
239      ValueType*
240      resolveUnary(ValueType& v,  size_t offset,int sampleNo,  size_t& roffset) const;
241    
242      /**
243      \brief Compute the value of the expression (binary operation) for the given sample.
244      \return Vector which stores the value of the subexpression for the given sample.
245      \param v A vector to store intermediate results.
246      \param offset Index in v to begin storing results.
247      \param sampleNo Sample number to evaluate.
248      \param roffset (output parameter) the offset in the return vector where the result begins.
249    
250      The return value will be an existing vector so do not deallocate it.
251      If the result is stored in v it should be stored at the offset given.
252      Everything from offset to the end of v should be considered available for this method to use.
253      */
254      ValueType*
255      resolveBinary(ValueType& v,  size_t offset,int sampleNo,  size_t& roffset) const;
256    
257  };  };
258    
259  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26