]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
LOT$: fix python tests
authoreap <eap@opencascade.com>
Fri, 6 Dec 2019 12:46:41 +0000 (15:46 +0300)
committereap <eap@opencascade.com>
Fri, 6 Dec 2019 12:46:41 +0000 (15:46 +0300)
src/MEDCoupling_Swig/DataArrayInt.i
src/MEDCoupling_Swig/MEDCouplingCommon.i
src/MEDCoupling_Swig/MEDCouplingDataArrayTraits.hxx
src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i
src/MEDCoupling_Swig/MEDCouplingPickleTest.py
src/MEDCoupling_Swig/MEDCouplingRemapperCommon.i
src/MEDCoupling_Swig/MEDCouplingRemapperTest.py
src/MEDCoupling_Swig/UsersGuideExamplesTest_numpy.py

index f24a21d1157c10647da1c313d29399d3d2dbcdd2..1f462d7a14123d49b5f72acd00afd3cd6c32a67c 100644 (file)
           }
         else if(MEDCouplingHasNumPyBindings() && PyArray_Check(elt0) && nbOfTuples==NULL && nbOfComp==NULL)
           {//ARRAY.New(numpyArray)
-            return BuildNewInstance<ARRAY,INT>(elt0,NPY_INT32,&PyCallBackDataArrayInt_RefType,"INT32");
+            return BuildNewInstance<ARRAY,INT>(elt0,NPYTraits<INT>::NPYObjectType,NPYTraits<INT>::NPYFunc,MEDCoupling::Traits<INT>::NPYStr);
           }
         else
           throw INTERP_KERNEL::Exception(msg.c_str());
index f0106b66861373b2de419754bdc800c0996043fc..706b60df23e7ab51ad138a95cf77d57aea9ba658 100644 (file)
@@ -61,8 +61,6 @@ using namespace INTERP_KERNEL;
 
 %}
 
-%template(ivec) std::vector<int>;
-%template(lvec) std::vector<long>;
 %template(dvec) std::vector<double>;
 %template(svec) std::vector<std::string>;
 
@@ -72,10 +70,12 @@ using namespace INTERP_KERNEL;
 //typedef std::int32_t mcIdType;
 typedef int mcIdType;
 typedef DataArrayInt32 DataArrayIdType;
+%template(ivec) std::vector<int>;
 #else
 //typedef std::int64_t mcIdType;
 typedef long int mcIdType;
 typedef DataArrayInt64 DataArrayIdType;
+%template(ivec) std::vector<long>;
 #endif
 
 
index ee04ca39a261df1c143aa37a157f2a882e215288..3187b80eb8e52152247ac079cbf25c09012c1cf1 100644 (file)
@@ -71,7 +71,8 @@ struct PyCallBackDataArraySt {
 };
 
 typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayByte> PyCallBackDataArrayChar;
-typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayInt> PyCallBackDataArrayInt;
+typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayInt32> PyCallBackDataArrayInt32;
+typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayInt64> PyCallBackDataArrayInt64;
 typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayFloat> PyCallBackDataArrayFloat;
 typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayDouble> PyCallBackDataArrayDouble;
 
@@ -85,9 +86,15 @@ extern "C"
     return (PyObject *)self;
   }
 
-  static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+  static PyObject *callbackmcdataarrayint32___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
   {
-    PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
+    PyCallBackDataArrayInt32 *self = (PyCallBackDataArrayInt32 *) ( type->tp_alloc(type, 0) );
+    return (PyObject *)self;
+  }
+  
+  static PyObject *callbackmcdataarrayint64___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
+  {
+    PyCallBackDataArrayInt64 *self = (PyCallBackDataArrayInt64 *) ( type->tp_alloc(type, 0) );
     return (PyObject *)self;
   }
   
@@ -124,7 +131,7 @@ extern "C"
 
   // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
   // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
