[SciPy-User] Seg. fault from scipy.interpolate or numpy

Bruce Southey bsouthey at gmail.com
Fri Apr 29 14:36:25 EDT 2011


On Fri, Apr 29, 2011 at 1:20 PM, Bruce Southey <bsouthey at gmail.com> wrote:
> On 04/29/2011 10:50 AM, James Turner wrote:
>>>>>
>>>>> So can you determine exactly which line it crashes on (especially the
>>>>> value yc) and the shapes of the arrays?
>>>>
>>>> Yes, it crashes on the last line, beginning "noise=", not in the loop.
>>>>
>>>> Good question about yc; it's value is 127, which is correct, as the
>>>> test array has a shape of (128, 2048).
>>>>
>>>> I just tried splitting up the last line into separate operations and
>>>> the one that crashes is objfit.clip(min=0.0). If I replace the last
>>>> line with just that call, I still get the crash.
>>>>
>>>> I thought I'd try printing objfit.min() and max() just for fun and
>>>> those work without crashing, returning -185.079 and 711.543.
>>>>
>>>> Thanks,
>>>>
>>>> James.
>>>
>>> Good!
>>> I think that you should be using 'a_min' not 'min' an the argument to an
>>> ndarray:
>>> clip(...)
>>> a.clip(a_min, a_max, out=None)
>>
>> Sorry for the slow reply again. I'm running NumPy 1.5.1 and when I
>> use a_min=0., I get an error that it's an invalid keyword argument,
>> but min=0 seems to work. That's odd! Anyway, I can give the minimum
>> as a positional argument and it makes no difference to the crash.
>
> Okay that is a bug in 1.6 as well!
>
>>>> a.clip(a_min=0, a_max=numpy.inf)
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> TypeError: 'a_max' is an invalid keyword argument for this function
>>>> help(a.clip)
> help on built-in function clip:
>
> clip(...)
>    a.clip(a_min, a_max, out=None)
>
>    Return an array whose values are limited to ``[a_min, a_max]``.
>
>
>>
>>> Also you could try using np.clip(objfit, 0.0) as it should be the same
>>> as objfit.clip(0.0).
>>
>> That doesn't work as it says 3 arguments are required -- but that
>> made me think to try adding a maximum to the clip method as well as
>> a minimum and voila, it doesn't crash! I don't want a maximum
>> though :-(. Does this make any sense to you? Maybe there is something
>> wrong with the way the function is wrapped (by the look if it) as a
>> method, but I can't see how it can be using an uninitialized maximum
>> value, as if my data were getting clipped to some random maximum it
>> should be obvious.
>
> Yes because it does not know the dtype in advance.
> But surely you can use positive and negative infinity:
>
> Python 2.5.5 (r255:77872, Nov  8 2010, 09:10:42)
> [GCC 4.5.1 20100924 (Red Hat 4.5.1-4)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import numpy as np
>>>> np.__version__
> '1.5.1'
>>>> help(np.clip)
>
>>>> a=np.arange(-10,10, dtype=float)
>>>> help(a.clip)
>
>>>> a.clip(a_min=0)
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> TypeError: 'a_min' is an invalid keyword argument for this function
>>>> a.clip(min=0)
> array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  2.,
>        3.,  4.,  5.,  6.,  7.,  8.,  9.])
>>>> np.clip(a,a_min=0, a_max=np.inf)
> array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  2.,
>        3.,  4.,  5.,  6.,  7.,  8.,  9.])
>>>>
>
>
>>>> a=np.arange(-10,10, dtype=float)
>>>> a
> array([-10.,  -9.,  -8.,  -7.,  -6.,  -5.,  -4.,  -3.,  -2.,  -1.,   0.,
>         1.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.])
>>>> a.clip(0)
> array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  2.,
>        3.,  4.,  5.,  6.,  7.,  8.,  9.])
>>>> np.clip(a,0, np.PINF)
> array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  2.,
>        3.,  4.,  5.,  6.,  7.,  8.,  9.])
>
>>
>>> But I am still curious is why it is crashing on your system. The ticket
>>> says
>>> Python 2.5 on a 64-bit Linux but your backtrace includes 'i686' which
>>> suggests
>>> that it is 32-bit. Can you be more specific of the versions of the
>>> software
>>> regarding 32 vs 64 bit?
>>
>> I am running 32-bit binaries on a 64-bit machine (our server
>> installation supports a variety of machines).
>>
>> Thanks,
>>
>> James.
>
> Bruce
>

Anyhow the clip bug was previously reported as ticket 1745:

http://projects.scipy.org/numpy/ticket/1745

So I will add this example to that ticket.

Bruce



More information about the SciPy-User mailing list