Issue 239 in mpmath: save and load data - ValueError: invalid digits

10 views
Skip to first unread message

mpm...@googlecode.com

unread,
May 22, 2013, 5:01:53 PM5/22/13
to mpmath...@googlegroups.com
Status: New
Owner: ----

New issue 239 by vaclav.s...@gtempaccount.com: save and load data -
ValueError: invalid digits
http://code.google.com/p/mpmath/issues/detail?id=239

I have stored some data using mpmath (backend = 'python').
I wanted to try mpmath with 'gmpy' but I cannot load my old data.

NOT WORKING - saving with 'python' backend and loading with 'gmpy' backend
WORKING - saving with 'gmpy' backend and loading with 'python' or 'gmpy'
backend


What steps will reproduce the problem?

######## SAVE DATA - mpmath.libmp.BACKEND == 'python'
#############################
import numpy as np
import pickle
import os
os.environ['MPMATH_NOGMPY'] = 'Y'
import mpmath as mp
mp.mp.dps = 1000

a = mp.mpf('1') / mp.mpf('3')
b = mp.mpf('1') / mp.mpf('10')
arr = np.array([a, b], dtype=object)

# save array as npy
np.save('data', arr)

# pickle variable a
output = open('data.pkl', 'wb')
pickle.dump(a, output)
output.close()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

######## LOAD DATA - mpmath.libmp.BACKEND == 'gmpy'
#############################
import numpy as np
import pickle
import os
# os.environ['MPMATH_NOGMPY'] = 'Y'
import mpmath as mp
mp.mp.dps = 1000

data = np.load(r'data.npy')
print data

pkl_file = open('data.pkl', 'rb')
data = pickle.load(pkl_file)
pkl_file.close()
print data
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


What is the expected output? What do you see instead?

#### EXPECTED OUTPUT #############################################
[ mpf('0.33333333333...')
mpf('0.100000000000...')]
0.333333333333333333...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#### REAL OUTPUT #############################################
Traceback (most recent call last):
File "/home/kelidas/workspace_git/scratch/scratch/recursion/test.py",
line 21, in <module>
data = np.load(r'data.npy')
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/npyio.py", line
378, in load
return format.read_array(fid)
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/format.py", line
449, in read_array
array = cPickle.load(fp)
File "/usr/local/lib/python2.7/dist-packages/mpmath/ctx_mp_python.py",
line 132, in __setstate__
def __setstate__(self, val): self._mpf_ = from_pickable(val)
File "/usr/local/lib/python2.7/dist-packages/mpmath/libmp/libmpf.py",
line 43, in from_pickable
return (sign, MPZ(man, 16), exp, bc)
ValueError: invalid digits
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


What version of the product are you using? On what operating system?
mpmath 0.17, kubuntu 11.10 32bit, Python 2.7.2+, gmpy2 2.0.0
mpmath 0.17, Windows 7 64bit, Enthought Canopy - Python 2.7.3, gmpy 1.15


Please provide any additional information below.



--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

mpm...@googlecode.com

unread,
Jun 12, 2013, 6:23:43 AM6/12/13
to mpmath...@googlegroups.com

Comment #1 on issue 239 by vaclav.s...@gtempaccount.com: save and load data
I solved this problem temporarily by changing "MPZ" to "long" in
mpmath/libmp/libmpf.py.

def from_pickable(x):
sign, man, exp, bc = x
return (sign, long(man, 16), exp, bc)
Reply all
Reply to author
Forward
0 new messages