1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 from MEDCoupling import *
24 if MEDCouplingHasNumPyBindings():
28 from platform import architecture
29 from sys import getrefcount
31 import os,gc,weakref,unittest
33 class MEDCouplingNumPyTest(unittest.TestCase):
35 @unittest.skipUnless(MEDCouplingHasNumPyBindings() and architecture()[0]=="64bit","requires numpy")
38 a=array(0,dtype=int32)
41 self.assertEqual(getrefcount(a),2)
42 a=a.cumsum(dtype=int32)
43 a=array(a,dtype=int64) ; a=array(a,dtype=int32)
44 self.assertEqual(getrefcount(a),2)
48 e=DataArrayInt(sz) ; e.fillWithValue(2)
49 self.assertTrue(d.isEqual(e))
51 a[:]=4 ; e.fillWithValue(4)
52 self.assertTrue(d.isEqual(e))
55 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
58 a=array(0,dtype=int32)
60 self.assertEqual(getrefcount(a),2)
62 self.assertEqual(getrefcount(a),3)
63 self.assertEqual(getrefcount(b),2)
67 e=DataArrayInt(sz*2) ; e.fillWithValue(5)
68 self.assertTrue(d.isEqual(e))
71 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
74 a=array(0,dtype=int32)
81 self.assertTrue(d.isEqual(DataArrayInt([6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,6,6,6])))
83 a=zeros((10,2),dtype=int32)
89 self.assertTrue(d.isEqual(DataArrayInt([0,0,0,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10])))
92 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
94 a=zeros(20,dtype=int32)
96 self.assertRaises(InterpKernelException,DataArrayInt.New,b) # b is not contiguous in memory
99 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
101 a=arange(20,dtype=int32)
102 self.assertEqual(weakref.getweakrefcount(a),0)
104 self.assertEqual(weakref.getweakrefcount(a),1)
105 self.assertTrue(not a.flags["OWNDATA"])
106 self.assertTrue(d.isIdentity())
107 self.assertEqual(len(d),20)
108 a[:]=2 # modifying a and d because a and d share the same chunk of data
109 self.assertTrue(d.isUniform(2))
110 del d # d is destroyed, a retrieves its ownership of its initial chunk of data
111 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
114 self.assertTrue(a.flags["OWNDATA"])
115 a[:]=4 # a can be used has usual
116 self.assertTrue(DataArrayInt(a).isUniform(4))
119 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
121 a=arange(20,dtype=int32)
122 d=DataArrayInt(a) # d owns data of a
123 e=DataArrayInt(a) # a not owned -> e only an access to chunk of a
124 self.assertTrue(d.isIdentity())
125 self.assertTrue(e.isIdentity())
127 self.assertTrue(d.isUniform(6))
128 self.assertTrue(e.isUniform(6))
129 del a # a destroyed -> d no change because owned and e array is has no more data set
130 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
133 self.assertTrue(d.isUniform(6))
134 self.assertTrue(not e.isAllocated())
137 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
139 a=array(0,dtype=int32) ; a.resize(10,2)
142 d=DataArrayInt(b) # d owns data of a
143 e=DataArrayInt(b) # a not owned -> e only an access to chunk of a
144 f=DataArrayInt(b) # a not owned -> e only an access to chunk of a
145 del d # d removed -> a ownes again data
146 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
149 self.assertTrue(e.isUniform(0))
151 self.assertTrue(e.isUniform(6))
152 self.assertTrue(f.isUniform(6))
153 self.assertEqual(b.tolist(),[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6])
154 self.assertEqual(a.tolist(),[[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6]])
156 del b # no impact on e and f because a is the base of a.
157 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
159 self.assertTrue(f.isIdentity())
160 self.assertTrue(e.isIdentity())
161 del a # a destroyed, but as c has its base set to a, a exists -> e and f not allocated
162 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
164 self.assertTrue(f.isIdentity())
165 self.assertTrue(e.isIdentity())
166 del c # c killed -> a killed -> e and d are put into not allocated state
167 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
169 self.assertTrue(not e.isAllocated())
170 self.assertTrue(not f.isAllocated())
173 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
175 a=arange(20,dtype=int32)
176 self.assertTrue(a.flags["OWNDATA"])
177 d=DataArrayInt(a) # d owns data of a
178 self.assertTrue(not a.flags["OWNDATA"])
179 d.pushBackSilent(20)# d pushBack so release of chunk of data -> a becomes owner of its data again
180 self.assertTrue(a.flags["OWNDATA"])
181 self.assertTrue(d.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20])))
182 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])
185 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
188 a=array(0,dtype=float64)
191 self.assertEqual(getrefcount(a),2)
192 a=a.cumsum(dtype=float64)
193 self.assertEqual(getrefcount(a),2)
197 e=DataArrayDouble(sz) ; e.fillWithValue(2)
198 self.assertTrue(d.isEqual(e,1e-14))
200 a[:]=4 ; e.fillWithValue(4)
201 self.assertTrue(d.isEqual(e,1e-14))
204 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
207 a=array(0,dtype=float64)
209 self.assertEqual(getrefcount(a),2)
211 self.assertEqual(getrefcount(a),3)
212 self.assertEqual(getrefcount(b),2)
216 e=DataArrayDouble(sz*2) ; e.fillWithValue(5)
217 self.assertTrue(d.isEqual(e,1e-14))
220 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
223 a=array(0,dtype=float64)
230 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))
232 a=zeros((10,2),dtype=float64)
238 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))
241 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
243 a=zeros(20,dtype=float64)
245 self.assertRaises(InterpKernelException,DataArrayDouble.New,b) # b is not contiguous in memory
248 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
250 a=arange(20,dtype=float64)
251 self.assertEqual(weakref.getweakrefcount(a),0)
253 self.assertEqual(weakref.getweakrefcount(a),1)
254 self.assertTrue(not a.flags["OWNDATA"])
255 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))
256 self.assertEqual(len(d),20)
257 a[:]=2 # modifying a and d because a and d share the same chunk of data
258 self.assertTrue(d.isUniform(2,1e-14))
259 del d # d is destroyed, a retrieves its ownership of its initial chunk of data
260 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
263 self.assertTrue(a.flags["OWNDATA"])
264 a[:]=4 # a can be used has usual
265 self.assertTrue(DataArrayDouble(a).isUniform(4,1e-14))
268 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
270 a=arange(20,dtype=float64)
271 d=DataArrayDouble(a) # d owns data of a
272 e=DataArrayDouble(a) # a not owned -> e only an access to chunk of a
273 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))
274 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))
276 self.assertTrue(d.isUniform(6,1e-14))
277 self.assertTrue(e.isUniform(6,1e-14))
278 del a # a destroyed -> d no change because owned and e array is has no more data set
279 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
282 self.assertTrue(d.isUniform(6,1e-14))
283 self.assertTrue(not e.isAllocated())
286 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
288 a=array(0,dtype=float64) ; a.resize(10,2)
291 d=DataArrayDouble(b) # d owns data of a
292 e=DataArrayDouble(b) # a not owned -> e only an access to chunk of a
293 f=DataArrayDouble(b) # a not owned -> e only an access to chunk of a
294 del d # d removed -> a ownes again data
295 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
298 self.assertTrue(e.isUniform(0,1e-14))
300 self.assertTrue(e.isUniform(6,1e-14))
301 self.assertTrue(f.isUniform(6,1e-14))
302 self.assertEqual(b.tolist(),[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6])
303 self.assertEqual(a.tolist(),[[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6]])
305 del b # no impact on e and f because a is the base of a.
306 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
308 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))
309 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))
310 del a # a destroyed, but as c has its base set to a, a exists -> e and f not allocated
311 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
313 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))
314 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))
315 del c # c killed -> a killed -> e and d are put into not allocated state
316 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
318 self.assertTrue(not e.isAllocated())
319 self.assertTrue(not f.isAllocated())
322 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
324 a=arange(20,dtype=float64)
325 self.assertTrue(a.flags["OWNDATA"])
326 d=DataArrayDouble(a) # d owns data of a
327 self.assertTrue(not a.flags["OWNDATA"])
328 d.pushBackSilent(20)# d pushBack so release of chunk of data -> a becomes owner of its data again
329 self.assertTrue(a.flags["OWNDATA"])
330 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))
331 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])
334 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
336 d=DataArrayInt.Range(0,20,1)
338 self.assertTrue(not a.flags["OWNDATA"])
340 self.assertTrue(d.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,100,100])))
341 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,100,100])
343 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
346 self.assertTrue(d.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,100,100])))
350 self.assertTrue(not a.flags["OWNDATA"])
352 self.assertTrue(d.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,200,200,200,200],10,2)))
353 self.assertEqual(a.tolist(),[[0,1],[2,3],[4,5],[6,7],[8,9],[10,11],[12,13],[14,15],[200,200],[200,200]])
355 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
357 self.assertTrue(d.isEqual(DataArrayInt([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,200,200,200,200],10,2)))
360 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
362 d=DataArrayInt.Range(0,20,1)
363 d=d.convertToDblArr()
365 self.assertTrue(not a.flags["OWNDATA"])
367 self.assertTrue(d.isEqual(DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,100,100]),1e-14))
368 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,100,100])
370 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
373 self.assertTrue(d.isEqual(DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,100,100]),1e-14))
377 self.assertTrue(not a.flags["OWNDATA"])
379 self.assertTrue(d.isEqual(DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,200,200,200,200],10,2),1e-14))
380 self.assertEqual(a.tolist(),[[0,1],[2,3],[4,5],[6,7],[8,9],[10,11],[12,13],[14,15],[200,200],[200,200]])
382 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
384 self.assertTrue(d.isEqual(DataArrayDouble([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,200,200,200,200],10,2),1e-14))
387 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
390 a=array(0,dtype=int32)
393 self.assertEqual(getrefcount(a),2)
395 self.assertEqual(10,d.getNumberOfTuples())
396 self.assertEqual(2,d.getNumberOfComponents())
397 self.assertEqual(sz,d.getNbOfElems())
398 self.assertTrue(d.isEqual(DataArrayInt([(4,4),(4,4),(4,4),(4,4),(4,4),(4,4),(4,4),(4,4),(4,4),(4,4)])))
400 self.assertTrue(d.isEqual(DataArrayInt([(7,7),(7,7),(7,7),(7,7),(7,7),(7,7),(7,7),(7,7),(7,7),(7,7)])))
403 self.assertRaises(InterpKernelException,DataArrayInt.New,b) # b has not dimension in [0,1] !
406 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
409 a=array(0,dtype=float64)
412 self.assertEqual(getrefcount(a),2)
414 self.assertEqual(10,d.getNumberOfTuples())
415 self.assertEqual(2,d.getNumberOfComponents())
416 self.assertEqual(sz,d.getNbOfElems())
417 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))
419 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))
422 self.assertRaises(InterpKernelException,DataArrayDouble.New,b) # b has not dimension in [0,1] !
425 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
427 #tests that only DataArray*(npArray) contructor is available
428 a=array(0,dtype=int32)
431 self.assertRaises(InterpKernelException,DataArrayInt.New,a,20)
432 self.assertRaises(InterpKernelException,DataArrayInt.New,a,20,1)
433 a=array(0,dtype=float64)
436 self.assertRaises(InterpKernelException,DataArrayDouble.New,a,20)
437 self.assertRaises(InterpKernelException,DataArrayDouble.New,a,20,1)
440 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
442 d=DataArrayDouble(10)
445 self.assertTrue(not a.flags["OWNDATA"])
448 self.assertTrue(a.flags["OWNDATA"])
449 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
454 self.assertTrue(not a.flags["OWNDATA"])
457 self.assertTrue(a.flags["OWNDATA"])
458 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
461 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
463 d=DataArrayDouble(10)
468 self.assertTrue(not a.flags["OWNDATA"])
469 self.assertTrue(not b.flags["OWNDATA"])
470 self.assertTrue(not c.flags["OWNDATA"])
471 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
472 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
473 self.assertEqual(c.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
476 self.assertTrue(a.flags["OWNDATA"])
477 self.assertTrue(not b.flags["OWNDATA"])
478 self.assertTrue(not c.flags["OWNDATA"])
479 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
480 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
481 self.assertEqual(c.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
488 self.assertTrue(not a.flags["OWNDATA"])
489 self.assertTrue(not b.flags["OWNDATA"])
490 self.assertTrue(not c.flags["OWNDATA"])
491 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
492 self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
493 self.assertEqual(c.tolist(),[0,1,2,3,4,5,6,7,8,9])
496 self.assertTrue(a.flags["OWNDATA"])
497 self.assertTrue(not b.flags["OWNDATA"])
498 self.assertTrue(not c.flags["OWNDATA"])
499 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
500 self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
501 self.assertEqual(c.tolist(),[0,1,2,3,4,5,6,7,8,9])
504 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
506 d=DataArrayDouble(10)
509 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
510 self.assertTrue(not a.flags["OWNDATA"])
511 self.assertTrue(a.base is None)
515 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
516 self.assertTrue(not a.flags["OWNDATA"])
517 self.assertTrue(a.base is None)
519 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
520 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
521 self.assertTrue(not a.flags["OWNDATA"])
522 self.assertTrue(not b.flags["OWNDATA"])
523 self.assertTrue(b.base is a)
526 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
527 self.assertTrue(not b.flags["OWNDATA"])
530 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
531 self.assertTrue(not b.flags["OWNDATA"])
536 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
537 self.assertTrue(not a.flags["OWNDATA"])
538 self.assertTrue(a.base is None)
542 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
543 self.assertTrue(not a.flags["OWNDATA"])
544 self.assertTrue(a.base is None)
546 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
547 self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
548 self.assertTrue(not a.flags["OWNDATA"])
549 self.assertTrue(not b.flags["OWNDATA"])
550 self.assertTrue(b.base is a)
553 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
554 self.assertTrue(not b.flags["OWNDATA"])
557 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
558 self.assertTrue(not b.flags["OWNDATA"])
561 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
563 a=arange(10,dtype=int32)
567 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
568 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),10)
569 self.assertTrue(d.isIdentity()) ; self.assertEqual(len(d),10)
570 c.pushBackSilent(10) # c and a,b are dissociated
571 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
572 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),11)
573 self.assertTrue(d.isIdentity()) ; self.assertEqual(len(d),10)
576 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
577 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),11)
578 self.assertTrue(not d.isAllocated())
581 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),11)
583 a=arange(10,dtype=int32)
586 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
587 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),10)
588 b.pushBackSilent(10) # c and a,b are dissociated
589 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),11)
590 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),10)
593 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),11)
594 self.assertTrue(not c.isAllocated())
597 self.assertTrue(not c.isAllocated())
599 a=float64(arange(5,dtype=int32))
603 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
604 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
605 self.assertTrue(d.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
606 c.pushBackSilent(10.) # c and a,b are dissociated
607 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
608 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
609 self.assertTrue(d.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
612 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
613 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
614 self.assertTrue(not d.isAllocated())
617 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
619 a=float64(arange(5,dtype=int32))
622 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
623 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
624 b.pushBackSilent(10.) # c and a,b are dissociated
625 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
626 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
629 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
630 self.assertTrue(not c.isAllocated())
633 self.assertTrue(not c.isAllocated())
636 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
638 d=DataArrayInt(15) ; d.iota()
641 self.assertEqual(a.ndim,2)
642 self.assertEqual(a.size,15)
643 self.assertEqual(a.shape,(5,3))
644 self.assertEqual(a.strides,(12,4))
645 self.assertEqual(a.nbytes,60)
646 self.assertEqual(a.itemsize,4)
647 self.assertEqual(a.tolist(),[[0,1,2],[3,4,5],[6,7,8],[9,10,11],[12,13,14]])
649 d2=d.convertToDblArr()
651 self.assertEqual(a2.ndim,2)
652 self.assertEqual(a2.size,15)
653 self.assertEqual(a2.shape,(5,3))
654 self.assertEqual(a2.strides,(24,8))
655 self.assertEqual(a2.nbytes,120)
656 self.assertEqual(a2.itemsize,8)
657 self.assertEqual(a2.tolist(),[[0.,1.,2.],[3.,4.,5.],[6.,7.,8.],[9.,10.,11.],[12.,13.,14.]])
664 #gc.set_debug(gc.DEBUG_LEAK)