/[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 1910 - (hide annotations)
Thu Oct 23 03:05:28 2008 UTC (11 years, 7 months ago) by jfenwick
File MIME type: text/plain
File size: 6929 byte(s)
Branch commit.
Support for ** added.

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

  ViewVC Help
Powered by ViewVC 1.1.26