escript  Revision_
DataTypes.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2020 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
14 * Development from 2019 by School of Earth and Environmental Sciences
15 **
16 *****************************************************************************/
17 
18 #ifndef __ESCRIPT_DATATYPES_H__
19 #define __ESCRIPT_DATATYPES_H__
20 
21 #include <boost/python/object_fwd.hpp>
22 
23 #include "system_dep.h"
24 #include "Assert.h"
25 
26 #include <complex>
27 #include <limits>
28 #include <string>
29 #include <vector>
30 
31 namespace escript {
32 
33 namespace DataTypes {
34 
42  //
43  // Some basic types which define the data values and view shapes.
44  typedef std::vector<int> ShapeType;
45  typedef std::vector<std::pair<int, int> > RegionType;
46  typedef std::vector<std::pair<int, int> > RegionLoopRangeType;
47  static const int maxRank=4;
48  static const ShapeType scalarShape;
49  typedef long vec_size_type;
50 
52  typedef double real_t;
53 
55  typedef std::complex<real_t> cplx_t;
56 
58 #ifdef ESYS_INDEXTYPE_LONG
59  typedef long index_t;
60 #else
61  typedef int index_t;
62 #endif
63 
64  typedef std::vector<index_t> IndexVector;
65 
66  typedef index_t dim_t;
67 
73  {
74  return std::numeric_limits<index_t>::min();
75  }
76 
82  {
83  return std::numeric_limits<index_t>::max();
84  }
85 
90  inline real_t real_t_max()
91  {
92  return std::numeric_limits<real_t>::max();
93  }
94 
99  inline real_t real_t_eps()
100  {
101  return std::numeric_limits<real_t>::epsilon();
102  }
103 
109  int
110  noValues(const DataTypes::ShapeType& shape);
111 
117  int
119 
127  std::string
128  shapeToString(const DataTypes::ShapeType& shape);
129 
139 
140 
199  getSliceRegion(const DataTypes::ShapeType& shape, const boost::python::object& key);
200 
216 
223  inline
224  int
226  {
227  return shape.size();
228  }
229 
230 
238  inline
241  {
242  ESYS_ASSERT(getRank(shape)==1, "Incorrect number of indices for the rank of this object.");
243  ESYS_ASSERT(i < DataTypes::noValues(shape), "Invalid index.");
244  return i;
245  }
246 
255  inline
258  vec_size_type j)
259  {
260  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
261  ESYS_ASSERT(getRank(shape)==2, "Incorrect number of indices for the rank of this object.");
262  vec_size_type temp=i+j*shape[0];
263  ESYS_ASSERT(temp < DataTypes::noValues(shape), "Invalid index.");
264  return temp;
265  }
266 
274  inline
278  {
279  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
280  ESYS_ASSERT(getRank(shape)==3, "Incorrect number of indices for the rank of this object.");
281  vec_size_type temp=i+j*shape[0]+k*shape[1]*shape[0];
282  ESYS_ASSERT(temp < DataTypes::noValues(shape), "Invalid index.");
283  return temp;
284  }
285 
293  inline
297  vec_size_type m)
298  {
299  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
300  ESYS_ASSERT(getRank(shape)==4, "Incorrect number of indices for the rank of this object.");
301  vec_size_type temp=i+j*shape[0]+k*shape[1]*shape[0]+m*shape[2]*shape[1]*shape[0];
302  ESYS_ASSERT(temp < DataTypes::noValues(shape), "Invalid index.");
303  return temp;
304  }
305 
309  inline
310  bool
311  checkShape(const ShapeType& s1, const ShapeType& s2)
312  {
313  return s1==s2;
314  }
315 
324  std::string
325  createShapeErrorMessage(const std::string& messagePrefix,
326  const DataTypes::ShapeType& other,
327  const DataTypes::ShapeType& thisShape);
328 
329  inline
330  bool
331  checkOffset(vec_size_type offset, int size, int noval)
332  {
333  return (size >= (offset+noval));
334  }
335 
336  } // End of namespace DataTypes
337 
338 } // End of namespace escript
339 
340 #endif // __ESCRIPT_DATATYPES_H__
341 
escript::DataTypes::maxRank
static const int maxRank
The maximum number of dimensions a datapoint can have.
Definition: DataTypes.h:47
ESCRIPT_DLL_API
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:30
escript::DataTypes::shapeToString
std::string shapeToString(const DataTypes::ShapeType &shape)
Return the given shape as a string.
Definition: DataTypes.cpp:117
escript::DataTypes::real_t
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:52
escript::DataTypes::index_t_min
index_t index_t_min()
Returns the minimum finite value for the index_t type.
Definition: DataTypes.h:72
escript::DataTypes::getRank
int getRank(const DataTypes::ShapeType &shape)
Return the rank (number of dimensions) of the given shape.
Definition: DataTypes.h:225
escript::DataTypes::checkOffset
bool checkOffset(vec_size_type offset, int size, int noval)
Definition: DataTypes.h:331
escript::DataTypes::checkShape
bool checkShape(const ShapeType &s1, const ShapeType &s2)
Test if two shapes are equal.
Definition: DataTypes.h:311
Assert.h
escript::DataTypes::real_t_max
real_t real_t_max()
Returns the maximum finite value for the real_t type.
Definition: DataTypes.h:90
escript::DataTypes::getSliceRegionLoopRange
DataTypes::RegionLoopRangeType getSliceRegionLoopRange(const DataTypes::RegionType &region)
Modify region to copy from in order to deal with the case where one range in the region contains iden...
Definition: DataTypes.cpp:188
escript::DataTypes::index_t_max
index_t index_t_max()
Returns the maximum finite value for the index_t type.
Definition: DataTypes.h:81
escript::DataTypes::vec_size_type
long vec_size_type
Definition: DataTypes.h:49
escript::DataException
Definition: DataException.h:28
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:66
escript::DataTypes::ShapeType
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:44
escript::DataTypes
Contains the types to represent Shapes, Regions, RegionLoop ranges and vectors of data as well as the...
Definition: DataTypes.cpp:88
escript::DataTypes::RegionType
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:45
escript::DataTypes::noValues
int noValues(const ShapeType &shape)
Calculate the number of values in a datapoint with the given shape.
Definition: DataTypes.cpp:91
escript::DataTypes::getResultSliceShape
DataTypes::ShapeType getResultSliceShape(const RegionType &region)
Determine the shape of the specified slice region.
Definition: DataTypes.cpp:173
escript::DataTypes::noValues
int noValues(const RegionLoopRangeType &region)
Calculate the number of values for the given region.
Definition: DataTypes.cpp:104
escript::DataTypes::RegionLoopRangeType
std::vector< std::pair< int, int > > RegionLoopRangeType
Definition: DataTypes.h:46
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:61
escript
Definition: AbstractContinuousDomain.cpp:23
escript::DataTypes::getRelIndex
vec_size_type getRelIndex(const DataTypes::ShapeType &shape, vec_size_type i)
Compute the offset (in 1D vector) of a given subscript with a shape.
Definition: DataTypes.h:240
DataTypes.h
escript::DataTypes::createShapeErrorMessage
std::string createShapeErrorMessage(const std::string &messagePrefix, const DataTypes::ShapeType &other, const DataTypes::ShapeType &thisShape)
Produce a string containing two shapes.
Definition: DataTypes.cpp:206
escript::DataTypes::real_t_eps
real_t real_t_eps()
Returns the machine epsilon for the real_t type.
Definition: DataTypes.h:99
system_dep.h
escript::DataTypes::cplx_t
std::complex< real_t > cplx_t
complex data type
Definition: DataTypes.h:55
ESYS_ASSERT
#define ESYS_ASSERT(a, b)
EsysAssert is a MACRO that will throw an exception if the boolean condition specified is false.
Definition: Assert.h:79
DataException.h
escript::DataTypes::getSliceRegion
DataTypes::RegionType getSliceRegion(const DataTypes::ShapeType &shape, const bp::object &key)
Definition: DataTypes.cpp:137
escript::DataTypes::scalarShape
static const ShapeType scalarShape
Use this instead of creating empty shape objects for scalars.
Definition: DataTypes.h:48
escript::DataTypes::IndexVector
std::vector< index_t > IndexVector
Definition: DataTypes.h:64