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<ntuples;i++)
ptr[i]=init+double(i);
bool DataArrayDouble::isUniform(double val, double eps) const
{
if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("DataArrayDouble::isUniform : must be applied on DataArrayDouble with only one component !");
+ throw INTERP_KERNEL::Exception("DataArrayDouble::isUniform : must be applied on DataArrayDouble with only one component, you can call 'rearrange' method before !");
int nbOfTuples=getNumberOfTuples();
const double *w=getConstPointer();
const double *end=w+nbOfTuples;
}
/*!
- * This method is equivalent to DataArrayInt::selectByTupleId except that an analyze to the content of input range to check that it will not lead to memory corruption !
+ * This method is equivalent to DataArrayDouble::selectByTupleId except that an analyze to the content of input range to check that it will not lead to memory corruption !
*/
DataArrayDouble *DataArrayDouble::selectByTupleIdSafe(const int *new2OldBg, const int *new2OldEnd) const throw(INTERP_KERNEL::Exception)
{
return ret;
}
+/*!
+ * Idem than DataArrayInt::selectByTupleIdSafe except that the input array is not constructed explicitely.
+ * The convention is as python one. ['bg','end') with steps of 'step'.
+ * Returns a newly created array.
+ */
+DataArrayDouble *DataArrayDouble::selectByTupleId2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception)
+{
+ if(end<bg)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::selectByTupleId2 : end before begin !");
+ if(step<=0)
+ throw INTERP_KERNEL::Exception("DataArrayDouble::selectByTupleId2 : invalid step should > 0 !");
+ MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> 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;i<newNbOfTuples;i++,srcPt+=step*nbComp)
+ std::copy(srcPt,srcPt+nbComp,pt+i*nbComp);
+ ret->copyStringInfoFrom(*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.
MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> ret(DataArrayDouble::New());
int newNbOfCompo=compoIds.size();
int oldNbOfCompo=getNumberOfComponents();
+ for(std::vector<int>::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);
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 !");
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 !");
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 !");
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<ntuples;i++)
ptr[i]=init+i;
void DataArrayInt::transformWithIndArr(const int *indArr)
{
if(getNumberOfComponents()!=1)
- throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component !");
+ throw INTERP_KERNEL::Exception("Call transformWithIndArr method on DataArrayInt with only one component, you can call 'rearrange' method before !");
int nbOfTuples=getNumberOfTuples();
int *pt=getPointer();
for(int i=0;i<nbOfTuples;i++)
return ret;
}
+/*!
+ * Idem than DataArrayInt::selectByTupleIdSafe except that the input array is not constructed explicitely.
+ * The convention is as python one. ['bg','end') with steps of 'step'.
+ * Returns a newly created array.
+ */
+DataArrayInt *DataArrayInt::selectByTupleId2(int bg, int end, int step) const throw(INTERP_KERNEL::Exception)
+{
+ if(end<bg)
+ throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleId2 : end before begin !");
+ if(step<=0)
+ throw INTERP_KERNEL::Exception("DataArrayInt::selectByTupleId2 : invalid step should > 0 !");
+ MEDCouplingAutoRefCountObjectPtr<DataArrayInt> 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;i<newNbOfTuples;i++,srcPt+=step*nbComp)
+ std::copy(srcPt,srcPt+nbComp,pt+i*nbComp);
+ ret->copyStringInfoFrom(*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].
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;
MEDCouplingAutoRefCountObjectPtr<DataArrayInt> ret(DataArrayInt::New());
int newNbOfCompo=compoIds.size();
int oldNbOfCompo=getNumberOfComponents();
+ for(std::vector<int>::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);
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<int> res;
int nbOfTuples=getNumberOfTuples();
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<int> res;
int nbOfTuples=getNumberOfTuples();
DataArrayInt *DataArrayInt::getIdsEqualList(const std::vector<int>& 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<int> vals2(vals.begin(),vals.end());
const int *cptr=getConstPointer();
std::vector<int> res;
DataArrayInt *DataArrayInt::getIdsNotEqualList(const std::vector<int>& 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<int> vals2(vals.begin(),vals.end());
const int *cptr=getConstPointer();
std::vector<int> res;
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);
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;
%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;
%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;
%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;
%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;
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<DataArrayDouble> 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<PySliceObject *>(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<int> 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<PySliceObject *>(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<int> v(newNbOfComp);
+ for(int i=0;i<newNbOfComp;i++)
+ v[i]=strt+i*step;
+ return ret->keepSelectedComponents(v);
+ }
+ }
};
%extend ParaMEDMEM::DataArrayInt
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<DataArrayInt> 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<PySliceObject *>(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<int> 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<PySliceObject *>(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<int> v(newNbOfComp);
+ for(int i=0;i<newNbOfComp;i++)
+ v[i]=strt+i*step;
+ return ret->keepSelectedComponents(v);
+ }
+ }
};
namespace ParaMEDMEM
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)