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 sys import getrefcount
30 import os,gc,weakref,unittest
32 class MEDCouplingNumPyTest(unittest.TestCase):
34 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
37 a=array(0,dtype=int32)
40 self.assertEqual(getrefcount(a),2)
41 a=a.cumsum(dtype=int32)
42 self.assertEqual(getrefcount(a),2)
46 e=DataArrayInt(sz) ; e.fillWithValue(2)
47 self.assertTrue(d.isEqual(e))
49 a[:]=4 ; e.fillWithValue(4)
50 self.assertTrue(d.isEqual(e))
53 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
56 a=array(0,dtype=int32)
58 self.assertEqual(getrefcount(a),2)
60 self.assertEqual(getrefcount(a),3)
61 self.assertEqual(getrefcount(b),2)
65 e=DataArrayInt(sz*2) ; e.fillWithValue(5)
66 self.assertTrue(d.isEqual(e))
69 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
72 a=array(0,dtype=int32)
79 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])))
81 a=zeros((10,2),dtype=int32)
87 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])))
90 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
92 a=zeros(20,dtype=int32)
94 self.assertRaises(InterpKernelException,DataArrayInt.New,b) # b is not contiguous in memory
97 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
99 a=arange(20,dtype=int32)
100 self.assertEqual(weakref.getweakrefcount(a),0)
102 self.assertEqual(weakref.getweakrefcount(a),1)
103 self.assertTrue(not a.flags["OWNDATA"])
104 self.assertTrue(d.isIdentity())
105 self.assertEqual(len(d),20)
106 a[:]=2 # modifying a and d because a and d share the same chunk of data
107 self.assertTrue(d.isUniform(2))
108 del d # d is destroyed, a retrieves its ownership of its initial chunk of data
109 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
112 self.assertTrue(a.flags["OWNDATA"])
113 a[:]=4 # a can be used has usual
114 self.assertTrue(DataArrayInt(a).isUniform(4))
117 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
119 a=arange(20,dtype=int32)
120 d=DataArrayInt(a) # d owns data of a
121 e=DataArrayInt(a) # a not owned -> e only an access to chunk of a
122 self.assertTrue(d.isIdentity())
123 self.assertTrue(e.isIdentity())
125 self.assertTrue(d.isUniform(6))
126 self.assertTrue(e.isUniform(6))
127 del a # a destroyed -> d no change because owned and e array is has no more data set
128 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
131 self.assertTrue(d.isUniform(6))
132 self.assertTrue(not e.isAllocated())
135 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
137 a=array(0,dtype=int32) ; a.resize(10,2)
140 d=DataArrayInt(b) # d owns data of a
141 e=DataArrayInt(b) # a not owned -> e only an access to chunk of a
142 f=DataArrayInt(b) # a not owned -> e only an access to chunk of a
143 del d # d removed -> a ownes again data
144 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
147 self.assertTrue(e.isUniform(0))
149 self.assertTrue(e.isUniform(6))
150 self.assertTrue(f.isUniform(6))
151 self.assertEqual(b.tolist(),[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6])
152 self.assertEqual(a.tolist(),[[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6]])
154 del b # no impact on e and f because a is the base of a.
155 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
157 self.assertTrue(f.isIdentity())
158 self.assertTrue(e.isIdentity())
159 del a # a destroyed, but as c has its base set to a, a exists -> e and f not allocated
160 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
162 self.assertTrue(f.isIdentity())
163 self.assertTrue(e.isIdentity())
164 del c # c killed -> a killed -> e and d are put into not allocated state
165 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
167 self.assertTrue(not e.isAllocated())
168 self.assertTrue(not f.isAllocated())
171 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
173 a=arange(20,dtype=int32)
174 self.assertTrue(a.flags["OWNDATA"])
175 d=DataArrayInt(a) # d owns data of a
176 self.assertTrue(not a.flags["OWNDATA"])
177 d.pushBackSilent(20)# d pushBack so release of chunk of data -> a becomes owner of its data again
178 self.assertTrue(a.flags["OWNDATA"])
179 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])))
180 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])
183 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
186 a=array(0,dtype=float64)
189 self.assertEqual(getrefcount(a),2)
190 a=a.cumsum(dtype=float64)
191 self.assertEqual(getrefcount(a),2)
195 e=DataArrayDouble(sz) ; e.fillWithValue(2)
196 self.assertTrue(d.isEqual(e,1e-14))
198 a[:]=4 ; e.fillWithValue(4)
199 self.assertTrue(d.isEqual(e,1e-14))
202 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
205 a=array(0,dtype=float64)
207 self.assertEqual(getrefcount(a),2)
209 self.assertEqual(getrefcount(a),3)
210 self.assertEqual(getrefcount(b),2)
214 e=DataArrayDouble(sz*2) ; e.fillWithValue(5)
215 self.assertTrue(d.isEqual(e,1e-14))
218 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
221 a=array(0,dtype=float64)
228 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))
230 a=zeros((10,2),dtype=float64)
236 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))
239 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
241 a=zeros(20,dtype=float64)
243 self.assertRaises(InterpKernelException,DataArrayDouble.New,b) # b is not contiguous in memory
246 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
248 a=arange(20,dtype=float64)
249 self.assertEqual(weakref.getweakrefcount(a),0)
251 self.assertEqual(weakref.getweakrefcount(a),1)
252 self.assertTrue(not a.flags["OWNDATA"])
253 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))
254 self.assertEqual(len(d),20)
255 a[:]=2 # modifying a and d because a and d share the same chunk of data
256 self.assertTrue(d.isUniform(2,1e-14))
257 del d # d is destroyed, a retrieves its ownership of its initial chunk of data
258 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
261 self.assertTrue(a.flags["OWNDATA"])
262 a[:]=4 # a can be used has usual
263 self.assertTrue(DataArrayDouble(a).isUniform(4,1e-14))
266 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
268 a=arange(20,dtype=float64)
269 d=DataArrayDouble(a) # d owns data of a
270 e=DataArrayDouble(a) # a not owned -> e only an access to chunk of a
271 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))
272 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))
274 self.assertTrue(d.isUniform(6,1e-14))
275 self.assertTrue(e.isUniform(6,1e-14))
276 del a # a destroyed -> d no change because owned and e array is has no more data set
277 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
280 self.assertTrue(d.isUniform(6,1e-14))
281 self.assertTrue(not e.isAllocated())
284 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
286 a=array(0,dtype=float64) ; a.resize(10,2)
289 d=DataArrayDouble(b) # d owns data of a
290 e=DataArrayDouble(b) # a not owned -> e only an access to chunk of a
291 f=DataArrayDouble(b) # a not owned -> e only an access to chunk of a
292 del d # d removed -> a ownes again data
293 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
296 self.assertTrue(e.isUniform(0,1e-14))
298 self.assertTrue(e.isUniform(6,1e-14))
299 self.assertTrue(f.isUniform(6,1e-14))
300 self.assertEqual(b.tolist(),[6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6])
301 self.assertEqual(a.tolist(),[[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6],[6,6]])
303 del b # no impact on e and f because a is the base of a.
304 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
306 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))
307 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))
308 del a # a destroyed, but as c has its base set to a, a exists -> e and f not allocated
309 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
311 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))
312 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))
313 del c # c killed -> a killed -> e and d are put into not allocated state
314 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
316 self.assertTrue(not e.isAllocated())
317 self.assertTrue(not f.isAllocated())
320 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
322 a=arange(20,dtype=float64)
323 self.assertTrue(a.flags["OWNDATA"])
324 d=DataArrayDouble(a) # d owns data of a
325 self.assertTrue(not a.flags["OWNDATA"])
326 d.pushBackSilent(20)# d pushBack so release of chunk of data -> a becomes owner of its data again
327 self.assertTrue(a.flags["OWNDATA"])
328 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))
329 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])
332 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
334 d=DataArrayInt.Range(0,20,1)
336 self.assertTrue(not a.flags["OWNDATA"])
338 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])))
339 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,100,100])
341 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
344 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])))
348 self.assertTrue(not a.flags["OWNDATA"])
350 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)))
351 self.assertEqual(a.tolist(),[[0,1],[2,3],[4,5],[6,7],[8,9],[10,11],[12,13],[14,15],[200,200],[200,200]])
353 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
355 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)))
358 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
360 d=DataArrayInt.Range(0,20,1)
361 d=d.convertToDblArr()
363 self.assertTrue(not a.flags["OWNDATA"])
365 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))
366 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,100,100])
368 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
371 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))
375 self.assertTrue(not a.flags["OWNDATA"])
377 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))
378 self.assertEqual(a.tolist(),[[0,1],[2,3],[4,5],[6,7],[8,9],[10,11],[12,13],[14,15],[200,200],[200,200]])
380 ##@@ Ensure a pass of the garbage collector so that the de-allocator of d is called
382 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))
385 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
388 a=array(0,dtype=int32)
391 self.assertEqual(getrefcount(a),2)
393 self.assertEqual(10,d.getNumberOfTuples())
394 self.assertEqual(2,d.getNumberOfComponents())
395 self.assertEqual(sz,d.getNbOfElems())
396 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)])))
398 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)])))
401 self.assertRaises(InterpKernelException,DataArrayInt.New,b) # b has not dimension in [0,1] !
404 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
407 a=array(0,dtype=float64)
410 self.assertEqual(getrefcount(a),2)
412 self.assertEqual(10,d.getNumberOfTuples())
413 self.assertEqual(2,d.getNumberOfComponents())
414 self.assertEqual(sz,d.getNbOfElems())
415 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))
417 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))
420 self.assertRaises(InterpKernelException,DataArrayDouble.New,b) # b has not dimension in [0,1] !
423 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
425 #tests that only DataArray*(npArray) contructor is available
426 a=array(0,dtype=int32)
429 self.assertRaises(InterpKernelException,DataArrayInt.New,a,20)
430 self.assertRaises(InterpKernelException,DataArrayInt.New,a,20,1)
431 a=array(0,dtype=float64)
434 self.assertRaises(InterpKernelException,DataArrayDouble.New,a,20)
435 self.assertRaises(InterpKernelException,DataArrayDouble.New,a,20,1)
438 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
440 d=DataArrayDouble(10)
443 self.assertTrue(not a.flags["OWNDATA"])
446 self.assertTrue(a.flags["OWNDATA"])
447 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
452 self.assertTrue(not a.flags["OWNDATA"])
455 self.assertTrue(a.flags["OWNDATA"])
456 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
459 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
461 d=DataArrayDouble(10)
466 self.assertTrue(not a.flags["OWNDATA"])
467 self.assertTrue(not b.flags["OWNDATA"])
468 self.assertTrue(not c.flags["OWNDATA"])
469 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
470 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
471 self.assertEqual(c.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
474 self.assertTrue(a.flags["OWNDATA"])
475 self.assertTrue(not b.flags["OWNDATA"])
476 self.assertTrue(not c.flags["OWNDATA"])
477 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
478 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
479 self.assertEqual(c.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
486 self.assertTrue(not a.flags["OWNDATA"])
487 self.assertTrue(not b.flags["OWNDATA"])
488 self.assertTrue(not c.flags["OWNDATA"])
489 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
490 self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
491 self.assertEqual(c.tolist(),[0,1,2,3,4,5,6,7,8,9])
494 self.assertTrue(a.flags["OWNDATA"])
495 self.assertTrue(not b.flags["OWNDATA"])
496 self.assertTrue(not c.flags["OWNDATA"])
497 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
498 self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
499 self.assertEqual(c.tolist(),[0,1,2,3,4,5,6,7,8,9])
502 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
504 d=DataArrayDouble(10)
507 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
508 self.assertTrue(not a.flags["OWNDATA"])
509 self.assertTrue(a.base is None)
513 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
514 self.assertTrue(not a.flags["OWNDATA"])
515 self.assertTrue(a.base is None)
517 self.assertEqual(a.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
518 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
519 self.assertTrue(not a.flags["OWNDATA"])
520 self.assertTrue(not b.flags["OWNDATA"])
521 self.assertTrue(b.base is a)
524 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
525 self.assertTrue(not b.flags["OWNDATA"])
528 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
529 self.assertTrue(not b.flags["OWNDATA"])
534 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
535 self.assertTrue(not a.flags["OWNDATA"])
536 self.assertTrue(a.base is None)
540 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
541 self.assertTrue(not a.flags["OWNDATA"])
542 self.assertTrue(a.base is None)
544 self.assertEqual(a.tolist(),[0,1,2,3,4,5,6,7,8,9])
545 self.assertEqual(b.tolist(),[0,1,2,3,4,5,6,7,8,9])
546 self.assertTrue(not a.flags["OWNDATA"])
547 self.assertTrue(not b.flags["OWNDATA"])
548 self.assertTrue(b.base is a)
551 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
552 self.assertTrue(not b.flags["OWNDATA"])
555 self.assertEqual(b.tolist(),[0.,1.,2.,3.,4.,5.,6.,7.,8.,9.])
556 self.assertTrue(not b.flags["OWNDATA"])
559 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
561 a=arange(10,dtype=int32)
565 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
566 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),10)
567 self.assertTrue(d.isIdentity()) ; self.assertEqual(len(d),10)
568 c.pushBackSilent(10) # c and a,b are dissociated
569 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
570 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),11)
571 self.assertTrue(d.isIdentity()) ; self.assertEqual(len(d),10)
574 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
575 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),11)
576 self.assertTrue(not d.isAllocated())
579 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),11)
581 a=arange(10,dtype=int32)
584 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
585 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),10)
586 b.pushBackSilent(10) # c and a,b are dissociated
587 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),11)
588 self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),10)
591 self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),11)
592 self.assertTrue(not c.isAllocated())
595 self.assertTrue(not c.isAllocated())
597 a=float64(arange(5,dtype=int32))
601 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
602 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
603 self.assertTrue(d.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
604 c.pushBackSilent(10.) # c and a,b are dissociated
605 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
606 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
607 self.assertTrue(d.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
610 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
611 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
612 self.assertTrue(not d.isAllocated())
615 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
617 a=float64(arange(5,dtype=int32))
620 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
621 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
622 b.pushBackSilent(10.) # c and a,b are dissociated
623 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
624 self.assertTrue(c.isEqual(DataArrayDouble([0.,1.,2.,3.,4.]),1e-12))
627 self.assertTrue(b.isEqual(DataArrayDouble([0.,1.,2.,3.,4.,10.]),1e-12))
628 self.assertTrue(not c.isAllocated())
631 self.assertTrue(not c.isAllocated())
634 @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
636 d=DataArrayInt(15) ; d.iota()
639 self.assertEqual(a.ndim,2)
640 self.assertEqual(a.size,15)
641 self.assertEqual(a.shape,(5,3))
642 self.assertEqual(a.strides,(12,4))
643 self.assertEqual(a.nbytes,60)
644 self.assertEqual(a.itemsize,4)
645 self.assertEqual(a.tolist(),[[0,1,2],[3,4,5],[6,7,8],[9,10,11],[12,13,14]])
647 d2=d.convertToDblArr()
649 self.assertEqual(a2.ndim,2)
650 self.assertEqual(a2.size,15)
651 self.assertEqual(a2.shape,(5,3))
652 self.assertEqual(a2.strides,(24,8))
653 self.assertEqual(a2.nbytes,120)
654 self.assertEqual(a2.itemsize,8)
655 self.assertEqual(a2.tolist(),[[0.,1.,2.],[3.,4.,5.],[6.,7.,8.],[9.,10.,11.],[12.,13.,14.]])
662 #gc.set_debug(gc.DEBUG_LEAK)