DataTypes.h
Go to the documentation of this file.
/*****************************************************************************
*
* Copyright (c) 2003-2020 by The University of Queensland
* http://www.uq.edu.au
*
* Primary Business: Queensland, Australia
* Licensed under the Apache License, version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Development until 2012 by Earth Systems Science Computational Center (ESSCC)
* Development 2012-2013 by School of Earth Sciences
* Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
* Development from 2019 by School of Earth and Environmental Sciences
**
*****************************************************************************/
#ifndef __ESCRIPT_DATATYPES_H__
#define __ESCRIPT_DATATYPES_H__
#include <boost/python/object_fwd.hpp>
#include "system_dep.h"
#include "Assert.h"
#include <complex>
#include <limits>
#include <string>
#include <vector>
namespace escript {
namespace DataTypes {
//
// Some basic types which define the data values and view shapes.
typedef std::vector<int> ShapeType;
typedef std::vector<std::pair<int, int> > RegionType;
typedef std::vector<std::pair<int, int> > RegionLoopRangeType;
static const int maxRank=4;
static const ShapeType scalarShape;
typedef long vec_size_type;
typedef double real_t;
typedef std::complex<real_t> cplx_t;
#ifdef ESYS_INDEXTYPE_LONG
typedef long index_t;
#else
typedef int index_t;
#endif
typedef std::vector<index_t> IndexVector;
typedef index_t dim_t;
inline index_t index_t_min()
{
return std::numeric_limits<index_t>::min();
}
inline index_t index_t_max()
{
return std::numeric_limits<index_t>::max();
}
inline real_t real_t_max()
{
return std::numeric_limits<real_t>::max();
}
inline real_t real_t_eps()
{
return std::numeric_limits<real_t>::epsilon();
}
ESCRIPT_DLL_API
int
noValues(const DataTypes::ShapeType& shape);
ESCRIPT_DLL_API
int
noValues(const DataTypes::RegionLoopRangeType& region);
ESCRIPT_DLL_API
std::string
shapeToString(const DataTypes::ShapeType& shape);
ESCRIPT_DLL_API
DataTypes::ShapeType
getResultSliceShape(const DataTypes::RegionType& region);
DataTypes::RegionType
getSliceRegion(const DataTypes::ShapeType& shape, const boost::python::object& key);
ESCRIPT_DLL_API
DataTypes::RegionLoopRangeType
getSliceRegionLoopRange(const DataTypes::RegionType& region);
inline
int
getRank(const DataTypes::ShapeType& shape)
{
return shape.size();
}
inline
vec_size_type
getRelIndex(const DataTypes::ShapeType& shape, vec_size_type i)
{
ESYS_ASSERT(getRank(shape)==1, "Incorrect number of indices for the rank of this object.");
ESYS_ASSERT(i < DataTypes::noValues(shape), "Invalid index.");
return i;
}
inline
vec_size_type
getRelIndex(const DataTypes::ShapeType& shape, vec_size_type i,
vec_size_type j)
{
// Warning: This is not C ordering. Do not try to figure out the params by looking at the code
ESYS_ASSERT(getRank(shape)==2, "Incorrect number of indices for the rank of this object.");
vec_size_type temp=i+j*shape[0];
ESYS_ASSERT(temp < DataTypes::noValues(shape), "Invalid index.");
return temp;
}
inline
vec_size_type
getRelIndex(const DataTypes::ShapeType& shape, vec_size_type i,
vec_size_type j, vec_size_type k)
{
// Warning: This is not C ordering. Do not try to figure out the params by looking at the code
ESYS_ASSERT(getRank(shape)==3, "Incorrect number of indices for the rank of this object.");
vec_size_type temp=i+j*shape[0]+k*shape[1]*shape[0];
ESYS_ASSERT(temp < DataTypes::noValues(shape), "Invalid index.");
return temp;
}
inline
vec_size_type
getRelIndex(const DataTypes::ShapeType& shape, vec_size_type i,
vec_size_type j, vec_size_type k,
vec_size_type m)
{
// Warning: This is not C ordering. Do not try to figure out the params by looking at the code
ESYS_ASSERT(getRank(shape)==4, "Incorrect number of indices for the rank of this object.");
vec_size_type temp=i+j*shape[0]+k*shape[1]*shape[0]+m*shape[2]*shape[1]*shape[0];
ESYS_ASSERT(temp < DataTypes::noValues(shape), "Invalid index.");
return temp;
}
inline
bool
checkShape(const ShapeType& s1, const ShapeType& s2)
{
return s1==s2;
}
ESCRIPT_DLL_API
std::string
createShapeErrorMessage(const std::string& messagePrefix,
const DataTypes::ShapeType& other,
const DataTypes::ShapeType& thisShape);
inline
bool
checkOffset(vec_size_type offset, int size, int noval)
{
return (size >= (offset+noval));
}
} // End of namespace DataTypes
} // End of namespace escript
#endif // __ESCRIPT_DATATYPES_H__
Assert.h
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
ESCRIPT_DLL_API
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:30
escript::DataTypes::cplx_t
std::complex< real_t > cplx_t
complex data type
Definition: DataTypes.h:55
escript::DataTypes::RegionType
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:45
escript::DataTypes::real_t_eps
real_t real_t_eps()
Returns the machine epsilon for the real_t type.
Definition: DataTypes.h:99
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
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:52
escript::DataTypes::IndexVector
std::vector< index_t > IndexVector
Definition: DataTypes.h:64
escript::DataTypes::checkShape
bool checkShape(const ShapeType &s1, const ShapeType &s2)
Test if two shapes are equal.
Definition: DataTypes.h:311
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::checkOffset
bool checkOffset(vec_size_type offset, int size, int noval)
Definition: DataTypes.h:331
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::scalarShape
static const ShapeType scalarShape
Use this instead of creating empty shape objects for scalars.
Definition: DataTypes.h:48
escript::DataTypes::RegionLoopRangeType
std::vector< std::pair< int, int > > RegionLoopRangeType
Definition: DataTypes.h:46
escript::DataTypes::ShapeType
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:44
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:66
escript::DataTypes::getSliceRegion
DataTypes::RegionType getSliceRegion(const DataTypes::ShapeType &shape, const bp::object &key)
Definition: DataTypes.cpp:137
escript::DataTypes::getResultSliceShape
DataTypes::ShapeType getResultSliceShape(const RegionType &region)
Determine the shape of the specified slice region.
Definition: DataTypes.cpp:173
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::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
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::index_t
int index_t
type for array/matrix indices used both globally and on each rank
Definition: DataTypes.h:61
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::maxRank
static const int maxRank
The maximum number of dimensions a datapoint can have.
Definition: DataTypes.h:47
escript::DataTypes::shapeToString
std::string shapeToString(const DataTypes::ShapeType &shape)
Return the given shape as a string.
Definition: DataTypes.cpp:117
escript::DataTypes::vec_size_type
long vec_size_type
Definition: DataTypes.h:49
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
Definition: AbstractContinuousDomain.cpp:23
system_dep.h