escript  Revision_
Classes | Typedefs | Functions | Variables
escript::DataTypes Namespace Reference

Contains the types to represent Shapes, Regions, RegionLoop ranges and vectors of data as well as the functions to manipulate them. More...

Classes

class  DataVectorAlt
 
class  DataVectorTaipan
 DataVectorTaipan implements an arbitrarily long vector of data values. DataVectorTaipan is the underlying data container for Data objects. More...
 

Typedefs

typedef std::vector< int > ShapeType
 The shape of a single datapoint. More...
 
typedef std::vector< std::pair< int, int > > RegionType
 
typedef std::vector< std::pair< int, int > > RegionLoopRangeType
 
typedef long vec_size_type
 
typedef double real_t
 type of all real-valued scalars in escript More...
 
typedef std::complex< real_tcplx_t
 complex data type More...
 
typedef int index_t
 type for array/matrix indices used both globally and on each rank More...
 
typedef std::vector< index_tIndexVector
 
typedef index_t dim_t
 
typedef escript::DataTypes::DataVectorAlt< real_tRealVectorType
 Vector to store underlying data. More...
 
typedef escript::DataTypes::DataVectorAlt< cplx_tCplxVectorType
 

Functions

int noValues (const DataTypes::ShapeType &shape)
 Calculate the number of values in a datapoint with the given shape. More...
 
int noValues (const DataTypes::RegionLoopRangeType &region)
 Calculate the number of values for the given region. More...
 
std::string shapeToString (const DataTypes::ShapeType &shape)
 Return the given shape as a string. More...
 
DataTypes::RegionType getSliceRegion (const DataTypes::ShapeType &shape, const bp::object &key)
 
DataTypes::ShapeType getResultSliceShape (const DataTypes::RegionType &region)
 Determine the shape of the specified slice region. More...
 
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 identical indexes, eg: <<1,1><0,3><0,3>> This situation implies we want to copy from an object with rank greater than that of this object. eg: we want to copy the values from a two dimensional slice out of a three dimensional object into a two dimensional object. We do this by taking a slice from the other object where one dimension of the slice region is of size 1. So in the above example, we modify the above region like so: <<1,2><0,3><0,3>> and take this slice. More...
 
std::string createShapeErrorMessage (const std::string &messagePrefix, const DataTypes::ShapeType &other, const DataTypes::ShapeType &thisShape)
 Produce a string containing two shapes. More...
 
index_t index_t_min ()
 Returns the minimum finite value for the index_t type. More...
 
index_t index_t_max ()
 Returns the maximum finite value for the index_t type. More...
 
real_t real_t_max ()
 Returns the maximum finite value for the real_t type. More...
 
real_t real_t_eps ()
 Returns the machine epsilon for the real_t type. More...
 
DataTypes::RegionType getSliceRegion (const DataTypes::ShapeType &shape, const boost::python::object &key)
 Determine the region specified by the given python slice object. More...
 
int getRank (const DataTypes::ShapeType &shape)
 Return the rank (number of dimensions) of the given shape. More...
 
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. More...
 
vec_size_type getRelIndex (const DataTypes::ShapeType &shape, vec_size_type i, vec_size_type j)
 Compute the offset (in 1D vector) of a given subscript with a shape. More...
 
vec_size_type getRelIndex (const DataTypes::ShapeType &shape, vec_size_type i, vec_size_type j, vec_size_type k)
 Compute the offset (in 1D vector) of a given subscript with a shape. More...
 
vec_size_type getRelIndex (const DataTypes::ShapeType &shape, vec_size_type i, vec_size_type j, vec_size_type k, vec_size_type m)
 Compute the offset (in 1D vector) of a given subscript with a shape. More...
 
bool checkShape (const ShapeType &s1, const ShapeType &s2)
 Test if two shapes are equal. More...
 
bool checkOffset (vec_size_type offset, int size, int noval)
 
void pointToStream (std::ostream &os, const RealVectorType::ElementType *data, const ShapeType &shape, int offset, bool needsep=true, const std::string &sep=",")
 Display a single value (with the specified shape) from the data. More...
 
std::string pointToString (const RealVectorType &data, const ShapeType &shape, int offset, const std::string &prefix)
 Display a single value (with the specified shape) from the data. More...
 
void copyPoint (RealVectorType &dest, vec_size_type doffset, vec_size_type nvals, const RealVectorType &src, vec_size_type soffset)
 Copy a point from one vector to another. Note: This version does not check to see if shapes are the same. More...
 
void fillComplexFromReal (const RealVectorType &r, CplxVectorType &c)
 copy data from a real vector to a complex vector The complex vector will be resized as needed and any previous values will be replaced. More...
 
