escript  Revision_Unversioneddirectory
DataTypes.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 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 
18 #if !defined escript_DataTypes_20080811_H
19 #define escript_DataTypes_20080811_H
20 #include "system_dep.h"
21 #include "DataVector.h"
22 #include <vector>
23 #include <string>
24 #include <boost/python/object.hpp>
25 #include <boost/python/extract.hpp>
26 
27 namespace escript {
28 
29 namespace DataTypes {
30 
35  //
36  // Some basic types which define the data values and view shapes.
38  typedef std::vector<int> ShapeType;
39  typedef std::vector<std::pair<int, int> > RegionType;
40  typedef std::vector<std::pair<int, int> > RegionLoopRangeType;
41  static const int maxRank=4;
42  static const ShapeType scalarShape;
43 
49  int
50  noValues(const DataTypes::ShapeType& shape);
51 
57  int
59 
67  std::string
68  shapeToString(const DataTypes::ShapeType& shape);
69 
79 
80 
140  getSliceRegion(const DataTypes::ShapeType& shape, const boost::python::object& key);
141 
157 
165  inline
166  int
168  {
169  return shape.size();
170  }
171 
172 
181  inline
184  {
185  EsysAssert((getRank(shape)==1),"Incorrect number of indices for the rank of this object.");
186  EsysAssert((i < DataTypes::noValues(shape)), "Error - Invalid index.");
187  return i;
188  }
189 
199  inline
203  {
204  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
205  EsysAssert((getRank(shape)==2),"Incorrect number of indices for the rank of this object.");
206  DataTypes::ValueType::size_type temp=i+j*shape[0];
207  EsysAssert((temp < DataTypes::noValues(shape)), "Error - Invalid index.");
208  return temp;
209  }
210 
219  inline
223  {
224  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
225  EsysAssert((getRank(shape)==3),"Incorrect number of indices for the rank of this object.");
226  DataTypes::ValueType::size_type temp=i+j*shape[0]+k*shape[1]*shape[0];
227  EsysAssert((temp < DataTypes::noValues(shape)), "Error - Invalid index.");
228  return temp;
229  }
230 
239  inline
244  {
245  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
246  EsysAssert((getRank(shape)==4),"Incorrect number of indices for the rank of this object.");
247  DataTypes::ValueType::size_type temp=i+j*shape[0]+k*shape[1]*shape[0]+m*shape[2]*shape[1]*shape[0];
248  EsysAssert((temp < DataTypes::noValues(shape)), "Error - Invalid index.");
249  return temp;
250  }
251 
256  inline
257  bool
258  checkShape(const ShapeType& s1, const ShapeType& s2)
259  {
260  return s1==s2;
261  }
262 
271  std::string
272  createShapeErrorMessage(const std::string& messagePrefix,
273  const DataTypes::ShapeType& other,
274  const DataTypes::ShapeType& thisShape);
275 
276 
292  void
293  copySlice(ValueType& left,
294  const ShapeType& leftShape,
295  ValueType::size_type leftOffset,
296  const ValueType& other,
297  const ShapeType& otherShape,
298  ValueType::size_type otherOffset,
299  const RegionLoopRangeType& region);
300 
316  void
317  copySliceFrom(ValueType& left,
318  const ShapeType& leftShape,
319  ValueType::size_type leftOffset,
320  const ValueType& other,
321  const ShapeType& otherShape,
322  ValueType::size_type otherOffset,
323  const RegionLoopRangeType& region);
324 
325 
341  void
342  pointToStream(std::ostream& os, const ValueType::ElementType* data,const ShapeType& shape, int offset, bool needsep=true, const std::string& sep=",");
343 
352  std::string
353  pointToString(const ValueType& data,const ShapeType& shape, int offset, const std::string& prefix);
354 
355 
365  void copyPoint(ValueType& dest, ValueType::size_type doffset, ValueType::size_type nvals, const ValueType& src, ValueType::size_type soffset);
366 
367  } // End of namespace DataTypes
368 
369 
370 } // End of namespace escript
371 
372 #endif
373 
DataVector implements an arbitrarily long vector of data values. DataVector is the underlying data co...
Definition: DataVector.h:44
escript::DataVector ValueType
Vector to store underlying data.
Definition: DataTypes.h:37
std::string shapeToString(const DataTypes::ShapeType &shape)
Return the given shape as a string.
Definition: DataTypes.cpp:120
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:39
Definition: AbstractContinuousDomain.cpp:24
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 s...
Definition: DataTypes.cpp:635
static const ShapeType scalarShape
Use this instead of creating empty shape objects for scalars.
Definition: DataTypes.h:42
bool checkShape(const ShapeType &s1, const ShapeType &s2)
Test if two shapes are equal.
Definition: DataTypes.h:258
void copySliceFrom(ValueType &left, const ShapeType &leftShape, ValueType::size_type thisOffset, 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 vec...
Definition: DataTypes.cpp:326
DataTypes::RegionType getSliceRegion(const DataTypes::ShapeType &shape, const boost::python::object &key)
Determine the region specified by the given python slice object.
Definition: DataTypes.cpp:140
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:38
std::string createShapeErrorMessage(const std::string &messagePrefix, const DataTypes::ShapeType &other, const DataTypes::ShapeType &thisShape)
Produce a string containing two shapes.
Definition: DataTypes.cpp:209
std::vector< std::pair< int, int > > RegionLoopRangeType
Definition: DataTypes.h:40
void pointToStream(std::ostream &os, const ValueType::ElementType *data, const ShapeType &shape, int offset, bool needsep, const std::string &sep)
Display a single value (with the specified shape) from the data.
Definition: DataTypes.cpp:479
double ElementType
Definition: DataVector.h:50
DataTypes::ShapeType getResultSliceShape(const RegionType &region)
Determine the shape of the specified slice region.
Definition: DataTypes.cpp:176
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:191
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.
Definition: DataTypes.h:183
#define EsysAssert(AssertTest, AssertMessage)
EsysAssert is a MACRO that will throw an exception if the boolean condition specified is false...
Definition: EsysAssert.h:96
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.
Definition: DataTypes.cpp:569
static const int maxRank
The maximum number of dimensions a datapoint can have.
Definition: DataTypes.h:41
void copySlice(ValueType &left, const ShapeType &leftShape, ValueType::size_type thisOffset, 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...
Definition: DataTypes.cpp:232
int noValues(const ShapeType &shape)
Calculate the number of values in a datapoint with the given shape.
Definition: DataTypes.cpp:94
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:54
int getRank(const DataTypes::ShapeType &shape)
Return the rank (number of dimensions) of the given shape.
Definition: DataTypes.h:167
long size_type
Definition: DataVector.h:60