escript  Revision_
DataTypes.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2018 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 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 #ifndef __ESCRIPT_DATATYPES_H__
18 #define __ESCRIPT_DATATYPES_H__
19 
20 #include <boost/python/object_fwd.hpp>
21 
22 #include "Assert.h"
23 
24 #include <complex>
25 #include <limits>
26 #include <string>
27 #include <vector>
28 
29 namespace escript {
30 
31 namespace DataTypes {
32 
40  //
41  // Some basic types which define the data values and view shapes.
42  typedef std::vector<int> ShapeType;
43  typedef std::vector<std::pair<int, int> > RegionType;
44  typedef std::vector<std::pair<int, int> > RegionLoopRangeType;
45  static const int maxRank=4;
46  static const ShapeType scalarShape;
47  typedef long vec_size_type;
48 
50  typedef double real_t;
51 
53  typedef std::complex<real_t> cplx_t;
54 
56 #ifdef ESYS_INDEXTYPE_LONG
57  typedef long index_t;
58 #else
59  typedef int index_t;
60 #endif
61 
62  typedef std::vector<index_t> IndexVector;
63 
64  typedef index_t dim_t;
65 
71  {
72  return std::numeric_limits<index_t>::min();
73  }
74 
79  inline index_t index_t_max()
80  {
81  return std::numeric_limits<index_t>::max();
82  }
83 
88  inline real_t real_t_max()
89  {
90  return std::numeric_limits<real_t>::max();
91  }
92 
97  inline real_t real_t_eps()
98  {
99  return std::numeric_limits<real_t>::epsilon();
100  }
101 
106  int
107  noValues(const DataTypes::ShapeType& shape);
108 
113  int
115 
122  std::string
123  shapeToString(const DataTypes::ShapeType& shape);
124 
133 
134 
193  getSliceRegion(const DataTypes::ShapeType& shape, const boost::python::object& key);
194 
209 
216  inline
217  int
218  getRank(const DataTypes::ShapeType& shape)
219  {
220  return shape.size();
221  }
222 
223 
231  inline
234  {
235  ESYS_ASSERT(getRank(shape)==1, "Incorrect number of indices for the rank of this object.");
236  ESYS_ASSERT(i < DataTypes::noValues(shape), "Invalid index.");
237  return i;
238  }
239 
248  inline
251  vec_size_type j)
252  {
253  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
254  ESYS_ASSERT(getRank(shape)==2, "Incorrect number of indices for the rank of this object.");
255  vec_size_type temp=i+j*shape[0];
256  ESYS_ASSERT(temp < DataTypes::noValues(shape), "Invalid index.");
257  return temp;
258  }
259 
267  inline
271  {
272  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
273  ESYS_ASSERT(getRank(shape)==3, "Incorrect number of indices for the rank of this object.");
274  vec_size_type temp=i+j*shape[0]+k*shape[1]*shape[0];
275  ESYS_ASSERT(temp < DataTypes::noValues(shape), "Invalid index.");
276  return temp;
277  }
278 
286  inline
290  vec_size_type m)
291  {
292  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
293  ESYS_ASSERT(getRank(shape)==4, "Incorrect number of indices for the rank of this object.");
294  vec_size_type temp=i+j*shape[0]+k*shape[1]*shape[0]+m*shape[2]*shape[1]*shape[0];
295  ESYS_ASSERT(temp < DataTypes::noValues(shape), "Invalid index.");
296  return temp;
297  }
298 
302  inline
303  bool
304  checkShape(const ShapeType& s1, const ShapeType& s2)
305  {
306  return s1==s2;
307  }
308 
316  std::string
317  createShapeErrorMessage(const std::string& messagePrefix,
318  const DataTypes::ShapeType& other,
319  const DataTypes::ShapeType& thisShape);
320 
321  inline
322  bool
323  checkOffset(vec_size_type offset, int size, int noval)
324  {
325  return (size >= (offset+noval));
326  }
327 
328  } // End of namespace DataTypes
329 
330 } // End of namespace escript
331 
332 #endif // __ESCRIPT_DATATYPES_H__
333 
escript::DataTypes::maxRank
static const int maxRank
The maximum number of dimensions a datapoint can have.
Definition: DataTypes.h:68
escript::DataTypes::shapeToString
std::string shapeToString(const DataTypes::ShapeType &shape)
Return the given shape as a string.
Definition: DataTypes.cpp:115
escript::DataTypes::real_t
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:73
escript::DataTypes::index_t_min
index_t index_t_min()
Returns the minimum finite value for the index_t type.
Definition: DataTypes.h:93
escript::DataTypes::getRank
int getRank(const DataTypes::ShapeType &shape)
Return the rank (number of dimensions) of the given shape.
Definition: DataTypes.h:241
escript::DataTypes::checkOffset
bool checkOffset(vec_size_type offset, int size, int noval)
Definition: DataTypes.h:346
escript::DataTypes::checkShape
bool checkShape(const ShapeType &s1, const ShapeType &s2)
Test if two shapes are equal.
Definition: DataTypes.h:327
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:111
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:186
escript::DataTypes::index_t_max
index_t index_t_max()
Returns the maximum finite value for the index_t type.
Definition: DataTypes.h:102
escript::DataTypes::vec_size_type
long vec_size_type
Definition: DataTypes.h:70
escript::DataException
Definition: DataException.h:37
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:87
escript::DataTypes::ShapeType
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:65
escript::DataTypes
Contains the types to represent Shapes, Regions, RegionLoop ranges and vectors of data as well as the...
Definition: DataTypes.cpp:85
escript::DataTypes::RegionType
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:66
escript::DataTypes::noValues
int noValues(const ShapeType &shape)
Calculate the number of values in a datapoint with the given shape.
Definition: DataTypes.cpp:89
escript::DataTypes::getResultSliceShape
DataTypes::ShapeType getResultSliceShape(const RegionType &region)
Determine the shape of the specified slice region.
Definition: DataTypes.cpp:171
escript::DataTypes::noValues
int noValues(const RegionLoopRangeType &region)
Calculate the number of values for the given region.
Definition: DataTypes.cpp:102
escript::DataTypes::RegionLoopRangeType
std::vector< std::pair< int, int > > RegionLoopRangeType
Definition: DataTypes.h:67
escript::DataTypes::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:82
escript
Definition: AbstractContinuousDomain.cpp:22
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:256
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:204
escript::DataTypes::real_t_eps
real_t real_t_eps()
Returns the machine epsilon for the real_t type.
Definition: DataTypes.h:120
escript::DataTypes::cplx_t
std::complex< real_t > cplx_t
complex data type
Definition: DataTypes.h:76
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:77
DataException.h
escript::DataTypes::getSliceRegion
DataTypes::RegionType getSliceRegion(const DataTypes::ShapeType &shape, const bp::object &key)
Definition: DataTypes.cpp:135
escript::DataTypes::scalarShape
static const ShapeType scalarShape
Use this instead of creating empty shape objects for scalars.
Definition: DataTypes.h:69
escript::DataTypes::IndexVector
std::vector< index_t > IndexVector
Definition: DataTypes.h:85