Escript  Revision_4320
DataTypes.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15 
16 
17 #if !defined escript_DataTypes_20080811_H
18 #define escript_DataTypes_20080811_H
19 #include "system_dep.h"
20 #include "DataVector.h"
21 #include <vector>
22 #include <string>
23 #include <boost/python/object.hpp>
24 #include <boost/python/extract.hpp>
25 
26 namespace escript {
27 
28 namespace DataTypes {
29 
34  //
35  // Some basic types which define the data values and view shapes.
37  typedef std::vector<int> ShapeType;
38  typedef std::vector<std::pair<int, int> > RegionType;
39  typedef std::vector<std::pair<int, int> > RegionLoopRangeType;
40  static const int maxRank=4;
41  static const ShapeType scalarShape;
42 
48  int
49  noValues(const DataTypes::ShapeType& shape);
50 
56  int
58 
66  std::string
67  shapeToString(const DataTypes::ShapeType& shape);
68 
78 
79 
139  getSliceRegion(const DataTypes::ShapeType& shape, const boost::python::object& key);
140 
156 
164  inline
165  int
167  {
168  return shape.size();
169  }
170 
171 
180  inline
183  {
184  EsysAssert((getRank(shape)==1),"Incorrect number of indices for the rank of this object.");
185  EsysAssert((i < DataTypes::noValues(shape)), "Error - Invalid index.");
186  return i;
187  }
188 
198  inline
202  {
203  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
204  EsysAssert((getRank(shape)==2),"Incorrect number of indices for the rank of this object.");
205  DataTypes::ValueType::size_type temp=i+j*shape[0];
206  EsysAssert((temp < DataTypes::noValues(shape)), "Error - Invalid index.");
207  return temp;
208  }
209 
218  inline
222  {
223  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
224  EsysAssert((getRank(shape)==3),"Incorrect number of indices for the rank of this object.");
225  DataTypes::ValueType::size_type temp=i+j*shape[0]+k*shape[1]*shape[0];
226  EsysAssert((temp < DataTypes::noValues(shape)), "Error - Invalid index.");
227  return temp;
228  }
229 
238  inline
243  {
244  // Warning: This is not C ordering. Do not try to figure out the params by looking at the code
245  EsysAssert((getRank(shape)==4),"Incorrect number of indices for the rank of this object.");
246  DataTypes::ValueType::size_type temp=i+j*shape[0]+k*shape[1]*shape[0]+m*shape[2]*shape[1]*shape[0];
247  EsysAssert((temp < DataTypes::noValues(shape)), "Error - Invalid index.");
248  return temp;
249  }
250 
255  inline
256  bool
257  checkShape(const ShapeType& s1, const ShapeType& s2)
258  {
259  return s1==s2;
260  }
261 
270  std::string
271  createShapeErrorMessage(const std::string& messagePrefix,
272  const DataTypes::ShapeType& other,
273  const DataTypes::ShapeType& thisShape);
274 
275 
291  void
292  copySlice(ValueType& left,
293  const ShapeType& leftShape,
294  ValueType::size_type leftOffset,
295  const ValueType& other,
296  const ShapeType& otherShape,
297  ValueType::size_type otherOffset,
298  const RegionLoopRangeType& region);
299 
315  void
316  copySliceFrom(ValueType& left,
317  const ShapeType& leftShape,
318  ValueType::size_type leftOffset,
319  const ValueType& other,
320  const ShapeType& otherShape,
321  ValueType::size_type otherOffset,
322  const RegionLoopRangeType& region);
323 
324 
340  void
341  pointToStream(std::ostream& os, const ValueType::ElementType* data,const ShapeType& shape, int offset, bool needsep=true, const std::string& sep=",");
342 
351  std::string
352  pointToString(const ValueType& data,const ShapeType& shape, int offset, const std::string& prefix);
353 
354 
364  void copyPoint(ValueType& dest, ValueType::size_type doffset, ValueType::size_type nvals, const ValueType& src, ValueType::size_type soffset);
365 
366  } // End of namespace DataTypes
367 
368 
369 } // End of namespace escript
370 
371 #endif
372