//
// 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>
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>
return ret;
}
-#endif
-
static PyObject *convertDataArrayChar(MEDCoupling::DataArrayChar *dac, int owner) throw(INTERP_KERNEL::Exception)
{
PyObject *ret=0;
#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
}
#endif
-
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)
pass
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
- def test2(self):
+ def tess2(self):
sz=20
a=array(0,dtype=int32)
a.resize(sz,2)
pass
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
- def test3(self):
+ def tess3(self):
sz=10
a=array(0,dtype=int32)
a.resize(sz,2)
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)
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
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)
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
pass
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
- def test9(self):
+ def tess9(self):
sz=20
a=array(0,dtype=float64)
a.resize(sz)
pass
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
- def test10(self):
+ def tess10(self):
sz=20
a=array(0,dtype=float64)
a.resize(sz,2)
pass
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
- def test11(self):
+ def tess11(self):
sz=10
a=array(0,dtype=float64)
a.resize(sz,2)
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)
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
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)
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
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"])
pass
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
- def test18(self):
+ def tess18(self):
d=DataArrayInt.Range(0,20,1)
d=d.convertToDblArr()
a=d.toNumPyArray()
pass
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
- def test19(self):
+ def tess19(self):
sz=20
a=array(0,dtype=int32)
a.resize(sz/2,2)
pass
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
- def test20(self):
+ def tess20(self):
sz=20
a=array(0,dtype=float64)
a.resize(sz/2,2)
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)
pass
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
- def test22(self):
+ def tess22(self):
d=DataArrayDouble(10)
d.iota()
a=d.toNumPyArray()
pass
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
- def test23(self):
+ def tess23(self):
d=DataArrayDouble(10)
d.iota()
a=d.toNumPyArray()
pass
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
- def test24(self):
+ def tess24(self):
d=DataArrayDouble(10)
d.iota()
a=d.toNumPyArray()
pass
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
- def test25(self):
+ def tess25(self):
a=arange(10,dtype=int32)
b=DataArrayInt(a)
c=DataArrayInt(a)
pass
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
- def test26(self):
+ def tess26(self):
d=DataArrayInt(15) ; d.iota()
d.rearrange(3)
a=d.toNumPyArray()
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))
pass
@unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
- def test28(self):
+ def tess28(self):
"""Test on DataArrayBytes"""
# use case 1
d=DataArrayByte(256)
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"""
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
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)
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
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