[Matrix-SIG] problems pickling arrays of PyObjects
Alan Grossfield
alan@groucho.med.jhmi.edu
Tue, 27 Oct 1998 13:50:59 -0500
Konrad>Now that I understand what the problem really is, the explanation is
Konrad>fairly simple: There is no provision to pickle general-object arrays
Konrad>at all in the current NumPy code, as is obvious from a quick glance at
Konrad>module Numeric. The pickled file contains simply the addresses of the
Konrad>elements.
Konrad>
Konrad>Array pickling needs a serious revision anyway (with cPickle support),
Here's a trivial patch to Numeric.py, which makes it complain if
you try to pickle an array of PyObjects.
diff -u Numeric.py.orig Numeric.py
--- Numeric.py.orig Tue Oct 27 13:15:24 1998
+++ Numeric.py Tue Oct 27 13:19:50 1998
@@ -186,6 +186,10 @@
# byte-order issues for portability.
def DumpArray(m, fp):
+
+ # patch -- check for array of PyObjects
+ if m.typecode() == 'O':
+ raise TypeError, "Numeric Pickler can't pickle arrays of Objects"
s = m.shape
if LittleEndian: endian = "L"
else: endian = "B"
Alan Grossfield
--------------------------------------------------------------------------
|"In theory, there is no difference between theory and practice. In |
|practice, there is." Jan L.A. van de Snepscheut |
--------------------------------------------------------------------------