/[escript]/branches/arrexp_2137_win/escript/src/DataConstant.h
ViewVC logotype

Contents of /branches/arrexp_2137_win/escript/src/DataConstant.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2212 - (show annotations)
Wed Jan 14 00:15:00 2009 UTC (11 years, 5 months ago) by jfenwick
File MIME type: text/plain
File size: 6837 byte(s)
Executive summary:

This commit adds copy on write checks to operations involving shared data. 

Changes:

new #defines:
~~~~~~~~~~~~~
Data.cpp has ASSIGNMENT_MEANS_DEEPCOPY (defaults to undefined).
Defining this will put the data = operator back to making deep copies instead
of sharing data (now the default.)

Data:
~~~~~
. Added exclusiveWrite method to copy the underlying data if it is shared.
. Some operators which took python objects now call the c++ versions intead of duplicating code.

DataAbstract and offspring:
~~~~~~~~~~~~~~~~~~~~~~~~~~~
. Added method to determine whether the data is currently shared.
. Added getVectorRO to children of DataReady.
. Added getTagRO.

. Operations which modify values in place (or return modifiable pointers) now use
a macro to check for sharing. In the case where a modification attempt is detected, it throws an exception. In the future, I will enable this only for debugging.

. This shold not really have been required but the compiler was not choosing the use the const version as I would have liked. Besides, this makes things explict.

. Moved (and de-inlined) getVector in DataConstant (It was virtual in a parent class).

Unit tests:
~~~~~~~~~~~
Added both python and c++ unit tests to check known cases of sharing and "inplace"
modification operations.

General:
~~~~~~~~
Removed some commented out code.