template<class VEC >
void copySlice (VEC &left, const ShapeType &leftShape, typename VEC::size_type leftOffset, const VEC &other, const ShapeType &otherShape, typename VEC::size_type otherOffset, const RegionLoopRangeType &region)
 Copy a data slice specified by the given region and offset from the "other" vector into the "left" vector at the given offset. More...
 
template<typename VEC >
void copySliceFrom (VEC &left, const ShapeType &leftShape, typename VEC::size_type leftOffset, const VEC &other, const ShapeType &otherShape, typename VEC::size_type otherOffset, const RegionLoopRangeType &region)
 Copy data into a slice specified by the given region and offset in the left vector from the other vector at the given offset. More...
 
void releaseUnusedMemory ()
 releases unused memory in the memory manager. More...
 

Variables

static const int maxRank =4
 The maximum number of dimensions a datapoint can have. More...
 
static const ShapeType scalarShape
 Use this instead of creating empty shape objects for scalars. More...
 
Taipan arrayManager
 

Detailed Description

Contains the types to represent Shapes, Regions, RegionLoop ranges and vectors of data as well as the functions to manipulate them.

Note
The contents of the namespace are spread between DataTypes.h and DataVector.h

Typedef Documentation

◆ cplx_t

typedef std::complex<real_t> escript::DataTypes::cplx_t

complex data type

◆ CplxVectorType

◆ dim_t

◆ index_t

type for array/matrix indices used both globally and on each rank

◆ IndexVector

◆ real_t

type of all real-valued scalars in escript

◆ RealVectorType

Vector to store underlying data.

◆ RegionLoopRangeType

typedef std::vector<std::pair<int, int> > escript::DataTypes::RegionLoopRangeType

◆ RegionType

typedef std::vector<std::pair<int, int> > escript::DataTypes::RegionType

◆ ShapeType

typedef std::vector<int> escript::DataTypes::ShapeType

The shape of a single datapoint.

◆ vec_size_type

Function Documentation

◆ checkOffset()

bool escript::DataTypes::checkOffset ( vec_size_type  offset,
int  size,
int  noval 
)
inline

Referenced by copySlice(), and copySliceFrom().

◆ checkShape()

bool escript::DataTypes::checkShape ( const ShapeType s1,
const ShapeType s2 
)
inline

◆ copyPoint()

void escript::DataTypes::copyPoint ( RealVectorType dest,
vec_size_type  doffset,
vec_size_type  nvals,
const RealVectorType src,
vec_size_type  soffset 
)

Copy a point from one vector to another. Note: This version does not check to see if shapes are the same.

Parameters
dest- vector to copy to
doffset- beginning of the target datapoint in dest
nvals- the number of values comprising the datapoint
src- vector to copy from
soffset- beginning of the datapoint in src

Referenced by escript::DataExpanded::copy(), and escript::DataExpanded::DataExpanded().

◆ copySlice()

template<class VEC >
void escript::DataTypes::copySlice ( VEC &  left,
const ShapeType leftShape,
typename VEC::size_type  leftOffset,
const VEC &  other,
const ShapeType otherShape,
typename VEC::size_type  otherOffset,
const RegionLoopRangeType region 
)

Copy a data slice specified by the given region and offset from the "other" vector into the "left" vector at the given offset.

Parameters
left- vector to copy into
leftShape- shape of datapoints for the left vector
leftOffset- location within left to start copying to
other- vector to copy from
otherShape- shape of datapoints for the other vector
otherOffset- location within other vector to start copying from
region- Input - Region in other vector to copy data from.

References checkOffset(), ESCRIPT_DLL_API, ESYS_ASSERT, getRank(), getRelIndex(), getResultSliceShape(), and noValues().

Referenced by escript::DataConstant::DataConstant(), escript::DataExpanded::DataExpanded(), and escript::DataTagged::DataTagged().

◆ copySliceFrom()

template<typename VEC >
void escript::DataTypes::copySliceFrom ( VEC &  left,
const ShapeType leftShape,
typename VEC::size_type  leftOffset,
const VEC &  other,
const ShapeType otherShape,
typename VEC::size_type  otherOffset,
const RegionLoopRangeType region 
)

Copy data into a slice specified by the given region and offset in the left vector from the other vector at the given offset.

Parameters
left- vector to copy into
leftShape- shape of datapoints for the left vector
leftOffset- location within left to start copying to
other- vector to copy from
otherShape- shape of datapoints for the other vector
otherOffset- location within other vector to start copying from
region- Input - Region in the left vector to copy data to.

References checkOffset(), ESYS_ASSERT, getRank(), getRelIndex(), getResultSliceShape(), and noValues().

