[Numpy-discussion] segfault problem with numpy and pickle
David Bolme
bolme1234@comcast....
Thu Jan 24 14:18:45 CST 2008
A am having some trouble when pickling numpy arrays. Basically I use
one python script to create the array and then pickle it. When I load
the pickled array using a different python script it appears to load
fine. When I try to perform a matrix multiply on the array with a
vector (using dot) python crashes with a segmentation violation. The
array contains 64bit floating point numbers and has a shape of (47,
16384) and the vector has a shape of (16384,1). Other shapes I have
tested also have this problem. A workaround is to create a new array
that is initialized with the data from the first. For example:
a = array(pickle.loads(buffer))
After calling this command the script runs fine.
Here is some information on my system setup:
OS: Macos X Leopard 64bit Intel
numpy.version.version = 1.0.5.dev4624
Below is a simple script that reproduces this error on my system. I
would like to get this problem fixed so that I don't have to use this
work around every time I load a pickled array. Is this a known bug? I
could not find it in the bug tracker.
Thanks in advance for the help.
Dave
import pickle
from numpy import array,dot,ones,random
# Create the arrays
a = random.normal(size=(47,128*128))
b = ones((128*128,2))
c = ones((128*128,1))
# Test dot
print "Computing dot product on original arrays..."
print dot(a,b).shape # WORKS
print dot(a,c).shape # WORKS
print "Pickle and unpickel the array with workaround."
buffer = pickle.dumps(a)
a = array(pickle.loads(buffer))
# Test dot
print "Computing dot product with workaround..."
print dot(a,b).shape # WORKS
print dot(a,c).shape # WORKS
print "Pickle and unpickel the array without workaround."
a = pickle.loads(buffer)
# Test dot
print "Computing dot product without workaround..."
print dot(a,b).shape # WORKS
print dot(a,c).shape # CRASH
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080124/d4afef37/attachment.html
More information about the Numpy-discussion
mailing list