[Numpy-discussion] Is numpy supposed to support the buffer protocol?
Christopher Barker
Chris.Barker at noaa.gov
Mon Aug 28 18:25:44 CDT 2006
HI all,
Robin Dunn has been working on adding better support for dumping data
directly to wxPython from the num* packages. I've been talking to him
about the new array interface, and he might well support it
(particularly if one of us contributes code), but in the meantime, he's
got a number of things working with python buffers. For instance:
wx.Image.SetDataBuffer(dataBuffer)
That sets the data for a wxImage to the buffer handed in. This isn't as
nice as the array protocol, as it has no way of checking anything other
than if the length of the buffer is correct, but it is a good way to
maximize performance for this sort of thing.
he's now working on adding methods for creating wx.Bitmaps directly from
buffers. In the process if testing some of this, I discovered that
numarray (which Robin is testing with) works fine, but numpy does not. I
get:
File "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-unicode/wx/_core.py",
line 2814, in SetDataBuffer
return _core_.Image_SetDataBuffer(*args, **kwargs)
TypeError: non-character array cannot be interpreted as character buffer
If I try to pass in a numpy array, while it works great with a numarray
array.
While I'm a great advocate of the new array protocol, it seems
supporting the buffer protocol also would be a good idea. I've enclosed
some simple test code. It works with numarray, but not numpy 1.0b4
Tested with Python 2.4.3, wxPython 2.6.3.0, Linux fedora core4
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ImageBuffer2.py
Type: text/x-python
Size: 793 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060828/156cbd2f/attachment.py
More information about the Numpy-discussion
mailing list