/[escript]/trunk/escript/src/DataVector.h
ViewVC logotype

Annotation of /trunk/escript/src/DataVector.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2271 - (hide annotations)
Mon Feb 16 05:08:29 2009 UTC (10 years, 9 months ago) by jfenwick
File MIME type: text/plain
File size: 6244 byte(s)
Merging version 2269 to trunk

1 jgs 121
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
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 ksteube 1312
14 ksteube 1811
15 jgs 117 #if !defined escript_DataVector_20050324_H
16     #define escript_DataVector_20050324_H
17 woo409 757 #include "system_dep.h"
18 jgs 117
19 robwdcock 682 #include "esysUtils/EsysAssert.h"
20 jgs 474
21 jgs 117 #include <vector>
22 jgs 474 #include <iostream>
23     #include <fstream>
24 jfenwick 1796 #include <boost/python/numeric.hpp>
25 jgs 117
26     namespace escript {
27    
28 jfenwick 2271 class WrappedArray;
29    
30 jgs 117 /**
31     \brief
32     DataVector implements an arbitrarily long vector of data values.
33 jgs 121 DataVector is the underlying data container for Data objects.
34 jgs 117
35     Description:
36     DataVector provides an implementation of a vector of data values for use
37     by DataBlocks2D and DataArrayView. Hiding the vector in this container
38     allows different implementations to be swapped in without disrupting the
39 jgs 121 client classes.
40 jgs 117 */
41    
42 woo409 757 class ESCRIPT_DLL_API DataVector {
43 jgs 117
44     public:
45    
46     //
47     // The type of the elements stored in the vector.
48     typedef double ElementType;
49    
50     //
51     // The underlying type used to implement the vector.
52 jgs 121 typedef ElementType * ValueType;
53 jgs 117
54     //
55 jgs 121 // Various types exported to clients of this class.
56     typedef ElementType value_type;
57     typedef long size_type;
58     typedef ElementType & reference;
59     typedef const ElementType & const_reference;
60 jgs 117
61     /**
62     \brief
63     Default constructor for DataVector.
64    
65     Description:
66     Constructs an empty DataVector object.
67     */
68     DataVector();
69    
70     /**
71     \brief
72     Copy constructor for DataVector.
73    
74     Description:
75     Constructs a DataVector object which is a copy of the
76     given DataVector object.
77     */
78     DataVector(const DataVector& other);
79    
80     /**
81     \brief
82     Constructor for DataVector.
83    
84     Description:
85     Constructs a DataVector object of length "size" with all elements
86 jgs 121 initilised to "val".
87 jgs 117
88     \param size - Input - Number of elements in the vector.
89 jgs 121 \param val - Input - Initial value for all elements in the vector. Default is 0.0.
90     \param blockSize - Input - size of blocks within the vector, overall vector
91     size must be a precise multiple of the block size. Default is 1.
92 jgs 151
93     In escript::Data, blocksize corresponds to the number of elements required to hold all
94     the data-points for a sample, ie: the product of the dimensions of a data-point and the
95     number of data-points per sample. Size is the total number of elements required to hold
96     all elements for all data-points in the given object, ie: number of samples * blocksize.
97 jgs 117 */
98 jgs 121 DataVector(const size_type size,
99     const value_type val=0.0,
100     const size_type blockSize=1);
101 jgs 117
102     /**
103     \brief
104     Default destructor for DataVector.
105    
106     Description:
107     Destroys the current DataVector object.
108     */
109     ~DataVector();
110    
111     /**
112     \brief
113     Resize the DataVector to the given length "newSize".
114     All current data is lost. All elements in the new DataVector are
115 jgs 121 initialised to "newVal".
116 jgs 117
117     \param newSize - Input - New size for the vector.
118 jgs 121 \param newVal - Input - New initial value for all elements in the vector.
119     \param newBlockSize - Input - New block size for the vector.
120 jgs 117 */
121     void
122 jgs 121 resize(const size_type newSize,
123     const value_type newVal=0.0,
124     const size_type newBlockSize=1);
125 jgs 117
126     /**
127 jfenwick 1796 \brief
128     Populates the vector with the data from value.
129 jfenwick 2271 This method currently throws an exception if the specified number of copies won't fit.
130     \warning This function does not attempt to perform shape checking.
131 jfenwick 1796 */
132     void
133 jfenwick 2271 copyFromArray(const escript::WrappedArray& value, size_type copies);
134 jfenwick 1796
135 jfenwick 2271 void
136     copyFromArrayToOffset(const WrappedArray& value, size_type offset, size_type copies);
137 jfenwick 1796
138    
139     /**
140 jgs 117 \brief
141     Return the number of elements in this DataVector.
142     */
143     inline
144 jgs 121 size_type
145 jgs 117 size() const;
146    
147     /**
148     \brief
149     DataVector assignment operator "=".
150     Assign the given DataVector object to this.
151     */
152     DataVector&
153     operator=(const DataVector& other);
154    
155     /**
156     \brief
157     DataVector equality comparison operator "==".
158     Return true if the given DataVector is equal to this.
159     */
160     bool
161 jgs 121 operator==(const DataVector& other) const;
162 jgs 117
163     /**
164     \brief
165     DataVector inequality comparison operator "!=".
166     Return true if the given DataVector is not equal to this.
167     */
168     bool
169 jgs 121 operator!=(const DataVector& other) const;
170 jgs 117
171     /**
172     \brief
173     Return a reference to the element at position i in this DataVector.
174     Will throw an exception if an invalid index "i" is given.
175    
176     NB: access to the element one past the end of the vector is permitted
177     in order to provide a facility equivalent to an end() pointer.
178     */
179     inline
180 jgs 121 reference
181     operator[](const size_type i);
182 jgs 117
183     inline
184 jgs 121 const_reference
185     operator[](const size_type i) const;
186 jgs 117
187 jgs 123
188 jgs 117 protected:
189    
190     private:
191    
192 jgs 121 size_type m_size;
193     size_type m_dim;
194     size_type m_N;
195    
196 jgs 117 //
197     // The container for the elements contained in this DataVector.
198 jgs 121 ValueType m_array_data;
199 jgs 117 };
200    
201 gross 797 /**
202     \brief
203     releases unused memory in the memory manager.
204     */
205    
206     ESCRIPT_DLL_API void releaseUnusedMemory();
207    
208    
209    
210 jgs 117 inline
211 jgs 121 DataVector::size_type
212 jgs 117 DataVector::size() const
213     {
214 jgs 121 return m_size;
215 jgs 117 }
216    
217     inline
218 jgs 121 DataVector::reference
219     DataVector::operator[](const DataVector::size_type i)
220 jgs 117 {
221 jfenwick 2152 EsysAssert(i<size(),"DataVector: invalid index specified. " << i << " of " << size());
222 jgs 121 return m_array_data[i];
223 jgs 117 }
224    
225     inline
226 jgs 121 DataVector::const_reference
227     DataVector::operator[](const DataVector::size_type i) const
228 jgs 117 {
229 jfenwick 2152 EsysAssert(i<size(),"DataVector: invalid index specified. " << i << " of " << size());
230 jgs 121 return m_array_data[i];
231 jgs 117 }
232    
233     } // end of namespace
234    
235     #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26