/[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 1713 by jfenwick, Wed Aug 20 05:04:28 2008 UTC revision 1714 by jfenwick, Thu Aug 21 00:01:55 2008 UTC
# Line 18  Line 18 
18  #include "system_dep.h"  #include "system_dep.h"
19  #include "DataVector.h"  #include "DataVector.h"
20  #include <vector>  #include <vector>
21    #include <boost/python/object.hpp>
22    
23  namespace escript {  namespace escript {
24    
# Line 58  namespace escript { Line 59  namespace escript {
59    std::string    std::string
60    shapeToString(const DataTypes::ShapeType& shape);    shapeToString(const DataTypes::ShapeType& shape);
61    
62      /**
63         \brief
64         Determine the shape of the specified slice region.
65    
66         \param region - Input -
67                           Slice region.
68      */
69      ESCRIPT_DLL_API
70      DataTypes::ShapeType
71      getResultSliceShape(const DataTypes::RegionType& region);
72    
73    
74     /**
75         \brief
76         Determine the region specified by the given python slice object.
77    
78         \param key - Input -
79                        python slice object specifying region to be returned.
80    
81         The slice object is a tuple of n python slice specifiers, where
82         n <= the rank of this Data object. Each slice specifier specifies the
83         range of indexes to be sliced from the corresponding dimension. The
84         first specifier corresponds to the first dimension, the second to the
85         second and so on. Where n < the rank, the remaining dimensions are
86         sliced across the full range of their indicies.
87    
88         Each slice specifier is of the form "a:b", which specifies a slice
89         from index a, up to but not including index b. Where index a is ommitted
90         a is assumed to be 0. Where index b is ommitted, b is assumed to be the
91         length of this dimension. Where both are ommitted (eg: ":") the slice is
92         assumed to encompass that entire dimension.
93    
94         Where one of the slice specifiers is a single integer, eg: [1], we
95         want to generate a rank-1 dimension object, as opposed to eg: [1,2]
96         which implies we want to take a rank dimensional object with one
97         dimension of size 1.
98    
99         The return value is a vector of pairs with length equal to the rank of
100         this object. Each pair corresponds to the range of indicies from the
101         corresponding dimension to be sliced from, as specified in the input
102         slice object.
103    
104         Examples:
105    
106           For a rank 1 object of shape(5):
107    
108             getSliceRegion(:)   => < <0,5> >
109             getSliceRegion(2:3) => < <2,3> >
110             getSliceRegion(:3)  => < <0,3> >
111             getSliceRegion(2:)  => < <2,5> >
112    
113           For a rank 2 object of shape(4,5):
114    
115             getSliceRegion(2:3) => < <2,3> <0,5> >
116             getSliceRegion(2)   => < <2,3> <0,5> >
117               NB: but return object requested will have rank 1, shape(5), with
118                   values taken from index 2 of this object's first dimension.
119    
120           For a rank 3 object of shape (2,4,6):
121    
122             getSliceRegion(0:2,0:4,0:6) => < <0,2> <0,4> <0,6> >
123             getSliceRegion(:,:,:)       => < <0,2> <0,4> <0,6> >
124             getSliceRegion(0:1)         => < <0,1> <0,4> <0,6> >
125             getSliceRegion(:1,0:2)      => < <0,1> <0,2> <0,6> >
126    
127      */
128       ESCRIPT_DLL_API
129       DataTypes::RegionType
130       getSliceRegion(const DataTypes::ShapeType& shape, const boost::python::object& key);
131    
132    
133    
134    ESCRIPT_DLL_API    ESCRIPT_DLL_API
135    inline    inline
# Line 67  namespace escript { Line 139  namespace escript {
139      return shape.size();      return shape.size();
140    }    }
141    
142   }   // End DataTypes    ESCRIPT_DLL_API
143      inline
144      DataTypes::ValueType::size_type
145      getRelIndex(const DataTypes::ShapeType& shape, DataTypes::ValueType::size_type i)
146      {
147        EsysAssert((getRank(shape)==1),"Incorrect number of indices for the rank of this object.");
148        EsysAssert((i < DataTypes::noValues(shape)), "Error - Invalid index.");
149        return i;
150      }
151    
152      ESCRIPT_DLL_API
153      inline
154      DataTypes::ValueType::size_type
155      getRelIndex(const DataTypes::ShapeType& shape, DataTypes::ValueType::size_type i,
156           DataTypes::ValueType::size_type j)
157      {
158        EsysAssert((getRank()==2),"Incorrect number of indices for the rank of this object.");
159        DataTypes::ValueType::size_type temp=i+j*shape[0];
160        EsysAssert((temp < DataTypes::noValues(shape)), "Error - Invalid index.");
161        return temp;
162      }
163    
164      ESCRIPT_DLL_API
165      inline
166      DataTypes::ValueType::size_type
167      getRelIndex(const DataTypes::ShapeType& shape, DataTypes::ValueType::size_type i,
168           DataTypes::ValueType::size_type j, DataTypes::ValueType::size_type k)
169      {
170        EsysAssert((getRank()==3),"Incorrect number of indices for the rank of this object.");
171        DataTypes::ValueType::size_type temp=i+j*shape[0]+k*shape[1]*shape[0];
172        EsysAssert((temp < DataTypes::noValues(shape)), "Error - Invalid index.");
173        return temp;
174      }
175    
176      ESCRIPT_DLL_API
177      inline
178      DataTypes::ValueType::size_type
179      getRelIndex(const DataTypes::ShapeType& shape, DataTypes::ValueType::size_type i,
180           DataTypes::ValueType::size_type j, DataTypes::ValueType::size_type k,
181           DataTypes::ValueType::size_type m)
182      {
183        EsysAssert((getRank()==4),"Incorrect number of indices for the rank of this object.");
184        DataTypes::ValueType::size_type temp=i+j*shape[0]+k*shape[1]*shape[0]+m*shape[2]*shape[1]*shape[0];
185        EsysAssert((temp < DataTypes::noValues(m_shape)), "Error - Invalid index.");
186        return temp;
187      }
188    
189    
190     }   // End namespace DataTypes
191    
192    
193  } // end of namespace  } // end of namespace escipt
194    
195  #endif  #endif

Legend:
Removed from v.1713  
changed lines
  Added in v.1714

  ViewVC Help
Powered by ViewVC 1.1.26