/[escript]/branches/schroedinger/escript/src/DataLazy.h
ViewVC logotype

Annotation of /branches/schroedinger/escript/src/DataLazy.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1899 - (hide annotations)
Mon Oct 20 05:13:24 2008 UTC (11 years, 7 months ago) by jfenwick
File MIME type: text/plain
File size: 6667 byte(s)
Branch commit.
Added some doco to DataLazy.
Made Data::integrate aware of DataLazy.


1 jfenwick 1865
2     /*******************************************************
3     *
4     * Copyright (c) 2003-2008 by University of Queensland
5     * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13    
14    
15     #if !defined escript_DataLazy_20081008_H
16     #define escript_DataLazy_20081008_H
17     #include "system_dep.h"
18    
19     #include "DataAbstract.h"
20    
21     #include <string>
22 jfenwick 1868 #include <functional>
23 jfenwick 1865
24 jfenwick 1879 #include "LocalOps.h" // for tensor_binary_op
25    
26 jfenwick 1865 namespace escript {
27    
28     enum ES_optype
29     {
30     UNKNOWNOP=0,
31 jfenwick 1868 IDENTITY=1,
32     ADD=2,
33     SUB=3,
34     MUL=4,
35 jfenwick 1886 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 jfenwick 1888 POS=24,
55     EXP=25,
56     SQRT=26,
57     RECIP=27,
58     GZ=28,
59     LZ=29,
60     GEZ=30,
61     LEZ=31
62 jfenwick 1865 };
63    
64     const std::string&
65     opToString(ES_optype op);
66    
67     /**
68     \class escript::DataLazy
69     \brief Wraps an expression tree of other DataObjects.
70     The values of DataPoints are computed when requested rather than all at once.
71 jfenwick 1879
72     NOTE: This class assumes that the Data being pointed at are immutable.
73 jfenwick 1865 */
74    
75 jfenwick 1879 class DataLazy;
76    
77     typedef POINTER_WRAPPER_CLASS(DataLazy) DataLazy_ptr;
78     typedef POINTER_WRAPPER_CLASS(const DataLazy) const_DataLazy_ptr;
79    
80 jfenwick 1865 class DataLazy : public DataAbstract
81     {
82    
83     typedef DataAbstract parent;
84     typedef DataTypes::ValueType ValueType;
85     typedef DataTypes::ShapeType ShapeType;
86    
87     public:
88 jfenwick 1899 /**
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 jfenwick 1865 ESCRIPT_DLL_API
94     DataLazy(DataAbstract_ptr p);
95    
96 jfenwick 1899
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 jfenwick 1865 ESCRIPT_DLL_API
105 jfenwick 1886 DataLazy(DataAbstract_ptr left, ES_optype op);
106    
107 jfenwick 1899 /**
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 jfenwick 1886 ESCRIPT_DLL_API
115 jfenwick 1865 DataLazy(DataAbstract_ptr left, DataAbstract_ptr right, ES_optype op);
116    
117     ESCRIPT_DLL_API
118     ~DataLazy();
119    
120     /**
121 jfenwick 1899 \brief Evaluate the lazy expression.
122     \return A DataReady with the value of the lazy expresion.
123 jfenwick 1865 */
124     ESCRIPT_DLL_API
125 jfenwick 1879 DataReady_ptr
126     resolve();
127 jfenwick 1865
128     ESCRIPT_DLL_API
129     std::string
130     toString() const;
131    
132     ESCRIPT_DLL_API
133     DataAbstract*
134     deepCopy();
135    
136    
137     /**
138     \brief
139     Return the number of doubles that would be stored for this Data object if it were resolved.
140     */
141     ESCRIPT_DLL_API
142     ValueType::size_type
143     getLength() const;
144    
145    
146     ESCRIPT_DLL_API
147     DataAbstract*
148     getSlice(const DataTypes::RegionType& region) const;
149    
150    
151     DataTypes::ValueType::size_type
152     getPointOffset(int sampleNo,
153     int dataPointNo) const;
154    
155 jfenwick 1879
156 jfenwick 1899 /**
157     \return the number of samples which need to be stored to evaluate the expression.
158     */
159 jfenwick 1879 ESCRIPT_DLL_API
160     int
161     getBuffsRequired() const;
162    
163 jfenwick 1889
164    
165 jfenwick 1865 private:
166 jfenwick 1899 DataReady_ptr m_id; // For IDENTITY nodes, stores a wrapped value.
167     DataLazy_ptr m_left, m_right; // operands for operation.
168     ES_optype m_op; // operation to perform.
169 jfenwick 1879 size_t m_length; // number of values represented by the operation
170    
171 jfenwick 1899 int m_buffsRequired; // how many samples are required to evaluate this expression
172 jfenwick 1879 size_t m_samplesize; // number of values required to store a sample
173    
174 jfenwick 1899 char m_readytype; // E for expanded, T for tagged, C for constant
175 jfenwick 1879
176 jfenwick 1889
177 jfenwick 1899 /**
178     Does the work for toString.
179     */
180 jfenwick 1886 void
181     intoString(std::ostringstream& oss) const;
182    
183 jfenwick 1899 /**
184     \brief Converts the DataLazy into an IDENTITY storing the value of the expression.
185     This method uses the original methods on the Data class to evaluate the expressions.
186     For this reason, it should not be used on DataExpanded instances. (To do so would defeat
187     the purpose of using DataLazy in the first place).
188     */
189 jfenwick 1889 void
190     collapse(); // converts the node into an IDENTITY node
191    
192 jfenwick 1899
193     /**
194     \brief Evaluates the expression using methods on Data.
195     This does the work for the collapse method.
196     For reasons of efficiency do not call this method on DataExpanded nodes.
197     */
198 jfenwick 1889 DataReady_ptr
199     collapseToReady();
200    
201 jfenwick 1899 /**
202     \brief Compute the value of the expression for the given sample.
203     \return Vector which stores the value of the subexpression for the given sample.
204     \param v A vector to store intermediate results.
205     \param offset Index in v to begin storing results.
206     \param sampleNo Sample number to evaluate.
207     \param roffset (output parameter) the offset in the return vector where the result begins.
208 jfenwick 1889
209 jfenwick 1899 The return value will be an existing vector so do not deallocate it.
210     */
211     const ValueType*
212     resolveSample(ValueType& v, size_t offset ,int sampleNo, size_t& roffset);
213 jfenwick 1889
214 jfenwick 1899 /**
215     \brief Compute the value of the expression (binary operation) 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     If the result is stored in v it should be stored at the offset given.
224     Everything from offset to the end of v should be considered available for this method to use.
225     */
226 jfenwick 1898 ValueType*
227     resolveUnary(ValueType& v, size_t offset,int sampleNo, size_t& roffset) const;
228 jfenwick 1889
229 jfenwick 1899 /**
230     \brief Compute the value of the expression (binary operation) for the given sample.
231     \return Vector which stores the value of the subexpression for the given sample.
232     \param v A vector to store intermediate results.
233     \param offset Index in v to begin storing results.
234     \param sampleNo Sample number to evaluate.
235     \param roffset (output parameter) the offset in the return vector where the result begins.
236    
237     The return value will be an existing vector so do not deallocate it.
238     If the result is stored in v it should be stored at the offset given.
239     Everything from offset to the end of v should be considered available for this method to use.
240     */
241 jfenwick 1898 ValueType*
242     resolveBinary(ValueType& v, size_t offset,int sampleNo, size_t& roffset) const;
243    
244 jfenwick 1865 };
245    
246     }
247     #endif

  ViewVC Help
Powered by ViewVC 1.1.26