]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
Behavior modification for slices in medcoupling and medloader. start==stop==length...
authorgeay <anthony.geay@cea.fr>
Wed, 5 Mar 2014 11:03:57 +0000 (12:03 +0100)
committergeay <anthony.geay@cea.fr>
Wed, 5 Mar 2014 11:03:57 +0000 (12:03 +0100)
src/MEDCoupling_Swig/MEDCouplingBasicsTest.py
src/MEDCoupling_Swig/MEDCouplingCommon.i
src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i
src/MEDCoupling_Swig/MEDCouplingMemArray.i
src/MEDCoupling_Swig/MEDCouplingNumPyTest.py
src/MEDLoader/MEDFileParameter.cxx
src/MEDLoader/MEDFileParameter.hxx
src/MEDLoader/Swig/MEDLoaderCommon.i
src/MEDLoader/Swig/MEDLoaderTypemaps.i

index 2af096bf8fb0bbace3eb25fdfdc35f17382287bc..026fb199e9d3c496b3571fcdfa93e4beb2f651be 100644 (file)
@@ -6020,13 +6020,7 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         else:
             self.assertTrue(False)
             pass
-        try:
-            da2=da[5:8,-2]
-        except InterpKernelException as e:
-            self.assertTrue(True)
-        else:
-            self.assertTrue(False)
-            pass
+        self.assertTrue(da[5:8,-2].isEqualWithoutConsideringStr(DataArrayInt([23,26,29])))
         da2=da[5:8,:-2]
         self.assertEqual([22, 25, 28],da2.getValues())
         try:
@@ -6075,13 +6069,7 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         else:
             self.assertTrue(False)
             pass
-        try:
-            da2=da[5:8,-2]
-        except InterpKernelException as e:
-            self.assertTrue(True)
-        else:
-            self.assertTrue(False)
-            pass
+        self.assertTrue(da[5:8,-2].isEqualWithoutConsideringStr(DataArrayDouble([23.,26.,29.]),1e-12))
         da2=da[5:8,:-2]
         self.assertEqual([22., 25., 28.],da2.getValues())
         try:
@@ -9583,13 +9571,13 @@ class MEDCouplingBasicsTest(unittest.TestCase):
     def testSwigGetItem3(self):
         da=DataArrayInt.New([4,5,6])
         self.assertEqual(5,da[1])
-        self.assertRaises(InterpKernelException,da.__getitem__,-1)
+        self.assertEqual(6,da[-1])
         self.assertRaises(InterpKernelException,da.__getitem__,3)
         da=DataArrayInt.New([4,5,6,7,8,9],2,3)
         self.assertEqual(9,da[1,2])
         da=DataArrayDouble.New([4.1,5.2,6.3])
         self.assertAlmostEqual(5.2,da[1],12)
-        self.assertRaises(InterpKernelException,da.__getitem__,-1)
+        self.assertAlmostEqual(6.3,da[-1],12)
         self.assertRaises(InterpKernelException,da.__getitem__,3)
         da=DataArrayDouble.New([4.12,5.12,6.12,7.12,8.12,9.12],2,3)
         self.assertAlmostEqual(9.12,da[1,2],12)
@@ -14379,6 +14367,78 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         self.assertTrue(m.getNodalConnectivityIndex().isEqual(DataArrayInt([0,13,20,27])))
         pass
 