1
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_DataConstant_20040323_H
16 #define escript_DataConstant_20040323_H
17 #include "system_dep.h"
18
19 #include "DataReady.h"
20 #include "WrappedArray.h"
21
22 #include <boost/python/numeric.hpp>
23
24 namespace escript {
25
26 /**
27 \brief
28 DataConstant stores a single data point which represents the entire
29 function space.
30
31 Description:
32 DataConstant stores a single data point which represents the entire
33 function space.
34 */
35 class DataConstant : public DataReady {
36 typedef DataReady parent;
37 public:
38
39 /**
40 \brief
41 Constructor for DataConstant objects.
42
43 Description:
44 Constructor for DataConstant objects.
45
46 \param value - Input - Data value for a single point.
47 \param what - Input - A description of what this data object represents.
48 */
49 ESCRIPT_DLL_API
50 DataConstant(const WrappedArray& value,
51 const FunctionSpace& what);
52
53
54 /**
55 \brief
56 Copy constructor. Performs a deep copy.
57 */
58 ESCRIPT_DLL_API
59 DataConstant(const DataConstant& other);
60
61
62 /**
63 \brief
64 Alternative constructor for DataConstant objects.
65
66 Description:
67 Alternative Constructor for DataConstant objects.
68 \param other - Input - Data object to copy from.
69 \param region - Input - region to copy.
70 */
71 ESCRIPT_DLL_API
72 DataConstant(const DataConstant& other,
73 const DataTypes::RegionType& region);
74
75 /**
76 \brief
77 Alternative constructor for DataConstant objects.
78
79 Description:
80 Alternative Constructor for DataConstant objects.
81 \param what - Input - A description of what this data object represents.
82 \param shape - Input - the shape of each data-point.
83 \param data - the data values for each data-point.
84 */
85 ESCRIPT_DLL_API
86 DataConstant(const FunctionSpace& what,
87 const DataTypes::ShapeType &shape,
88 const DataTypes::ValueType &data);
89
90
91 ESCRIPT_DLL_API
92 bool
93 isConstant() const
94 {
95 return true;
96 };
97
98
99 /**
100 \brief
101 Write the data as a string.
102 */
103 ESCRIPT_DLL_API
104 std::string
105 toString() const;
106
107 /**
108 \brief Return a deep copy of the current object.
109 */
110 ESCRIPT_DLL_API
111 virtual
112 DataAbstract*
113 deepCopy();
114
115
116 /**
117 \brief
118 dumps the object into a netCDF file
119 */
120 ESCRIPT_DLL_API
121 virtual
122 void
123 dump(const std::string fileName) const;
124
125 /**
126 \brief
127 sets all values to zero
128 */
129 ESCRIPT_DLL_API
130 virtual
131 void
132 setToZero();
133
134 /**
135 \brief
136 Return the offset for the given sample. This is a somewhat artificial notion
137 but returns the offset in bytes for the given point into the container
138 holding the point data. Only really necessary to avoid many DataArrayView
139 objects.
140 \param sampleNo - Input - sample number.
141 \param dataPointNo - Input - data point number for the sample.
142 */
143 ESCRIPT_DLL_API
144 virtual
145 DataTypes::ValueType::size_type
146 getPointOffset(int sampleNo,
147 int dataPointNo) const;
148
149 ESCRIPT_DLL_API
150 virtual
151 DataTypes::ValueType::size_type
152 getPointOffset(int sampleNo,
153 int dataPointNo);
154
155 // /**
156 /* \brief
157 Return a view into the data for the data point specified.
158 \param sampleNo - Input - sample number.
159 \param dataPointNo - Input - data point number for the sample.*/
160 // */
161 // ESCRIPT_DLL_API
162 // virtual
163 // DataArrayView
164 // getDataPoint(int sampleNo,
165 // int dataPointNo);
166
167 /**
168 \brief
169 Return the number of doubles stored for the Data object.
170 */
171 ESCRIPT_DLL_API
172 virtual
173 DataTypes::ValueType::size_type
174 getLength() const;
175
176 /**
177 \brief
178 Factory method that returns a newly created DataConstant object
179 sliced from the specified region of this object.
180 The caller is reponsible for managing the object created.
181 \param region - Input - region to slice from this object.
182 */
183 ESCRIPT_DLL_API
184 virtual
185 DataAbstract*
186 getSlice(const DataTypes::RegionType& region) const;
187
188 /**
189 \brief
190 Copy the specified region from the given value.
191 \param value - Input - Data object to copy from.
192 \param region - Input - Region to copy.
193 */
194 ESCRIPT_DLL_API
195 virtual
196 void
197 setSlice(const DataAbstract* value,
198 const DataTypes::RegionType& region);
199
200
201 /**
202 \brief
203 Computes a symmetric matrix (A + AT) / 2
204
205 \param ev - Output - symmetric matrix
206
207 */
208 ESCRIPT_DLL_API
209 virtual void
210 symmetric(DataAbstract* ev);
211
212 /**
213 \brief
214 Computes a nonsymmetric matrix (A - AT) / 2
215
216 \param ev - Output - nonsymmetric matrix
217
218 */
219 ESCRIPT_DLL_API
220 virtual void
221 nonsymmetric(DataAbstract* ev);
222
223 /**
224 \brief
225 Computes the trace of a matrix
226
227 \param ev - Output - trace of matrix
228
229 */
230 ESCRIPT_DLL_API
231 virtual void
232 trace(DataAbstract* ev, int axis_offset);
233
234 /**
235 \brief
236 Transpose each data point of this Data object around the given axis.
237
238 \param ev - Output - transpose of matrix
239
240 */
241 ESCRIPT_DLL_API
242 virtual void
243 transpose(DataAbstract* ev, int axis_offset);
244
245 /**
246 \brief
247 swaps components axis0 and axis1
248
249 \param ev - Output - swapped components
250
251 */
252 ESCRIPT_DLL_API
253 virtual void
254 swapaxes(DataAbstract* ev, int axis0, int axis1);
255
256
257 /**
258 \brief
259 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
260
261 \param ev - Output - eigenvalues in increasing order at each data point
262
263 */
264 ESCRIPT_DLL_API
265 virtual void
266 eigenvalues(DataAbstract* ev);
267
268 /**
269 \brief
270 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
271
272 \param ev - Output - eigenvalues in increasing order at each data point
273 \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
274 and the first nonzero component is positive.
275 \param tol - Input - eigenvalue with relative distance tol are treated as equal.
276
277 */
278
279 ESCRIPT_DLL_API
280 virtual void
281 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
282
283
284 /**
285 \brief
286 Return a reference to the underlying DataVector.
287 */
288 ESCRIPT_DLL_API
289 DataTypes::ValueType&
290 getVector();
291
292 ESCRIPT_DLL_API
293 const DataTypes::ValueType&
294 getVector() const;
295
296 ESCRIPT_DLL_API
297 const DataTypes::ValueType&
298 getVectorRO() const;
299
300 protected:
301
302 private:
303 //
304 // the actual data
305 DataTypes::ValueType m_data;
306
307 };
308
309 } // end of namespace
310 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26