From: Anthony Geay Date: Wed, 26 Apr 2017 09:06:05 +0000 (+0200) Subject: On the roae X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=79a93c17c2a015e15f4e1e62d412ce3e1a3fe44c;p=tools%2Fmedcoupling.git On the roae --- diff --git a/MEDCouplingConfig.cmake.in b/MEDCouplingConfig.cmake.in index 8621eead1..fdfaa65de 100644 --- a/MEDCouplingConfig.cmake.in +++ b/MEDCouplingConfig.cmake.in @@ -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) diff --git a/src/MEDCoupling_Swig/CMakeLists.txt b/src/MEDCoupling_Swig/CMakeLists.txt index a3cf107e3..1bd321ef9 100644 --- a/src/MEDCoupling_Swig/CMakeLists.txt +++ b/src/MEDCoupling_Swig/CMakeLists.txt @@ -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) diff --git a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i index 830c1e727..1b71f2493 100644 --- a/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingDataArrayTypemaps.i @@ -16,12 +16,13 @@ // // 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 @@ -72,245 +73,6 @@ int InterpreteNegativeInt(int val, int nbelem) return val; } -#ifdef WITH_NUMPY -#include -#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(wronc[0]); - PyObject *obj=PyWeakref_GetObject(weakRefOnOwner); - if(obj!=Py_None) - { - Py_XINCREF(obj); - PyArrayObject *objC=reinterpret_cast(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 -struct PyCallBackDataArraySt { - PyObject_HEAD - MCData *_pt_mc; -}; - -typedef struct PyCallBackDataArraySt PyCallBackDataArrayChar; -typedef struct PyCallBackDataArraySt PyCallBackDataArrayInt; -typedef struct PyCallBackDataArraySt 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& 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& 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& 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 @@ -587,8 +349,6 @@ PyObject *ToCSRMatrix(const std::vector >& 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::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::ArrayType , T >(elt0,NPY_DOUBLE,&PyCallBackDataArrayDouble_RefType,MEDCoupling::Traits::NPYStr); + return BuildNewInstance< typename MEDCoupling::Traits::ArrayType , T >(elt0,NPYTraits::NPYObjectType,NPYTraits::NPYFunc,MEDCoupling::Traits::NPYStr); } #endif else @@ -2778,4 +2538,3 @@ static typename MEDCoupling::Traits::ArrayType *DataArrayT_New(PyObject *elt0 } #endif - diff --git a/src/MEDCoupling_Swig/MEDCouplingNumPyTest.py b/src/MEDCoupling_Swig/MEDCouplingNumPyTest.py index 7664d2b27..0cc933558 100644 --- a/src/MEDCoupling_Swig/MEDCouplingNumPyTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingNumPyTest.py @@ -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 diff --git a/src/MEDLoader/Swig/CMakeLists.txt b/src/MEDLoader/Swig/CMakeLists.txt index 5377a3db3..80c2f4a22 100644 --- a/src/MEDLoader/Swig/CMakeLists.txt +++ b/src/MEDLoader/Swig/CMakeLists.txt @@ -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) diff --git a/src/MEDPartitioner_Swig/CMakeLists.txt b/src/MEDPartitioner_Swig/CMakeLists.txt index 3e025745f..b24d4cead 100644 --- a/src/MEDPartitioner_Swig/CMakeLists.txt +++ b/src/MEDPartitioner_Swig/CMakeLists.txt @@ -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) diff --git a/src/ParaMEDMEM_Swig/CMakeLists.txt b/src/ParaMEDMEM_Swig/CMakeLists.txt index 603a63ad3..2b8697538 100644 --- a/src/ParaMEDMEM_Swig/CMakeLists.txt +++ b/src/ParaMEDMEM_Swig/CMakeLists.txt @@ -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") diff --git a/src/RENUMBER_Swig/CMakeLists.txt b/src/RENUMBER_Swig/CMakeLists.txt index 95e83e3df..a6f6de555 100644 --- a/src/RENUMBER_Swig/CMakeLists.txt +++ b/src/RENUMBER_Swig/CMakeLists.txt @@ -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)