+    def testSwigExtendedSlice1(self):
+        d=DataArrayInt([5,6,7])
+        self.assertTrue(d[2:].isEqual(DataArrayInt([7])))
+        self.assertTrue(d[3:].isEqual(DataArrayInt([])))
+        try:
+            d[4:]
+        except InterpKernelException as e:
+            self.assertTrue(True)
+        else:
+            self.assertTrue(False)
+            pass
+        d=DataArrayInt([5,6,7,8])
+        self.assertEqual(d[-1],8)
+        self.assertEqual(d[-4],5)
+        try:
+            d[-5]
+        except InterpKernelException as e:
+            self.assertTrue(True)
+        else:
+            self.assertTrue(False)
+            pass
+        self.assertTrue(d[2::-1].isEqual(DataArrayInt([7,6,5])))
+        self.assertTrue(d[0::-1].isEqual(DataArrayInt([5])))
+        self.assertTrue(d[-1::-1].isEqual(DataArrayInt([8,7,6,5])))
+        self.assertTrue(d[-3::-1].isEqual(DataArrayInt([6,5])))
+        self.assertTrue(d[-5::-1].isEqual(DataArrayInt([])))
+        try:
+            d[-6::-1]
+        except InterpKernelException as e:
+            self.assertTrue(True)
+        else:
+            self.assertTrue(False)
+            pass
+        d=DataArrayInt([])
+        self.assertTrue(d[0:].isEqual(DataArrayInt([])))
+        #
+        d=DataArrayDouble([5,6,7])
+        self.assertTrue(d[2:].isEqual(DataArrayDouble([7]),1e-12))
+        self.assertTrue(d[3:].isEqual(DataArrayDouble([]),1e-12))
+        try:
+            d[4:]
+        except InterpKernelException as e:
+            self.assertTrue(True)
+        else:
+            self.assertTrue(False)
+            pass
+        d=DataArrayDouble([5,6,7,8])
+        self.assertAlmostEqual(d[-1],8.,12)
+        self.assertAlmostEqual(d[-4],5.,12)
+        try:
+            d[-5]
+        except InterpKernelException as e:
+            self.assertTrue(True)
+        else:
+            self.assertTrue(False)
+            pass
+        self.assertTrue(d[2::-1].isEqual(DataArrayDouble([7,6,5]),1e-12))
+        self.assertTrue(d[0::-1].isEqual(DataArrayDouble([5]),1e-12))
+        self.assertTrue(d[-1::-1].isEqual(DataArrayDouble([8,7,6,5]),1e-12))
+        self.assertTrue(d[-3::-1].isEqual(DataArrayDouble([6,5]),1e-12))
+        self.assertTrue(d[-5::-1].isEqual(DataArrayDouble([]),1e-12))
+        try:
+            d[-6::-1]
+        except InterpKernelException as e:
+            self.assertTrue(True)
+        else:
+            self.assertTrue(False)
+            pass
+        d=DataArrayDouble([])
+        self.assertTrue(d[0:].isEqual(DataArrayDouble([]),1e-12))
+        pass
+
     def setUp(self):
         pass
     pass
index b9d0854f2506e931ab38c4fb7d425cb936753cf9..eb4e14fcfac95b69b9ed8a9efda263ab69aa35ef 100644 (file)
@@ -2080,8 +2080,7 @@ namespace ParaMEDMEM
         arrIndxIn->checkAllocated();
         if(arrIndxIn->getNumberOfComponents()!=1)
           throw INTERP_KERNEL::Exception("ExtractFromIndexedArrays2 (wrap) : number of components of last argument must be equal to one !");
-        if(PySlice_GetIndices(sliC,arrIndxIn->getNumberOfTuples(),&strt,&stp,&step)!=0)
-          throw INTERP_KERNEL::Exception("ExtractFromIndexedArrays2 (wrap) : Invalid slice regarding nb of elements !");
+        GetIndicesOfSlice(sliC,arrIndxIn->getNumberOfTuples(),&strt,&stp,&step,"ExtractFromIndexedArrays2 (wrap) : Invalid slice regarding nb of elements !");
         DataArrayInt *arrOut=0,*arrIndexOut=0;
         MEDCouplingUMesh::ExtractFromIndexedArrays2(strt,stp,step,arrIn,arrIndxIn,arrOut,arrIndexOut);
         PyObject *ret=PyTuple_New(2);
