gc.collect()
pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test29(self):
+ """Same as test9 with float32"""
+ sz=20
+ a=array(0,dtype=float64)
+ a.resize(sz)
+ a[:]=4
+ self.assertEqual(getrefcount(a),2)
+ a=a.cumsum(dtype=float64)
+ self.assertEqual(getrefcount(a),2)
+ d=DataArrayDouble(a)
+ d[:]=2
+ #
+ e=DataArrayDouble(sz) ; e.fillWithValue(2)
+ self.assertTrue(d.isEqual(e,1e-14))
+ #
+ a[:]=4 ; e.fillWithValue(4)
+ self.assertTrue(d.isEqual(e,1e-14))
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test30(self):
+ """Same as test10 with float32"""
+ sz=20
+ a=array(0,dtype=float64)
+ a.resize(sz,2)
+ self.assertEqual(getrefcount(a),2)
+ b=a.reshape(2*sz)
+ self.assertEqual(getrefcount(a),3)
+ self.assertEqual(getrefcount(b),2)
+ b[:]=5
+ d=DataArrayDouble(b)
+ #
+ e=DataArrayDouble(sz*2) ; e.fillWithValue(5)
+ self.assertTrue(d.isEqual(e,1e-14))
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test31(self):
+ """Same as test11 with float32"""
+ sz=10
+ a=array(0,dtype=float64)
+ a.resize(sz,2)
+ b=a.reshape(2*sz)
+ c=a.reshape(2,sz)
+ b[:]=6
+ b[7:17]=7
+ d=DataArrayDouble(b)
+ self.assertTrue(d.isEqual(DataArrayDouble([6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,6,6,6]),1e-14))
+ #
+ a=zeros((10,2),dtype=float64)
+ b=a.T
+ c=b.view()
+ a.shape=20
+ a[3:]=10.
+ d=DataArrayDouble(a)
+ self.assertTrue(d.isEqual(DataArrayDouble([0,0,0,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10]),1e-14))
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test32(self):
+ """Same as test12 with float32"""
+ 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 test33(self):
+ """Same as test13 with float32"""
+ a=arange(20,dtype=float64)
+ self.assertEqual(weakref.getweakrefcount(a),0)
+ d=DataArrayDouble(a)
+ self.assertEqual(weakref.getweakrefcount(a),1)
+ self.assertTrue(not a.flags["OWNDATA"])
+ self.assertTrue(d.isEqual(DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-14))
+ self.assertEqual(len(d),20)
+ a[:]=2 # modifying a and d because a and d share the same chunk of data
+ self.assertTrue(d.isUniform(2,1e-14))
+ del d # d is destroyed, a retrieves its ownership of its initial chunk of data
+ ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+ import gc
+ gc.collect()
+ self.assertTrue(a.flags["OWNDATA"])
+ a[:]=4 # a can be used has usual
+ self.assertTrue(DataArrayDouble(a).isUniform(4,1e-14))
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test14(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
+ self.assertTrue(d.isEqual(DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-14))
+ self.assertTrue(e.isEqual(DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-14))
+ a[:]=6
+ self.assertTrue(d.isUniform(6,1e-14))
+ self.assertTrue(e.isUniform(6,1e-14))
+ del a # a destroyed -> d no change because owned and e array is has no more data set
+ ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+ import gc
+ gc.collect()
+ self.assertTrue(d.isUniform(6,1e-14))
+ self.assertTrue(not e.isAllocated())
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test15(self):
+ a=array(0,dtype=float64) ; a.resize(10,2)
+ b=a.reshape(20)
+ c=a.reshape(2,10)
+ d=DataArrayDouble(b) # d owns data of a
+ e=DataArrayDouble(b) # a not owned -> e only an access to chunk of a
+ f=DataArrayDouble(b) # a not owned -> e only an access to chunk of a
+ del d # d removed -> a ownes again data
+ ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+ import gc
+ gc.collect()
+ self.assertTrue(e.isUniform(0,1e-14))
+ e[:]=6
+ self.assertTrue(e.isUniform(6,1e-14))
+ self.assertTrue(f.isUniform(6,1e-14))
+ self.assertEqual(b.tolist(),[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6])
+ self.assertEqual(a.tolist(),[[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6]])
+ b[:]=arange(20)
+ del b # no impact on e and f because a is the base of a.
+ ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+ gc.collect()
+ self.assertTrue(f.isEqual(DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-14))
+ self.assertTrue(e.isEqual(DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-14))
+ del a # a destroyed, but as c has its base set to a, a exists -> e and f not allocated
+ ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+ gc.collect()
+ self.assertTrue(f.isEqual(DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-14))
+ self.assertTrue(e.isEqual(DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]),1e-14))
+ del c # c killed -> a killed -> e and d are put into not allocated state
+ ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
+ gc.collect()
+ self.assertTrue(not e.isAllocated())
+ self.assertTrue(not f.isAllocated())
+ pass
+
+ @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+ def test16(self):
+ a=arange(20,dtype=float64)
+ self.assertTrue(a.flags["OWNDATA"])
+ d=DataArrayDouble(a) # d owns data of a
+ self.assertTrue(not a.flags["OWNDATA"])
+ d.pushBackSilent(20)# d pushBack so release of chunk of data -> a becomes owner of its data again
+ self.assertTrue(a.flags["OWNDATA"])
+ self.assertTrue(d.isEqual(DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]),1e-14))
+ 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
+
def setUp(self):
pass
pass