Referenced by escript::DataConstant::setSlice(), escript::DataExpanded::setSlice(), and escript::DataTagged::setSlice().

◆ createShapeErrorMessage()

std::string escript::DataTypes::createShapeErrorMessage ( const std::string &  messagePrefix,
const DataTypes::ShapeType other,
const DataTypes::ShapeType thisShape 
)

Produce a string containing two shapes.

Parameters
messagePrefix- Beginning of the message.
other- displayed in the message as "Other shape"
thisShape- displayed in the message as "This shape"

References shapeToString().

Referenced by escript::DataTagged::addTaggedValue(), checkShape(), escript::DataExpanded::copy(), escript::DataConstant::setSlice(), escript::DataExpanded::setSlice(), escript::DataTagged::setSlice(), and escript::DataTagged::setTaggedValue().

◆ fillComplexFromReal()

void escript::DataTypes::fillComplexFromReal ( const RealVectorType r,
CplxVectorType c 
)

copy data from a real vector to a complex vector The complex vector will be resized as needed and any previous values will be replaced.

Referenced by escript::DataConstant::complicate(), escript::DataExpanded::complicate(), escript::DataTagged::complicate(), escript::DataExpanded::setTaggedValue(), and escript::Data::setTaggedValue().

◆ getRank()

int escript::DataTypes::getRank ( const DataTypes::ShapeType shape)
inline

◆ getRelIndex() [1/4]

vec_size_type escript::DataTypes::getRelIndex ( const DataTypes::ShapeType shape,
vec_size_type  i 
)
inline

◆ getRelIndex() [2/4]

vec_size_type escript::DataTypes::getRelIndex ( const DataTypes::ShapeType shape,
vec_size_type  i,
vec_size_type  j 
)
inline

Compute the offset (in 1D vector) of a given subscript with a shape.

Parameters
shape- Input - Shape of the datapoint.
i- Input - row
j- Input - column
Returns
offset relative to the beginning of the datapoint.

References ESYS_ASSERT, getRank(), and noValues().

◆ getRelIndex() [3/4]

vec_size_type escript::DataTypes::getRelIndex ( const DataTypes::ShapeType shape,
vec_size_type  i,
vec_size_type  j,
vec_size_type  k 
)
inline

Compute the offset (in 1D vector) of a given subscript with a shape.

Parameters
shape- Input - Shape of the datapoint.
i,j,k- Input - subscripts to locate.
Returns
offset relative to the beginning of the datapoint.

References ESYS_ASSERT, getRank(), and noValues().

◆ getRelIndex() [4/4]

vec_size_type escript::DataTypes::getRelIndex ( const DataTypes::ShapeType shape,
vec_size_type  i,
vec_size_type  j,
vec_size_type  k,
vec_size_type  m 
)
inline

Compute the offset (in 1D vector) of a given subscript with a shape.

Parameters
shape- Input - Shape of the datapoint.
i,j,k,m- Input - subscripts to locate.
Returns
offset relative to the beginning of the datapoint.

References ESYS_ASSERT, getRank(), and noValues().

◆ getResultSliceShape()

DataTypes::ShapeType escript::DataTypes::getResultSliceShape ( const DataTypes::RegionType region)

Determine the shape of the specified slice region.

Parameters
region- Input - Slice region

Referenced by copySlice(), copySliceFrom(), escript::DataTagged::DataTagged(), real_t_eps(), escript::DataConstant::setSlice(), escript::DataExpanded::setSlice(), and escript::DataTagged::setSlice().

◆ getSliceRegion() [1/2]

DataTypes::RegionType escript::DataTypes::getSliceRegion ( const DataTypes::ShapeType shape,
const bp::object &  key 
)

◆ getSliceRegion() [2/2]

DataTypes::RegionType escript::DataTypes::getSliceRegion ( const DataTypes::ShapeType shape,
const boost::python::object &  key 
)

Determine the region specified by the given python slice object.

Parameters
shape- Input - Shape of the object being sliced.
key- Input - python slice object specifying region to be returned.

The slice object is a tuple of n python slice specifiers, where n <= the rank of this Data object. Each slice specifier specifies the range of indexes to be sliced from the corresponding dimension. The first specifier corresponds to the first dimension, the second to the second and so on. Where n < the rank, the remaining dimensions are sliced across the full range of their indices.

Each slice specifier is of the form "a:b", which specifies a slice from index a, up to but not including index b. Where index a is omitted a is assumed to be 0. Where index b is omitted, b is assumed to be the length of this dimension. Where both are omitted (eg: ":") the slice is assumed to encompass that entire dimension.

Where one of the slice specifiers is a single integer, eg: [1], we want to generate a rank-1 dimension object, as opposed to eg: [1,2] which implies we want to take a rank dimensional object with one dimension of size 1.

