/[escript]/branches/arrayview_from_1695_trunk/escript/src/DataTypes.h
ViewVC logotype

Diff of /branches/arrayview_from_1695_trunk/escript/src/DataTypes.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1734 by jfenwick, Thu Aug 28 06:11:56 2008 UTC revision 1781 by jfenwick, Thu Sep 11 05:03:14 2008 UTC
# Line 1  Line 1 
1    
2  /* $Id$ */  /* $Id:    $ */
3    
4  /*******************************************************  /*******************************************************
5   *   *
# Line 20  Line 20 
20  #include <vector>  #include <vector>
21  #include <string>  #include <string>
22  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
23    #include <boost/python/extract.hpp>
24    
25  namespace escript {  namespace escript {
26    
27   namespace DataTypes {  namespace DataTypes {
28    
29    /**
30    \namespace escript::DataTypes
31    \brief Contains the types to represent Shapes, Regions, RegionLoop ranges and vectors of data as well as the functions to manipulate them.
32    */
33    //    //
34    // Some basic types which define the data values and view shapes.    // Some basic types which define the data values and view shapes.
35    typedef DataVector                        ValueType;    typedef DataVector                        ValueType;//!< Vector to store underlying data.
36    typedef std::vector<int>                  ShapeType;    typedef std::vector<int>                  ShapeType;//!< The shape of a single datapoint.
37    typedef std::vector<std::pair<int, int> > RegionType;    typedef std::vector<std::pair<int, int> > RegionType;
38    typedef std::vector<std::pair<int, int> > RegionLoopRangeType;    typedef std::vector<std::pair<int, int> > RegionLoopRangeType;
39    static const int maxRank=4;    static const int maxRank=4;//!< The maximum number of dimensions a datapoint can have.
40    static const ShapeType scalarShape;    static const ShapeType scalarShape;//!< Use this instead of creating empty shape objects for scalars.
41    
 // This file contains static functions moved from DataArrayView  
