python-matplotlib: Exception when drawing image on 64-bit system

Bug #295719 reported by gpk
6
Affects Status Importance Assigned to Milestone
matplotlib
Unknown
Unknown
matplotlib (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

Binary package hint: python-matplotlib

This bug is also reported on the matplotlib sourceforge site, because I'm not sure if it's their
problem (i.e. code that is not 64-bit clean) or a packaging problem (i.e. some improper mix
of 32 and 64 bit code). Sorry for the duplication. Sourceforge bug ID: 2243945.

stars:~$ lsb_release -rd
Description: Ubuntu 8.10
Release: 8.10
stars:~$

stars:src$ apt-cache policy python-matplotlib
python-matplotlib:
  Installed: 0.98.3-4ubuntu1
  Candidate: 0.98.3-4ubuntu1
  Version table:
 *** 0.98.3-4ubuntu1 0
        500 http://gb.archive.ubuntu.com intrepid/universe Packages
        100 /var/lib/dpkg/status
stars:src$

When I run on a Ubuntu 8.10 system on an AMD-64 processor, I get an
exception:

Traceback (most recent call last):
File
"/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py", line
333, in expose_event
self._render_figure(self._pixmap, w, h)
File
"/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gtk.py", line
321, in _render_figure
self.figure.draw (self._renderer)
File "/usr/lib/python2.5/site-packages/matplotlib/figure.py", line 759,
in draw
for a in self.axes: a.draw(renderer)
File "/usr/lib/python2.5/site-packages/matplotlib/axes.py", line 1465, in
draw
im.draw(renderer)
File "/usr/lib/python2.5/site-packages/matplotlib/image.py", line 239, in
draw
*self.get_transformed_clip_path_and_affine())
File
"/usr/lib/python2.5/site-packages/matplotlib/backends/backend_gdk.py", line
119, in draw_image
array[:,:,:] = image_array
ValueError: shape mismatch: objects cannot be broadcast to a single shape

If I go into the backend_gdk.py code and add a print statement on the
relevant sizes
array = pixbuf_get_pixels_array(pixbuf)
print 'arrayshape=', array.shape, 'image_array.shape=',
image_array.shape, rows, cols
array[:,:,:] = image_array
I find that
arrayshape= (372, 0, 497) image_array.shape= (372, 497, 4) 372 497

The zero in the middle is particularly odd. This array is generated by
_backend_gdk.c in the vicinity of line 46, and the code looks fine,
but I'll bet dollars to doughnuts that it's a 32bit/64-bit problem.
The "dims" array is presumably 64-bit integers, and
PyArray_FromDimsAndData probably expects dims to be 32-bit integers.
As a result, it'd treat the high 32-bits of the first dimension as a
dimension in its own right (giving the zero), and put the low 32 bits
of the second dimension in the third slot.

Is this a Ubuntu packaging problem (somehow mixing 32 and 64 bit libraries)
or
is it a matplotlib problem?

Revision history for this message
Benjamin Drung (bdrung) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better. The package is build once for i386 and once for amd64. So there should be no 32 and 64 bit libraries mixed. Building matplotlib 0.98.3-6 on intrepid produces following warning. It looks like that the warning has something to do with this bug.

building 'matplotlib.backends._backend_gdk' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -O2 -fPIC -I/usr/lib/python2.4/site-packages/numpy/core/include -I/usr/include -I. -I/usr/include -I. -I/usr/include/pygtk-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/python2.4 -c src/backend_gdk.c -o build/temp.linux-x86_64-2.4/src/backend_gdk.o
In file included from /usr/include/gtk-2.0/gtk/gtk.h:224,
                 from /usr/include/pygtk-2.0/pygtk/pygtk.h:8,
                 from src/backend_gdk.c:9:
/usr/include/gtk-2.0/gtk/gtkitemfactory.h:47: warning: function declaration isn’t a prototype
src/backend_gdk.c: In function ‘pixbuf_get_pixels_array’:
src/backend_gdk.c:48: warning: passing argument 2 of ‘(struct PyObject * (*)(int, int *, struct PyArray_Descr *, char *))*(PyArray_API + 544u)’ from incompatible pointer type

