]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
On the roae
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 26 Apr 2017 09:06:05 +0000 (11:06 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 26 Apr 2017 09:06:05 +0000 (11:06 +0200)
MEDCouplingConfig.cmake.in
src/MEDCoupling_Swig/CMakeLists.txt
src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i
src/MEDCoupling_Swig/MEDCouplingNumPyTest.py
src/MEDLoader/Swig/CMakeLists.txt
src/MEDPartitioner_Swig/CMakeLists.txt
src/ParaMEDMEM_Swig/CMakeLists.txt
src/RENUMBER_Swig/CMakeLists.txt

index 8621eead1e6de553a3c66ebdc4c5fd30cf5bcfda..fdfaa65de6c65717888f2d4617f5fc38f7a7aa0b 100644 (file)
@@ -116,6 +116,7 @@ SET(MEDCOUPLING_INSTALL_DOC "@MEDCOUPLING_INSTALL_BINS@")
 SET(MEDCoupling_interpkernel interpkernel)
 SET(MEDCoupling_medcoupling medcoupling)
 SET(MEDCoupling_medcouplingremapper medcouplingremapper)
+SET(MEDCoupling_medcouplinghelpyer medcouplinghelpyer)
 SET(MEDCoupling_medloader medloader)
 SET(MEDCoupling_renumbercpp renumbercpp)
 SET(MEDCoupling_medpartitionercpp medpartitionercpp)
index a3cf107e343143fcd98a56ca7b1e7da006e4a8cb..1bd321ef94444dc27e5f955610294d7a6e3ae5cd 100644 (file)
@@ -56,6 +56,7 @@ SET (MC_Swig_interf
     MEDCouplingRemapper.i
     MEDCouplingTypemaps.i
     MEDCouplingDataArrayTypemaps.i
+    MEDCouplingDataArrayTraits.hxx
 )
 
 INCLUDE_DIRECTORIES(
@@ -87,8 +88,12 @@ IF(MEDCOUPLING_BUILD_DOC)
         swig_ready)
 ENDIF()
 
+ADD_LIBRARY(medcouplinghelpyer MEDCouplingDataArrayTraits.cxx)
+TARGET_LINK_LIBRARIES(medcouplinghelpyer ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} medcoupling)
+INSTALL(TARGETS medcouplinghelpyer EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${MEDCOUPLING_INSTALL_LIBS})
+
 SWIG_ADD_MODULE(MEDCoupling python MEDCoupling.i)
-SWIG_LINK_LIBRARIES(MEDCoupling ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} medcoupling)
+SWIG_LINK_LIBRARIES(MEDCoupling medcouplinghelpyer)
 
 SET_SOURCE_FILES_PROPERTIES(MEDCouplingRemapper.i PROPERTIES CPLUSPLUS ON)
 SET_SOURCE_FILES_PROPERTIES(MEDCouplingRemapper.i PROPERTIES SWIG_DEFINITIONS "-shadow")
@@ -100,7 +105,7 @@ SET (SWIG_MODULE_MEDCouplingRemapper_EXTRA_DEPS ${MEDCoupling_SWIG_DPYS_FILES}
     ${interpkernel_HEADERS_HXX} ${interpkernel_HEADERS_TXX})
 
 SWIG_ADD_MODULE(MEDCouplingRemapper python MEDCouplingRemapper.i)
-SWIG_LINK_LIBRARIES(MEDCouplingRemapper ${PYTHON_LIBRARIES} medcouplingremapper)
+SWIG_LINK_LIBRARIES(MEDCouplingRemapper medcouplingremapper medcouplinghelpyer)
 
 IF(WIN32)
   SET_TARGET_PROPERTIES(_MEDCouplingRemapper PROPERTIES DEBUG_OUTPUT_NAME _MEDCouplingRemapper_d)
index 830c1e727fc193876ec0a10f021b12c897a68128..1b71f2493b3d074ab8a4b6d9fe70c2a10c0b80cb 100644 (file)
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-// Author : Anthony Geay (CEA/DEN)
+// Author : Anthony Geay (EDF R&D)
 
 #ifndef __MEDCOUPLINGDATAARRAYTYPEMAPS_I__
 #define __MEDCOUPLINGDATAARRAYTYPEMAPS_I__
 
 #include "InterpKernelAutoPtr.hxx"