42    /**    /**
43       \brief       \brief
44       Calculate the number of values for the given shape.       Calculate the number of values in a datapoint with the given shape.
45    
46         \param shape
47    */    */
48    ESCRIPT_DLL_API    ESCRIPT_DLL_API
49    int    int
50    noValues(const DataTypes::ShapeType& shape);    noValues(const DataTypes::ShapeType& shape);
51    
52    /**    /**
53       \brief       \brief
54       Calculate the number of values for the given region.       Calculate the number of values for the given region.
55    
56        \param region
57    */    */
58    ESCRIPT_DLL_API    ESCRIPT_DLL_API
59    int    int
# Line 76  namespace escript { Line 85  namespace escript {
85       \brief       \brief
86       Determine the region specified by the given python slice object.       Determine the region specified by the given python slice object.
87    
88         \param shape - Input - Shape of the object being sliced.
89       \param key - Input -       \param key - Input -
90                      python slice object specifying region to be returned.                      python slice object specifying region to be returned.
91    
# Line 147  namespace escript { Line 157  namespace escript {
157    DataTypes::RegionLoopRangeType    DataTypes::RegionLoopRangeType
158    getSliceRegionLoopRange(const DataTypes::RegionType& region);    getSliceRegionLoopRange(const DataTypes::RegionType& region);
159    
160      /**
161       \brief Return the rank (number of dimensions) of the given shape.
162    
163       \param shape
164       \return the rank.
165      */
166    ESCRIPT_DLL_API    ESCRIPT_DLL_API
167    inline    inline
168    int    int
# Line 155  namespace escript { Line 171  namespace escript {
171      return shape.size();      return shape.size();
172    }    }
173    
174    
175      /**
176      \brief Compute the offset (in 1D vector) of a given subscript with a shape.
177    
178      \param shape - Input - Shape of the datapoint.
179      \param i - Input - subscript to locate.
180      \return offset relative to the beginning of the datapoint.
181      */
182    ESCRIPT_DLL_API    ESCRIPT_DLL_API
183    inline    inline
184    DataTypes::ValueType::size_type    DataTypes::ValueType::size_type
# Line 165  namespace escript { Line 189  namespace escript {
189      return i;      return i;
190    }    }
191    
192      /**
193      \brief Compute the offset (in 1D vector) of a given subscript with a shape.
194    
195      \param shape - Input - Shape of the datapoint.
196      \param i,j - Input - subscripts to locate.
197      \return offset relative to the beginning of the datapoint.
198      */
199    ESCRIPT_DLL_API    ESCRIPT_DLL_API
200    inline    inline
201    DataTypes::ValueType::size_type    DataTypes::ValueType::size_type
# Line 177  namespace escript { Line 208  namespace escript {
208      return temp;      return temp;
209    }    }
210    
211      /**
212      \brief Compute the offset (in 1D vector) of a given subscript with a shape.
213    
214      \param shape - Input - Shape of the datapoint.
215      \param i,j,k - Input - subscripts to locate.
216      \return offset relative to the beginning of the datapoint.
217      */
218    ESCRIPT_DLL_API    ESCRIPT_DLL_API
219    inline    inline
220    DataTypes::ValueType::size_type    DataTypes::ValueType::size_type
# Line 189  namespace escript { Line 227  namespace escript {
227      return temp;      return temp;
228    }    }
229    
230      /**
231      \brief Compute the offset (in 1D vector) of a given subscript with a shape.
232    
233      \param shape - Input - Shape of the datapoint.
234      \param i,j,k,m - Input - subscripts to locate.
235      \return offset relative to the beginning of the datapoint.
236      */
237    ESCRIPT_DLL_API    ESCRIPT_DLL_API
238    inline    inline
239    DataTypes::ValueType::size_type    DataTypes::ValueType::size_type
# Line 202  namespace escript { Line 247  namespace escript {
247      return temp;      return temp;
248    }    }
249    
250      /**
251         \brief Test if two shapes are equal.
252      */
253    ESCRIPT_DLL_API    ESCRIPT_DLL_API
254    inline    inline
255    bool    bool
# Line 210  namespace escript { Line 258  namespace escript {
258      return s1==s2;      return s1==s2;
259    }    }
260    
261      /**
262       \brief Produce a string containing two shapes.
263    
264       \param messagePrefix - Beginning of the message.
265       \param other - displayed in the message as "Other shape"
266       \param thisShape - displayed in the message as "This shape"
267      */
268     std::string     std::string
269     createShapeErrorMessage(const std::string& messagePrefix,     createShapeErrorMessage(const std::string& messagePrefix,
270                                            const DataTypes::ShapeType& other,                                            const DataTypes::ShapeType& other,
# Line 219  namespace escript { Line 274  namespace escript {
274    /**    /**
275       \brief       \brief
276       Copy a data slice specified by the given region and offset from the       Copy a data slice specified by the given region and offset from the
277       given view into this view at the given offset.       "other" view into the "left" view at the given offset.
278        
279       \param thisOffset - Input -       \param left - vector to copy into
280                        Copy the slice to this offset in this view.       \param leftShape - shape of datapoints for the left vector
281       \param other - Input -       \param leftOffset - location within left to start copying to
282                        View to copy data from.       \param other - vector to copy from
283       \param otherOffset - Input -       \param otherShape - shape of datapoints for the other vector
284                        Copy the slice from this offset in the given view.       \param otherOffset - location within other vector to start copying from
285       \param region - Input -       \param region - Input -
286                        Region in other view to copy data from.                        Region in other view to copy data from.
287    */    */
288     void     void
289     copySlice(ValueType& left,     copySlice(ValueType& left,
290                  const ShapeType& leftShape,                  const ShapeType& leftShape,
291                  ValueType::size_type thisOffset,                  ValueType::size_type leftOffset,
292                              const ValueType& other,                              const ValueType& other,
293                  const ShapeType& otherShape,                  const ShapeType& otherShape,
294                              ValueType::size_type otherOffset,                              ValueType::size_type otherOffset,
# Line 242  namespace escript { Line 297  namespace escript {
297    /**    /**
298       \brief       \brief
299       Copy data into a slice specified by the given region and offset in       Copy data into a slice specified by the given region and offset in
300       this view from the given view at the given offset.       the left vector from the other vector at the given offset.
301    
302       \param thisOffset - Input -       \param left - vector to copy into
303                      Copy the slice to this offset in this view.       \param leftShape - shape of datapoints for the left vector
304       \param other - Input -       \param leftOffset - location within left to start copying to
305                      View to copy data from.       \param other - vector to copy from
306       \param otherOffset - Input -       \param otherShape - shape of datapoints for the other vector
307                      Copy the slice from this offset in the given view.       \param otherOffset - location within other vector to start copying from
308       \param region - Input -       \param region - Input -
309                      Region in this view to copy data to.                        Region in the left vector to copy data to.
310    */    */
311     void     void
312     copySliceFrom(ValueType& left,     copySliceFrom(ValueType& left,
313                  const ShapeType& leftShape,                  const ShapeType& leftShape,
314                  ValueType::size_type thisOffset,                  ValueType::size_type leftOffset,
315                                  const ValueType& other,                                  const ValueType& other,
316                  const ShapeType& otherShape,                  const ShapeType& otherShape,
317                                  ValueType::size_type otherOffset,                                  ValueType::size_type otherOffset,
318                                  const RegionLoopRangeType& region);                                  const RegionLoopRangeType& region);
319    
320    
321       /**
322          \brief Display a single value (with the specified shape) from the data.
323    
324         \param data - vector containing the datapoint
325         \param shape - shape of the datapoint
326         \param offset - start of the datapoint within data
327         \param prefix - string to prepend to the output
328       */
329       std::string
330       pointToString(const ValueType& data,const ShapeType& shape, int offset, const std::string& prefix);
331    
332    
333       /**
334          \brief Extract shape information from the supplied numarray.
335       */
336       inline
337       ShapeType
338       shapeFromNumArray(const boost::python::numeric::array& value)
339       {
340          // extract the shape of the numarray
341        DataTypes::ShapeType tempShape;
342        for (int i=0; i < value.getrank(); i++) {
343            tempShape.push_back(boost::python::extract<int>(value.getshape()[i]));
344        }
345        return tempShape;
346       }
347    
348    
349       /**
350          \brief  Copy a point from one vector to another. Note: This version does not check to see if shapes are the same.
351    
352       \param dest - vector to copy to
353       \param doffset - beginning of the target datapoint in dest
354       \param nvals - the number of values comprising the datapoint
355       \param src - vector to copy from
356       \param soffset - beginning of the datapoint in src
357       */
358       void copyPoint(ValueType& dest, ValueType::size_type doffset, ValueType::size_type nvals, const ValueType& src, ValueType::size_type soffset);
359    
360   }   // End namespace DataTypes   }   // End namespace DataTypes
361    
362    
363  } // end of namespace escipt  } // end of namespace escipt
364    
365  #endif  #endif
366    

Legend:
Removed from v.1734  
changed lines
  Added in v.1781

  ViewVC Help
Powered by ViewVC 1.1.26