index 4b890dc50d3c470a10aa51c490608719811fb991..46527b8234a74a66a00224005d5e310acace7e53 100644 (file)
 
 #include "InterpKernelAutoPtr.hxx"
 
+/*!
+ * This method is an extention of PySlice_GetIndices but less
+ * open than PySlice_GetIndicesEx that accepts too many situations.
+ */
+void GetIndicesOfSlice(PySliceObject *slice, Py_ssize_t length, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
+{
+  int ret(PySlice_GetIndices(slice,length,start,stop,step));
+  if(ret==0)
+    return ;
+  if(*step>0 && *start==*stop && length==*start)
+    return ;
+  throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
+}
+
+/*!
+ * This method allows to retrieve slice info from \a slice.
+ */
+void GetIndicesOfSliceExplicitely(PySliceObject *slice, Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, const char *msgInCaseOfFailure)
+{
+  int ret(PySlice_GetIndices(slice,std::numeric_limits<int>::max(),start,stop,step));
+  if(ret==0)
+    {
+      if(*start!=std::numeric_limits<int>::max() && *stop!=std::numeric_limits<int>::max())
+        return ;
+      std::ostringstream oss;
+      oss << msgInCaseOfFailure << " The input slice contains some unknowns that can't be determined in static method ! The input slice must be explicit here !";
+      throw INTERP_KERNEL::Exception(oss.str().c_str());
+    }
+  throw INTERP_KERNEL::Exception(msgInCaseOfFailure);
+}
+
+int InterpreteNegativeInt(int val, int nbelem)
+{
+  if(val<0)
+    {
+      int newVal(nbelem+val);
+      if(newVal<0)
+        {
+          std::ostringstream oss; oss << "interpreteNegativeInt : request for negative int=" << val << " but number of elems is equal to " << nbelem << " !";
+          throw INTERP_KERNEL::Exception(oss.str().c_str());
+        }
+      return newVal;
+    }
+  else
+    return val;
+}
+
 #ifdef WITH_NUMPY
 #include <numpy/arrayobject.h>
 
@@ -1420,12 +1467,7 @@ static void convertObjToPossibleCpp2(PyObject *value, int nbelem, int& sw, int&
     {
       Py_ssize_t strt=2,stp=2,step=2;
       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
-      if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
-        if(nbelem!=0 || strt!=0 || stp!=0)
-          {
-            std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
-            throw INTERP_KERNEL::Exception(oss.str().c_str());
-          }
+      GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
       p.first=strt;
       p.second.first=stp;
       p.second.second=step;
@@ -1462,6 +1504,18 @@ static void convertObjToPossibleCpp2(PyObject *value, int nbelem, int& sw, int&
   throw INTERP_KERNEL::Exception(msg);
 }
 
+/*!
+ * Idem than convertObjToPossibleCpp2
+ */
+static void convertObjToPossibleCpp2WithNegIntInterp(PyObject *value, int nbelem, int& sw, int& iTyypp, std::vector<int>& stdvecTyypp, std::pair<int, std::pair<int,int> >& p, ParaMEDMEM::DataArrayInt *& daIntTyypp) throw(INTERP_KERNEL::Exception)
+{
+  convertObjToPossibleCpp2(value,nbelem,sw,iTyypp,stdvecTyypp,p,daIntTyypp);
+  if(sw==1)
+    {
+      iTyypp=InterpreteNegativeInt(iTyypp,nbelem);
+    }
+}
+
 /*!
  * if python int -> cpp int sw=1
  * if python tuple[int] -> cpp vector<int> sw=2
@@ -1518,12 +1572,7 @@ static void convertObjToPossibleCpp22(PyObject *value, int nbelem, int& sw, int&
     {
       Py_ssize_t strt=2,stp=2,step=2;
       PySliceObject *oC=reinterpret_cast<PySliceObject *>(value);
-      if(PySlice_GetIndices(oC,nbelem,&strt,&stp,&step)!=0)
-        if(nbelem!=0 || strt!=0 || stp!=0)
-          {
-            std::ostringstream oss; oss << "Slice in subscriptable object DataArray invalid : number of elements is : " << nbelem;
-            throw INTERP_KERNEL::Exception(oss.str().c_str());
-          }
+      GetIndicesOfSlice(oC,nbelem,&strt,&stp,&step,"Slice in subscriptable object DataArray invalid !");
       p.first=strt;
       p.second.first=stp;
       p.second.second=step;
@@ -1653,7 +1702,7 @@ static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo,
 {
   if(!PyTuple_Check(value))
     {
-      convertObjToPossibleCpp2(value,nbTuple,sw,it,vt,pt,dt);
+      convertObjToPossibleCpp2WithNegIntInterp(value,nbTuple,sw,it,vt,pt,dt);
       return ;
     }
   else
@@ -1663,9 +1712,9 @@ static void convertObjToPossibleCpp3(PyObject *value, int nbTuple, int nbCompo,
         throw INTERP_KERNEL::Exception("Unexpected nb of slice element : 1 or 2 expected !\n1st is for tuple selection, 2nd for component selection !");
       PyObject *ob0=PyTuple_GetItem(value,0);
       int sw1,sw2;
-      convertObjToPossibleCpp2(ob0,nbTuple,sw1,it,vt,pt,dt);
+      convertObjToPossibleCpp2WithNegIntInterp(ob0,nbTuple,sw1,it,vt,pt,dt);
       PyObject *ob1=PyTuple_GetItem(value,1);
-      convertObjToPossibleCpp2(ob1,nbCompo,sw2,ic,vc,pc,dc);
+      convertObjToPossibleCpp2WithNegIntInterp(ob1,nbCompo,sw2,ic,vc,pc,dc);
       sw=4*sw2+sw1;
     }
 }
index dbdc40bec13a41ffc9aad345f0a97f2389b34ba7..c17ed322bbee0db8fb4732d034dbb5400646030c 100644 (file)
@@ -408,10 +408,7 @@ namespace ParaMEDMEM
           throw INTERP_KERNEL::Exception("DataArray::GetSlice (wrap) : expecting a pyslice as second (first) parameter !");
         Py_ssize_t strt=2,stp=2,step=2;
         PySliceObject *sly=reinterpret_cast<PySliceObject *>(slic);
-        if(PySlice_GetIndices(sly,std::numeric_limits<int>::max(),&strt,&stp,&step)!=0)
-          throw INTERP_KERNEL::Exception("DataArray::GetSlice (wrap) : the input slice is invalid !");
-        if(strt==std::numeric_limits<int>::max() || stp==std::numeric_limits<int>::max())
-          throw INTERP_KERNEL::Exception("DataArray::GetSlice (wrap) : the input slice contains some unknowns that can't be determined in static method ! Call DataArray::getSlice (non static) instead !");
+        GetIndicesOfSliceExplicitely(sly,&strt,&stp,&step,"DataArray::GetSlice (wrap) : the input slice is invalid !");
         int a,b;
         DataArray::GetSlice(strt,stp,step,sliceId,nbOfSlices,a,b);
         return PySlice_New(PyInt_FromLong(a),PyInt_FromLong(b),PyInt_FromLong(step));
@@ -423,8 +420,7 @@ namespace ParaMEDMEM
           throw INTERP_KERNEL::Exception("DataArray::getSlice (wrap) : expecting a pyslice as second (first) parameter !");
         Py_ssize_t strt=2,stp=2,step=2;
         PySliceObject *sly=reinterpret_cast<PySliceObject *>(slic);
-        if(PySlice_GetIndices(sly,self->getNumberOfTuples(),&strt,&stp,&step)!=0)
-          throw INTERP_KERNEL::Exception("DataArray::getSlice (wrap) : the input slice is invalid !");
+        GetIndicesOfSlice(sly,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getSlice (wrap) : the input slice is invalid !");
         int a,b;
         DataArray::GetSlice(strt,stp,step,sliceId,nbOfSlices,a,b);
         return PySlice_New(PyInt_FromLong(a),PyInt_FromLong(b),PyInt_FromLong(step));
@@ -436,10 +432,7 @@ namespace ParaMEDMEM
           throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBES (wrap) : expecting a pyslice as second (first) parameter !");
         Py_ssize_t strt=2,stp=2,step=2;
         PySliceObject *sly=reinterpret_cast<PySliceObject *>(slic);
-        if(PySlice_GetIndices(sly,std::numeric_limits<int>::max(),&strt,&stp,&step)!=0)
-          throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBES (wrap) : the input slice is invalid !");
-        if(strt==std::numeric_limits<int>::max() || stp==std::numeric_limits<int>::max())
-          throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBES (wrap) : the input slice contains some unknowns that can't be determined in static method !");
+        GetIndicesOfSliceExplicitely(sly,&strt,&stp,&step,"DataArray::GetNumberOfItemGivenBES (wrap) : the input slice is invalid !");
         return DataArray::GetNumberOfItemGivenBES(strt,stp,step,"");
       }
 
@@ -449,10 +442,7 @@ namespace ParaMEDMEM
           throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBESRelative (wrap) : expecting a pyslice as second (first) parameter !");
         Py_ssize_t strt=2,stp=2,step=2;
         PySliceObject *sly=reinterpret_cast<PySliceObject *>(slic);
-        if(PySlice_GetIndices(sly,std::numeric_limits<int>::max(),&strt,&stp,&step)!=0)
-          throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !");
-        if(strt==std::numeric_limits<int>::max() || stp==std::numeric_limits<int>::max())
-          throw INTERP_KERNEL::Exception("DataArray::GetNumberOfItemGivenBESRelative (wrap) : the input slice contains some unknowns that can't be determined in static method !");
+        GetIndicesOfSliceExplicitely(sly,&strt,&stp,&step,"DataArray::GetNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !");
         return DataArray::GetNumberOfItemGivenBESRelative(strt,stp,step,"");
       }
       
@@ -469,8 +459,7 @@ namespace ParaMEDMEM
           throw INTERP_KERNEL::Exception("DataArray::getNumberOfItemGivenBES (wrap) : expecting a pyslice as second (first) parameter !");
         Py_ssize_t strt=2,stp=2,step=2;
         PySliceObject *sly=reinterpret_cast<PySliceObject *>(slic);
-        if(PySlice_GetIndices(sly,self->getNumberOfTuples(),&strt,&stp,&step)!=0)
-          throw INTERP_KERNEL::Exception("DataArray::getNumberOfItemGivenBES (wrap) : the input slice is invalid !");
+        GetIndicesOfSlice(sly,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getNumberOfItemGivenBES (wrap) : the input slice is invalid !");
         return DataArray::GetNumberOfItemGivenBES(strt,stp,step,"");
       }
 
@@ -480,8 +469,7 @@ namespace ParaMEDMEM
           throw INTERP_KERNEL::Exception("DataArray::getNumberOfItemGivenBESRelative (wrap) : expecting a pyslice as second (first) parameter !");
         Py_ssize_t strt=2,stp=2,step=2;
         PySliceObject *sly=reinterpret_cast<PySliceObject *>(slic);
-        if(PySlice_GetIndices(sly,self->getNumberOfTuples(),&strt,&stp,&step)!=0)
-          throw INTERP_KERNEL::Exception("DataArray::getNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !");
+        GetIndicesOfSlice(sly,self->getNumberOfTuples(),&strt,&stp,&step,"DataArray::getNumberOfItemGivenBESRelative (wrap) : the input slice is invalid !");
         return DataArray::GetNumberOfItemGivenBESRelative(strt,stp,step,"");
       }
     }
@@ -2271,7 +2259,7 @@ namespace ParaMEDMEM
         ParaMEDMEM::DataArrayInt *daIntTyypp=0;
         const double *pt=self->getConstPointer();
         int nbc=self->getNumberOfCompo();
-        convertObjToPossibleCpp2(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
+        convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
         switch(sw)
           {
           case 1:
@@ -2340,7 +2328,7 @@ namespace ParaMEDMEM
         std::pair<int, std::pair<int,int> > slic;
         ParaMEDMEM::DataArrayInt *daIntTyypp=0;
         double *pt=self->getPointer();
-        convertObjToPossibleCpp2(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp);
+        convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp);
         switch(sw2)
           {
           case 1:
@@ -2779,8 +2767,7 @@ namespace ParaMEDMEM
           throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr (wrap) : expecting a pyslice as second (first) parameter !");
         Py_ssize_t strt=2,stp=2,step=2;
         PySliceObject *sly=reinterpret_cast<PySliceObject *>(slic);
-        if(PySlice_GetIndices(sly,std::numeric_limits<int>::max(),&strt,&stp,&step)!=0)
-          throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr (wrap) : the input slice is invalid !");
+        GetIndicesOfSliceExplicitely(sly,&strt,&stp,&step,"DataArrayInt::buildExplicitArrOfSliceOnScaledArr (wrap) : the input slice is invalid !");
         if(strt==std::numeric_limits<int>::max() || stp==std::numeric_limits<int>::max())
           throw INTERP_KERNEL::Exception("DataArrayInt::buildExplicitArrOfSliceOnScaledArr (wrap) : the input slice contains some unknowns that can't be determined in static method ! Call DataArray::getSlice (non static) instead !");
         return self->buildExplicitArrOfSliceOnScaledArr(strt,stp,step);
@@ -4534,7 +4521,7 @@ namespace ParaMEDMEM
         ParaMEDMEM::DataArrayInt *daIntTyypp=0;
         const int *pt=self->getConstPointer();
         int nbc=self->getNumberOfCompo();
-        convertObjToPossibleCpp2(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
+        convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw,singleVal,multiVal,slic,daIntTyypp);
         switch(sw)
           {
           case 1:
@@ -4604,7 +4591,7 @@ namespace ParaMEDMEM
         std::pair<int, std::pair<int,int> > slic;
         ParaMEDMEM::DataArrayInt *daIntTyypp=0;
         int *pt=self->getPointer();
-        convertObjToPossibleCpp2(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp);
+        convertObjToPossibleCpp2WithNegIntInterp(obj,nbc,sw2,singleVal,multiVal,slic,daIntTyypp);
         switch(sw2)
           {
           case 1:
@@ -5531,7 +5518,7 @@ namespace ParaMEDMEM
         std::vector<int> stdvecTyyppArr;
         std::pair<int, std::pair<int,int> > sTyyppArr;
         ParaMEDMEM::DataArrayInt *daIntTyypp=0;
-        convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp);
+        convertObjToPossibleCpp2WithNegIntInterp(obj,self->getNumberOfTuples(),sw,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp);
         switch(sw)
           {
           case 1:
@@ -5556,7 +5543,7 @@ namespace ParaMEDMEM
         ParaMEDMEM::DataArrayInt *daIntTyypp=0;
         int nbOfCompo=self->getNumberOfComponents();
         int nbOfTuples=self->getNumberOfTuples();
-        convertObjToPossibleCpp2(obj,nbOfTuples,sw1,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp);
+        convertObjToPossibleCpp2WithNegIntInterp(obj,nbOfTuples,sw1,iTypppArr,stdvecTyyppArr,sTyyppArr,daIntTyypp);
         int sw2;
         char vc; std::string sc; std::vector<std::string> vsc; DataArrayChar *dacc=0;
         convertObjToPossibleCpp6(value,sw2,vc,sc,vsc,dacc);
index 9631ee00e4b0e35c4f7ce0ca6ec9d060c291408f..6a622128587bb747640f3fa0981484d0a941c01d 100644 (file)
@@ -31,7 +31,7 @@ import os,gc,weakref,unittest
 
 class MEDCouplingNumPyTest(unittest.TestCase):
     
-    @unittest.skipUnless(MEDCouplingHasNumPyBindings() and architecture()[0]=="64bit","requires numpy")
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
     def test1(self):
         sz=20
         a=array(0,dtype=int32)
index d715f1b04b2d75dc7b1a9433b62eb3288b5a1c6e..f2f6a392073a69752d9b822d53f8e366f6ac7c83 100644 (file)
@@ -666,6 +666,11 @@ void MEDFileParameterMultiTS::eraseTimeStepIds(const int *startIds, const int *e
   _param_per_ts=paramPerTs;
 }
 
+int MEDFileParameterMultiTS::getNumberOfTS() const
+{
+  return (int) getIterations().size();
+}
+
 std::vector< std::pair<int,int> > MEDFileParameterMultiTS::getIterations() const
 {
   std::vector< std::pair<int,int> > ret;
index f1035d588131e81c02b254788ba84fc15244ac4a..fe38140001e289379281864a54c889c3de8f2697 100644 (file)
@@ -138,6 +138,7 @@ namespace ParaMEDMEM
     MEDLOADER_EXPORT int getPosGivenTime(double time, double eps=1e-8) const;
     MEDLOADER_EXPORT MEDFileParameter1TS *getTimeStepAtPos(int posId) const;
     MEDLOADER_EXPORT void eraseTimeStepIds(const int *startIds, const int *endIds);
+    MEDLOADER_EXPORT int getNumberOfTS() const;
     MEDLOADER_EXPORT std::vector< std::pair<int,int> > getIterations() const;
     MEDLOADER_EXPORT std::vector< std::pair<int,int> > getTimeSteps(std::vector<double>& ret1) const;
     MEDLOADER_EXPORT void simpleRepr2(int bkOffset, std::ostream& oss) const;
index 63acae414dcfeca2b6017eaa6c84bfbf6a05833c..c88e65e157052c3d6df7f8b2c9a1b4b8731d2fed 100644 (file)
@@ -1026,7 +1026,7 @@ namespace ParaMEDMEM
          {
            if(PyInt_Check(obj))
              {
-               MEDFileMesh *ret=self->getMeshAtPos((int)PyInt_AS_LONG(obj));
+               MEDFileMesh *ret=self->getMeshAtPos(InterpreteNegativeInt((int)PyInt_AS_LONG(obj),self->getNumberOfMeshes()));
                if(ret)
                  ret->incrRef();
                return ret;
@@ -1810,12 +1810,8 @@ namespace ParaMEDMEM
           {
             Py_ssize_t strt=2,stp=2,step=2;
             PySliceObject *oC=reinterpret_cast<PySliceObject *>(elts);
-            if(PySlice_GetIndices(oC,self->getNumberOfTS(),&strt,&stp,&step)==0)
-              {
-                self->eraseTimeStepIds2(strt,stp,step);
-              }
-            else
-              throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS.__delitem__ : error in input slice !");
+            GetIndicesOfSlice(oC,self->getNumberOfTS(),&strt,&stp,&step,"MEDFileAnyTypeFieldMultiTS.__delitem__ : error in input slice !");
+            self->eraseTimeStepIds2(strt,stp,step);
           }
         else
           {
@@ -1880,10 +1876,8 @@ namespace ParaMEDMEM
           {
             Py_ssize_t strt=2,stp=2,step=2;
             PySliceObject *oC=reinterpret_cast<PySliceObject *>(elt0);
-            if(PySlice_GetIndices(oC,self->getNumberOfTS(),&strt,&stp,&step)==0)
-              return convertMEDFileFieldMultiTS(self->buildSubPartSlice(strt,stp,step),SWIG_POINTER_OWN | 0);
-            else
-              throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS.__getitem__ : error in input slice !");
+            GetIndicesOfSlice(oC,self->getNumberOfTS(),&strt,&stp,&step,"MEDFileAnyTypeFieldMultiTS.__getitem__ : error in input slice !");
+            return convertMEDFileFieldMultiTS(self->buildSubPartSlice(strt,stp,step),SWIG_POINTER_OWN | 0);
           }
         else
           return convertMEDFileField1TS(self->getTimeStepAtPos(MEDFileAnyTypeFieldMultiTSgetitemSingleTS__(self,elt0)),SWIG_POINTER_OWN | 0);
@@ -2377,10 +2371,8 @@ namespace ParaMEDMEM
              {
                Py_ssize_t strt=2,stp=2,step=2;
                PySliceObject *oC=reinterpret_cast<PySliceObject *>(elts);
-               if(PySlice_GetIndices(oC,self->getNumberOfFields(),&strt,&stp,&step)==0)
-                 self->destroyFieldsAtPos2(strt,stp,step);
-               else
-                 throw INTERP_KERNEL::Exception("MEDFileFields.__delitem__ : error in input slice !");
+               GetIndicesOfSlice(oC,self->getNumberOfFields(),&strt,&stp,&step,"MEDFileFields.__delitem__ : error in input slice !");
+               self->destroyFieldsAtPos2(strt,stp,step);
              }
            else
              {
@@ -2497,6 +2489,7 @@ namespace ParaMEDMEM
     double getDoubleValue(int iteration, int order) const throw(INTERP_KERNEL::Exception);
     int getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception);
     int getPosGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception);
+    int getNumberOfTS() const throw(INTERP_KERNEL::Exception);
     %extend
     {
       MEDFileParameterMultiTS()
@@ -2567,7 +2560,7 @@ namespace ParaMEDMEM
       {
         if(elt0 && PyInt_Check(elt0))
           {//fmts[3]
-            int pos=PyInt_AS_LONG(elt0);
+            int pos=InterpreteNegativeInt(PyInt_AS_LONG(elt0),self->getNumberOfTS());
             return pos;
           }
         else if(elt0 && PyTuple_Check(elt0))
@@ -2711,7 +2704,7 @@ namespace ParaMEDMEM
       {
         if(PyInt_Check(obj))
           {
-            MEDFileParameterMultiTS *ret=self->getParamAtPos((int)PyInt_AS_LONG(obj));
+            MEDFileParameterMultiTS *ret=self->getParamAtPos(InterpreteNegativeInt((int)PyInt_AS_LONG(obj),self->getNumberOfParams()));
             if(ret)
               ret->incrRef();
             return ret;
index 96ad8994e0a43f56c06cd909dfcc78f405f97f1a..7e7fde21766be96cecf4c7203889107d5c422cc1 100644 (file)
@@ -310,7 +310,7 @@ int MEDFileAnyTypeFieldMultiTSgetitemSingleTS__(const MEDFileAnyTypeFieldMultiTS
 {
   if(elt0 && PyInt_Check(elt0))
     {//fmts[3]
-      return PyInt_AS_LONG(elt0);
+      return InterpreteNegativeInt(PyInt_AS_LONG(elt0),self->getNumberOfTS());
     }
   else if(elt0 && PyTuple_Check(elt0))
     {
@@ -347,7 +347,7 @@ int MEDFileFieldsgetitemSingleTS__(const MEDFileFields *self, PyObject *obj) thr
 {
   if(PyInt_Check(obj))
     {
-      return (int)PyInt_AS_LONG(obj);
+      return InterpreteNegativeInt((int)PyInt_AS_LONG(obj),self->getNumberOfFields());
     }
   else if(PyString_Check(obj))
     {