The return value is a vector of pairs with length equal to the rank of this object. Each pair corresponds to the range of indices from the corresponding dimension to be sliced from, as specified in the input slice object.

Examples:

For a rank 1 object of shape(5):

getSliceRegion(:) => < <0,5> > getSliceRegion(2:3) => < <2,3> > getSliceRegion(:3) => < <0,3> > getSliceRegion(2:) => < <2,5> >

For a rank 2 object of shape(4,5):

getSliceRegion(2:3) => < <2,3> <0,5> > getSliceRegion(2) => < <2,3> <0,5> > NB: but return object requested will have rank 1, shape(5), with values taken from index 2 of this object's first dimension.

For a rank 3 object of shape (2,4,6):

getSliceRegion(0:2,0:4,0:6) => < <0,2> <0,4> <0,6> > getSliceRegion(:,:,:) => < <0,2> <0,4> <0,6> > getSliceRegion(0:1) => < <0,1> <0,4> <0,6> > getSliceRegion(:1,0:2) => < <0,1> <0,2> <0,6> >

Note: Not unit tested in c++.

◆ getSliceRegionLoopRange()

DataTypes::RegionLoopRangeType escript::DataTypes::getSliceRegionLoopRange ( const DataTypes::RegionType region)

Modify region to copy from in order to deal with the case where one range in the region contains identical indexes, eg: <<1,1><0,3><0,3>> This situation implies we want to copy from an object with rank greater than that of this object. eg: we want to copy the values from a two dimensional slice out of a three dimensional object into a two dimensional object. We do this by taking a slice from the other object where one dimension of the slice region is of size 1. So in the above example, we modify the above region like so: <<1,2><0,3><0,3>> and take this slice.

Referenced by escript::DataConstant::DataConstant(), escript::DataExpanded::DataExpanded(), escript::DataTagged::DataTagged(), real_t_eps(), escript::DataConstant::setSlice(), escript::DataExpanded::setSlice(), and escript::DataTagged::setSlice().

◆ index_t_max()

index_t escript::DataTypes::index_t_max ( )
inline

◆ index_t_min()

index_t escript::DataTypes::index_t_min ( )
inline

◆ noValues() [1/2]

int escript::DataTypes::noValues ( const ShapeType shape)

◆ noValues() [2/2]

int escript::DataTypes::noValues ( const RegionLoopRangeType region)

Calculate the number of values for the given region.

Referenced by noValues().

◆ pointToStream()

void escript::DataTypes::pointToStream ( std::ostream &  os,
const RealVectorType::ElementType data,
const ShapeType shape,
int  offset,
bool  needsep = true,
const std::string &  sep = "," 
)

Display a single value (with the specified shape) from the data.

Despite its similar name this function behaves differently to pointToString. There are no prefixes or (i,j,k) identifiers on each field. each datapoint is printed without new lines. It also works with double* rather than vectors so be careful what you pass it.

Parameters
os- stream to write to
data- vector containing the datapoint
shape- shape of the datapoint
offset- start of the datapoint within data
needsep- Does this output need to start with a separator
sep- separator string to print between components

Referenced by escript::saveDataCSV().

◆ pointToString()

std::string escript::DataTypes::pointToString ( const RealVectorType data,
const ShapeType shape,
int  offset,
const std::string &  prefix 
)

Display a single value (with the specified shape) from the data.

Parameters
data- vector containing the datapoint
shape- shape of the datapoint
offset- start of the datapoint within data
prefix- string to prepend to the output

Referenced by escript::DataLazy::resolveNodeTProd(), escript::DataConstant::toString(), escript::DataExpanded::toString(), and escript::DataTagged::toString().

◆ real_t_eps()

real_t escript::DataTypes::real_t_eps ( )
inline

◆ real_t_max()

real_t escript::DataTypes::real_t_max ( )
inline

◆ releaseUnusedMemory()

void escript::DataTypes::releaseUnusedMemory ( )

releases unused memory in the memory manager.

References escript::Taipan::release_unused_arrays().

Referenced by BOOST_PYTHON_MODULE().

◆ shapeToString()

std::string escript::DataTypes::shapeToString ( const DataTypes::ShapeType shape)

Variable Documentation

◆ arrayManager

Taipan escript::DataTypes::arrayManager

◆ maxRank

const int escript::DataTypes::maxRank =4
static

The maximum number of dimensions a datapoint can have.

Referenced by escript::DataConstant::dump(), escript::DataExpanded::dump(), escript::DataTagged::dump(), and escript::load().

◆ scalarShape

const ShapeType escript::DataTypes::scalarShape
static