upiterbarg / mpmath

Automatically exported from code.google.com/p/mpmath
Other
0 stars 0 forks source link

mpmathify should work for complex sympy numbers #154

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
>>> from sympy import *
>>> mpmath.mpmathify(S(1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy/mpmath/mptypes.py", line 363, in convert
    raise TypeError("cannot create mpf from " + repr(x))
TypeError: cannot create mpf from 1

Let's also make sure that sympy matrices are supported.

Original issue reported on code.google.com by Vinzent.Steinberg@gmail.com on 30 Jul 2009 at 11:16

GoogleCodeExporter commented 9 years ago
Are you working on this?

Original comment by fredrik....@gmail.com on 31 Jul 2009 at 7:27

GoogleCodeExporter commented 9 years ago
I was not, but I probably will do it soon, as this is imho important and easy 
to fix.

Original comment by Vinzent.Steinberg@gmail.com on 5 Aug 2009 at 3:59

GoogleCodeExporter commented 9 years ago
Should this be fixed in sympy (adding an _mpmath_ attribute, for which 
mpmathify is
already checking) or in mpmath?

Original comment by Vinzent.Steinberg@gmail.com on 6 Aug 2009 at 8:21

GoogleCodeExporter commented 9 years ago
Adding _mpmath_ to sympy is certainly preferrable, as otherwise mpmath will 
need to
worry about sympy internals.

Original comment by fredrik....@gmail.com on 6 Aug 2009 at 8:26

GoogleCodeExporter commented 9 years ago
There is already Number._as_mpf_val(prec), which should do the job. Which 
precision
should be used when converting to mpf? Should mpmathify convert sympy integers 
to
Python integers?

Original comment by Vinzent.Steinberg@gmail.com on 6 Aug 2009 at 9:00

GoogleCodeExporter commented 9 years ago
> which should do the job. Which precision should be used when converting to 
mpf?

What do you mean? mpmathify calls x._mpmath_ with the appropriate precision.

> Should mpmathify convert sympy integers to Python integers?

The easiest solution might be to add an _mpf_ property to sympy integers (not 
sure if
that will break anything).

Original comment by fredrik....@gmail.com on 6 Aug 2009 at 9:18

GoogleCodeExporter commented 9 years ago
So why not rename _as_mpf_val to _mpmath_? (Should work for Rational.)

I'd add just add an _mpmath_ property to Integer.

Original comment by Vinzent.Steinberg@gmail.com on 6 Aug 2009 at 9:50

GoogleCodeExporter commented 9 years ago
I sent a patch to the sympy list. What about complex numbers? This has to be
implemented in mpmath, unless Add grows an _mpmath_ method.

Original comment by Vinzent.Steinberg@gmail.com on 13 Aug 2009 at 12:03

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
It fixed it in sympy HEAD, and added support in mpmathify for matrices.
I'm not sure how to support complex numbers.

Original comment by Vinzent.Steinberg@gmail.com on 14 Aug 2009 at 8:07

GoogleCodeExporter commented 9 years ago
Easiest way to enable conversion for any SymPy object is to add _mpmath_ to 
Basic and
have it call evalf.

Original comment by fredrik....@gmail.com on 22 Aug 2009 at 8:41