Salome HOME
Remove DataArrayInt::isIdentity-> DataArrayInt::isIdentity2 for everybody. Remove...
[tools/medcoupling.git] / src / MEDCoupling_Swig / MEDCouplingNumPyTest.py
index 78dc02d1809640f9fbeb35e17b8c4fad6a81034c..308e33e27786fa9d30e45fd117cd1f9be5348956 100644 (file)
@@ -1,10 +1,10 @@
 #  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2013  CEA/DEN, EDF R&D
+# Copyright (C) 2007-2015  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# version 2.1 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -17,7 +17,6 @@
 #
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
-# 
 
 from MEDCoupling import *
 
@@ -25,6 +24,7 @@ if MEDCouplingHasNumPyBindings():
     from numpy import *
     pass
 
+from platform import architecture
 from sys import getrefcount
 
 import os,gc,weakref,unittest
@@ -39,6 +39,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         a[:]=4
         self.assertEqual(getrefcount(a),2)
         a=a.cumsum(dtype=int32)
+        a=array(a,dtype=int64) ; a=array(a,dtype=int32)
         self.assertEqual(getrefcount(a),2)
         d=DataArrayInt(a)
         d[:]=2
@@ -101,8 +102,7 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         d=DataArrayInt(a)
         self.assertEqual(weakref.getweakrefcount(a),1)
         self.assertTrue(not a.flags["OWNDATA"])
-        self.assertTrue(d.isIdentity())
-        self.assertEqual(len(d),20)
+        self.assertTrue(d.isIdentity2(20))
         a[:]=2 # modifying a and d because a and d share the same chunk of data
         self.assertTrue(d.isUniform(2))
         del d # d is destroyed, a retrieves its ownership of its initial chunk of data
@@ -119,8 +119,8 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         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 
-        self.assertTrue(d.isIdentity())
-        self.assertTrue(e.isIdentity())
+        self.assertTrue(d.isIdentity2(d.getNumberOfTuples()))
+        self.assertTrue(e.isIdentity2(e.getNumberOfTuples()))
         a[:]=6
         self.assertTrue(d.isUniform(6))
         self.assertTrue(e.isUniform(6))
@@ -154,13 +154,13 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         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.isIdentity())
-        self.assertTrue(e.isIdentity())
+        self.assertTrue(f.isIdentity2(f.getNumberOfTuples()))
+        self.assertTrue(e.isIdentity2(e.getNumberOfTuples()))
         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.isIdentity())
-        self.assertTrue(e.isIdentity())
+        self.assertTrue(f.isIdentity2(f.getNumberOfTuples()))
+        self.assertTrue(e.isIdentity2(e.getNumberOfTuples()))
         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()        
@@ -562,33 +562,33 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         b=DataArrayInt(a)
         c=DataArrayInt(a)
         d=DataArrayInt(a)
-        self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
-        self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),10)
-        self.assertTrue(d.isIdentity()) ; self.assertEqual(len(d),10)
+        self.assertTrue(b.isIdentity2(10))
+        self.assertTrue(c.isIdentity2(10))
+        self.assertTrue(d.isIdentity2(10))
         c.pushBackSilent(10) # c and a,b are dissociated
-        self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
-        self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),11)
-        self.assertTrue(d.isIdentity()) ; self.assertEqual(len(d),10)
+        self.assertTrue(b.isIdentity2(10))
+        self.assertTrue(c.isIdentity2(11))
+        self.assertTrue(d.isIdentity2(10))
         del a
         gc.collect()
-        self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
-        self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),11)
+        self.assertTrue(b.isIdentity2(10))
+        self.assertTrue(c.isIdentity2(11))
         self.assertTrue(not d.isAllocated())
         del b
         gc.collect()
-        self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),11)
+        self.assertTrue(c.isIdentity2(11))
         #
         a=arange(10,dtype=int32)
         b=DataArrayInt(a)
         c=DataArrayInt(a)
-        self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),10)
-        self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),10)
+        self.assertTrue(b.isIdentity2(10))
+        self.assertTrue(c.isIdentity2(10))
         b.pushBackSilent(10) # c and a,b are dissociated
-        self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),11)
-        self.assertTrue(c.isIdentity()) ; self.assertEqual(len(c),10)
+        self.assertTrue(b.isIdentity2(11))
+        self.assertTrue(c.isIdentity2(10))
         del a
         gc.collect()
-        self.assertTrue(b.isIdentity()) ; self.assertEqual(len(b),11)
+        self.assertTrue(b.isIdentity2(11))
         self.assertTrue(not c.isAllocated())
         del b
         gc.collect()
@@ -655,6 +655,14 @@ class MEDCouplingNumPyTest(unittest.TestCase):
         self.assertEqual(a2.tolist(),[[0.,1.,2.],[3.,4.,5.],[6.,7.,8.],[9.,10.,11.],[12.,13.,14.]])
         pass
 
+    @unittest.skipUnless(MEDCouplingHasNumPyBindings(),"requires numpy")
+    def test27(self):
+        m0=DenseMatrix(DataArrayDouble([2,3,4,5,1,6]),2,3)
+        m0np=m0.toNumPyMatrix()
+        self.assertEqual(m0np.shape,(2,3))
+        self.assertEqual(m0np.tolist(),[[2.0,3.0,4.0],[5.0,1.0,6.0]])
+        pass
+
     def setUp(self):
         pass
     pass