Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pickling fails with mpmath numbers #74

Closed
fredrik-johansson opened this issue Mar 27, 2008 · 4 comments
Closed

pickling fails with mpmath numbers #74

fredrik-johansson opened this issue Mar 27, 2008 · 4 comments
Labels
bug an unexpected problem or unintended behavior imported Priority-Medium

Comments

@fredrik-johansson
Copy link
Collaborator

Hello, in order to save large amounts of high-precision data,
I need to serialize mpmath numbers. Unfortunately, this fails with an
exception I don't understand, since the method **getstate** seems to be
defined (see below). Converting to and from strings is only a temporary
option, because it is way too slow and wastes space.

Example:

In [2]:import mpmath

In [3]:a = mpmath.mpc(1+2j)

In [4]:a
Out[4]:mpc(real='1.0', imag='2.0')

In [5]:import pickle

In [6]:pickle.dumps(a)

Results in:

<type 'exceptions.TypeError'>: a class that defines **slots** without
defining **getstate** cannot be pickled What version of the product are you using? On what operating system? Python 2.5
mpmath 0.7
on opensuse 10.2

Original issue for #74: http://code.google.com/p/mpmath/issues/detail?id=34

Original author: https://code.google.com/u/109204080795773808200/

@fredrik-johansson
Copy link
Collaborator Author

This bug has been fixed in svn.

If you don't want to install the svn version, you can make your copy of 0.7 work by
adding the following methods to the mpf class in mptypes.py:

```
def __getstate__(self): return self._mpf_
def __setstate__(self, val): self._mpf_ = val
```

And the following to the mpc class:

```
def __getstate__(self): return self._mpc_
def __setstate__(self, val): self._mpc_ = val
```

Original comment: http://code.google.com/p/mpmath/issues/detail?id=34#c1

Original author: https://code.google.com/u/111502149103757882156/

@fredrik-johansson
Copy link
Collaborator Author

I must correct myself: the **getstate** and **setstate** methods should only be added
to the mpf class.

Original comment: http://code.google.com/p/mpmath/issues/detail?id=34#c2

Original author: https://code.google.com/u/111502149103757882156/

@fredrik-johansson
Copy link
Collaborator Author

Pickling works with SVN version.
This is so cool!
Thanks!

Original comment: http://code.google.com/p/mpmath/issues/detail?id=34#c3

Original author: https://code.google.com/u/109204080795773808200/

@fredrik-johansson
Copy link
Collaborator Author

**Status:** Fixed  

Original comment: http://code.google.com/p/mpmath/issues/detail?id=34#c4

Original author: https://code.google.com/u/111502149103757882156/

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior imported Priority-Medium
Projects
None yet
Development

No branches or pull requests

1 participant