Skip to content
This repository

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
minrk commented July 16, 2011

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 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
Collaborator

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

Min RK
Owner
minrk commented July 16, 2011

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

Min RK minrk closed this pull request from a commit July 16, 2011
Min RK 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 August 15, 2011
Fernando Perez fperez referenced this pull request from a commit January 10, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 16, 2011
Min RK 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
This page is out of date. Refresh to see the latest.
8  IPython/parallel/tests/test_newserialized.py
@@ -16,6 +16,8 @@
16 16
 # Imports
17 17
 #-------------------------------------------------------------------------------
18 18
 
  19
+import sys
  20
+
19 21
 from unittest import TestCase
20 22
 
21 23
 from IPython.testing.decorators import parametric
@@ -23,6 +25,8 @@
23 25
 from IPython.utils.pickleutil import can, uncan, CannedObject, CannedFunction
24 26
 from IPython.parallel.tests.clienttest import skip_without
25 27
 
  28
+if sys.version_info[0] >= 3:
  29
+    buffer = memoryview
26 30
 
27 31
 class CanningTestCase(TestCase):
28 32
     def test_canning(self):
@@ -88,10 +92,10 @@ def test_ndarray_serialized(self):
88 92
         self.assertEquals(md['shape'], a.shape)
89 93
         self.assertEquals(md['dtype'], a.dtype.str)
90 94
         buff = ser1.getData()
91  
-        self.assertEquals(buff, numpy.getbuffer(a))
  95
+        self.assertEquals(buff, buffer(a))
92 96
         s = ns.Serialized(buff, td, md)
93 97
         final = ns.unserialize(s)
94  
-        self.assertEquals(numpy.getbuffer(a), numpy.getbuffer(final))
  98
+        self.assertEquals(buffer(a), buffer(final))
95 99
         self.assertTrue((a==final).all())
96 100
         self.assertEquals(a.dtype.str, final.dtype.str)
97 101
         self.assertEquals(a.shape, final.shape)
14  IPython/utils/newserialized.py
@@ -35,6 +35,8 @@ class SerializationError(Exception):
35 35
     py3k = True
36 36
 else:
37 37
     py3k = False
  38
+    if sys.version_info[:2] <= (2,6):
  39
+        memoryview = buffer
38 40
 
39 41
 #-----------------------------------------------------------------------------
40 42
 # Classes and functions
@@ -101,10 +103,7 @@ def __init__(self, unSerialized):
101 103
         self.data = None
102 104
         self.obj = unSerialized.getObject()
103 105
         if numpy is not None and isinstance(self.obj, numpy.ndarray):
104  
-            if py3k or len(self.obj.shape) == 0: # length 0 arrays are just pickled
105  
-                # FIXME:
106  
-                # also use pickle for numpy arrays on py3k, since
107  
-                # pyzmq doesn't rebuild from memoryviews properly
  106
+            if len(self.obj.shape) == 0: # length 0 arrays are just pickled
108 107
                 self.typeDescriptor = 'pickle'
109 108
                 self.metadata = {}
110 109
             else:
@@ -125,7 +124,7 @@ def __init__(self, unSerialized):
125 124
     
126 125
     def _generateData(self):
127 126
         if self.typeDescriptor == 'ndarray':
128  
-            self.data = numpy.getbuffer(self.obj)
  127
+            self.data = buffer(self.obj)
129 128
         elif self.typeDescriptor in ('bytes', 'buffer'):
130 129
             self.data = self.obj
131 130
         elif self.typeDescriptor == 'pickle':
@@ -158,11 +157,10 @@ def getObject(self):
158 157
         typeDescriptor = self.serialized.getTypeDescriptor()
159 158
         if numpy is not None and typeDescriptor == 'ndarray':
160 159
                 buf = self.serialized.getData()
161  
-                if isinstance(buf, (bytes, buffer)):
  160
+                if isinstance(buf, (bytes, buffer, memoryview)):
162 161
                     result = numpy.frombuffer(buf, dtype = self.serialized.metadata['dtype'])
163 162
                 else:
164  
-                    # memoryview
165  
-                    result = numpy.array(buf, dtype = self.serialized.metadata['dtype'])
  163
+                    raise TypeError("Expected bytes or buffer/memoryview, but got %r"%type(buf))
166 164
                 result.shape = self.serialized.metadata['shape']
167 165
         elif typeDescriptor == 'pickle':
168 166
             result = pickle.loads(self.serialized.getData())
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.