8000 BUG: Fix strange behavior of infinite-step-size/underflow-case in arange by Licht-T · Pull Request #10263 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix strange behavior of infinite-step-size/underflow-case in arange #10263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 4, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use npy_signbit
  • Loading branch information
Licht-T committed Dec 23, 2017
commit e2cc3e63b98e710eb3d13ae0e9eeba80baec7090
5 changes: 2 additions & 3 deletions numpy/core/src/multiarray/ctors.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "templ_common.h" /* for npy_mul_with_overflow_intp */
#include "alloc.h"
#include <assert.h>
#include <math.h>

#include "get_attr_string.h"

Expand Down Expand Up @@ -2976,7 +2975,7 @@ PyArray_Arange(double start, double stop, double step, int type_num)
tmp_len = delta/step;

if (tmp_len == 0.0 && delta != 0.0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a comment explaining why it is a special case

Isn't this only satisfied if step is inf anyway?

Copy link
Contributor Author
@Licht-T Licht-T Dec 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eric-wieser This also considers some underflow cases. eg. in master branch,

>>> m = np.float32(3.40282347E+38)
>>> e = np.float32(1.401298E-45)
>>> m
3.4028235e+38
>>> e
1.4012985e-45
>>> e/m
0.0
>>> np.arange(np.float32(0), e, m)
array([], dtype=float64)

if (signbit(tmp_len)) {
if (npy_signbit(tmp_len)) {
length = -1.0;
}
else {
Expand Down Expand Up @@ -3108,7 +3107,7 @@ _calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, i
}

if (val_is_zero && next_is_nonzero) {
if (signbit(value)) {
if (npy_signbit(value)) {
len = -1.0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be 0. as it is effectively ceil(-eps)

}
else {
Expand Down
0