[pypy-dev] works in python2.4, fails in pypy
Ondrej Certik
ondrej at certik.cz
Mon Aug 25 12:50:35 CEST 2008
On Mon, Aug 25, 2008 at 12:08 PM, Maciej Fijalkowski <fijall at gmail.com> wrote:
> I'm not sure whether it's sympy's fault or pypy's fault. It might be
> that pypy is too strict about that.
>
> Arguments look like this:
>
> (Pdb++) bases[0].__mro__
> (Function, <class 'sympy.core.basic.Basic'>, <class
> 'sympy.core.assumptions.AssumeMeths'>, <type 'object'>)
> (Pdb++) bases[1].__mro__
> (<class 'sympy.core.basic.Atom'>, <class 'sympy.core.basic.Basic'>,
> <class 'sympy.core.assumptions.AssumeMeths'>, <type 'object'>)
> (Pdb++) cls
> <class 'sympy.core.function.FunctionClass'>
> (Pdb++) cls.__mro__
> (<class 'sympy.core.function.FunctionClass'>, <class
> 'sympy.core.basic.BasicMeta'>, <class 'sympy.core.basic.BasicType'>,
> <type 'type'>, <type 'object'>)
> (Pdb++)
>
> And it seems that bases[0] and bases[1] are incompatible (why?)
Don't know. This patch fixes it:
diff --git a/sympy/core/function.py b/sympy/core/function.py
index 76a0f5b..a99c21d 100644
--- a/sympy/core/function.py
+++ b/sympy/core/function.py
@@ -362,7 +362,7 @@ class Function(Basic):
x = sympify(x)
return cls(x).diff(x, n).subs(x, 0) * x**n / C.Factorial(n)
-class WildFunction(Function, Atom):
+class WildFunction(Function):
"""
WildFunction() matches any expression but another WildFunction()
XXX is this as intended, does it work ?
But now there is this problem:
>>>> import sympy
Traceback (most recent call last):
File "<console>", line 1, in <interactive>
File "/home/ondra/repos/sympy/sympy/__init__.py", line 22, in <module>
from concrete import *
File "/home/ondra/repos/sympy/sympy/concrete/__init__.py", line 2, in <module>
from products import product, Product
File "/home/ondra/repos/sympy/sympy/concrete/products.py", line 5, in <module>
from sympy.simplify import powsimp
File "/home/ondra/repos/sympy/sympy/simplify/__init__.py", line 10,
in <module>
from rewrite import cancel, trim, apart
File "/home/ondra/repos/sympy/sympy/simplify/rewrite.py", line 22, in <module>
def cancel(f, *symbols):
TypeError: threaded() takes no non-keyword argument (1 given)
Any idea what's wrong here? Here is the code:
@threaded()
def cancel(f, *symbols):
"""Cancel common factors in a given rational function.
and:
def threaded(**flags):
Seems a-ok to me. Is pypy using some strict things? I don't know, but
this patch fixes it:
diff --git a/sympy/utilities/decorator.py b/sympy/utilities/decorator.py
index 0043de1..f812b51 100644
--- a/sympy/utilities/decorator.py
+++ b/sympy/utilities/decorator.py
@@ -3,7 +3,7 @@ from sympy.core.add import Add
from sympy.core.sympify import sympify
from sympy.core.relational import Relational
-def threaded(**flags):
+def threaded(*args, **flags):
Now it imports. Wow!
>>>> import sympy
>>>> from sympy import var
>>>> var("x y z")
(x, y, z)
>>>> x**2
x**2
>>>> from sympy import sin
>>>> e = sin(x)
>>>> e.series(x, 0, 5)
x - 1/6*x**3 + O(x**5)
Guys, this is awesome!
I did some timings:
$ ~/repos/pypy-dist/pypy/translator/goal/pypy-c
Python 2.4.1 (pypy 1.0.0 build 57617) on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``Python 300''
>>>> from sympy import *
>>>> var("x")
x
>>>> from timeit import default_timer as clock
>>>> t = clock(); a= sin(x).series(x, 0, 1000); t = clock()-t; print t
3.31447815895
Compare to python:
$ python
Python 2.5.2 (r252:60911, Aug 8 2008, 09:22:44)
[GCC 4.3.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy import *
>>> var("x")
x
>>> from timeit import default_timer as clock
>>> t = clock(); a= sin(x).series(x, 0, 1000); t = clock()-t; print t
0.704444885254
So pypy is roughly 4.7x slower on this particular thing.
Do you have any plans to release pypy? I think it's getting very useful.
Ondrej
More information about the Pypy-dev
mailing list