Revision history for this message
Kjell Braden (afflux) wrote :

Can you please provide some come snippet to recreate this bug?

Changed in matplotlib:
status: New → Incomplete
Revision history for this message
gpk (gpk-kochanski) wrote :

At the moment, only a big complicated one. However, I think Benjamin Drung dug up
something worth inspecting. My bet is that he found the problem.

Please take a look at the incompatible pointer type problem he found; if that isn't relevant
or isn't trivial to fix, I'll boil my code down to a small test case.

Revision history for this message
Kjell Braden (afflux) wrote :

We are closing this bug report because it lacks the information we need to investigate the problem. If this still happens to you, please provide a test case.
Thanks for your understanding.

Changed in matplotlib:
status: Incomplete → Invalid
Revision history for this message
gpk (gpk-kochanski) wrote : Re: [Bug 295719] Re: python-matplotlib: Exception when drawing image on 64-bit system

It does, but I haven't had time to boil down the test case. Sorry.

Kjell Braden wrote:
> We are closing this bug report because it lacks the information we need to investigate the problem. If this still happens to you, please provide a test case.
> Thanks for your understanding.
>
> ** Changed in: matplotlib (Ubuntu)
> Status: Incomplete => Invalid
>

Revision history for this message
Benjamin Drung (bdrung) wrote :

Setting status back to incomplete.

Changed in matplotlib:
status: Invalid → Incomplete
Revision history for this message
agb (a-g-basden) wrote :

here is an example of code that fails on 64 bit machines running 8.10, but works on 8.04.
Just run it with eg
python tmp.py

Revision history for this message
Kjell Braden (afflux) wrote :

Thanks, this testcase seems to work. I'll try some debugging.

Changed in matplotlib:
status: Incomplete → Confirmed
Kjell Braden (afflux)
Changed in matplotlib:
assignee: nobody → afflux
status: Confirmed → In Progress
Revision history for this message
John D Hunter (jdh2358) wrote : Re: [Bug 295719] Re: python-matplotlib: Exception when drawing image on 64-bit system

On Wed, Jan 14, 2009 at 8:38 AM, Kjell Braden <email address hidden> wrote:
> Thanks, this testcase seems to work. I'll try some debugging.
>
> ** Changed in: matplotlib (Ubuntu)
> Status: Incomplete => Confirmed
>
> --
> python-matplotlib: Exception when drawing image on 64-bit system
> https://bugs.launchpad.net/bugs/295719
> You received this bug notification because you are a direct subscriber
> of the bug.
>

I have not been able to replicate the bug on a 64bit ubuntu 8.10 box.
here is the platform info for the machine I tested on using the script
http://launchpadlibrarian.net/21208878/tmp.py. I am running svn HEAD
though, but I am not aware of anything that would have changed
regarding float32 images on 64 bit architectures

uqbar[~]> uname -a
Linux uqbar 2.6.27-9-generic #1 SMP Thu Nov 20 22:15:32 UTC 2008
x86_64 GNU/Linux
uqbar[~]> cat /etc/issue
Ubuntu 8.10 \n \l

uqbar[~]> python -c 'import platform;print platform.architecture()'
('64bit', 'ELF')

Revision history for this message
Kjell Braden (afflux) wrote :

John, in svn HEAD r6036 fixed this problem, which seems to need a newer numpy version, (PyArray_SimpleNewFromData does not use the same conversion code for the dimensions as PyArray_FromDimsAndData uses)

The attached patch fixes this issue for me. Can someone confirm that this does not affect i386?

We have to wait for bug 317208 and two more sync requests to be done before we can upload this change, as matpotlib currently FTBFS.

Revision history for this message
Kjell Braden (afflux) wrote :

Woops, accidentally changed the affected source package.

Kjell Braden (afflux)
Changed in matplotlib:
importance: Undecided → Medium
status: In Progress → Triaged
assignee: afflux → nobody
Revision history for this message
Benjamin Drung (bdrung) wrote :

This bug is fixed with 0.98.5.2-1 in jaunty. The example code runs without exceptions.

Changed in matplotlib:
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.