/[escript]/trunk/escript/src/DataArrayView.cpp
ViewVC logotype

Diff of /trunk/escript/src/DataArrayView.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 102 by jgs, Wed Dec 15 07:08:39 2004 UTC revision 108 by jgs, Thu Jan 27 06:21:59 2005 UTC
# Line 30  namespace escript { Line 30  namespace escript {
30    
31  DataArrayView::DataArrayView():  DataArrayView::DataArrayView():
32      m_shape(),      m_shape(),
33      m_offset(),      m_offset(0),
34      m_noValues()      m_noValues(0)
35  {  {
36      m_data=0;      m_data=0;
37  }  }
# Line 45  DataArrayView::DataArrayView(ValueType& Line 45  DataArrayView::DataArrayView(ValueType&
45      m_noValues(noValues(viewShape))      m_noValues(noValues(viewShape))
46  {  {
47      //      //
48      // check the shape and throw an exception if an illegal shape is specified      // check the shape rank and size and throw an exception if a
49        // shape incompatible with the given data array is specified
50      if (viewShape.size() > m_maxRank) {      if (viewShape.size() > m_maxRank) {
51        stringstream temp;        stringstream temp;
52        temp << "Error- Couldn't construct DataArrayView, invalid rank."        temp << "Error- Couldn't construct DataArrayView, invalid rank."
53         << "Input data rank: " << viewShape.size()         << "Input data rank: " << viewShape.size() << " "
54         << " Maximum rank allowed for DataArrayView: "         << "Maximum rank allowed for DataArrayView: " << m_maxRank;
        << m_maxRank;  
55        throw DataException(temp.str());        throw DataException(temp.str());
56      }      }
57      if (m_data->size() < (noValues()+m_offset)) {      if (m_data->size() < (m_offset+noValues())) {
58        stringstream temp;        stringstream temp;
59        temp << "Error- Couldn't construct DataArrayView, insufficient storage."        temp << "Error- Couldn't construct DataArrayView, insufficient data values. "
60         << " Shape requires: " << noValues()+m_offset << " values."         << "Shape requires: " << noValues()+m_offset << " values."
61         << " Data values available: " << m_data->size();         << "Data values available: " << m_data->size();
62        throw DataException(temp.str());        throw DataException(temp.str());
63      }      }
64  }  }
# Line 74  DataArrayView::DataArrayView(const DataA Line 74  DataArrayView::DataArrayView(const DataA
74  bool  bool
75  DataArrayView::isEmpty() const  DataArrayView::isEmpty() const
76  {  {
77      return(m_data==0);      return (m_data==0);
78  }  }
79    
80  void  void
81  DataArrayView::copy(const boost::python::numeric::array& value)  DataArrayView::copy(const boost::python::numeric::array& value)
82  {  {
83      DataArrayView::ShapeType tempShape;          DataArrayView::ShapeType tempShape;    
84      for (int i=0; i<value.getrank(); ++i) {      for (int i=0; i<value.getrank(); i++) {
85        tempShape.push_back(extract<int>(value.getshape()[i]));        tempShape.push_back(extract<int>(value.getshape()[i]));
86      }      }
87    
88      EsysAssert((!isEmpty()&&checkShape(tempShape)),      EsysAssert((!isEmpty()&&checkShape(tempShape)),
89             createShapeErrorMessage("Error - Couldn't copy due to shape mismatch.",tempShape));             createShapeErrorMessage("Error - Couldn't copy due to shape mismatch.",tempShape));
90    
# Line 130  void Line 131  void
131  DataArrayView::copy(ValueType::size_type offset,  DataArrayView::copy(ValueType::size_type offset,
132                      const DataArrayView& other)                      const DataArrayView& other)
133  {  {
134      EsysAssert((!isEmpty()&&checkShape(other.getShape())),      EsysAssert((!isEmpty()&&!other.isEmpty()&&checkOffset(offset)),
135               "Error - Couldn't copy due to insufficient storage.");
136        EsysAssert((checkShape(other.getShape())),
137             createShapeErrorMessage("Error - Couldn't copy due to shape mismatch.",other.getShape()));             createShapeErrorMessage("Error - Couldn't copy due to shape mismatch.",other.getShape()));
138      memcpy(&(*m_data)[offset],&(*other.m_data)[other.m_offset],sizeof(double)*noValues());      if (checkOffset(offset)) {
139          memcpy(&(*m_data)[offset],&(*other.m_data)[other.m_offset],sizeof(double)*noValues());
140        } else {
141          throw DataException("Error - invalid offset specified.");
142        }
143  }  }
144    
145  void  void
# Line 140  DataArrayView::copy(ValueType::size_type Line 147  DataArrayView::copy(ValueType::size_type
147                      const DataArrayView& other,                      const DataArrayView& other,
148                      ValueType::size_type otherOffset)                      ValueType::size_type otherOffset)
149  {  {
150      EsysAssert((!isEmpty()&&checkShape(other.getShape())),      EsysAssert((!isEmpty()&&!other.isEmpty()&&checkOffset(thisOffset)&&other.checkOffset(otherOffset)),
151               "Error - Couldn't copy due to insufficient storage.");
152        EsysAssert((checkShape(other.getShape())),
153             createShapeErrorMessage("Error - Couldn't copy due to shape mismatch.",other.getShape()));             createShapeErrorMessage("Error - Couldn't copy due to shape mismatch.",other.getShape()));
154      memcpy(&(*m_data)[thisOffset],&(*other.m_data)[otherOffset],sizeof(double)*noValues());      if (checkOffset(thisOffset)&&other.checkOffset(otherOffset)) {
155          memcpy(&(*m_data)[thisOffset],&(*other.m_data)[otherOffset],sizeof(double)*noValues());
156        } else {
157          throw DataException("Error - invalid offset specified.");
158        }
159  }  }
160    
161  void  void
162  DataArrayView::copy(ValueType::size_type offset,  DataArrayView::copy(ValueType::size_type offset,
163                      ValueType::value_type value)                      ValueType::value_type value)
164  {  {
165      //      EsysAssert((!isEmpty()&&checkOffset(offset)),
166      // fill the entire view with the single value             "Error - Couldn't copy due to insufficient storage.");
167      EsysAssert(!isEmpty(),"Error - View is empty");      if (checkOffset(offset)) {
168      ValueType temp(noValues(),value);        ValueType temp(noValues(),value);
169      memcpy(&(*m_data)[offset],&temp[0],sizeof(double)*noValues());        memcpy(&(*m_data)[offset],&temp[0],sizeof(double)*noValues());
170        } else {
171          throw DataException("Error - invalid offset specified.");
172        }
173  }  }
174    
175  int  int
# Line 175  DataArrayView::noValues(const ShapeType& Line 191  DataArrayView::noValues(const ShapeType&
191      //      //
192      // An empty shape vector means rank 0 which contains 1 value      // An empty shape vector means rank 0 which contains 1 value
193      int noValues=1;      int noValues=1;
194      for (i=shape.begin();i!=shape.end();++i) {      for (i=shape.begin();i!=shape.end();i++) {
195        noValues*=(*i);        noValues*=(*i);
196      }      }
197      return noValues;      return noValues;
198  }  }
199    
200    int
201    DataArrayView::noValues(const RegionLoopRangeType& region)
202    {
203        //
204        // An empty region vector means rank 0 which contains 1 value
205        int noValues=1;
206        for (int i=0; i<region.size(); i++) {
207          noValues*=region[i].second-region[i].first;
208        }
209        return noValues;
210    }
211    
212  int  int
213  DataArrayView::noValues() const  DataArrayView::noValues() const
# Line 203  DataArrayView::createShapeErrorMessage(c Line 231  DataArrayView::createShapeErrorMessage(c
231       << " Other shape: " << shapeToString(other);       << " Other shape: " << shapeToString(other);
232      return temp.str();      return temp.str();
233  }  }
234    
235    DataArrayView::ValueType::size_type
236    DataArrayView::getOffset() const
237    {
238      return m_offset;
239    }
240    
241  void  void
242  DataArrayView::setOffset(ValueType::size_type offset)  DataArrayView::setOffset(ValueType::size_type offset)
243  {  {
244      EsysAssert((m_data->size() >= (noValues()+offset)), "Invalid offset");      EsysAssert((checkOffset(offset)), "Error - Invalid offset.");
245      m_offset=offset;      if (checkOffset(offset)) {
246          m_offset=offset;
247        } else {
248          throw DataException("Error - invalid offset specified.");
249        }
250    }
251    
252    void
253    DataArrayView::incrOffset()
254    {
255        EsysAssert((checkOffset(m_offset+noValues())), "Error - Cannot increment offset.");
256        if (checkOffset(m_offset+noValues())) {
257          m_offset=m_offset+noValues();
258        } else {
259          throw DataException("Error - Cannot increment offset.");
260        }
261    }
262    
263    bool
264    DataArrayView::checkOffset() const
265    {
266        return checkOffset(m_offset);
267    }
268    
269    bool
270    DataArrayView::checkOffset(ValueType::size_type offset) const
271    {
272        return (m_data->size() >= (offset+noValues()));
273    }
274    
275    DataArrayView::ValueType&
276    DataArrayView::getData() const
277    {
278      EsysAssert(!isEmpty(),"Error - View is empty");
279      return *m_data;
280    }
281    
282    DataArrayView::ValueType::reference
283    DataArrayView::getData(ValueType::size_type i) const
284    {
285      //
286      // don't do any index checking so allow one past the end of the
287      // vector providing the equivalent of end()
288      return (*m_data)[m_offset+i];
289  }  }
290    
291  DataArrayView::ShapeType  DataArrayView::ShapeType
# Line 218  DataArrayView::getResultSliceShape(const Line 295  DataArrayView::getResultSliceShape(const
295      RegionType::const_iterator i;      RegionType::const_iterator i;
296      DataArrayView::ShapeType result;      DataArrayView::ShapeType result;
297      for (i=region.begin();i!=region.end();i++) {      for (i=region.begin();i!=region.end();i++) {
298        dimSize=((i->second) - (i->first));        dimSize=((i->second)-(i->first));
299        if (dimSize!=0) {        if (dimSize!=0) {
300      result.push_back(dimSize);      result.push_back(dimSize);
301        }        }
# Line 229  DataArrayView::getResultSliceShape(const Line 306  DataArrayView::getResultSliceShape(const
306  DataArrayView::RegionType  DataArrayView::RegionType
307  DataArrayView::getSliceRegion(const boost::python::object& key) const  DataArrayView::getSliceRegion(const boost::python::object& key) const
308  {  {
309    int slice_rank, out_rank, i;    int slice_rank, i;
310    int this_rank=getRank();    int this_rank=getRank();
311      DataArrayView::RegionType out(this_rank);
312    /* allow for case where key is singular eg: [1], this implies we    /* allow for case where key is singular eg: [1], this implies we
313       want to generate a rank-1 dimension object, as opposed to eg: [1,2]       want to generate a rank-1 dimension object, as opposed to eg: [1,2]
314       which implies we want to take a rank dimensional object with one       which implies we want to take a rank dimensional object with one
# Line 238  DataArrayView::getSliceRegion(const boos Line 316  DataArrayView::getSliceRegion(const boos
316    extract<tuple> key_tuple(key);    extract<tuple> key_tuple(key);
317    if (key_tuple.check()) {    if (key_tuple.check()) {
318        slice_rank=extract<int> (key.attr("__len__")());        slice_rank=extract<int> (key.attr("__len__")());
319          /* ensure slice is correctly dimensioned */
320          if (slice_rank>this_rank) {
321               throw DataException("Error - rank of slices does not match rank of slicee");
322          } else {
323             /* calculate values for slice range */
324             for (i=0;i<slice_rank;i++) {
325               out[i]=getSliceRange(key[i],getShape()[i]);
326             }
327          }
328    } else {    } else {
329        slice_rank=1;        slice_rank=1;
330    }        if (slice_rank>this_rank) {
331    /* ensure slice is correctly dimensioned */             throw DataException("Error - rank of slices does not match rank of slicee");
332    if (slice_rank>=this_rank) {        } else {
333         out_rank=slice_rank;             out[0]=getSliceRange(key,getShape()[0]);
334    } else {        }
        out_rank=this_rank;  
   }  
   DataArrayView::RegionType out(out_rank);  
   /* calculate values for slice range */  
   if (key_tuple.check()) {  
     for (i=0;i<slice_rank;i++) {  
       out[i]=getSliceRange(key[i],getShape()[i]);  
     }  
   } else {  
     out[0]=getSliceRange(key,getShape()[0]);  
335    }    }
336    for (i=slice_rank;i<this_rank;i++) {    for (i=slice_rank;i<this_rank;i++) {
337      out[i]=std::pair<int,int>(0,getShape()[i]);      out[i]=std::pair<int,int>(0,getShape()[i]);
# Line 292  getSliceRange(const boost::python::objec Line 369  getSliceRange(const boost::python::objec
369        }        }
370      }      }
371    }    }
372      if (s0 < 0)
373         throw DataException("Error - slice index out of range.");
374      if (s0 == s1 and s1 >= shape)
375         throw DataException("Error - slice index out of range.");
376      if (s0 != s1 and  s1>shape)
377         throw DataException("Error - slice index out of range.");
378      if (s0 > s1)
379         throw DataException("Error - lower index must less or equal upper index.");
380    return std::pair<int,int>(s0,s1);    return std::pair<int,int>(s0,s1);
381  }  }
382    
383    DataArrayView::RegionLoopRangeType
384    getSliceRegionLoopRange(const DataArrayView::RegionType& region)
385    {
386        DataArrayView::RegionLoopRangeType region_loop_range(region.size());
387        for (int i=0;i<region.size();i++) {
388          if (region[i].first==region[i].second) {
389            region_loop_range[i].first=region[i].first;
390            region_loop_range[i].second=region[i].second+1;
391          } else {
392            region_loop_range[i].first=region[i].first;
393            region_loop_range[i].second=region[i].second;
394          }
395        }
396        return region_loop_range;
397    }
398    
399  void  void
400  DataArrayView::copySlice(const DataArrayView& other,  DataArrayView::copySlice(const DataArrayView& other,
401                           const RegionType& region)                           const RegionLoopRangeType& region)
402  {  {
403      //      //
404      // version of copySlice that uses the default offsets      // version of copySlice that uses the default offsets
# Line 308  void Line 409  void
409  DataArrayView::copySlice(ValueType::size_type thisOffset,  DataArrayView::copySlice(ValueType::size_type thisOffset,
410                           const DataArrayView& other,                           const DataArrayView& other,
411                           ValueType::size_type otherOffset,                           ValueType::size_type otherOffset,
412                           const RegionType& region)                           const RegionLoopRangeType& region)
413  {  {
414    
415      //      //
416      // Make sure this object is not empty      // Make sure views are not empty
417      EsysAssert(!isEmpty(),"Error - this data object is empty.");  
418        EsysAssert(!isEmpty(),
419                   "Error - this view is empty.");
420        EsysAssert(!other.isEmpty(),
421                   "Error - other view is empty.");
422    
423      //      //
424      // Modify region to copy from in order to      // Check the view to be sliced from is compatible with the region to be sliced,
425      // deal with the case where one range in the region contains identical indexes,      // and that the region to be sliced is compatible with this view:
     // 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.  
426    
427      RegionType slice_region=region;      EsysAssert(checkOffset(thisOffset),
428      for (int i=0;i<slice_region.size();i++) {                 "Error - offset incompatible with this view.");
429        if (slice_region[i].first==slice_region[i].second) {      EsysAssert(otherOffset+noValues()<=other.getData().size(),
430          (slice_region[i].second)++;                 "Error - offset incompatible with other view.");
       }  
     }  
431    
432      //      EsysAssert(other.getRank()==region.size(),
433      // Check the object to be sliced from is compatible with the region to be sliced,                 "Error - slice not same rank as view to be sliced from.");
     // and that the region to be sliced is compatible with this object:  
     // 1: the region to be sliced should be the same rank as the other object.  
     // 2: the other object should have at least as many datapoints at the region requires.  
     // 3: the region should have the same number of datapoints as this object  
434    
435      DataArrayView::ShapeType slice_shape=getResultSliceShape(slice_region);      EsysAssert(noValues()==noValues(getResultSliceShape(region)),
436      EsysAssert(other.getRank()==slice_region.size(),                 "Error - slice shape not compatible shape for this view.");
                "Error - slice rank incompatible with object to be sliced from.");  
     EsysAssert((noValues(slice_shape)<=other.noValues()),  
                "Error - slice shape incompatible with object to be sliced from.");  
     EsysAssert((noValues(slice_shape)==noValues()),  
                "Error - slice shape incompatible with this object.");  
437    
438      //      //
439      // copy the values in the specified slice_region of the other object into this object      // copy the values in the specified region of the other view into this view
440    
441      int numCopy=0;      int numCopy=0;
442      switch (slice_region.size()) {  
443        switch (region.size()) {
444      case 0:      case 0:
445        /* this case should never be encountered, as python will never pass us an empty slice */        /* this case should never be encountered,
446        (*m_data)[thisOffset]=(*other.m_data)[otherOffset];           as python will never pass us an empty region.
447             here for completeness only, allows slicing of a scalar */
448          (*m_data)[thisOffset+numCopy]=(*other.m_data)[otherOffset+other.relIndex()];
449          numCopy++;
450        break;        break;
451      case 1:      case 1:
452        for (int i=slice_region[0].first;i<slice_region[0].second;i++) {        for (int i=region[0].first;i<region[0].second;i++) {
453      (*m_data)[numCopy+thisOffset]=(*other.m_data)[i+otherOffset];      (*m_data)[thisOffset+numCopy]=(*other.m_data)[otherOffset+other.relIndex(i)];
454      numCopy++;          numCopy++;
455        }        }
456        break;        break;
457      case 2:      case 2:
458        for (int j=slice_region[1].first;j<slice_region[1].second;j++) {        for (int j=region[1].first;j<region[1].second;j++) {
459      for (int i=slice_region[0].first;i<slice_region[0].second;i++) {      for (int i=region[0].first;i<region[0].second;i++) {
460        (*m_data)[numCopy+thisOffset]=(*other.m_data)[other.relIndex(i,j)+otherOffset];        (*m_data)[thisOffset+numCopy]=(*other.m_data)[otherOffset+other.relIndex(i,j)];
461        numCopy++;        numCopy++;
462      }      }
463        }        }
464        break;        break;
465      case 3:      case 3:
466        for (int k=slice_region[2].first;k<slice_region[2].second;k++) {        for (int k=region[2].first;k<region[2].second;k++) {
467      for (int j=slice_region[1].first;j<slice_region[1].second;j++) {      for (int j=region[1].first;j<region[1].second;j++) {
468        for (int i=slice_region[0].first;i<slice_region[0].second;i++) {        for (int i=region[0].first;i<region[0].second;i++) {
469          (*m_data)[numCopy+thisOffset]=(*other.m_data)[other.relIndex(i,j,k)+otherOffset];          (*m_data)[thisOffset+numCopy]=(*other.m_data)[otherOffset+other.relIndex(i,j,k)];
470          numCopy++;          numCopy++;
471        }        }
472      }      }
473        }        }
474        break;        break;
475      case 4:      case 4:
476        for (int l=slice_region[3].first;l<slice_region[3].second;l++) {        for (int l=region[3].first;l<region[3].second;l++) {
477      for (int k=slice_region[2].first;k<slice_region[2].second;k++) {      for (int k=region[2].first;k<region[2].second;k++) {
478        for (int j=slice_region[1].first;j<slice_region[1].second;j++) {        for (int j=region[1].first;j<region[1].second;j++) {
479          for (int i=slice_region[0].first;i<slice_region[0].second;i++) {          for (int i=region[0].first;i<region[0].second;i++) {
480            (*m_data)[numCopy+thisOffset]=(*other.m_data)[other.relIndex(i,j,k,l)+otherOffset];            (*m_data)[thisOffset+numCopy]=(*other.m_data)[otherOffset+other.relIndex(i,j,k,l)];
481            numCopy++;            numCopy++;
482          }          }
483        }        }
# Line 395  DataArrayView::copySlice(ValueType::size Line 486  DataArrayView::copySlice(ValueType::size
486        break;        break;
487      default:      default:
488        stringstream mess;        stringstream mess;
489        mess << "Error - (copySlice) Invalid rank: " << slice_region.size() << " for region.";        mess << "Error - (copySlice) Invalid slice region rank: " << region.size();
490        throw DataException(mess.str());        throw DataException(mess.str());
491      }      }
492  }  }
493    
494  void  void
495  DataArrayView::copySliceFrom(const DataArrayView& other,  DataArrayView::copySliceFrom(const DataArrayView& other,
496                               const RegionType& region)                               const RegionLoopRangeType& region_loop_range)
497  {  {
498      //      //
499      // version of slice that uses the default offset      // version of copySliceFrom that uses the default offsets
500      copySliceFrom(m_offset,other,other.m_offset,region);      copySliceFrom(m_offset,other,other.m_offset,region_loop_range);
501  }  }
502    
503  void  void
504  DataArrayView::copySliceFrom(ValueType::size_type thisOffset,  DataArrayView::copySliceFrom(ValueType::size_type thisOffset,
505                               const DataArrayView& other,                               const DataArrayView& other,
506                               ValueType::size_type otherOffset,                               ValueType::size_type otherOffset,
507                               const RegionType& region)                               const RegionLoopRangeType& region)
508  {  {
509    
510      //      //
511      // Make sure this object is not empty      // Make sure views are not empty
512      EsysAssert(!isEmpty(),"Error - this data object is empty.");  
513        EsysAssert(!isEmpty(),
514                   "Error - this view is empty.");
515        EsysAssert(!other.isEmpty(),
516                   "Error - other view is empty.");
517    
518      //      //
519      // Modify region to copy in order to      // Check this view is compatible with the region to be sliced,
520      // deal with the case where one range in the region contains identical idexes,      // and that the region to be sliced is compatible with the other view:
     // eg: <<1,1><0,3><0,3>>  
     // This situation implies we want to copy from an object with rank less than that of this  
     // object. eg: we want to copy the values from a two dimensional object into a two dimensional  
     // slice of a three dimensional object.  
     // We do this by copying to a slice from this 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 copy into this slice.  
521    
522      RegionType slice_region=region;      EsysAssert(other.checkOffset(otherOffset),
523      for (int i=0;i<slice_region.size();i++) {                 "Error - offset incompatible with other view.");
524        if (slice_region[i].first==slice_region[i].second) {      EsysAssert(thisOffset+other.noValues()<=getData().size(),
525          (slice_region[i].second)++;                 "Error - offset incompatible with this view.");
       }  
     }  
526    
527      //      EsysAssert(getRank()==region.size(),
528      // Check the object to be coped from is compatible with the slice region to be copied                 "Error - slice not same rank as this view.");
     // into, and that the region to be sliced into is compatible with this object:  
     // 1: the region to be sliced into should be the same rank as this object.  
     // 2: the other object should have exactly the same number of data points as the  
     //    region to be sliced into requires.  
     // 3: the region can be a higher rank than the other object, provided 2 holds.  
     // 4: this object must have at least as many data points as the region requires.  
529    
530      //      EsysAssert(other.getRank()==0 || other.noValues()==noValues(getResultSliceShape(region)),
531      // Check region size and shape                 "Error - slice shape not compatible shape for other view.");
     DataArrayView::ShapeType slice_shape=getResultSliceShape(slice_region);  
     EsysAssert((getRank()==slice_region.size()),"Error - Invalid slice region.");  
     EsysAssert((noValues(slice_shape)==other.noValues()),  
                "Error - slice shape incompatible with object to be sliced from.");  
     EsysAssert(other.getRank()<=slice_region.size(),  
                "Error - slice rank incompatible with object to be sliced from.");  
     EsysAssert((noValues(slice_shape)<=noValues()),  
                "Error - slice shape incompatible with this object.");  
532    
533      //      //
534      // copy the values in the other object into the specified slice_region of this object      // copy the values in the other view into the specified region of this view
535    
536      int numCopy=0;      // allow for case where other view is a scalar
537      switch (slice_region.size()) {      if (other.getRank()==0) {
538      case 0:  
539        /* this case should never be encountered, as python will never pass us an empty slice */          int numCopy=0;
540        (*m_data)[thisOffset]=(*other.m_data)[otherOffset];  
541        break;          switch (region.size()) {
542      case 1:          case 0:
543        for (int i=slice_region[0].first;i<slice_region[0].second;i++) {          /* this case should never be encountered,
544      (*m_data)[i+thisOffset]=(*other.m_data)[numCopy+otherOffset];             as python will never pass us an empty region.
545      numCopy++;             here for completeness only, allows slicing of a scalar */
546        }            (*m_data)[thisOffset+relIndex()]=(*other.m_data)[otherOffset];
       break;  
     case 2:  
       for (int j=slice_region[1].first;j<slice_region[1].second;j++) {  
     for (int i=slice_region[0].first;i<slice_region[0].second;i++) {  
       (*m_data)[relIndex(i,j)+thisOffset]=(*other.m_data)[numCopy+otherOffset];  
547        numCopy++;        numCopy++;
548      }            break;
549        }          case 1:
550        break;            for (int i=region[0].first;i<region[0].second;i++) {
551      case 3:          (*m_data)[thisOffset+relIndex(i)]=(*other.m_data)[otherOffset];
       for (int k=slice_region[2].first;k<slice_region[2].second;k++) {  
     for (int j=slice_region[1].first;j<slice_region[1].second;j++) {  
       for (int i=slice_region[0].first;i<slice_region[0].second;i++) {  
         (*m_data)[relIndex(i,j,k)+thisOffset]=(*other.m_data)[numCopy+otherOffset];  
552          numCopy++;          numCopy++;
553        }            }
554      }            break;
555        }          case 2:
556        break;            for (int j=region[1].first;j<region[1].second;j++) {
557      case 4:          for (int i=region[0].first;i<region[0].second;i++) {
558        for (int l=slice_region[3].first;l<slice_region[3].second;l++) {            (*m_data)[thisOffset+relIndex(i,j)]=(*other.m_data)[otherOffset];
     for (int k=slice_region[2].first;k<slice_region[2].second;k++) {  
       for (int j=slice_region[1].first;j<slice_region[1].second;j++) {  
         for (int i=slice_region[0].first;i<slice_region[0].second;i++) {  
           (*m_data)[relIndex(i,j,k,l)+thisOffset]=(*other.m_data)[numCopy+otherOffset];  
559            numCopy++;            numCopy++;
560          }          }
561        }            }
562      }            break;
563        }          case 3:
564        break;            for (int k=region[2].first;k<region[2].second;k++) {
565      default:          for (int j=region[1].first;j<region[1].second;j++) {
566        stringstream mess;            for (int i=region[0].first;i<region[0].second;i++) {
567        mess << "Error - (copySliceFrom) Invalid rank: " << slice_region.size() << " for region.";              (*m_data)[thisOffset+relIndex(i,j,k)]=(*other.m_data)[otherOffset];
568        throw DataException(mess.str());              numCopy++;
569              }
570            }
571              }
572              break;
573            case 4:
574              for (int l=region[3].first;l<region[3].second;l++) {
575            for (int k=region[2].first;k<region[2].second;k++) {
576              for (int j=region[1].first;j<region[1].second;j++) {
577                for (int i=region[0].first;i<region[0].second;i++) {
578                  (*m_data)[thisOffset+relIndex(i,j,k,l)]=(*other.m_data)[otherOffset];
579                  numCopy++;
580                }
581              }
582            }
583              }
584              break;
585            default:
586              stringstream mess;
587              mess << "Error - (copySliceFrom) Invalid slice region rank: " << region.size();
588              throw DataException(mess.str());
589            }
590    
591        } else {
592    
593            int numCopy=0;
594    
595            switch (region.size()) {
596            case 0:
597            /* this case should never be encountered,
598               as python will never pass us an empty region.
599               here for completeness only, allows slicing of a scalar */
600              (*m_data)[thisOffset+relIndex()]=(*other.m_data)[otherOffset+numCopy];
601          numCopy++;
602              break;
603            case 1:
604              for (int i=region[0].first;i<region[0].second;i++) {
605            (*m_data)[thisOffset+relIndex(i)]=(*other.m_data)[otherOffset+numCopy];
606            numCopy++;
607              }
608              break;
609            case 2:
610              for (int j=region[1].first;j<region[1].second;j++) {
611            for (int i=region[0].first;i<region[0].second;i++) {
612              (*m_data)[thisOffset+relIndex(i,j)]=(*other.m_data)[otherOffset+numCopy];
613              numCopy++;
614            }
615              }
616              break;
617            case 3:
618              for (int k=region[2].first;k<region[2].second;k++) {
619            for (int j=region[1].first;j<region[1].second;j++) {
620              for (int i=region[0].first;i<region[0].second;i++) {
621                (*m_data)[thisOffset+relIndex(i,j,k)]=(*other.m_data)[otherOffset+numCopy];
622                numCopy++;
623              }
624            }
625              }
626              break;
627            case 4:
628              for (int l=region[3].first;l<region[3].second;l++) {
629            for (int k=region[2].first;k<region[2].second;k++) {
630              for (int j=region[1].first;j<region[1].second;j++) {
631                for (int i=region[0].first;i<region[0].second;i++) {
632                  (*m_data)[thisOffset+relIndex(i,j,k,l)]=(*other.m_data)[otherOffset+numCopy];
633                  numCopy++;
634                }
635              }
636            }
637              }
638              break;
639            default:
640              stringstream mess;
641              mess << "Error - (copySliceFrom) Invalid slice region rank: " << region.size();
642              throw DataException(mess.str());
643            }
644    
645      }      }
646    
647  }  }
648    
649  DataArrayView::ShapeType  DataArrayView::ShapeType
# Line 527  DataArrayView::determineResultShape(cons Line 663  DataArrayView::determineResultShape(cons
663  string  string
664  DataArrayView::toString(const string& suffix) const  DataArrayView::toString(const string& suffix) const
665  {  {
666      EsysAssert(!isEmpty(),"Error - View is empty");      EsysAssert(!isEmpty(),"Error - View is empty.");
667      stringstream temp;      stringstream temp;
668      string finalSuffix=suffix;      string finalSuffix=suffix;
669      if (suffix.length() > 0) {      if (suffix.length() > 0) {
# Line 728  bool operator==(const DataArrayView& lef Line 864  bool operator==(const DataArrayView& lef
864      // of the view is the same.      // of the view is the same.
865      bool result=(left.m_shape==right.m_shape);      bool result=(left.m_shape==right.m_shape);
866      if (result) {      if (result) {
867        for (int i=0;i<left.noValues();++i) {        for (int i=0;i<left.noValues();i++) {
868      result=result && (left.getData(i)==right.getData(i));      result=result && (left.getData(i)==right.getData(i));
869        }        }
870      }      }

Legend:
Removed from v.102  
changed lines
  Added in v.108

  ViewVC Help
Powered by ViewVC 1.1.26