17 #ifndef __ESCRIPT_DATAVECTOR_H__ 18 #define __ESCRIPT_DATAVECTOR_H__ 140 typename VEC::size_type leftOffset,
143 typename VEC::size_type otherOffset,
149 ESYS_ASSERT(!left.size()==0,
"left data is empty.");
150 ESYS_ASSERT(!other.size()==0,
"other data is empty.");
156 "offset incompatible with this vector.");
158 "offset incompatible with other vector.");
161 "slice not same rank as vector to be sliced from.");
164 "slice shape not compatible shape for this vector.");
172 switch (region.size()) {
179 left[leftOffset+numCopy]=other[otherOffset];
183 for (
int i=region[0].first;i<region[0].second;i++) {
184 left[leftOffset+numCopy]=other[otherOffset+
getRelIndex(otherShape,i)];
189 for (
int j=region[1].first;j<region[1].second;j++) {
190 for (
int i=region[0].first;i<region[0].second;i++) {
192 left[leftOffset+numCopy]=other[otherOffset+
getRelIndex(otherShape,i,j)];
198 for (
int k=region[2].first;k<region[2].second;k++) {
199 for (
int j=region[1].first;j<region[1].second;j++) {
200 for (
int i=region[0].first;i<region[0].second;i++) {
202 left[leftOffset+numCopy]=other[otherOffset+
getRelIndex(otherShape,i,j,k)];
209 for (
int l=region[3].first;l<region[3].second;l++) {
210 for (
int k=region[2].first;k<region[2].second;k++) {
211 for (
int j=region[1].first;j<region[1].second;j++) {
212 for (
int i=region[0].first;i<region[0].second;i++) {
214 left[leftOffset+numCopy]=other[otherOffset+
getRelIndex(otherShape,i,j,k,l)];
222 std::stringstream mess;
223 mess <<
"Error - (copySlice) Invalid slice region rank: " << region.size();
242 template<
typename VEC>
247 typename VEC::size_type leftOffset,
250 typename VEC::size_type otherOffset,
256 ESYS_ASSERT(left.size()!=0,
"this vector is empty.");
257 ESYS_ASSERT(other.size()!=0,
"other vector is empty.");
264 "offset incompatible with other vector.");
266 "offset incompatible with this vector.");
269 "slice not same rank as this vector.");
272 "slice shape not compatible shape for other vector.");
283 switch (region.size()) {
289 left[leftOffset]=other[otherOffset];
293 for (
int i=region[0].first;i<region[0].second;i++) {
294 left[leftOffset+
getRelIndex(leftShape,i)]=other[otherOffset];
299 for (
int j=region[1].first;j<region[1].second;j++) {
300 for (
int i=region[0].first;i<region[0].second;i++) {
301 left[leftOffset+
getRelIndex(leftShape,i,j)]=other[otherOffset];
307 for (
int k=region[2].first;k<region[2].second;k++) {
308 for (
int j=region[1].first;j<region[1].second;j++) {
309 for (
int i=region[0].first;i<region[0].second;i++) {
310 left[leftOffset+
getRelIndex(leftShape,i,j,k)]=other[otherOffset];
317 for (
int l=region[3].first;l<region[3].second;l++) {
318 for (
int k=region[2].first;k<region[2].second;k++) {
319 for (
int j=region[1].first;j<region[1].second;j++) {
320 for (
int i=region[0].first;i<region[0].second;i++) {
321 left[leftOffset+
getRelIndex(leftShape,i,j,k,l)]=other[otherOffset];
329 std::stringstream mess;
330 mess <<
"Error - (copySliceFrom) Invalid slice region rank: " << region.size();
339 switch (region.size()) {
345 left[leftOffset]=other[otherOffset+numCopy];
349 for (
int i=region[0].first;i<region[0].second;i++) {
350 left[leftOffset+
getRelIndex(leftShape,i)]=other[otherOffset+numCopy];
355 for (
int j=region[1].first;j<region[1].second;j++) {
356 for (
int i=region[0].first;i<region[0].second;i++) {
357 left[leftOffset+
getRelIndex(leftShape,i,j)]=other[otherOffset+numCopy];
363 for (
int k=region[2].first;k<region[2].second;k++) {
364 for (
int j=region[1].first;j<region[1].second;j++) {
365 for (
int i=region[0].first;i<region[0].second;i++) {
366 left[leftOffset+
getRelIndex(leftShape,i,j,k)]=other[otherOffset+numCopy];
373 for (
int l=region[3].first;l<region[3].second;l++) {
374 for (
int k=region[2].first;k<region[2].second;k++) {
375 for (
int j=region[1].first;j<region[1].second;j++) {
376 for (
int i=region[0].first;i<region[0].second;i++) {
377 left[leftOffset+
getRelIndex(leftShape,i,j,k,l)]=other[otherOffset+numCopy];
385 std::stringstream mess;
386 mess <<
"Error - (copySliceFrom) Invalid slice region rank: " << region.size();
397 #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:245
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:138
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:38
escript::DataTypes::DataVectorAlt< cplx_t > CplxVectorType
Definition: DataVector.h:39
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...