Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Rightclick on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Hazen Babcock <hbabcock@ma...>  20090408 23:34:01

Hello, Apologies if this has already been reported... While using Numpy and PLplot I've stumbled over a potential problem with the interface. Numpy arrays are not necessarily contiguous in memory, i.e. if I have a 2D array: p = [[1,2],[2,3],[3,4]] And I do: plplot.plpoin(p[:,0], p[:,1], 9) Then I'll get a segmentation fault. Surprisingly, I have found that even some 1D arrays are not be contiguous. Should we be trying to protect the user by doing something like this to all the arrays that we get from numpy? plplot.plpoin(numpy.ascontiguousarray(p[:,0]), numpy.ascontiguousarray(p[:,1]), 9) Hazen 
From: Alan W. Irwin <irwin@be...>  20090409 01:27:35

On 20090408 19:330400 Hazen Babcock wrote: > > Hello, > > Apologies if this has already been reported... > > While using Numpy and PLplot I've stumbled over a potential problem with > the interface. Numpy arrays are not necessarily contiguous in memory, > i.e. if I have a 2D array: > > p = [[1,2],[2,3],[3,4]] > > And I do: > plplot.plpoin(p[:,0], p[:,1], 9) > > Then I'll get a segmentation fault. Surprisingly, I have found that even > some 1D arrays are not be contiguous. Should we be trying to protect the > user by doing something like this to all the arrays that we get from numpy? > plplot.plpoin(numpy.ascontiguousarray(p[:,0]), > numpy.ascontiguousarray(p[:,1]), 9) Your report got me curious since I use plenty of two dimensional array in python/numpy without problems. So I just now tried the following: >>> from numpy import * >>> p = [[1,2],[2,3],[3,4]] >>> p [[1, 2], [2, 3], [3, 4]] >>> p[:,0] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: list indices must be integers However, if you put an array around it all is well. >>> p = array(p) >>> p array([[1, 2], [2, 3], [3, 4]]) >>> p[:,0] array([1, 2, 3]) >>> p[:,1] array([2, 3, 4]) I haven't tried it, but I am virtually positive array([1, 2, 3]) and array([2, 3, 4]) would work fine as arguments to plpoin. Thus, is the problem that you forgot to turn the ordinary twodimensional python array into a numpy one (with array) before you tried to create onedimensional array results from twodimensional ones? Alan __________________________ Alan W. Irwin Astronomical research affiliation with Department of Physics and Astronomy, University of Victoria (astrowww.phys.uvic.ca). Programming affiliations with the FreeEOS equationofstate implementation for stellar interiors (freeeos.sf.net); PLplot scientific plotting software package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project (lbproject.sf.net). __________________________ Linuxpowered Science __________________________ 
From: Hazen Babcock <hbabcock@ma...>  20090409 15:03:06

Alan W. Irwin wrote: > On 20090408 19:330400 Hazen Babcock wrote: > >> Hello, >> >> Apologies if this has already been reported... >> >> While using Numpy and PLplot I've stumbled over a potential problem with >> the interface. Numpy arrays are not necessarily contiguous in memory, >> i.e. if I have a 2D array: >> >> p = [[1,2],[2,3],[3,4]] >> >> And I do: >> plplot.plpoin(p[:,0], p[:,1], 9) >> >> Then I'll get a segmentation fault. Surprisingly, I have found that even >> some 1D arrays are not be contiguous. Should we be trying to protect the >> user by doing something like this to all the arrays that we get from numpy? >> plplot.plpoin(numpy.ascontiguousarray(p[:,0]), >> numpy.ascontiguousarray(p[:,1]), 9) > > Your report got me curious since I use plenty of two dimensional array > in python/numpy without problems. So I just now tried the following: > >>>> from numpy import * >>>> p = [[1,2],[2,3],[3,4]] >>>> p > [[1, 2], [2, 3], [3, 4]] >>>> p[:,0] > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > TypeError: list indices must be integers > > However, if you put an array around it all is well. > >>>> p = array(p) >>>> p > array([[1, 2], > [2, 3], > [3, 4]]) >>>> p[:,0] > array([1, 2, 3]) >>>> p[:,1] > array([2, 3, 4]) > > I haven't tried it, but I am virtually positive array([1, 2, 3]) and > array([2, 3, 4]) would work fine as arguments to plpoin. > > Thus, is the problem that you forgot to turn the ordinary twodimensional > python array into a numpy one (with array) before you tried to create > onedimensional array results from twodimensional ones? When I ran into this issue I was using numpy arrays that I'd have saved (and then reloaded) using Pytables. For some reason when I used slices of these array in the call to plploin I would get a segfault, but if I created an intermediate variable that stored a contiguous version of each slice of interest from the array then everything was fine. I just assumed that this was a numpy / plplot issue, but now in trying to write a test case without using pytables I don't see any problem. This works as expected for me either way: import numpy import plplot plplot.plsdev("xcairo") plplot.plspage(72, 72, 800, 800, 0, 0) plplot.plinit() plplot.plenv(0.0, 2.0, 0.0, 2.0, 0, 0) for i in range(1000): objs = numpy.random.random((200,6)) objs[:,2] += 1.0 if 0: x = numpy.ascontiguousarray(objs[:,1]) y = numpy.ascontiguousarray(objs[:,2]) plplot.plpoin(x, y, 1) else: plplot.plpoin(objs[:,1], objs[:,2], 1) plplot.pllab("X", "Y", "Spot Locations") plplot.plend() So it must be something unusual about arrays that have been stored and reloaded using pytables. Hazen 
Sign up for the SourceForge newsletter:
No, thanks