8000 numpy.allclose does not deal well with the minimal value of int* dtypes (Trac #1684) · Issue #2280 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
numpy.allclose does not deal well with the minimal value of int* dtypes (Trac #1684) #2280
Closed
@numpy-gitbot

Description

@numpy-gitbot

Original ticket http://projects.scipy.org/numpy/ticket/1684 on 2010-11-22 by trac user lamblin, assigned to unknown.

If I create an array containing the minimal value of an int dtype, for instance an 'int8' array containing -128, numpy.allclose fails to detect it is "close" to itself, although it is equal.

>>> a = numpy.asarray(-128, dtype='int8')
>>> numpy.all(a == a)
True
>>> numpy.allclose(a, a)
False

I would expect:

>>> numpy.allclose(a, a)
True

This is due to the fact that the tolerance uses numpy.absolute, and in that case, it is negative:

>>> numpy.absolute(a)
array([-128], dtype=int8)

I reproduced the same with int16 and -215, int32 and -231, and int64 and -2**63.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0