1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2008-2022 EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
22 "Test de fonctionnement et de performances de Numpy et Scipy"
29 numpy.set_printoptions(precision=5)
31 # ==============================================================================
32 class Test_Adao(unittest.TestCase):
33 def test1_Systeme(self):
36 print(" %s"%self.test1_Systeme.__doc__)
37 print(" Les caracteristiques des applications et outils systeme :")
38 import sys ; v=sys.version.split() ; print(" - Python systeme....: %s"%v[0])
39 import numpy ; print(" - Numpy.............: %s"%numpy.version.version)
41 import scipy ; print(" - Scipy.............: %s"%scipy.version.version)
43 print(" - Scipy.............: %s"%("absent",))
44 if tuple(map(int,numpy.version.version.split("."))) < (1,23,0):
45 import numpy.distutils.system_info as sysinfo
46 la = sysinfo.get_info('lapack')
48 print(' - Lapack............: %s/lib%s.so'%(la['library_dirs'][0],la['libraries'][0]))
50 print(' - Lapack............: absent')
52 print(' - Lapack............: numpy n\'indique plus où le trouver')
56 #~ @unittest.skip("Debug")
57 def test_Numpy01(self, dimension = 10000, precision = 1.e-17, repetitions = 10):
60 print(" %s"%self.test_Numpy01.__doc__)
61 print(" Taille du test..................................: %.0e"%__d)
63 A = numpy.array([numpy.arange(dimension)+1.,]*__d)
64 x = numpy.arange(__d)+1.
65 print(" La duree elapsed moyenne de l'initialisation est: %4.1f s"%(time.time()-t_init))
68 for i in range(repetitions):
70 print(" La duree elapsed pour %3i produits est de.......: %4.1f s"%(repetitions, time.time()-t_init))
71 r = [__d*(__d+1.)*(2.*__d+1.)/6.,]*__d
72 if max(abs(b-r)) > precision:
73 raise ValueError("Resultat du test errone (1)")
75 print(" Test correct, erreur maximale inferieure a %s"%precision)
79 #~ @unittest.skip("Debug")
80 def test_Numpy02(self, dimension = 3000, precision = 1.e-17, repetitions = 100):
83 print(" %s"%self.test_Numpy02.__doc__)
84 print(" Taille du test..................................: %.0e"%__d)
86 A = numpy.random.normal(0.,1.,size=(__d,__d))
87 x = numpy.random.normal(0.,1.,size=(__d,))
88 print(" La duree elapsed moyenne de l'initialisation est: %4.1f s"%(time.time()-t_init))
91 for i in range(repetitions):
93 print(" La duree elapsed pour %3i produits est de.......: %4.1f s"%(repetitions, time.time()-t_init))
97 #~ @unittest.skip("Debug")
98 def test_Scipy01(self, dimension = 3000, precision = 1.e-17, repetitions = 10):
101 print(" %s"%self.test_Scipy01.__doc__)
102 print(" Taille du test..................................: %.0e"%__d)
104 A = numpy.array([numpy.arange(dimension)+1.,]*__d)
105 x = numpy.arange(__d)+1.
106 print(" La duree elapsed moyenne de l'initialisation est: %4.1f s"%(time.time()-t_init))
109 for i in range(repetitions):
111 print(" La duree elapsed pour %3i produits est de.......: %4.1f s"%(repetitions, time.time()-t_init))
112 r = [__d*(__d+1.)*(2.*__d+1.)/6.,]*__d
113 if max(abs(b-r)) > precision:
114 raise ValueError("Resultat du test errone (1)")
116 print(" Test correct, erreur maximale inferieure a %s"%precision)
120 # ==============================================================================
121 if __name__ == "__main__":
122 numpy.random.seed(1000)
123 print("\nAUTODIAGNOSTIC\n==============")
124 sys.stderr = sys.stdout
125 unittest.main(verbosity=2)
127 print(" Les résultats obtenus sont corrects.")