escript  Revision_Unversioneddirectory
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...

Typedefs

typedef escript::DataVector ValueType
 Vector to store underlying data. More...
 
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
 

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 boost::python::object &key)
 Determine the region specified by the given python slice object. More...
 
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...
 
bool checkOffset (ValueType::size_type offset, int size, int noval)
 
void copySlice (ValueType &left, const ShapeType &leftShape, ValueType::size_type leftOffset, const ValueType &other, const ShapeType &otherShape, ValueType::size_type otherOffset, const RegionLoopRangeType &region)
 Copy a data slice specified by the given region and offset from the "other" view into the "left" view at the given offset. More...
 
void copySliceFrom (ValueType &left, const ShapeType &leftShape, ValueType::size_type leftOffset, const ValueType &other, const ShapeType &otherShape, ValueType::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 pointToStream (std::ostream &os, const ValueType::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 ValueType &data, const ShapeType &shape, int offset, const std::string &prefix)
 Display a single value (with the specified shape) from the data. More...
 
void copyPoint (ValueType &dest, ValueType::size_type doffset, ValueType::size_type nvals, const ValueType &src, ValueType::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...
 
int getRank (const DataTypes::ShapeType &shape)
 Return the rank (number of dimensions) of the given shape. More...
 
DataTypes::ValueType::size_type getRelIndex (const DataTypes::ShapeType &shape, DataTypes::ValueType::size_type i)
 Compute the offset (in 1D vector) of a given subscript with a shape. More...
 
DataTypes::ValueType::size_type getRelIndex (const DataTypes::ShapeType &shape, DataTypes::ValueType::size_type i, DataTypes::ValueType::size_type j)
 Compute the offset (in 1D vector) of a given subscript with a shape. More...
 
DataTypes::ValueType::size_type getRelIndex (const DataTypes::ShapeType &shape, DataTypes::ValueType::size_type i, DataTypes::ValueType::size_type j, DataTypes::ValueType::size_type k)
 Compute the offset (in 1D vector) of a given subscript with a shape. More...
 
DataTypes::ValueType::size_type getRelIndex (const DataTypes::ShapeType &shape, DataTypes::ValueType::size_type i, DataTypes::ValueType::size_type j, DataTypes::ValueType::size_type k, DataTypes::ValueType::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...
 

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...
 

Detailed Description

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

Typedef Documentation

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

The shape of a single datapoint.

Vector to store underlying data.

Function Documentation

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

Referenced by copyPoint(), copySlice(), and copySliceFrom().

bool escript::DataTypes::checkShape ( const ShapeType s1,
const ShapeType s2 
)
inline
void escript::DataTypes::copyPoint ( ValueType dest,
ValueType::size_type  doffset,
ValueType::size_type  nvals,
const ValueType src,
ValueType::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

References checkOffset(), EsysAssert, and escript::DataVector::size().

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

void escript::DataTypes::copySlice ( ValueType left,
const ShapeType leftShape,
ValueType::size_type  leftOffset,
const ValueType other,
const ShapeType otherShape,
ValueType::size_type  otherOffset,
const RegionLoopRangeType region 
)

Copy a data slice specified by the given region and offset from the "other" view into the "left" view 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 view to copy data from.

References checkOffset(), EsysAssert, getRank(), getRelIndex(), getResultSliceShape(), noValues(), and escript::DataVector::size().

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

void escript::DataTypes::copySliceFrom ( ValueType left,
const ShapeType leftShape,
ValueType::size_type  leftOffset,
const ValueType other,
const ShapeType otherShape,
ValueType::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(), EsysAssert, getRank(), getRelIndex(), getResultSliceShape(), noValues(), and escript::DataVector::size().

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

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().

int escript::DataTypes::getRank ( const DataTypes::ShapeType shape)
inline
DataTypes::ValueType::size_type escript::DataTypes::getRelIndex ( const DataTypes::ShapeType shape,
DataTypes::ValueType::size_type  i 
)
inline
DataTypes::ValueType::size_type escript::DataTypes::getRelIndex ( const DataTypes::ShapeType shape,
DataTypes::ValueType::size_type  i,
DataTypes::ValueType::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 ESCRIPT_DLL_API, EsysAssert, getRank(), and noValues().

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 ESCRIPT_DLL_API, EsysAssert, getRank(), and noValues().

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 ESCRIPT_DLL_API, EsysAssert, getRank(), and noValues().

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(), escript::DataConstant::setSlice(), escript::DataExpanded::setSlice(), and escript::DataTagged::setSlice().

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++.

Referenced by escript::Data::getItem(), and escript::Data::setItemD().

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(), escript::DataConstant::setSlice(), escript::DataExpanded::setSlice(), and escript::DataTagged::setSlice().

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

Calculate the number of values for the given region.

Referenced by copySlice(), copySliceFrom(), and noValues().

void escript::DataTypes::pointToStream ( std::ostream &  os,
const ValueType::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

References EsysAssert, getRank(), and getRelIndex().

Referenced by checkShape(), and escript::saveDataCSV().

std::string escript::DataTypes::pointToString ( const ValueType 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

References EsysAssert, getRank(), getRelIndex(), and escript::DataVector::size().

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

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

Variable Documentation

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().

const ShapeType escript::DataTypes::scalarShape
static