Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

don't special case for py3k+numpy #587

Closed
wants to merge 1 commit into from

2 participants

Min RK Thomas Kluyver
Min RK
Owner

py3k+numpy non-copying recv works fine now, with released pyzmq. There was no need to make any changes in pyzmq.

shoudl close #478

Min RK minrk don't special case for py3k+numpy
py3k+numpy non-copying recv works fine now, with released pyzmq.  There was no need to make any changes in pyzmq.

closes gh-478
22b4e57
Thomas Kluyver
Owner

Great, thanks. Did something change in numpy or did you just find a way to do it?

Min RK
Owner

I figured something out wrt memoryviews, it wasn't a numpy or pyzmq problem.

Min RK minrk closed this pull request from a commit
Min RK minrk don't special case for py3k+numpy
py3k+numpy non-copying recv works fine now, with released pyzmq.  There was no need to make any changes in pyzmq.

closes gh-478, closes gh-587 (rebased)
487466d
Min RK minrk closed this in 487466d
Fernando Perez fperez referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
matthew von rocketstein mattvonrocketstein referenced this pull request from a commit in mattvonrocketstein/ipython
Min RK minrk don't special case for py3k+numpy
py3k+numpy non-copying recv works fine now, with released pyzmq.  There was no need to make any changes in pyzmq.

closes gh-478, closes gh-587 (rebased)
398ed43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 16, 2011
  1. Min RK

    don't special case for py3k+numpy

    minrk authored
    py3k+numpy non-copying recv works fine now, with released pyzmq.  There was no need to make any changes in pyzmq.
    
    closes gh-478
This page is out of date. Refresh to see the latest.
8 IPython/parallel/tests/test_newserialized.py
View
@@ -16,6 +16,8 @@
# Imports
#-------------------------------------------------------------------------------
+import sys
+
from unittest import TestCase
from IPython.testing.decorators import parametric
@@ -23,6 +25,8 @@
from IPython.utils.pickleutil import can, uncan, CannedObject, CannedFunction
from IPython.parallel.tests.clienttest import skip_without
+if sys.version_info[0] >= 3:
+ buffer = memoryview
class CanningTestCase(TestCase):
def test_canning(self):
@@ -88,10 +92,10 @@ def test_ndarray_serialized(self):
self.assertEquals(md['shape'], a.shape)
self.assertEquals(md['dtype'], a.dtype.str)
buff = ser1.getData()
- self.assertEquals(buff, numpy.getbuffer(a))
+ self.assertEquals(buff, buffer(a))
s = ns.Serialized(buff, td, md)
final = ns.unserialize(s)
- self.assertEquals(numpy.getbuffer(a), numpy.getbuffer(final))
+ self.assertEquals(buffer(a), buffer(final))
self.assertTrue((a==final).all())
self.assertEquals(a.dtype.str, final.dtype.str)
self.assertEquals(a.shape, final.shape)
14 IPython/utils/newserialized.py
View
@@ -35,6 +35,8 @@ class SerializationError(Exception):
py3k = True
else:
py3k = False
+ if sys.version_info[:2] <= (2,6):
+ memoryview = buffer
#-----------------------------------------------------------------------------
# Classes and functions
@@ -101,10 +103,7 @@ def __init__(self, unSerialized):
self.data = None
self.obj = unSerialized.getObject()
if numpy is not None and isinstance(self.obj, numpy.ndarray):
- if py3k or len(self.obj.shape) == 0: # length 0 arrays are just pickled
- # FIXME:
- # also use pickle for numpy arrays on py3k, since
- # pyzmq doesn't rebuild from memoryviews properly
+ if len(self.obj.shape) == 0: # length 0 arrays are just pickled
self.typeDescriptor = 'pickle'
self.metadata = {}
else:
@@ -125,7 +124,7 @@ def __init__(self, unSerialized):
def _generateData(self):
if self.typeDescriptor == 'ndarray':
- self.data = numpy.getbuffer(self.obj)
+ self.data = buffer(self.obj)
elif self.typeDescriptor in ('bytes', 'buffer'):
self.data = self.obj
elif self.typeDescriptor == 'pickle':
@@ -158,11 +157,10 @@ def getObject(self):
typeDescriptor = self.serialized.getTypeDescriptor()
if numpy is not None and typeDescriptor == 'ndarray':
buf = self.serialized.getData()
- if isinstance(buf, (bytes, buffer)):
+ if isinstance(buf, (bytes, buffer, memoryview)):
result = numpy.frombuffer(buf, dtype = self.serialized.metadata['dtype'])
else:
- # memoryview
- result = numpy.array(buf, dtype = self.serialized.metadata['dtype'])
+ raise TypeError("Expected bytes or buffer/memoryview, but got %r"%type(buf))
result.shape = self.serialized.metadata['shape']
elif typeDescriptor == 'pickle':
result = pickle.loads(self.serialized.getData())
Something went wrong with that request. Please try again.