00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #if !defined escript_DataTypes_20080811_H
00016 #define escript_DataTypes_20080811_H
00017 #include "system_dep.h"
00018 #include "DataVector.h"
00019 #include <vector>
00020 #include <string>
00021 #include <boost/python/object.hpp>
00022 #include <boost/python/extract.hpp>
00023
00024 namespace escript {
00025
00026 namespace DataTypes {
00027
00032
00033
00034 typedef DataVector ValueType;
00035 typedef std::vector<int> ShapeType;
00036 typedef std::vector<std::pair<int, int> > RegionType;
00037 typedef std::vector<std::pair<int, int> > RegionLoopRangeType;
00038 static const int maxRank=4;
00039 static const ShapeType scalarShape;
00040
00047 ESCRIPT_DLL_API
00048 int
00049 noValues(const DataTypes::ShapeType& shape);
00050
00057 ESCRIPT_DLL_API
00058 int
00059 noValues(const DataTypes::RegionLoopRangeType& region);
00060
00067 ESCRIPT_DLL_API
00068 std::string
00069 shapeToString(const DataTypes::ShapeType& shape);
00070
00078 ESCRIPT_DLL_API
00079 DataTypes::ShapeType
00080 getResultSliceShape(const DataTypes::RegionType& region);
00081
00082
00140 ESCRIPT_DLL_API
00141 DataTypes::RegionType
00142 getSliceRegion(const DataTypes::ShapeType& shape, const boost::python::object& key);
00143
00156 ESCRIPT_DLL_API
00157 DataTypes::RegionLoopRangeType
00158 getSliceRegionLoopRange(const DataTypes::RegionType& region);
00159
00166 ESCRIPT_DLL_API
00167 inline
00168 int
00169 getRank(const DataTypes::ShapeType& shape)
00170 {
00171 return shape.size();
00172 }
00173
00174
00182 ESCRIPT_DLL_API
00183 inline
00184 DataTypes::ValueType::size_type
00185 getRelIndex(const DataTypes::ShapeType& shape, DataTypes::ValueType::size_type i)
00186 {
00187 EsysAssert((getRank(shape)==1),"Incorrect number of indices for the rank of this object.");
00188 EsysAssert((i < DataTypes::noValues(shape)), "Error - Invalid index.");
00189 return i;
00190 }
00191
00200 ESCRIPT_DLL_API
00201 inline
00202 DataTypes::ValueType::size_type
00203 getRelIndex(const DataTypes::ShapeType& shape, DataTypes::ValueType::size_type i,
00204 DataTypes::ValueType::size_type j)
00205 {
00206
00207 EsysAssert((getRank(shape)==2),"Incorrect number of indices for the rank of this object.");
00208 DataTypes::ValueType::size_type temp=i+j*shape[0];
00209 EsysAssert((temp < DataTypes::noValues(shape)), "Error - Invalid index.");
00210 return temp;
00211 }
00212
00220 ESCRIPT_DLL_API
00221 inline
00222 DataTypes::ValueType::size_type
00223 getRelIndex(const DataTypes::ShapeType& shape, DataTypes::ValueType::size_type i,
00224 DataTypes::ValueType::size_type j, DataTypes::ValueType::size_type k)
00225 {
00226
00227 EsysAssert((getRank(shape)==3),"Incorrect number of indices for the rank of this object.");
00228 DataTypes::ValueType::size_type temp=i+j*shape[0]+k*shape[1]*shape[0];
00229 EsysAssert((temp < DataTypes::noValues(shape)), "Error - Invalid index.");
00230 return temp;
00231 }
00232
00240 ESCRIPT_DLL_API
00241 inline
00242 DataTypes::ValueType::size_type
00243 getRelIndex(const DataTypes::ShapeType& shape, DataTypes::ValueType::size_type i,
00244 DataTypes::ValueType::size_type j, DataTypes::ValueType::size_type k,
00245 DataTypes::ValueType::size_type m)
00246 {
00247
00248 EsysAssert((getRank(shape)==4),"Incorrect number of indices for the rank of this object.");
00249 DataTypes::ValueType::size_type temp=i+j*shape[0]+k*shape[1]*shape[0]+m*shape[2]*shape[1]*shape[0];
00250 EsysAssert((temp < DataTypes::noValues(shape)), "Error - Invalid index.");
00251 return temp;
00252 }
00253
00257 ESCRIPT_DLL_API
00258 inline
00259 bool
00260 checkShape(const ShapeType& s1, const ShapeType& s2)
00261 {
00262 return s1==s2;
00263 }
00264
00272 ESCRIPT_DLL_API
00273 std::string
00274 createShapeErrorMessage(const std::string& messagePrefix,
00275 const DataTypes::ShapeType& other,
00276 const DataTypes::ShapeType& thisShape);
00277
00278
00293 ESCRIPT_DLL_API
00294 void
00295 copySlice(ValueType& left,
00296 const ShapeType& leftShape,
00297 ValueType::size_type leftOffset,
00298 const ValueType& other,
00299 const ShapeType& otherShape,
00300 ValueType::size_type otherOffset,
00301 const RegionLoopRangeType& region);
00302
00317 ESCRIPT_DLL_API
00318 void
00319 copySliceFrom(ValueType& left,
00320 const ShapeType& leftShape,
00321 ValueType::size_type leftOffset,
00322 const ValueType& other,
00323 const ShapeType& otherShape,
00324 ValueType::size_type otherOffset,
00325 const RegionLoopRangeType& region);
00326
00327
00336 std::string
00337 pointToString(const ValueType& data,const ShapeType& shape, int offset, const std::string& prefix);
00338
00339
00349 void copyPoint(ValueType& dest, ValueType::size_type doffset, ValueType::size_type nvals, const ValueType& src, ValueType::size_type soffset);
00350
00351 }
00352
00353
00354 }
00355
00356 #endif
00357