17 #ifndef __ESCRIPT_DATAVECTOR_H__ 18 #define __ESCRIPT_DATAVECTOR_H__ 26 #ifdef ESYS_HAVE_BOOST_NUMPY 27 #include <boost/python.hpp> 28 #include <boost/python/numpy.hpp> 83 #ifdef ESYS_HAVE_BOOST_NUMPY 86 pointToNumpyArrayOld(boost::python::numpy::ndarray& dataArray,
const RealVectorType::ElementType* data,
const ShapeType& shape,
long offset,
long numsamples,
long dpps,
long numdata);
90 pointToNumpyArrayOld(boost::python::numpy::ndarray& dataArray,
const CplxVectorType::ElementType* data,
const ShapeType& shape,
long offset,
long numsamples,
long dpps,
long numdata);
175 typename VEC::size_type leftOffset,
178 typename VEC::size_type otherOffset,
184 ESYS_ASSERT(!left.size()==0,
"left data is empty.");
185 ESYS_ASSERT(!other.size()==0,
"other data is empty.");
191 "offset incompatible with this vector.");
193 "offset incompatible with other vector.");
196 "slice not same rank as vector to be sliced from.");
199 "slice shape not compatible shape for this vector.");
207 switch (region.size()) {
214 left[leftOffset+numCopy]=other[otherOffset];
218 for (
int i=region[0].first;i<region[0].second;i++) {
219 left[leftOffset+numCopy]=other[otherOffset+
getRelIndex(otherShape,i)];
224 for (
int j=region[1].first;j<region[1].second;j++) {
225 for (
int i=region[0].first;i<region[0].second;i++) {
227 left[leftOffset+numCopy]=other[otherOffset+
getRelIndex(otherShape,i,j)];
233 for (
int k=region[2].first;k<region[2].second;k++) {
234 for (
int j=region[1].first;j<region[1].second;j++) {
235 for (
int i=region[0].first;i<region[0].second;i++) {
237 left[leftOffset+numCopy]=other[otherOffset+
getRelIndex(otherShape,i,j,k)];
244 for (
int l=region[3].first;l<region[3].second;l++) {
245 for (
int k=region[2].first;k<region[2].second;k++) {
246 for (
int j=region[1].first;j<region[1].second;j++) {
247 for (
int i=region[0].first;i<region[0].second;i++) {
249 left[leftOffset+numCopy]=other[otherOffset+
getRelIndex(otherShape,i,j,k,l)];
257 std::stringstream mess;
258 mess <<
"Error - (copySlice) Invalid slice region rank: " << region.size();
277 template<
typename VEC>
282 typename VEC::size_type leftOffset,
285 typename VEC::size_type otherOffset,
291 ESYS_ASSERT(left.size()!=0,
"this vector is empty.");
292 ESYS_ASSERT(other.size()!=0,
"other vector is empty.");
299 "offset incompatible with other vector.");
301 "offset incompatible with this vector.");
304 "slice not same rank as this vector.");
307 "slice shape not compatible shape for other vector.");
318 switch (region.size()) {
324 left[leftOffset]=other[otherOffset];
328 for (
int i=region[0].first;i<region[0].second;i++) {
329 left[leftOffset+
getRelIndex(leftShape,i)]=other[otherOffset];
334 for (
int j=region[1].first;j<region[1].second;j++) {
335 for (
int i=region[0].first;i<region[0].second;i++) {
336 left[leftOffset+
getRelIndex(leftShape,i,j)]=other[otherOffset];
342 for (
int k=region[2].first;k<region[2].second;k++) {
343 for (
int j=region[1].first;j<region[1].second;j++) {
344 for (
int i=region[0].first;i<region[0].second;i++) {
345 left[leftOffset+
getRelIndex(leftShape,i,j,k)]=other[otherOffset];
352 for (
int l=region[3].first;l<region[3].second;l++) {
353 for (
int k=region[2].first;k<region[2].second;k++) {
354 for (
int j=region[1].first;j<region[1].second;j++) {
355 for (
int i=region[0].first;i<region[0].second;i++) {
356 left[leftOffset+
getRelIndex(leftShape,i,j,k,l)]=other[otherOffset];
364 std::stringstream mess;
365 mess <<
"Error - (copySliceFrom) Invalid slice region rank: " << region.size();
374 switch (region.size()) {
380 left[leftOffset]=other[otherOffset+numCopy];
384 for (
int i=region[0].first;i<region[0].second;i++) {
385 left[leftOffset+
getRelIndex(leftShape,i)]=other[otherOffset+numCopy];
390 for (
int j=region[1].first;j<region[1].second;j++) {
391 for (
int i=region[0].first;i<region[0].second;i++) {
392 left[leftOffset+
getRelIndex(leftShape,i,j)]=other[otherOffset+numCopy];
398 for (
int k=region[2].first;k<region[2].second;k++) {
399 for (
int j=region[1].first;j<region[1].second;j++) {
400 for (
int i=region[0].first;i<region[0].second;i++) {
401 left[leftOffset+
getRelIndex(leftShape,i,j,k)]=other[otherOffset+numCopy];
408 for (
int l=region[3].first;l<region[3].second;l++) {
409 for (
int k=region[2].first;k<region[2].second;k++) {
410 for (
int j=region[1].first;j<region[1].second;j++) {
411 for (
int i=region[0].first;i<region[0].second;i++) {
412 left[leftOffset+
getRelIndex(leftShape,i,j,k,l)]=other[otherOffset+numCopy];
420 std::stringstream mess;
421 mess <<
"Error - (copySliceFrom) Invalid slice region rank: " << region.size();
432 #endif // __ESCRIPT_DATAVECTOR_H__ bool checkOffset(vec_size_type offset, int size, int noval)
Definition: DataTypes.h:323
Definition: AbstractContinuousDomain.cpp:22
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 s...
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.
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:233
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:42
std::vector< std::pair< int, int > > RegionLoopRangeType
Definition: DataTypes.h:44
DataTypes::ShapeType getResultSliceShape(const RegionType ®ion)
Determine the shape of the specified slice region.
Definition: DataTypes.cpp:172
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 ®ion)
Copy data into a slice specified by the given region and offset in the left vector from the other vec...
Definition: DataVector.h:280
Definition: DataVectorAlt.h:36
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.
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 ®ion)
Copy a data slice specified by the given region and offset from the "other" vector into the "left" ve...
Definition: DataVector.h:173
T ElementType
Definition: DataVectorAlt.h:42
int noValues(const ShapeType &shape)
Calculate the number of values in a datapoint with the given shape.
Definition: DataTypes.cpp:90
Definition: DataException.h:26
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:29
escript::DataTypes::DataVectorAlt< real_t > RealVectorType
Vector to store underlying data.
Definition: DataVector.h:43
escript::DataTypes::DataVectorAlt< cplx_t > CplxVectorType
Definition: DataVector.h:44
int getRank(const DataTypes::ShapeType &shape)
Return the rank (number of dimensions) of the given shape.
Definition: DataTypes.h:218
#define ESYS_ASSERT(a, b)
EsysAssert is a MACRO that will throw an exception if the boolean condition specified is false...
Definition: Assert.h:78
long vec_size_type
Definition: DataTypes.h:47
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...