Skip to content

segfault float96 + None (Trac #698) #1296

Closed

Description

@numpy-gitbot

Original ticket http://projects.scipy.org/numpy/ticket/698 on 2008-03-14 by trac user gabriel, assigned to @stefanv.

If I (accidentally) try to add None to a float96, I get a segmentation fault instead of an error:

In [1]: import numpy

In [2]: numpy.version
Out[2]: '1.0.4'

In [3]: numpy.float96(3.0) + None
Segmentation fault (core dumped)

Ubuntu linux on a pentium 4. Numpy compiled from tarball.

Best, Gabriel

Activity

  1. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @stefanv wrote on 2008-03-18

    Verified with SVN on OSX.

  2. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @teoliphant wrote on 2008-03-19

    This is a recursion problem. The longdouble add calls the ufunc add which (because everything is upcast to object arrays and because object arrays ask their elements how to add themselves, it calls back to the scalar add which continues the recursion.

  3. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @stefanv wrote on 2008-03-19

    When I investigated the problem yesterday, I realised that there must be a recursive call, given a traceback of several hundreds of lines! What is the best way to address this?

  4. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @teoliphant wrote on 2008-03-19

    The core reason behind this problem is that longdouble's are the only data-types (along with clong_double) that returns their corresponding numpy scalars when getitem is called.

  5. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @stefanv wrote on 2008-03-20

    Is that the reason for this problem, or for the intp problem? If for this problem, could you expand a bit?

  6. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @teoliphant wrote on 2008-03-21

    All of the numpy scalars implement their math by using the corresponding ufuncs. The ufuncs for "object" arrays use the math defined by the corresponding objects. This causes the recursion because adding to "None" upcasts everything to an object before attempting the ufunc calls. In the case of long doubles this creates an array of numpy long double scalars. As object arrays, the ufunc refers to the objects in the array to complete the math (which in this case calls back to the same ufunc which started it).

    The right fix to the cycle is to break it by either

    1. defining math separately for longdouble and clongdouble scalars or
    2. returning a different object for the getitem call of longdouble and clongdouble arrays.

    A quick fix would be to special-case somehow.

  7. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @charris wrote on 2008-03-22

    So the numpy scalars are objects? What does getitem return when called on, say float64?

  8. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @charris wrote on 2008-04-25

    Since float64(None), I think this problem will be fixed if the None is cast to a float64. So a special test for none in the code that picks the output type should do the trick.

  9. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @charris wrote on 2008-04-25

    Make that: Since float96(None) is nan.

  10. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    Milestone changed to 1.1.0 by @jarrodmillman on 2008-05-15

  11. numpy-gitbot commented on Oct 19, 2012

    @numpy-gitbot
    Author

    @cournape wrote on 2008-08-23

    Solved in r5680 and backported to 1.1.x. Thanks Travis !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions