escript
Revision_
|
00001 00002 /***************************************************************************** 00003 * 00004 * Copyright (c) 2003-2014 by University of Queensland 00005 * http://www.uq.edu.au 00006 * 00007 * Primary Business: Queensland, Australia 00008 * Licensed under the Open Software License version 3.0 00009 * http://www.opensource.org/licenses/osl-3.0.php 00010 * 00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC) 00012 * Development 2012-2013 by School of Earth Sciences 00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp) 00014 * 00015 *****************************************************************************/ 00016 00017 00018 #if !defined escript_DataTypes_20080811_H 00019 #define escript_DataTypes_20080811_H 00020 #include "system_dep.h" 00021 #include "DataVector.h" 00022 #include <vector> 00023 #include <string> 00024 #include <boost/python/object.hpp> 00025 #include <boost/python/extract.hpp> 00026 00027 namespace escript { 00028 00029 namespace DataTypes { 00030 00035 // 00036 // Some basic types which define the data values and view shapes. 00037 typedef escript::DataVector ValueType; 00038 typedef std::vector<int> ShapeType; 00039 typedef std::vector<std::pair<int, int> > RegionType; 00040 typedef std::vector<std::pair<int, int> > RegionLoopRangeType; 00041 static const int maxRank=4; 00042 static const ShapeType scalarShape; 00043 00048 ESCRIPT_DLL_API 00049 int 00050 noValues(const DataTypes::ShapeType& shape); 00051 00056 ESCRIPT_DLL_API 00057 int 00058 noValues(const DataTypes::RegionLoopRangeType& region); 00059 00066 ESCRIPT_DLL_API 00067 std::string 00068 shapeToString(const DataTypes::ShapeType& shape); 00069 00076 ESCRIPT_DLL_API 00077 DataTypes::ShapeType 00078 getResultSliceShape(const DataTypes::RegionType& region); 00079 00080 00138 ESCRIPT_DLL_API 00139 DataTypes::RegionType 00140 getSliceRegion(const DataTypes::ShapeType& shape, const boost::python::object& key); 00141 00154 ESCRIPT_DLL_API 00155 DataTypes::RegionLoopRangeType 00156 getSliceRegionLoopRange(const DataTypes::RegionType& region); 00157 00164 ESCRIPT_DLL_API 00165 inline 00166 int 00167 getRank(const DataTypes::ShapeType& shape) 00168 { 00169 return shape.size(); 00170 } 00171 00172 00180 ESCRIPT_DLL_API 00181 inline 00182 DataTypes::ValueType::size_type 00183 getRelIndex(const DataTypes::ShapeType& shape, DataTypes::ValueType::size_type i) 00184 { 00185 EsysAssert((getRank(shape)==1),"Incorrect number of indices for the rank of this object."); 00186 EsysAssert((i < DataTypes::noValues(shape)), "Error - Invalid index."); 00187 return i; 00188 } 00189 00198 ESCRIPT_DLL_API 00199 inline 00200 DataTypes::ValueType::size_type 00201 getRelIndex(const DataTypes::ShapeType& shape, DataTypes::ValueType::size_type i, 00202 DataTypes::ValueType::size_type j) 00203 { 00204 // Warning: This is not C ordering. Do not try to figure out the params by looking at the code 00205 EsysAssert((getRank(shape)==2),"Incorrect number of indices for the rank of this object."); 00206 DataTypes::ValueType::size_type temp=i+j*shape[0]; 00207 EsysAssert((temp < DataTypes::noValues(shape)), "Error - Invalid index."); 00208 return temp; 00209 } 00210 00218 ESCRIPT_DLL_API 00219 inline 00220 DataTypes::ValueType::size_type 00221 getRelIndex(const DataTypes::ShapeType& shape, DataTypes::ValueType::size_type i, 00222 DataTypes::ValueType::size_type j, DataTypes::ValueType::size_type k) 00223 { 00224 // Warning: This is not C ordering. Do not try to figure out the params by looking at the code 00225 EsysAssert((getRank(shape)==3),"Incorrect number of indices for the rank of this object."); 00226 DataTypes::ValueType::size_type temp=i+j*shape[0]+k*shape[1]*shape[0]; 00227 EsysAssert((temp < DataTypes::noValues(shape)), "Error - Invalid index."); 00228 return temp; 00229 } 00230 00238 ESCRIPT_DLL_API 00239 inline 00240 DataTypes::ValueType::size_type 00241 getRelIndex(const DataTypes::ShapeType& shape, DataTypes::ValueType::size_type i, 00242 DataTypes::ValueType::size_type j, DataTypes::ValueType::size_type k, 00243 DataTypes::ValueType::size_type m) 00244 { 00245 // Warning: This is not C ordering. Do not try to figure out the params by looking at the code 00246 EsysAssert((getRank(shape)==4),"Incorrect number of indices for the rank of this object."); 00247 DataTypes::ValueType::size_type temp=i+j*shape[0]+k*shape[1]*shape[0]+m*shape[2]*shape[1]*shape[0]; 00248 EsysAssert((temp < DataTypes::noValues(shape)), "Error - Invalid index."); 00249 return temp; 00250 } 00251 00255 ESCRIPT_DLL_API 00256 inline 00257 bool 00258 checkShape(const ShapeType& s1, const ShapeType& s2) 00259 { 00260 return s1==s2; 00261 } 00262 00270 ESCRIPT_DLL_API 00271 std::string 00272 createShapeErrorMessage(const std::string& messagePrefix, 00273 const DataTypes::ShapeType& other, 00274 const DataTypes::ShapeType& thisShape); 00275 00276 00291 ESCRIPT_DLL_API 00292 void 00293 copySlice(ValueType& left, 00294 const ShapeType& leftShape, 00295 ValueType::size_type leftOffset, 00296 const ValueType& other, 00297 const ShapeType& otherShape, 00298 ValueType::size_type otherOffset, 00299 const RegionLoopRangeType& region); 00300 00315 ESCRIPT_DLL_API 00316 void 00317 copySliceFrom(ValueType& left, 00318 const ShapeType& leftShape, 00319 ValueType::size_type leftOffset, 00320 const ValueType& other, 00321 const ShapeType& otherShape, 00322 ValueType::size_type otherOffset, 00323 const RegionLoopRangeType& region); 00324 00325 00341 void 00342 pointToStream(std::ostream& os, const ValueType::ElementType* data,const ShapeType& shape, int offset, bool needsep=true, const std::string& sep=","); 00343 00352 std::string 00353 pointToString(const ValueType& data,const ShapeType& shape, int offset, const std::string& prefix); 00354 00355 00365 void copyPoint(ValueType& dest, ValueType::size_type doffset, ValueType::size_type nvals, const ValueType& src, ValueType::size_type soffset); 00366 00367 } // End of namespace DataTypes 00368 00369 00370 } // End of namespace escript 00371 00372 #endif 00373