1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2008-2023 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')
55 #~ @unittest.skip("Debug")
56 def test_Numpy01(self, dimension = 10000, precision = 1.e-17, repetitions = 10):
59 print(" %s"%self.test_Numpy01.__doc__)
60 print(" Taille du test..................................: %.0e"%__d)
62 A = numpy.array([numpy.arange(dimension)+1.,]*__d)
63 x = numpy.arange(__d)+1.
64 print(" La duree elapsed moyenne de l'initialisation est: %4.1f s"%(time.time()-t_init))
67 for i in range(repetitions):
69 print(" La duree elapsed pour %3i produits est de.......: %4.1f s"%(repetitions, time.time()-t_init))
70 r = [__d*(__d+1.)*(2.*__d+1.)/6.,]*__d
71 if max(abs(b-r)) > precision:
72 raise ValueError("Resultat du test errone (1)")
74 print(" Test correct, erreur maximale inferieure a %s"%precision)
78 #~ @unittest.skip("Debug")
79 def test_Numpy02(self, dimension = 3000, precision = 1.e-17, repetitions = 100):
82 print(" %s"%self.test_Numpy02.__doc__)
83 print(" Taille du test..................................: %.0e"%__d)
85 A = numpy.random.normal(0.,1.,size=(__d,__d))
86 x = numpy.random.normal(0.,1.,size=(__d,))
87 print(" La duree elapsed moyenne de l'initialisation est: %4.1f s"%(time.time()-t_init))
90 for i in range(repetitions):
92 print(" La duree elapsed pour %3i produits est de.......: %4.1f s"%(repetitions, time.time()-t_init))
96 #~ @unittest.skip("Debug")
97 def test_Scipy01(self, dimension = 3000, precision = 1.e-17, repetitions = 10):
100 print(" %s"%self.test_Scipy01.__doc__)
101 print(" Taille du test..................................: %.0e"%__d)
103 A = numpy.array([numpy.arange(dimension)+1.,]*__d)
104 x = numpy.arange(__d)+1.
105 print(" La duree elapsed moyenne de l'initialisation est: %4.1f s"%(time.time()-t_init))
108 for i in range(repetitions):
110 print(" La duree elapsed pour %3i produits est de.......: %4.1f s"%(repetitions, time.time()-t_init))
111 r = [__d*(__d+1.)*(2.*__d+1.)/6.,]*__d
112 if max(abs(b-r)) > precision:
113 raise ValueError("Resultat du test errone (1)")
115 print(" Test correct, erreur maximale inferieure a %s"%precision)
119 # ==============================================================================
120 if __name__ == "__main__":
121 numpy.random.seed(1000)
122 print("\nAUTODIAGNOSTIC\n==============")
123 sys.stderr = sys.stdout
124 unittest.main(verbosity=2)
126 print(" Les résultats obtenus sont corrects.")