+#include "MEDCouplingDataArrayTraits.hxx"
 
 #include <sstream>
 
@@ -72,245 +73,6 @@ int InterpreteNegativeInt(int val, int nbelem)
     return val;
 }
 
-#ifdef WITH_NUMPY
-#include <numpy/arrayobject.h>
-#if NPY_API_VERSION <= 0x00000006
-#  define MED_NUMPY_OWNDATA NPY_OWNDATA
-#else
-#  define MED_NUMPY_OWNDATA NPY_ARRAY_OWNDATA
-#endif
-
-// specific DataArray deallocator callback. This deallocator is used both in the constructor of DataArray and in the toNumPyArr
-// method. This dellocator uses weakref to determine if the linked numArr is still alive or not. If alive the ownership is given to it.
-// if no more alive the "standart" DataArray deallocator is called.
-void numarrdeal(void *pt, void *wron)
-{
-  void **wronc=(void **)wron;
-  PyObject *weakRefOnOwner=reinterpret_cast<PyObject *>(wronc[0]);
-  PyObject *obj=PyWeakref_GetObject(weakRefOnOwner);
-  if(obj!=Py_None)
-    {
-      Py_XINCREF(obj);
-      PyArrayObject *objC=reinterpret_cast<PyArrayObject *>(obj);
-      objC->flags|=MED_NUMPY_OWNDATA;
-      Py_XDECREF(weakRefOnOwner);
-      Py_XDECREF(obj);
-    }
-  else
-    {
-      typedef void (*MyDeallocator)(void *,void *);
-      MyDeallocator deall=(MyDeallocator)wronc[1];
-      deall(pt,NULL);
-      Py_XDECREF(weakRefOnOwner);
-    }
-  delete [] wronc;
-}
-
-template<class MCData>
-struct PyCallBackDataArraySt {
-    PyObject_HEAD
-    MCData *_pt_mc;
-};
-
-typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayByte> PyCallBackDataArrayChar;
-typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayInt> PyCallBackDataArrayInt;
-typedef struct PyCallBackDataArraySt<MEDCoupling::DataArrayDouble> PyCallBackDataArrayDouble;
-
-extern "C"
-{
-  static int callbackmcdataarray___init__(PyObject *self, PyObject *args, PyObject *kwargs) { return 0; }
-  
-  static PyObject *callbackmcdataarraychar___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
-  {
-    PyCallBackDataArrayChar *self = (PyCallBackDataArrayChar *) ( type->tp_alloc(type, 0) );
-    return (PyObject *)self;
-  }
-
-  static PyObject *callbackmcdataarrayint___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
-  {
-    PyCallBackDataArrayInt *self = (PyCallBackDataArrayInt *) ( type->tp_alloc(type, 0) );
-    return (PyObject *)self;
-  }
-
-  static PyObject *callbackmcdataarraydouble___new__(PyTypeObject *type, PyObject *args, PyObject *kwargs)
-  {
-    PyCallBackDataArrayDouble *self = (PyCallBackDataArrayDouble *) ( type->tp_alloc(type, 0) );
-    return (PyObject *)self;
-  }
-  
-  static void callbackmcdataarray_dealloc(PyObject *self)
-  {
-    Py_TYPE(self)->tp_free(self);
-  }
-
-  
-  // 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 *callbackmcdataarraychar_call(PyCallBackDataArrayChar *self, PyObject *args, PyObject *kw)
-  {
-    if(self->_pt_mc)
-      {
-        MEDCoupling::MemArray<char>& 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 *callbackmcdataarrayint_call(PyCallBackDataArrayInt *self, PyObject *args, PyObject *kw)
-  {
-    if(self->_pt_mc)
-      {
-        MEDCoupling::MemArray<int>& 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 *callbackmcdataarraydouble_call(PyCallBackDataArrayDouble *self, PyObject *args, PyObject *kw)
-  {
-    if(self->_pt_mc)
-      {
-        MEDCoupling::MemArray<double>& mma=self->_pt_mc->accessToMemArray();
-        mma.destroy();
-      }
-    Py_XINCREF(Py_None);
-    return Py_None;
-  }
-}
-
-PyTypeObject PyCallBackDataArrayChar_RefType = {
-  PyVarObject_HEAD_INIT(&PyType_Type, 0)
-  "callbackmcdataarraychar",
-  sizeof(PyCallBackDataArrayChar),
-  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)callbackmcdataarraychar_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*/
-  callbackmcdataarraychar___new__,            /*tp_new*/
-  PyObject_GC_Del,            /*tp_free*/
-};
-
-
-PyTypeObject PyCallBackDataArrayInt_RefType = {
-  PyVarObject_HEAD_INIT(&PyType_Type, 0)
-  "callbackmcdataarrayint",
-  sizeof(PyCallBackDataArrayInt),
-  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)callbackmcdataarrayint_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*/
-  callbackmcdataarrayint___new__,            /*tp_new*/
-  PyObject_GC_Del,            /*tp_free*/
-};
-
-PyTypeObject PyCallBackDataArrayDouble_RefType = {
-  PyVarObject_HEAD_INIT(&PyType_Type, 0)
-  "callbackmcdataarraydouble",
-  sizeof(PyCallBackDataArrayDouble),
-  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)callbackmcdataarraydouble_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*/
-  callbackmcdataarraydouble___new__,            /*tp_new*/
-  PyObject_GC_Del,            /*tp_free*/
-};
-
 // this is the second type of specific deallocator, only valid for the constructor of DataArrays taking numpy array
 // in input when an another DataArray is already client of this.
 template<class MCData>
@@ -587,8 +349,6 @@ PyObject *ToCSRMatrix(const std::vector<std::map<int,double> >& m, int nbCols) t
   return ret;
 }
 
