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 "Assert.h"
24 
25 #include <complex>
26 #include <limits>
27 #include <string>
28 #include <vector>
29 
30 namespace escript {
31 
32 namespace DataTypes {
33 
41  //
42  // Some basic types which define the data values and view shapes.
43  typedef std::vector<int> ShapeType;
44  typedef std::vector<std::pair<int, int> > RegionType;
45  typedef std::vector<std::pair<int, int> > RegionLoopRangeType;
46  static const int maxRank=4;
47  static const ShapeType scalarShape;
48  typedef long vec_size_type;
49 
51  typedef double real_t;
52 
54  typedef std::complex<real_t> cplx_t;
55 
57 #ifdef ESYS_INDEXTYPE_LONG
58  typedef long index_t;
59 #else
60  typedef int index_t;
61 #endif
62 
63  typedef std::vector<index_t> IndexVector;
64 
65  typedef index_t dim_t;
66 
72  {
73  return std::numeric_limits<index_t>::min();
74  }
75 
81  {
82  return std::numeric_limits<index_t>::max();
83  }
84 
89  inline real_t real_t_max()
90  {
91  return std::numeric_limits<real_t>::max();
92  }
93 
98  inline real_t real_t_eps()
99  {
100  return std::numeric_limits<real_t>::epsilon();
101  }
102 
107  int
108  noValues(const DataTypes::ShapeType& shape);
109 
114  int
116 
123  std::string
124  shapeToString(const DataTypes::ShapeType& shape);
125 
134 
135 
194  getSliceRegion(const DataTypes::ShapeType& shape, const boost::python::object& key);
195 
210 
217  inline
218  int
220  {
221  return shape.size();
222  }
223 
224 
232  inline
235  {
236  ESYS_ASSERT(getRank(shape)==1, "Incorrect number of indices for the rank of this object.");
237  ESYS_ASSERT(i < DataTypes::noValues(shape), "Invalid index.");
238  return i;
239  }
240 
249  inline
252  vec_size_type j)
253  {
254  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
255  ESYS_ASSERT(getRank(shape)==2, "Incorrect number of indices for the rank of this object.");
256  vec_size_type temp=i+j*shape[0];
257  ESYS_ASSERT(temp < DataTypes::noValues(shape), "Invalid index.");
258  return temp;
259  }
260 
268  inline
272  {
273  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
274  ESYS_ASSERT(getRank(shape)==3, "Incorrect number of indices for the rank of this object.");
275  vec_size_type temp=i+j*shape[0]+k*shape[1]*shape[0];
276  ESYS_ASSERT(temp < DataTypes::noValues(shape), "Invalid index.");
277  return temp;
278  }
279 
287  inline
291  vec_size_type m)
292  {
293  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
294  ESYS_ASSERT(getRank(shape)==4, "Incorrect number of indices for the rank of this object.");
295  vec_size_type temp=i+j*shape[0]+k*shape[1]*shape[0]+m*shape[2]*shape[1]*shape[0];
296  ESYS_ASSERT(temp < DataTypes::noValues(shape), "Invalid index.");
297  return temp;
298  }
299 
303  inline
304  bool
305  checkShape(const ShapeType& s1, const ShapeType& s2)
306  {
307  return s1==s2;
308  }
309 
317  std::string
318  createShapeErrorMessage(const std::string& messagePrefix,
319  const DataTypes::ShapeType& other,
320  const DataTypes::ShapeType& thisShape);
321 
322  inline
323  bool
324  checkOffset(vec_size_type offset, int size, int noval)
325  {
326  return (size >= (offset+noval));
327  }
328 
329  } // End of namespace DataTypes
330 
331 } // End of namespace escript
332 
333 #endif // __ESCRIPT_DATATYPES_H__
334 
escript::DataTypes::maxRank
static const int maxRank
The maximum number of dimensions a datapoint can have.
Definition: DataTypes.h:46
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:51
escript::DataTypes::index_t_min
index_t index_t_min()
Returns the minimum finite value for the index_t type.
Definition: DataTypes.h:71
escript::DataTypes::getRank
int getRank(const DataTypes::ShapeType &shape)
Return the rank (number of dimensions) of the given shape.
Definition: DataTypes.h:219
escript::DataTypes::checkOffset
bool checkOffset(vec_size_type offset, int size, int noval)
Definition: DataTypes.h:324
escript::DataTypes::checkShape
bool checkShape(const ShapeType &s1, const ShapeType &s2)
Test if two shapes are equal.
Definition: DataTypes.h:305
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:89
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:80
escript::DataTypes::vec_size_type
long vec_size_type
Definition: DataTypes.h:48
escript::DataException
Definition: DataException.h:28
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:65
escript::DataTypes::ShapeType
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:43
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:44
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:45
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:60
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:234
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:98
escript::DataTypes::cplx_t
std::complex< real_t > cplx_t
complex data type
Definition: DataTypes.h:54
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:47
escript::DataTypes::IndexVector
std::vector< index_t > IndexVector
Definition: DataTypes.h:63