1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2008-2021 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",))
45 import numpy.distutils.system_info as sysinfo ; la = sysinfo.get_info('lapack') ; print(" - Lapack............: %s/lib%s.so"%(la['library_dirs'][0],la['libraries'][0]))
47 print(" - Lapack............: %s"%("absent",))
51 def test_Numpy01(self, dimension = 10000, precision = 1.e-17, repetitions = 10):
54 print(" %s"%self.test_Numpy01.__doc__)
55 print(" Taille du test..................................: %.0e"%__d)
57 A = numpy.array([numpy.arange(dimension)+1.,]*__d)
58 x = numpy.arange(__d)+1.
59 print(" La duree elapsed moyenne de l'initialisation est: %4.1f s"%(time.time()-t_init))
62 for i in range(repetitions):
64 print(" La duree elapsed pour %3i produits est de.......: %4.1f s"%(repetitions, time.time()-t_init))
65 r = [__d*(__d+1.)*(2.*__d+1.)/6.,]*__d
66 if max(abs(b-r)) > precision:
67 raise ValueError("Resultat du test errone (1)")
69 print(" Test correct, erreur maximale inferieure a %s"%precision)
73 def test_Numpy02(self, dimension = 3000, precision = 1.e-17, repetitions = 100):
76 print(" %s"%self.test_Numpy02.__doc__)
77 print(" Taille du test..................................: %.0e"%__d)
79 A = numpy.random.normal(0.,1.,size=(__d,__d))
80 x = numpy.random.normal(0.,1.,size=(__d,))
81 print(" La duree elapsed moyenne de l'initialisation est: %4.1f s"%(time.time()-t_init))
84 for i in range(repetitions):
86 print(" La duree elapsed pour %3i produits est de.......: %4.1f s"%(repetitions, time.time()-t_init))
90 def test_Scipy01(self, dimension = 3000, precision = 1.e-17, repetitions = 10):
93 print(" %s"%self.test_Scipy01.__doc__)
94 print(" Taille du test..................................: %.0e"%__d)
96 A = numpy.array([numpy.arange(dimension)+1.,]*__d)
97 x = numpy.arange(__d)+1.
98 print(" La duree elapsed moyenne de l'initialisation est: %4.1f s"%(time.time()-t_init))
101 for i in range(repetitions):
103 print(" La duree elapsed pour %3i produits est de.......: %4.1f s"%(repetitions, time.time()-t_init))
104 r = [__d*(__d+1.)*(2.*__d+1.)/6.,]*__d
105 if max(abs(b-r)) > precision:
106 raise ValueError("Resultat du test errone (1)")
108 print(" Test correct, erreur maximale inferieure a %s"%precision)
112 # ==============================================================================
113 if __name__ == "__main__":
114 numpy.random.seed(1000)
115 print("\nAUTODIAGNOSTIC\n==============")
116 sys.stderr = sys.stdout
117 unittest.main(verbosity=2)
119 print(" Les résultats obtenus sont corrects.")