-  static PyObject *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
+  static PyObject *callbackmcdataarrayint32_call(PyCallBackDataArrayInt32 *self, PyObject *args, PyObject *kw)
   {
     if(self->_pt_mc)
       {
@@ -135,6 +142,19 @@ extern "C"
     return Py_None;
   }
 
+  // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
+  // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
+  static PyObject *callbackmcdataarrayint64_call(PyCallBackDataArrayInt64 *self, PyObject *args, PyObject *kw)
+  {
+    if(self->_pt_mc)
+      {
+        MEDCoupling::MemArray<long>& mma=self->_pt_mc->accessToMemArray();
+        mma.destroy();
+      }
+    Py_XINCREF(Py_None);
+    return Py_None;
+  }
+
   // real callback called when a numpy arr having more than one DataArray instance client on it is destroyed.
   // In this case, all the "weak" clients, except the first one, invoke this call back that desable the content of these "weak" clients.
   static PyObject *callbackmcdataarrayfloat_call(PyCallBackDataArrayFloat *self, PyObject *args, PyObject *kw)
@@ -205,10 +225,10 @@ PyTypeObject PyCallBackDataArrayChar_RefType = {
 };
 
 
-PyTypeObject PyCallBackDataArrayInt_RefType = {
+PyTypeObject PyCallBackDataArrayInt32_RefType = {
   PyVarObject_HEAD_INIT(&PyType_Type, 0)
-  "callbackmcdataarrayint",
-  sizeof(PyCallBackDataArrayInt),
+  "callbackmcdataarrayint32",
+  sizeof(PyCallBackDataArrayInt32),
   0,
   callbackmcdataarray_dealloc,            /*tp_dealloc*/
   0,                          /*tp_print*/
@@ -220,7 +240,7 @@ PyTypeObject PyCallBackDataArrayInt_RefType = {
   0,                          /*tp_as_sequence*/
   0,                          /*tp_as_mapping*/
   0,                          /*tp_hash*/
-  (ternaryfunc)callbackmcdataarrayint_call,  /*tp_call*/
+  (ternaryfunc)callbackmcdataarrayint32_call,  /*tp_call*/
   0,                          /*tp_str*/
   0,                          /*tp_getattro*/
   0,                          /*tp_setattro*/
@@ -243,7 +263,50 @@ PyTypeObject PyCallBackDataArrayInt_RefType = {
   0,                          /*tp_dictoffset*/
   callbackmcdataarray___init__,           /*tp_init*/
   PyType_GenericAlloc,        /*tp_alloc*/
-  callbackmcdataarrayint___new__,            /*tp_new*/
+  callbackmcdataarrayint32___new__,            /*tp_new*/
+  PyObject_GC_Del,            /*tp_free*/
+};
+
+
+PyTypeObject PyCallBackDataArrayInt64_RefType = {
+  PyVarObject_HEAD_INIT(&PyType_Type, 0)
+  "callbackmcdataarrayint64",
+  sizeof(PyCallBackDataArrayInt64),
+  0,
+  callbackmcdataarray_dealloc,            /*tp_dealloc*/
+  0,                          /*tp_print*/
+  0,                          /*tp_getattr*/
+  0,                          /*tp_setattr*/
+  0,                          /*tp_compare*/
+  0,                          /*tp_repr*/
+  0,                          /*tp_as_number*/
+  0,                          /*tp_as_sequence*/
+  0,                          /*tp_as_mapping*/
+  0,                          /*tp_hash*/
+  (ternaryfunc)callbackmcdataarrayint64_call,  /*tp_call*/
+  0,                          /*tp_str*/
+  0,                          /*tp_getattro*/
+  0,                          /*tp_setattro*/
+  0,                          /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,  /*tp_flags*/
+  0,                          /*tp_doc*/
+  0,                          /*tp_traverse*/
+  0,                          /*tp_clear*/
+  0,                          /*tp_richcompare*/
+  0,                          /*tp_weaklistoffset*/
+  0,                          /*tp_iter*/
+  0,                          /*tp_iternext*/
+  0,                          /*tp_methods*/
+  0,                          /*tp_members*/
+  0,                          /*tp_getset*/
+  0,                          /*tp_base*/
+  0,                          /*tp_dict*/
+  0,                          /*tp_descr_get*/
+  0,                          /*tp_descr_set*/
+  0,                          /*tp_dictoffset*/
+  callbackmcdataarray___init__,           /*tp_init*/
+  PyType_GenericAlloc,        /*tp_alloc*/
+  callbackmcdataarrayint64___new__,            /*tp_new*/
   PyObject_GC_Del,            /*tp_free*/
 };
 
@@ -352,6 +415,22 @@ struct NPYTraits<float>
   static PyTypeObject *NPYFunc;
   static PyObject *Array_SWIGTYPE;
 };
+
+template<>
+struct NPYTraits<int>
+{
+  static const int NPYObjectType=NPY_INT32;
+  static PyTypeObject *NPYFunc;
+  static PyObject *Array_SWIGTYPE;
+};
+
+template<>
+struct NPYTraits<long>
+{
+  static const int NPYObjectType=NPY_INT64;
+  static PyTypeObject *NPYFunc;
+  static PyObject *Array_SWIGTYPE;
+};
 #endif
 
 #endif
index b23df939f42bbbd66cac47fdeb5f2ea29d3ac02a..85a7a9d16e771601311629d19b4e0719fdd88f1e 100644 (file)
@@ -167,6 +167,9 @@ MCData *BuildNewInstance(PyObject *elt0, int npyObjectType, PyTypeObject *pytype
   if(PyArray_DESCR(elt0)->type_num != npyObjectType)
     {
       std::ostringstream oss; oss << "Input numpy array has not the type " << msg << "!";
+#ifdef _DEBUG_
+      oss << " type_num == " << PyArray_DESCR(elt0)->type_num;
+#endif
       throw INTERP_KERNEL::Exception(oss.str().c_str());
     }
   npy_intp sz0=PyArray_DIM(elt0,0);
@@ -3122,7 +3125,7 @@ bool isCSRMatrix(PyObject *m)
 #endif
 }
 
-void convertCSR_MCDataToVectMapIntDouble(const MEDCoupling::DataArrayIdType *indptrPtr, const MEDCoupling::DataArrayIdType *indicesPtr, const MEDCoupling::DataArrayDouble *dataPtr, std::vector<std::map<mcIdType,double> >& mCpp)
+void convertCSR_MCDataToVectMapIntDouble(const MEDCoupling::DataArrayInt32 *indptrPtr, const MEDCoupling::DataArrayInt32 *indicesPtr, const MEDCoupling::DataArrayDouble *dataPtr, std::vector<std::map<mcIdType,double> >& mCpp)
 {
   auto nbOfRows(indptrPtr->getNumberOfTuples()-1);
   if(nbOfRows<0)
@@ -3354,6 +3357,10 @@ PyObject *DataArrayT_isub__internal(PyObject *trueSelf, PyObject *obj, typename
 PyTypeObject *NPYTraits<double>::NPYFunc=&PyCallBackDataArrayDouble_RefType;
 
 PyTypeObject *NPYTraits<float>::NPYFunc=&PyCallBackDataArrayFloat_RefType;
+
+PyTypeObject *NPYTraits<int>::NPYFunc=&PyCallBackDataArrayInt32_RefType;
+
+PyTypeObject *NPYTraits<long>::NPYFunc=&PyCallBackDataArrayInt64_RefType;
 #endif
 
 template<class T>
index e5f6bb732227071af260d0bf08a921b354555900..c0c633e1ae7e6d78d25e37022e3a0ed639275155 100644 (file)
@@ -347,7 +347,7 @@ class MEDCouplingPickleTest(unittest.TestCase):
         f.setName("aname")
         a=f.getArray()
         b=a[:] ; b.iota(7000)
-        f.setArray(DataArrayInt.Meld(a,b))
+        f.setArray(DataArrayInt32.Meld(a,b))
         f.getArray().setInfoOnComponents(["u1","vv2"])
         f.checkConsistencyLight();
         #
index 6c4e27c31d8c3fa1feb230e751aa0f1abff169c1..8368ec2342fb35be61c9b19e815bea0c73a0c80a 100644 (file)
@@ -97,14 +97,15 @@ namespace MEDCoupling
                  PyObject *indptr(PyObject_GetAttrString(m,"indptr"));
                  PyObject *indices(PyObject_GetAttrString(m,"indices"));
                  PyObject *data(PyObject_GetAttrString(m,"data"));
-                 MCAuto<DataArrayIdType> indptrPtr, indicesPtr;
-#if defined(MEDCOUPLING_USE_64BIT_IDS)
-                 indptrPtr = MEDCoupling_DataArrayInt64_New__SWIG_1(indptr,NULL,NULL);
-                 indicesPtr = MEDCoupling_DataArrayInt64_New__SWIG_1(indices,NULL,NULL);
-#else
+                 MCAuto<DataArrayInt32> indptrPtr, indicesPtr;
+                 // csr_matrix.indptr and csr_matrix.indices are always dtype=int32
+// #if defined(MEDCOUPLING_USE_64BIT_IDS)
+//                  indptrPtr = MEDCoupling_DataArrayInt64_New__SWIG_1(indptr,NULL,NULL);
+//                  indicesPtr = MEDCoupling_DataArrayInt64_New__SWIG_1(indices,NULL,NULL);
+// #else
                  indptrPtr = MEDCoupling_DataArrayInt32_New__SWIG_1(indptr,NULL,NULL);
                  indicesPtr = MEDCoupling_DataArrayInt32_New__SWIG_1(indices,NULL,NULL);
-#endif
+//#endif
                  MCAuto<DataArrayDouble> dataPtr(MEDCoupling_DataArrayDouble_New__SWIG_1(data,NULL,NULL));
                  convertCSR_MCDataToVectMapIntDouble(indptrPtr,indicesPtr,dataPtr,mCpp);
                  Py_XDECREF(data); Py_XDECREF(indptr); Py_XDECREF(indices);
index e6aedde615fbfcc1cbbc554f4e30aeff62ebd260..58054d5192bf4d97490c27f447c95b37b7042a08 100644 (file)
@@ -806,8 +806,8 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         vals*=1e-5
         eps0=DataArrayDouble(m0.data)-vals ; eps0.abs()
         self.assertTrue(eps0.findIdsInRange(1e-17,1e300).empty())
-        self.assertTrue(DataArrayInt(m0.indices).isEqual(DataArrayInt([0,1,3,1,4,5,4,6,7,6,8,9,8,10,11,10,12,13,12,14,15,14,16,17,16,18,19,18,20,21,20,22,23,22,24,25,24,26,27,0,2,3,1,3,5,4,5,7,6,7,9,8,9,11,10,11,13,12,13,15,14,15,17,16,17,19,18,19,21,20,21,23,22,23,25,24,25,27,0,2,3,1,3,5,4,5,7,6,7,9,8,9,11,10,11,13,12,13,15,14,15,17,16,17,19,18,19,21,20,21,23,22,23,25,24,25,27,0,2,3,1,3,5,4,5,7,6,7,9,8,9,11,10,11,13,12,13,15,14,15,17,16,17,19,18,19,21,20,21,23,22,23,25,24,25,27,0,2,3,1,3,5,4,5,7,6,7,9,8,9,11,10,11,13,12,13,15,14,15,17,16,17,19,18,19,21,20,21,23,22,23,25,24,25,27,0,1,3,1,4,5,4,6,7,6,8,9,8,10,11,10,12,13,12,14,15,14,16,17,16,18,19,18,20,21,20,22,23,22,24,25,24,26,27,0,1,3,1,4,5,4,6,7,6,8,9,8,10,11,10,12,13,12,14,15,14,16,17,16,18,19,18,20,21,20,22,23,22,24,25,24,26,27,0,1,3,1,4,5,4,6,7,6,8,9,8,10,11,10,12,13,12,14,15,14,16,17,16,18,19,18,20,21,20,22,23,22,24,25,24,26,27])))
-        self.assertTrue(DataArrayInt(m0.indptr).isEqual(DataArrayInt([0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147,150,153,156,159,162,165,168,171,174,177,180,183,186,189,192,195,198,201,204,207,210,213,216,219,222,225,228,231,234,237,240,243,246,249,252,255,258,261,264,267,270,273,276,279,282,285,288,291,294,297,300,303,306,309,312])))
+        self.assertTrue(DataArrayInt32(m0.indices).isEqual(DataArrayInt32([0,1,3,1,4,5,4,6,7,6,8,9,8,10,11,10,12,13,12,14,15,14,16,17,16,18,19,18,20,21,20,22,23,22,24,25,24,26,27,0,2,3,1,3,5,4,5,7,6,7,9,8,9,11,10,11,13,12,13,15,14,15,17,16,17,19,18,19,21,20,21,23,22,23,25,24,25,27,0,2,3,1,3,5,4,5,7,6,7,9,8,9,11,10,11,13,12,13,15,14,15,17,16,17,19,18,19,21,20,21,23,22,23,25,24,25,27,0,2,3,1,3,5,4,5,7,6,7,9,8,9,11,10,11,13,12,13,15,14,15,17,16,17,19,18,19,21,20,21,23,22,23,25,24,25,27,0,2,3,1,3,5,4,5,7,6,7,9,8,9,11,10,11,13,12,13,15,14,15,17,16,17,19,18,19,21,20,21,23,22,23,25,24,25,27,0,1,3,1,4,5,4,6,7,6,8,9,8,10,11,10,12,13,12,14,15,14,16,17,16,18,19,18,20,21,20,22,23,22,24,25,24,26,27,0,1,3,1,4,5,4,6,7,6,8,9,8,10,11,10,12,13,12,14,15,14,16,17,16,18,19,18,20,21,20,22,23,22,24,25,24,26,27,0,1,3,1,4,5,4,6,7,6,8,9,8,10,11,10,12,13,12,14,15,14,16,17,16,18,19,18,20,21,20,22,23,22,24,25,24,26,27])))
+        self.assertTrue(DataArrayInt32(m0.indptr).isEqual(DataArrayInt32([0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147,150,153,156,159,162,165,168,171,174,177,180,183,186,189,192,195,198,201,204,207,210,213,216,219,222,225,228,231,234,237,240,243,246,249,252,255,258,261,264,267,270,273,276,279,282,285,288,291,294,297,300,303,306,309,312])))
         #
         rem2=MEDCouplingRemapper() ; rem2.setIntersectionType(Barycentric)
         rem2.prepare(b,a,"P0P1")
@@ -839,7 +839,7 @@ class MEDCouplingBasicsTest(unittest.TestCase):
         rem.setMinDotBtwPlane3DSurfIntersect(0.99)# this line is important it is to tell to remapper to select only cells with very close orientation
         rem.prepare(skinAndNonConformCells,skinAndNonConformCells,"P0P0")
         mat=rem.getCrudeCSRMatrix()
-        indptr=DataArrayInt(mat.indptr)
+        indptr=DataArrayInt32(mat.indptr) #not depend on MEDCouplingUse64BitIDs()
         indptr2=indptr.deltaShiftIndex()
         cellIdsOfNonConformCells=indptr2.findIdsNotEqual(1)
         cellIdsOfSkin=indptr2.findIdsEqual(1)
index 6ad489506ebd66f9c51068333cb1b4fb22397c85..cdca7ec5f7c7463418eac0d50b6905150f6fa998 100644 (file)
@@ -35,7 +35,7 @@ else:
 # NumPy is an optional pre-requisite!
 assert(MEDCoupling.MEDCouplingHasNumPyBindings())
 a=numpy.arange(20,dtype=numpy.int32)
-d=DataArrayInt(a) # d owns data of a
-e=DataArrayInt(a) # a not owned -> e only an access to chunk of a
+d=DataArrayInt32(a) # d owns data of a
+e=DataArrayInt32(a) # a not owned -> e only an access to chunk of a
 a1=d.toNumPyArray()
 #! [UG_DataArrayNumpy_0]