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

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

  ViewVC Help
Powered by ViewVC 1.1.26