-#endif
-
 static PyObject *convertDataArrayChar(MEDCoupling::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
 {
   PyObject *ret=0;
@@ -2769,7 +2529,7 @@ static typename MEDCoupling::Traits<T>::ArrayType *DataArrayT_New(PyObject *elt0
 #ifdef WITH_NUMPY
   else if(PyArray_Check(elt0) && nbOfTuples==NULL && elt2==NULL)
     {//DataArrayDouble.New(numpyArray)
-      return BuildNewInstance< typename MEDCoupling::Traits<T>::ArrayType , T >(elt0,NPY_DOUBLE,&PyCallBackDataArrayDouble_RefType,MEDCoupling::Traits<T>::NPYStr);
+      return BuildNewInstance< typename MEDCoupling::Traits<T>::ArrayType , T >(elt0,NPYTraits<T>::NPYObjectType,NPYTraits<T>::NPYFunc,MEDCoupling::Traits<T>::NPYStr);
     }
 #endif
   else
@@ -2778,4 +2538,3 @@ static typename MEDCoupling::Traits<T>::ArrayType *DataArrayT_New(PyObject *elt0
 }
 
 #endif
-
index 7664d2b2704c3791ea723bf78cab990d38e3d2eb..0cc93355867e8c0b47f4567ef65756a9464b1b4e 100644 (file)
@@ -32,7 +32,7 @@ import os,gc,weakref,unittest
 class MEDCouplingNumPyTest(unittest.TestCase):
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test1(self):
+    def tess1(self):
         sz=20
         a=array(0,dtype=int32)
         a.resize(sz)
@@ -52,7 +52,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test2(self):
+    def tess2(self):
         sz=20
         a=array(0,dtype=int32)
         a.resize(sz,2)
@@ -68,7 +68,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test3(self):
+    def tess3(self):
         sz=10
         a=array(0,dtype=int32)
         a.resize(sz,2)
@@ -89,14 +89,14 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test4(self):
+    def tess4(self):
         a=zeros(20,dtype=int32)
         b = a[::-1]
         self.assertRaises(InterpKernelException,DataArrayInt.New,b) # b is not contiguous in memory
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test5(self):
+    def tess5(self):
         a=arange(20,dtype=int32)
         self.assertEqual(weakref.getweakrefcount(a),0)
         d=DataArrayInt(a)
@@ -115,7 +115,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test6(self):
+    def tess6(self):
         a=arange(20,dtype=int32)
         d=DataArrayInt(a) # d owns data of a
         e=DataArrayInt(a) # a not owned -> e only an access to chunk of a 
@@ -133,7 +133,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test7(self):
+    def tess7(self):
         a=array(0,dtype=int32) ; a.resize(10,2)
         b=a.reshape(20)
         c=a.reshape(2,10)
@@ -169,7 +169,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test8(self):
+    def tess8(self):
         a=arange(20,dtype=int32)
         self.assertTrue(a.flags["OWNDATA"])
         d=DataArrayInt(a) # d owns data of a
@@ -181,7 +181,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test9(self):
+    def tess9(self):
         sz=20
         a=array(0,dtype=float64)
         a.resize(sz)
@@ -200,7 +200,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test10(self):
+    def tess10(self):
         sz=20
         a=array(0,dtype=float64)
         a.resize(sz,2)
@@ -216,7 +216,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test11(self):
+    def tess11(self):
         sz=10
         a=array(0,dtype=float64)
         a.resize(sz,2)
@@ -237,14 +237,14 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test12(self):
+    def tess12(self):
         a=zeros(20,dtype=float64)
         b = a[::-1]
         self.assertRaises(InterpKernelException,DataArrayDouble.New,b) # b is not contiguous in memory
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test13(self):
+    def tess13(self):
         a=arange(20,dtype=float64)
         self.assertEqual(weakref.getweakrefcount(a),0)
         d=DataArrayDouble(a)
@@ -264,7 +264,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test14(self):
+    def tess14(self):
         a=arange(20,dtype=float64)
         d=DataArrayDouble(a) # d owns data of a
         e=DataArrayDouble(a) # a not owned -> e only an access to chunk of a 
@@ -282,7 +282,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test15(self):
+    def tess15(self):
         a=array(0,dtype=float64) ; a.resize(10,2)
         b=a.reshape(20)
         c=a.reshape(2,10)
@@ -318,7 +318,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test16(self):
+    def tess16(self):
         a=arange(20,dtype=float64)
         self.assertTrue(a.flags["OWNDATA"])
         d=DataArrayDouble(a) # d owns data of a
@@ -330,7 +330,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test17(self):
+    def tess17(self):
         d=DataArrayInt.Range(0,20,1)
         a=d.toNumPyArray()
         self.assertTrue(not a.flags["OWNDATA"])
@@ -356,7 +356,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test18(self):
+    def tess18(self):
         d=DataArrayInt.Range(0,20,1)
         d=d.convertToDblArr()
         a=d.toNumPyArray()
@@ -383,7 +383,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test19(self):
+    def tess19(self):
         sz=20
         a=array(0,dtype=int32)
         a.resize(sz/2,2)
@@ -402,7 +402,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test20(self):
+    def tess20(self):
         sz=20
         a=array(0,dtype=float64)
         a.resize(sz/2,2)
@@ -421,7 +421,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test21(self):
+    def tess21(self):
         #tests that only DataArray*(npArray) contructor is available
         a=array(0,dtype=int32)
         a.resize(20)
@@ -436,7 +436,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test22(self):
+    def tess22(self):
         d=DataArrayDouble(10)
         d.iota()
         a=d.toNumPyArray()
@@ -457,7 +457,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test23(self):
+    def tess23(self):
         d=DataArrayDouble(10)
         d.iota()
         a=d.toNumPyArray()
@@ -500,7 +500,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test24(self):
+    def tess24(self):
         d=DataArrayDouble(10)
         d.iota()
         a=d.toNumPyArray()
@@ -557,7 +557,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test25(self):
+    def tess25(self):
         a=arange(10,dtype=int32)
         b=DataArrayInt(a)
         c=DataArrayInt(a)
@@ -632,7 +632,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test26(self):
+    def tess26(self):
         d=DataArrayInt(15) ; d.iota()
         d.rearrange(3)
         a=d.toNumPyArray()
@@ -656,7 +656,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test27(self):
+    def tess27(self):
         m0=DenseMatrix(DataArrayDouble([2,3,4,5,1,6]),2,3)
         m0np=m0.toNumPyMatrix()
         self.assertEqual(m0np.shape,(2,3))
@@ -664,7 +664,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test28(self):
+    def tess28(self):
         """Test on DataArrayBytes"""
         # use case 1
         d=DataArrayByte(256)
@@ -756,27 +756,27 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         gc.collect()
         pass
 
-
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
     def test29(self):
         """Same as test9 with float32"""
         sz=20
-        a=array(0,dtype=float64)
+        a=array(0,dtype=float32)
         a.resize(sz)
         a[:]=4
         self.assertEqual(getrefcount(a),2)
-        a=a.cumsum(dtype=float64)
+        a=a.cumsum(dtype=float32)
         self.assertEqual(getrefcount(a),2)
-        d=DataArrayDouble(a)
+        d=DataArrayFloat(a)
         d[:]=2
         #
-        e=DataArrayDouble(sz) ; e.fillWithValue(2)
+        e=DataArrayFloat(sz) ; e.fillWithValue(2)
         self.assertTrue(d.isEqual(e,1e-14))
         #
         a[:]=4 ; e.fillWithValue(4)
         self.assertTrue(d.isEqual(e,1e-14))
         pass
     
+class MEDCouplingNumPyTest2:
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
     def test30(self):
         """Same as test10 with float32"""
@@ -846,7 +846,8 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
     
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test14(self):
+    def test34(self):
+        """Same as test14 with float32"""
         a=arange(20,dtype=float64)
         d=DataArrayDouble(a) # d owns data of a
         e=DataArrayDouble(a) # a not owned -> e only an access to chunk of a 
@@ -864,7 +865,8 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test15(self):
+    def test35(self):
+        """Same as test15 with float32"""
         a=array(0,dtype=float64) ; a.resize(10,2)
         b=a.reshape(20)
         c=a.reshape(2,10)
@@ -900,7 +902,8 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         pass
 
     @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
-    def test16(self):
+    def test36(self):
+        """Same as test16 with float32"""
         a=arange(20,dtype=float64)
         self.assertTrue(a.flags["OWNDATA"])
         d=DataArrayDouble(a) # d owns data of a
@@ -911,6 +914,150 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])
         pass
 
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test37(self):
+        """Same as test20 with float32"""
+        sz=20
+        a=array(0,dtype=float64)
+        a.resize(sz/2,2)
+        a[:]=4
+        self.assertEqual(getrefcount(a),2)
+        d=DataArrayDouble(a)
+        self.assertEqual(10,d.getNumberOfTuples())
+        self.assertEqual(2,d.getNumberOfComponents())
+        self.assertEqual(sz,d.getNbOfElems())
+        self.assertTrue(d.isEqual(DataArrayDouble([(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.),(4.,4.)]),1e-14))
+        a[:]=7
+        self.assertTrue(d.isEqual(DataArrayDouble([(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.),(7.,7.)]),1e-14))
+        #
+        b=a.reshape((2,5,2))
+        self.assertRaises(InterpKernelException,DataArrayDouble.New,b) # b has not dimension in [0,1] !
+        pass
+
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test38(self):
+        """Same as test22 with float32"""
+        d=DataArrayDouble(10)
+        d.iota()
+        a=d.toNumPyArray()
+        self.assertTrue(not a.flags["OWNDATA"])
+        del d
+        gc.collect()
+        self.assertTrue(a.flags["OWNDATA"])
+        self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        #
+        d=DataArrayInt(10)
+        d.iota()
+        a=d.toNumPyArray()
+        self.assertTrue(not a.flags["OWNDATA"])
+        del d
+        gc.collect()
+        self.assertTrue(a.flags["OWNDATA"])
+        self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        pass
+
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test39(self):
+        """Same as test23 with float32"""
+        d=DataArrayDouble(10)
+        d.iota()
+        a=d.toNumPyArray()
+        b=d.toNumPyArray()
+        c=d.toNumPyArray()
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(not b.flags["OWNDATA"])
+        self.assertTrue(not c.flags["OWNDATA"])
+        self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertEqual(c.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        del d
+        gc.collect()
+        self.assertTrue(a.flags["OWNDATA"])
+        self.assertTrue(not b.flags["OWNDATA"])
+        self.assertTrue(not c.flags["OWNDATA"])
+        self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertEqual(c.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        #
+        d=DataArrayInt(10)
+        d.iota()
+        a=d.toNumPyArray()
+        b=d.toNumPyArray()
+        c=d.toNumPyArray()
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(not b.flags["OWNDATA"])
+        self.assertTrue(not c.flags["OWNDATA"])
+        self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertEqual(c.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        del d
+        gc.collect()
+        self.assertTrue(a.flags["OWNDATA"])
+        self.assertTrue(not b.flags["OWNDATA"])
+        self.assertTrue(not c.flags["OWNDATA"])
+        self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertEqual(c.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        pass
+
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test40(self):
+        """Same as test24 with float32"""
+        d=DataArrayDouble(10)
+        d.iota()
+        a=d.toNumPyArray()
+        self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(a.base is None)
+        del a
+        gc.collect()
+        a=d.toNumPyArray()
+        self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(a.base is None)
+        b=d.toNumPyArray()
+        self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(not b.flags["OWNDATA"])
+        self.assertTrue(b.base is a)
+        del a
+        gc.collect()
+        self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertTrue(not b.flags["OWNDATA"])
+        del d
+        gc.collect()
+        self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertTrue(not b.flags["OWNDATA"])
+        #
+        d=DataArrayInt(10)
+        d.iota()
+        a=d.toNumPyArray()
+        self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(a.base is None)
+        del a
+        gc.collect()
+        a=d.toNumPyArray()
+        self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(a.base is None)
+        b=d.toNumPyArray()
+        self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
+        self.assertTrue(not a.flags["OWNDATA"])
+        self.assertTrue(not b.flags["OWNDATA"])
+        self.assertTrue(b.base is a)
+        del a
+        gc.collect()
+        self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertTrue(not b.flags["OWNDATA"])
+        del d
+        gc.collect()
+        self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
+        self.assertTrue(not b.flags["OWNDATA"])
+        pass
+
     def setUp(self):
         pass
     pass
index 5377a3db323612b5eb307bfd81a5d901f4518586..80c2f4a22345d96b6b06786a6e53a396ce2963fd 100644 (file)
@@ -63,7 +63,7 @@ IF(MEDCOUPLING_BUILD_DOC)
 ENDIF()
 
 SWIG_ADD_MODULE(MEDLoader python MEDLoader.i)
-SWIG_LINK_LIBRARIES(MEDLoader ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} medloader medcoupling)
+SWIG_LINK_LIBRARIES(MEDLoader medloader medcouplinghelpyer)
 IF(WIN32)
   SET_TARGET_PROPERTIES(_MEDLoader PROPERTIES DEBUG_OUTPUT_NAME _MEDLoader_d)
 ENDIF(WIN32)
index 3e025745fc3e10da396811b3429587af3235332e..b24d4cead4d2b63d54aff1c756095dd0d1942894 100644 (file)
@@ -49,7 +49,7 @@ INCLUDE_DIRECTORIES(
   )
 
 SWIG_ADD_MODULE(MEDPartitioner python MEDPartitioner.i)
-SWIG_LINK_LIBRARIES(MEDPartitioner ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} medpartitionercpp)
+SWIG_LINK_LIBRARIES(MEDPartitioner medpartitionercpp medcouplinghelpyer)
 
 IF(WIN32)
   SET_TARGET_PROPERTIES(_MEDPartitioner PROPERTIES DEBUG_OUTPUT_NAME _MEDPartitioner_d)
index 603a63ad3f6cc40086318f9268db5483c6cc7f2f..2b86975384124e101b04472a15ec8780bd4857ba 100644 (file)
@@ -53,7 +53,7 @@ SET (SWIG_MODULE_ParaMEDMEM_EXTRA_DEPS ${ParaMEDMEM_SWIG_DPYS_FILES}
     ${interpkernel_HEADERS_HXX} ${interpkernel_HEADERS_TXX})
 
 SWIG_ADD_MODULE(ParaMEDMEM python ParaMEDMEM.i)
-SWIG_LINK_LIBRARIES(ParaMEDMEM ${PYTHON_LIBRARIES} paramedmem medloader)
+SWIG_LINK_LIBRARIES(ParaMEDMEM paramedmem medloader medcouplinghelpyer)
 
 SET_SOURCE_FILES_PROPERTIES(ParaMEDMEM.i PROPERTIES CPLUSPLUS ON)
 SET_SOURCE_FILES_PROPERTIES(ParaMEDMEM.i PROPERTIES SWIG_DEFINITIONS "-shadow")
index 95e83e3df7685b51fd7f35a3d16a72a444a47335..a6f6de55585eb5ff15a1be77b2d7ff0e2c413231 100644 (file)
@@ -53,7 +53,7 @@ INCLUDE_DIRECTORIES(
   )
 
 SWIG_ADD_MODULE(MEDRenumber python MEDRenumber.i)
-SWIG_LINK_LIBRARIES(MEDRenumber ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} renumbercpp)
+SWIG_LINK_LIBRARIES(MEDRenumber renumbercpp medcouplinghelpyer)
 
 IF(WIN32)
   SET_TARGET_PROPERTIES(_MEDRenumber PROPERTIES DEBUG_OUTPUT_NAME _MEDRenumber_d)