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 self.assertEqual(getrefcount(a),2)
47 e=DataArrayInt(sz) ; e.fillWithValue(2)
48 self.assertTrue(d.isEqual(e))
50 a[:]=4 ; e.fillWithValue(4)
51 self.assertTrue(d.isEqual(e))
54 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
57 a=array(0,dtype=int32)
59 self.assertEqual(getrefcount(a),2)
61 self.assertEqual(getrefcount(a),3)
62 self.assertEqual(getrefcount(b),2)
66 e=DataArrayInt(sz*2) ; e.fillWithValue(5)
67 self.assertTrue(d.isEqual(e))
70 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
73 a=array(0,dtype=int32)
80 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])))
82 a=zeros((10,2),dtype=int32)
88 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])))
91 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
93 a=zeros(20,dtype=int32)
95 self.assertRaises(InterpKernelException,DataArrayInt.New,b) # b is not contiguous in memory
98 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
100 a=arange(20,dtype=int32)
101 self.assertEqual(weakref.getweakrefcount(a),0)
103 self.assertEqual(weakref.getweakrefcount(a),1)
104 self.assertTrue(not a.flags["OWNDATA"])
105 self.assertTrue(d.isIdentity())
106 self.assertEqual(len(d),20)
107 a[:]=2 # modifying a and d because a and d share the same chunk of data
108 self.assertTrue(d.isUniform(2))
109 del d # d is destroyed, a retrieves its ownership of its initial chunk of data
110 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
113 self.assertTrue(a.flags["OWNDATA"])
114 a[:]=4 # a can be used has usual
115 self.assertTrue(DataArrayInt(a).isUniform(4))
118 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
120 a=arange(20,dtype=int32)
121 d=DataArrayInt(a) # d owns data of a
122 e=DataArrayInt(a) # a not owned -> e only an access to chunk of a
123 self.assertTrue(d.isIdentity())
124 self.assertTrue(e.isIdentity())
126 self.assertTrue(d.isUniform(6))
127 self.assertTrue(e.isUniform(6))
128 del a # a destroyed -> d no change because owned and e array is has no more data set
129 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
132 self.assertTrue(d.isUniform(6))
133 self.assertTrue(not e.isAllocated())
136 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
138 a=array(0,dtype=int32) ; a.resize(10,2)
141 d=DataArrayInt(b) # d owns data of a
142 e=DataArrayInt(b) # a not owned -> e only an access to chunk of a
143 f=DataArrayInt(b) # a not owned -> e only an access to chunk of a
144 del d # d removed -> a ownes again data
145 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
148 self.assertTrue(e.isUniform(0))
150 self.assertTrue(e.isUniform(6))
151 self.assertTrue(f.isUniform(6))
152 self.assertEqual(b.tolist(),[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6])
153 self.assertEqual(a.tolist(),[[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6]])
155 del b # no impact on e and f because a is the base of a.
156 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
158 self.assertTrue(f.isIdentity())
159 self.assertTrue(e.isIdentity())
160 del a # a destroyed, but as c has its base set to a, a exists -> e and f not allocated
161 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
163 self.assertTrue(f.isIdentity())
164 self.assertTrue(e.isIdentity())
165 del c # c killed -> a killed -> e and d are put into not allocated state
166 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
168 self.assertTrue(not e.isAllocated())
169 self.assertTrue(not f.isAllocated())
172 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
174 a=arange(20,dtype=int32)
175 self.assertTrue(a.flags["OWNDATA"])
176 d=DataArrayInt(a) # d owns data of a
177 self.assertTrue(not a.flags["OWNDATA"])
178 d.pushBackSilent(20)# d pushBack so release of chunk of data -> a becomes owner of its data again
179 self.assertTrue(a.flags["OWNDATA"])
180 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])))
181 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])
184 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
187 a=array(0,dtype=float64)
190 self.assertEqual(getrefcount(a),2)
191 a=a.cumsum(dtype=float64)
192 self.assertEqual(getrefcount(a),2)
196 e=DataArrayDouble(sz) ; e.fillWithValue(2)
197 self.assertTrue(d.isEqual(e,1e-14))
199 a[:]=4 ; e.fillWithValue(4)
200 self.assertTrue(d.isEqual(e,1e-14))
203 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
206 a=array(0,dtype=float64)
208 self.assertEqual(getrefcount(a),2)
210 self.assertEqual(getrefcount(a),3)
211 self.assertEqual(getrefcount(b),2)
215 e=DataArrayDouble(sz*2) ; e.fillWithValue(5)
216 self.assertTrue(d.isEqual(e,1e-14))
219 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
222 a=array(0,dtype=float64)
229 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))
231 a=zeros((10,2),dtype=float64)
237 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))
240 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
242 a=zeros(20,dtype=float64)
244 self.assertRaises(InterpKernelException,DataArrayDouble.New,b) # b is not contiguous in memory
247 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
249 a=arange(20,dtype=float64)
250 self.assertEqual(weakref.getweakrefcount(a),0)
252 self.assertEqual(weakref.getweakrefcount(a),1)
253 self.assertTrue(not a.flags["OWNDATA"])
254 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))
255 self.assertEqual(len(d),20)
256 a[:]=2 # modifying a and d because a and d share the same chunk of data
257 self.assertTrue(d.isUniform(2,1e-14))
258 del d # d is destroyed, a retrieves its ownership of its initial chunk of data
259 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
262 self.assertTrue(a.flags["OWNDATA"])
263 a[:]=4 # a can be used has usual
264 self.assertTrue(DataArrayDouble(a).isUniform(4,1e-14))
267 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
269 a=arange(20,dtype=float64)
270 d=DataArrayDouble(a) # d owns data of a
271 e=DataArrayDouble(a) # a not owned -> e only an access to chunk of a
272 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))
273 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))
275 self.assertTrue(d.isUniform(6,1e-14))
276 self.assertTrue(e.isUniform(6,1e-14))
277 del a # a destroyed -> d no change because owned and e array is has no more data set
278 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
281 self.assertTrue(d.isUniform(6,1e-14))
282 self.assertTrue(not e.isAllocated())
285 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
287 a=array(0,dtype=float64) ; a.resize(10,2)
290 d=DataArrayDouble(b) # d owns data of a
291 e=DataArrayDouble(b) # a not owned -> e only an access to chunk of a
292 f=DataArrayDouble(b) # a not owned -> e only an access to chunk of a
293 del d # d removed -> a ownes again data
294 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
297 self.assertTrue(e.isUniform(0,1e-14))
299 self.assertTrue(e.isUniform(6,1e-14))
300 self.assertTrue(f.isUniform(6,1e-14))
301 self.assertEqual(b.tolist(),[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6])
302 self.assertEqual(a.tolist(),[[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6]])
304 del b # no impact on e and f because a is the base of a.
305 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
307 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))
308 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))
309 del a # a destroyed, but as c has its base set to a, a exists -> e and f not allocated
310 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
312 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))
313 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))
314 del c # c killed -> a killed -> e and d are put into not allocated state
315 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
317 self.assertTrue(not e.isAllocated())
318 self.assertTrue(not f.isAllocated())
321 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
323 a=arange(20,dtype=float64)
324 self.assertTrue(a.flags["OWNDATA"])
325 d=DataArrayDouble(a) # d owns data of a
326 self.assertTrue(not a.flags["OWNDATA"])
327 d.pushBackSilent(20)# d pushBack so release of chunk of data -> a becomes owner of its data again
328 self.assertTrue(a.flags["OWNDATA"])
329 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))
330 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])
333 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
335 d=DataArrayInt.Range(0,20,1)
337 self.assertTrue(not a.flags["OWNDATA"])
339 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])))
340 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,100,100])
342 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
345 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])))
349 self.assertTrue(not a.flags["OWNDATA"])
351 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)))
352 self.assertEqual(a.tolist(),[[0,1],[2,3],[4,5],[6,7],[8,9],[10,11],[12,13],[14,15],[200,200],[200,200]])
354 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
356 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)))
359 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
361 d=DataArrayInt.Range(0,20,1)
362 d=d.convertToDblArr()
364 self.assertTrue(not a.flags["OWNDATA"])
366 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))
367 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,100,100])
369 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
372 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))
376 self.assertTrue(not a.flags["OWNDATA"])
378 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))
379 self.assertEqual(a.tolist(),[[0,1],[2,3],[4,5],[6,7],[8,9],[10,11],[12,13],[14,15],[200,200],[200,200]])
381 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
383 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))
386 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
389 a=array(0,dtype=int32)
392 self.assertEqual(getrefcount(a),2)
394 self.assertEqual(10,d.getNumberOfTuples())
395 self.assertEqual(2,d.getNumberOfComponents())
396 self.assertEqual(sz,d.getNbOfElems())
397 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)])))
399 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)])))
402 self.assertRaises(InterpKernelException,DataArrayInt.New,b) # b has not dimension in [0,1] !
405 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
408 a=array(0,dtype=float64)
411 self.assertEqual(getrefcount(a),2)
413 self.assertEqual(10,d.getNumberOfTuples())
414 self.assertEqual(2,d.getNumberOfComponents())
415 self.assertEqual(sz,d.getNbOfElems())
416 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))
418 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))
421 self.assertRaises(InterpKernelException,DataArrayDouble.New,b) # b has not dimension in [0,1] !
424 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
426 #tests that only DataArray*(npArray) contructor is available
427 a=array(0,dtype=int32)
430 self.assertRaises(InterpKernelException,DataArrayInt.New,a,20)
431 self.assertRaises(InterpKernelException,DataArrayInt.New,a,20,1)
432 a=array(0,dtype=float64)
435 self.assertRaises(InterpKernelException,DataArrayDouble.New,a,20)
436 self.assertRaises(InterpKernelException,DataArrayDouble.New,a,20,1)
439 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
441 d=DataArrayDouble(10)
444 self.assertTrue(not a.flags["OWNDATA"])
447 self.assertTrue(a.flags["OWNDATA"])
448 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
453 self.assertTrue(not a.flags["OWNDATA"])
456 self.assertTrue(a.flags["OWNDATA"])
457 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
460 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
462 d=DataArrayDouble(10)
467 self.assertTrue(not a.flags["OWNDATA"])
468 self.assertTrue(not b.flags["OWNDATA"])
469 self.assertTrue(not c.flags["OWNDATA"])
470 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
471 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
472 self.assertEqual(c.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
475 self.assertTrue(a.flags["OWNDATA"])
476 self.assertTrue(not b.flags["OWNDATA"])
477 self.assertTrue(not c.flags["OWNDATA"])
478 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
479 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
480 self.assertEqual(c.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
487 self.assertTrue(not a.flags["OWNDATA"])
488 self.assertTrue(not b.flags["OWNDATA"])
489 self.assertTrue(not c.flags["OWNDATA"])
490 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
491 self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
492 self.assertEqual(c.tolist(),[0,1,2,3,4,5,6,7,8,9])
495 self.assertTrue(a.flags["OWNDATA"])
496 self.assertTrue(not b.flags["OWNDATA"])
497 self.assertTrue(not c.flags["OWNDATA"])
498 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
499 self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
500 self.assertEqual(c.tolist(),[0,1,2,3,4,5,6,7,8,9])
503 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
505 d=DataArrayDouble(10)
508 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
509 self.assertTrue(not a.flags["OWNDATA"])
510 self.assertTrue(a.base is None)
514 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
515 self.assertTrue(not a.flags["OWNDATA"])
516 self.assertTrue(a.base is None)
518 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
519 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
520 self.assertTrue(not a.flags["OWNDATA"])
521 self.assertTrue(not b.flags["OWNDATA"])
522 self.assertTrue(b.base is a)
525 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
526 self.assertTrue(not b.flags["OWNDATA"])
529 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
530 self.assertTrue(not b.flags["OWNDATA"])
535 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
536 self.assertTrue(not a.flags["OWNDATA"])
537 self.assertTrue(a.base is None)
541 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
542 self.assertTrue(not a.flags["OWNDATA"])
543 self.assertTrue(a.base is None)
545 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
546 self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
547 self.assertTrue(not a.flags["OWNDATA"])
548 self.assertTrue(not b.flags["OWNDATA"])
549 self.assertTrue(b.base is a)
552 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
553 self.assertTrue(not b.flags["OWNDATA"])
556 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
557 self.assertTrue(not b.flags["OWNDATA"])
560 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
562 a=arange(10,dtype=int32)
566 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
567 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),10)
568 self.assertTrue(d.isIdentity()) ; self.assertEqual(len(d),10)
569 c.pushBackSilent(10) # c and a,b are dissociated
570 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
571 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),11)
572 self.assertTrue(d.isIdentity()) ; self.assertEqual(len(d),10)
575 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
576 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),11)
577 self.assertTrue(not d.isAllocated())
580 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),11)
582 a=arange(10,dtype=int32)
585 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
586 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),10)
587 b.pushBackSilent(10) # c and a,b are dissociated
588 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),11)
589 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),10)
592 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),11)
593 self.assertTrue(not c.isAllocated())
596 self.assertTrue(not c.isAllocated())
598 a=float64(arange(5,dtype=int32))
602 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
603 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
604 self.assertTrue(d.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
605 c.pushBackSilent(10.) # c and a,b are dissociated
606 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
607 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
608 self.assertTrue(d.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
611 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
612 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
613 self.assertTrue(not d.isAllocated())
616 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
618 a=float64(arange(5,dtype=int32))
621 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
622 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
623 b.pushBackSilent(10.) # c and a,b are dissociated
624 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
625 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
628 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
629 self.assertTrue(not c.isAllocated())
632 self.assertTrue(not c.isAllocated())
635 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
637 d=DataArrayInt(15) ; d.iota()
640 self.assertEqual(a.ndim,2)
641 self.assertEqual(a.size,15)
642 self.assertEqual(a.shape,(5,3))
643 self.assertEqual(a.strides,(12,4))
644 self.assertEqual(a.nbytes,60)
645 self.assertEqual(a.itemsize,4)
646 self.assertEqual(a.tolist(),[[0,1,2],[3,4,5],[6,7,8],[9,10,11],[12,13,14]])
648 d2=d.convertToDblArr()
650 self.assertEqual(a2.ndim,2)
651 self.assertEqual(a2.size,15)
652 self.assertEqual(a2.shape,(5,3))
653 self.assertEqual(a2.strides,(24,8))
654 self.assertEqual(a2.nbytes,120)
655 self.assertEqual(a2.itemsize,8)
656 self.assertEqual(a2.tolist(),[[0.,1.,2.],[3.,4.,5.],[6.,7.,8.],[9.,10.,11.],[12.,13.,14.]])
663 #gc.set_debug(gc.DEBUG_LEAK)