From: ageay Date: Wed, 6 Apr 2011 08:31:51 +0000 (+0000) Subject: Addition of __getitem__ on DataArray* X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=648746e575286342d11741a91f7dd56b14a96224;p=tools%2Fmedcoupling.git Addition of __getitem__ on DataArray* --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index bb42d9c97..75c857862 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -244,7 +244,7 @@ void DataArrayDouble::iota(double init) throw(INTERP_KERNEL::Exception) if(!ptr) throw INTERP_KERNEL::Exception("DataArrayDouble::iota : allocate first !"); if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component!"); + throw INTERP_KERNEL::Exception("DataArrayDouble::iota : works only for arrays with only one component, you can call 'rearrange' method before !"); int ntuples=getNumberOfTuples(); for(int i=0;i 0 !"); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); + int nbComp=getNumberOfComponents(); + int newNbOfTuples=(end-bg)/step; + ret->alloc(newNbOfTuples,nbComp); + double *pt=ret->getPointer(); + const double *srcPt=getConstPointer()+bg*nbComp; + for(int i=0;icopyStringInfoFrom(*this); + ret->incrRef(); + return ret; +} + /*! * This methods has a similar behaviour than std::string::substr. This method returns a newly created DataArrayInt that is part of this with same number of components. * The intervall is specified by [tupleIdBg,tupleIdEnd) except if tupleIdEnd ==-1 in this case the [tupleIdBg,this->end()) will be kept. @@ -612,6 +636,12 @@ DataArrayDouble *DataArrayDouble::keepSelectedComponents(const std::vector& MEDCouplingAutoRefCountObjectPtr ret(DataArrayDouble::New()); int newNbOfCompo=compoIds.size(); int oldNbOfCompo=getNumberOfComponents(); + for(std::vector::const_iterator it=compoIds.begin();it!=compoIds.end();it++) + if((*it)<0 || (*it)>=oldNbOfCompo) + { + std::ostringstream oss; oss << "DataArrayDouble::keepSelectedComponents : invalid requested component : " << *it << " whereas it should be in [0," << oldNbOfCompo << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } int nbOfTuples=getNumberOfTuples(); ret->alloc(nbOfTuples,newNbOfCompo); ret->copyPartOfStringInfoFrom(*this,compoIds); @@ -700,7 +730,7 @@ void DataArrayDouble::checkNoNullValues() const throw(INTERP_KERNEL::Exception) double DataArrayDouble::getMaxValue(int& tupleId) const throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : must be applied on DataArrayDouble with only one component !"); + throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !"); int nbOfTuples=getNumberOfTuples(); if(nbOfTuples<=0) throw INTERP_KERNEL::Exception("DataArrayDouble::getMaxValue : array exists but number of tuples must be > 0 !"); @@ -722,7 +752,7 @@ double DataArrayDouble::getMaxValue2(DataArrayInt*& tupleIds) const throw(INTERP double DataArrayDouble::getMinValue(int& tupleId) const throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : must be applied on DataArrayDouble with only one component !"); + throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !"); int nbOfTuples=getNumberOfTuples(); if(nbOfTuples<=0) throw INTERP_KERNEL::Exception("DataArrayDouble::getMinValue : array exists but number of tuples must be > 0 !"); @@ -744,7 +774,7 @@ double DataArrayDouble::getMinValue2(DataArrayInt*& tupleIds) const throw(INTERP double DataArrayDouble::getAverageValue() const throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : must be applied on DataArrayDouble with only one component !"); + throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !"); int nbOfTuples=getNumberOfTuples(); if(nbOfTuples<=0) throw INTERP_KERNEL::Exception("DataArrayDouble::getAverageValue : array exists but number of tuples must be > 0 !"); @@ -1780,7 +1810,7 @@ void DataArrayInt::iota(int init) throw(INTERP_KERNEL::Exception) if(!ptr) throw INTERP_KERNEL::Exception("DataArrayInt::iota : allocate first !"); if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::iota : works only for arrays with only one component!"); + throw INTERP_KERNEL::Exception("DataArrayInt::iota : works only for arrays with only one component, you can call 'rearrange' method before !"); int ntuples=getNumberOfTuples(); for(int i=0;i 0 !"); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + int nbComp=getNumberOfComponents(); + int newNbOfTuples=(end-bg)/step; + ret->alloc(newNbOfTuples,nbComp); + int *pt=ret->getPointer(); + const int *srcPt=getConstPointer()+bg*nbComp; + for(int i=0;icopyStringInfoFrom(*this); + ret->incrRef(); + return ret; +} + /*! * This method works only for arrays having single component. * If this contains the array a1 containing [9,10,0,6,4,11,3,7] this method returns an array a2 [5,6,0,3,2,7,1,4]. @@ -2172,7 +2226,7 @@ bool DataArrayInt::isIdentity() const bool DataArrayInt::isUniform(int val) const { if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::isUniform : must be applied on DataArrayInt with only one component !"); + throw INTERP_KERNEL::Exception("DataArrayInt::isUniform : must be applied on DataArrayInt with only one component, you can call 'rearrange' method before !"); int nbOfTuples=getNumberOfTuples(); const int *w=getConstPointer(); const int *end=w+nbOfTuples; @@ -2285,6 +2339,12 @@ DataArrayInt *DataArrayInt::keepSelectedComponents(const std::vector& compo MEDCouplingAutoRefCountObjectPtr ret(DataArrayInt::New()); int newNbOfCompo=compoIds.size(); int oldNbOfCompo=getNumberOfComponents(); + for(std::vector::const_iterator it=compoIds.begin();it!=compoIds.end();it++) + if((*it)<0 || (*it)>=oldNbOfCompo) + { + std::ostringstream oss; oss << "DataArrayDouble::keepSelectedComponents : invalid requested component : " << *it << " whereas it should be in [0," << oldNbOfCompo << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } int nbOfTuples=getNumberOfTuples(); ret->alloc(nbOfTuples,newNbOfCompo); ret->copyPartOfStringInfoFrom(*this,compoIds); @@ -2356,7 +2416,7 @@ void DataArrayInt::SetArrayIn(DataArrayInt *newArray, DataArrayInt* &arrayToSet) DataArrayInt *DataArrayInt::getIdsEqual(int val) const throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqual : the array must have only one component !"); + throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqual : the array must have only one component, you can call 'rearrange' method before !"); const int *cptr=getConstPointer(); std::vector res; int nbOfTuples=getNumberOfTuples(); @@ -2372,7 +2432,7 @@ DataArrayInt *DataArrayInt::getIdsEqual(int val) const throw(INTERP_KERNEL::Exce DataArrayInt *DataArrayInt::getIdsNotEqual(int val) const throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqual : the array must have only one component !"); + throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqual : the array must have only one component, you can call 'rearrange' method before !"); const int *cptr=getConstPointer(); std::vector res; int nbOfTuples=getNumberOfTuples(); @@ -2388,7 +2448,7 @@ DataArrayInt *DataArrayInt::getIdsNotEqual(int val) const throw(INTERP_KERNEL::E DataArrayInt *DataArrayInt::getIdsEqualList(const std::vector& vals) const throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqualList : the array must have only one component !"); + throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqualList : the array must have only one component, you can call 'rearrange' method before !"); std::set vals2(vals.begin(),vals.end()); const int *cptr=getConstPointer(); std::vector res; @@ -2405,7 +2465,7 @@ DataArrayInt *DataArrayInt::getIdsEqualList(const std::vector& vals) const DataArrayInt *DataArrayInt::getIdsNotEqualList(const std::vector& vals) const throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=1) - throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqualList : the array must have only one component !"); + throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqualList : the array must have only one component, you can call 'rearrange' method before !"); std::set vals2(vals.begin(),vals.end()); const int *cptr=getConstPointer(); std::vector res; diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 4984326f6..64d50d6c8 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -154,6 +154,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayDouble *renumberAndReduce(const int *old2New, int newNbOfTuple) const; MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const; MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayDouble *selectByTupleId2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayDouble *changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception); @@ -266,6 +267,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *renumberAndReduce(const int *old2NewBg, int newNbOfTuple) const; MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId(const int *new2OldBg, const int *new2OldEnd) const; MEDCOUPLING_EXPORT DataArrayInt *selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *selectByTupleId2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *checkAndPreparePermutation() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void changeSurjectiveFormat(int targetNb, DataArrayInt *&arr, DataArrayInt *&arrI) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT bool isIdentity() const; diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 33a267735..2a68c9612 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -121,6 +121,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::keepSelectedComponents; %newobject ParaMEDMEM::DataArrayInt::selectByTupleId; %newobject ParaMEDMEM::DataArrayInt::selectByTupleIdSafe; +%newobject ParaMEDMEM::DataArrayInt::selectByTupleId2; %newobject ParaMEDMEM::DataArrayInt::checkAndPreparePermutation; %newobject ParaMEDMEM::DataArrayInt::renumber; %newobject ParaMEDMEM::DataArrayInt::renumberR; @@ -143,6 +144,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::buildIntersection; %newobject ParaMEDMEM::DataArrayInt::deltaShiftIndex; %newobject ParaMEDMEM::DataArrayInt::buildPermutationArr; +%newobject ParaMEDMEM::DataArrayInt::__getitem__; %newobject ParaMEDMEM::DataArrayDouble::New; %newobject ParaMEDMEM::DataArrayDouble::convertToIntArr; %newobject ParaMEDMEM::DataArrayDouble::deepCpy; @@ -161,6 +163,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayDouble::getIdsInRange; %newobject ParaMEDMEM::DataArrayDouble::selectByTupleId; %newobject ParaMEDMEM::DataArrayDouble::selectByTupleIdSafe; +%newobject ParaMEDMEM::DataArrayDouble::selectByTupleId2; %newobject ParaMEDMEM::DataArrayDouble::applyFunc; %newobject ParaMEDMEM::DataArrayDouble::applyFunc2; %newobject ParaMEDMEM::DataArrayDouble::applyFunc3; @@ -181,6 +184,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayDouble::fromPolarToCart; %newobject ParaMEDMEM::DataArrayDouble::fromCylToCart; %newobject ParaMEDMEM::DataArrayDouble::fromSpherToCart; +%newobject ParaMEDMEM::DataArrayDouble::__getitem__; %newobject ParaMEDMEM::MEDCouplingMesh::deepCpy; %newobject ParaMEDMEM::MEDCouplingMesh::checkTypeConsistencyAndContig; %newobject ParaMEDMEM::MEDCouplingMesh::getCoordinatesAndOwner; @@ -1507,6 +1511,84 @@ namespace ParaMEDMEM convertPyObjToVecDataArrayDblCst(li,tmp); return DataArrayDouble::Meld(tmp); } + + DataArrayDouble *__getitem__(PyObject *ob) throw(INTERP_KERNEL::Exception) + { + self->checkAllocated(); + int nbOfTuples=self->getNumberOfTuples(); + bool isTuple=PyTuple_Check(ob); + PyObject *obj=0; + if(!isTuple) + obj=ob; + else + { + int sz=PyTuple_Size(ob); + if(sz!=2) + throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !"); + obj=PyTuple_GetItem(ob,0); + } + MEDCouplingAutoRefCountObjectPtr ret; + { + if(PyInt_Check(obj)) + { + int val=(int)PyInt_AS_LONG(obj); + ret=self->selectByTupleIdSafe(&val,&val+1); + } + else + { + if(!PySlice_Check(obj)) + { + std::ostringstream oss; + oss << "Expecting a slice or an integer for subscriptable object DataArrayDouble on tuples !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + Py_ssize_t strt,stp,step; + PySliceObject *oC=reinterpret_cast(obj); + if(PySlice_GetIndices(oC,nbOfTuples,&strt,&stp,&step)!=0) + { + std::ostringstream oss; oss << "Slice in subscriptable object DataArrayDouble invalid : number of tuples is : " << nbOfTuples << " : check with your 1st slice !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + ret=self->selectByTupleId2(strt,stp,step); + } + } + if(!isTuple) + { + ret->incrRef(); + return ret; + } + int nbOfComponents=self->getNumberOfComponents(); + PyObject *obj1=PyTuple_GetItem(ob,1); + if(PyInt_Check(obj1)) + { + int val=(int)PyInt_AS_LONG(obj1); + std::vector v(1,val); + return ret->keepSelectedComponents(v); + } + else + { + if(!PySlice_Check(obj1)) + { + std::ostringstream oss; + oss << "Expecting a slice or an integer for subscriptable object DataArrayDouble on components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + Py_ssize_t strt,stp,step; + PySliceObject *oC=reinterpret_cast(obj1); + if(PySlice_GetIndices(oC,nbOfComponents,&strt,&stp,&step)!=0) + { + std::ostringstream oss; oss << "Slice in subscriptable object DataArrayDouble invalid : number of components is : " << nbOfComponents << " : check with your 2nd slice !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(step<=0) + throw INTERP_KERNEL::Exception("2nd Slice in subscriptable object DataArrayDouble invalid : should be > 0 !"); + Py_ssize_t newNbOfComp=(stp-strt)/step; + std::vector v(newNbOfComp); + for(int i=0;ikeepSelectedComponents(v); + } + } }; %extend ParaMEDMEM::DataArrayInt @@ -1832,6 +1914,84 @@ namespace ParaMEDMEM PyTuple_SetItem(ret,1,PyInt_FromLong(tmp)); return ret; } + + DataArrayInt *__getitem__(PyObject *ob) throw(INTERP_KERNEL::Exception) + { + self->checkAllocated(); + int nbOfTuples=self->getNumberOfTuples(); + bool isTuple=PyTuple_Check(ob); + PyObject *obj=0; + if(!isTuple) + obj=ob; + else + { + int sz=PyTuple_Size(ob); + if(sz!=2) + throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !"); + obj=PyTuple_GetItem(ob,0); + } + MEDCouplingAutoRefCountObjectPtr ret; + { + if(PyInt_Check(obj)) + { + int val=(int)PyInt_AS_LONG(obj); + ret=self->selectByTupleIdSafe(&val,&val+1); + } + else + { + if(!PySlice_Check(obj)) + { + std::ostringstream oss; + oss << "Expecting a slice or an integer for subscriptable object DataArrayInt on tuples !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + Py_ssize_t strt,stp,step; + PySliceObject *oC=reinterpret_cast(obj); + if(PySlice_GetIndices(oC,nbOfTuples,&strt,&stp,&step)!=0) + { + std::ostringstream oss; oss << "Slice in subscriptable object DataArrayInt invalid : number of tuples is : " << nbOfTuples << " : check with your 1st slice !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + ret=self->selectByTupleId2(strt,stp,step); + } + } + if(!isTuple) + { + ret->incrRef(); + return ret; + } + int nbOfComponents=self->getNumberOfComponents(); + PyObject *obj1=PyTuple_GetItem(ob,1); + if(PyInt_Check(obj1)) + { + int val=(int)PyInt_AS_LONG(obj1); + std::vector v(1,val); + return ret->keepSelectedComponents(v); + } + else + { + if(!PySlice_Check(obj1)) + { + std::ostringstream oss; + oss << "Expecting a slice or an integer for subscriptable object DataArrayInt on components !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + Py_ssize_t strt,stp,step; + PySliceObject *oC=reinterpret_cast(obj1); + if(PySlice_GetIndices(oC,nbOfComponents,&strt,&stp,&step)!=0) + { + std::ostringstream oss; oss << "Slice in subscriptable object DataArrayInt invalid : number of components is : " << nbOfComponents << " : check with your 2nd slice !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(step<=0) + throw INTERP_KERNEL::Exception("2nd Slice in subscriptable object DataArrayInt invalid : should be > 0 !"); + Py_ssize_t newNbOfComp=(stp-strt)/step; + std::vector v(newNbOfComp); + for(int i=0;ikeepSelectedComponents(v); + } + } }; namespace ParaMEDMEM diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 8661bcc5b..2cf25a4d8 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -5896,6 +5896,116 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(expected1,b.getValues()) pass + def testSwigGetItem1(self): + da=DataArrayInt.New() + da.alloc(16,3) + da.rearrange(1) + da.iota(7) + da.rearrange(3) + da.setInfoOnComponent(0,"X [m]") + da.setInfoOnComponent(1,"Y [m]") + da.setInfoOnComponent(2,"Z [km]") + da2=da[5:-1] + self.assertEqual([22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51],da2.getValues()) + da2=da[4] + self.assertEqual([19, 20, 21],da2.getValues()) + try: + da2=da[4:17] + except InterpKernelException as e: + self.assertTrue(True) + else: + self.assertTrue(False) + pass + da2=da[5:-2,2] + self.assertEqual([24, 27, 30, 33, 36, 39, 42, 45, 48],da2.getValues()) + da2=da[5:8,:] + self.assertEqual([22, 23, 24, 25, 26, 27, 28, 29, 30],da2.getValues()) + da2=da[:] + self.assertTrue(da2.isEqual(da)) + da2=da[:,:] + self.assertTrue(da2.isEqual(da)) + try: + da2=da[:,:,:] + except InterpKernelException as e: + self.assertTrue(True) + else: + self.assertTrue(False) + pass + try: + da2=da[5:8,-2] + except InterpKernelException as e: + self.assertTrue(True) + else: + self.assertTrue(False) + pass + da2=da[5:8,:-2] + self.assertEqual([22, 25, 28],da2.getValues()) + try: + da2=da[5:-18,2] + except InterpKernelException as e: + self.assertTrue(True) + else: + self.assertTrue(False) + pass + da2=da[5:5,2] + self.assertEqual([],da2.getValues()) + pass + + def testSwigGetItem2(self): + da=DataArrayDouble.New() + da.alloc(16,3) + da.rearrange(1) + da.iota(7) + da.rearrange(3) + da.setInfoOnComponent(0,"X [m]") + da.setInfoOnComponent(1,"Y [m]") + da.setInfoOnComponent(2,"Z [km]") + da2=da[5:-1] + self.assertEqual([22., 23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50., 51.],da2.getValues()) + da2=da[4] + self.assertEqual([19., 20., 21],da2.getValues()) + try: + da2=da[4:17] + except InterpKernelException as e: + self.assertTrue(True) + else: + self.assertTrue(False) + pass + da2=da[5:-2,2] + self.assertEqual([24., 27., 30., 33., 36., 39., 42., 45., 48.],da2.getValues()) + da2=da[5:8,:] + self.assertEqual([22., 23., 24., 25., 26., 27., 28., 29., 30.],da2.getValues()) + da2=da[:] + self.assertTrue(da2.isEqual(da,1e-12)) + da2=da[:,:] + self.assertTrue(da2.isEqual(da,1e-12)) + try: + da2=da[:,:,:] + except InterpKernelException as e: + self.assertTrue(True) + else: + self.assertTrue(False) + pass + try: + da2=da[5:8,-2] + except InterpKernelException as e: + self.assertTrue(True) + else: + self.assertTrue(False) + pass + da2=da[5:8,:-2] + self.assertEqual([22., 25., 28.],da2.getValues()) + try: + da2=da[5:-18,2] + except InterpKernelException as e: + self.assertTrue(True) + else: + self.assertTrue(False) + pass + da2=da[5:5,2] + self.assertEqual([],da2.getValues()) + pass + def testDAIAggregateMulti1(self): a=DataArrayInt.New() a.setValues(range(4),2,2)