Debian Codegraph @

wxgeometrie/mathlib/internal_objects.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 ##--------------------------------------#######
4 # Objets mathlib #
5 ##--------------------------------------#######
6 # WxGeometrie
7 # Dynamic geometry, graph plotter, and more for french mathematic teachers.
8 # Copyright (C) 2005-2013 Nicolas Pourcelot
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
24 import numpy
25
26 UfuncType = type(numpy.absolute)
27 fonctions_numpy = [key for key, val in numpy.__dict__.items() if type(val) == UfuncType]
28
29 class ObjetMathematique(object):
30 "Classe mère de la plupart des objets mathématiques."
31
32 def __lt__(self, y):
33 return not self >= y
34
35 def __ge__(self, y):
36 return self > y or self == y
37
38 def __le__(self, y):
39 return not self > y
40
41 def __ne__(self, y):
42 return not self.__eq__(y)
43
44 def __bool__(self): # la valeur logique de l'objet (la doc officielle est fausse ??)
45 return self != 0 # utilisée dans un test "if" par exemple.
46
47 def __truediv__(self, y):
48 return self.__div__(y)
49
50 def __rtruediv__(self, y):
51 return self.__rdiv__(y)
52
53 def __sub__(self, y): return self + (- y)
54
55 def __rsub__(self, y): return y + (- self)
56
57 def __radd__(self,y): return self.__add__(y)
58
59 def __rmul__(self, y): return self.__mul__(y)
60
61 def __pos__(self): return self
62
63
64
65 class Reel(ObjetMathematique):
66 """Classe mère pour les objets mathématiques supportant les fonctions usuelles.
67 Permet de leur appliquer les opérations mathématiques de pylab."""
68
69 for nom in fonctions_numpy:
70 exec("""
71 def %s(self, *args):
72 arguments = []
73 for arg in args:
74 arguments.append(float(arg))
75 return numpy.%s(float(self), *arguments)""" %(nom, nom))
76 del nom