/[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 1903 - (hide annotations)
Wed Oct 22 06:11:01 2008 UTC (11 years, 7 months ago) by jfenwick
File MIME type: text/plain
File size: 6819 byte(s)
More fixes to doxygen for scons.
Added += and other forms of +

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

  ViewVC Help
Powered by ViewVC 1.1.26