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
Add PyObject_RichCompareBool success check
  • Loading branch information
Licht-T committed May 4, 2018
commit d68afb36dd37ca9d8ed8604830cf8e5c2b14a94d
10 changes: 10 additions & 0 deletions numpy/core/src/multiarray/ctors.c
Original file line number Diff line number Diff line change
Expand Up @@ -3105,6 +3105,12 @@ _calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, i
}

next_is_nonzero = PyObject_RichCompareBool(*next, zero, Py_NE);
Copy link
Member

Choose a reason for hiding this comment

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

Could use PyObject_IsTrue, but that might be worse on unusual types

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eric-wieser IMO, PyObject_RichCompareBool is better because this is clear what we do.

if (next_is_nonzero == -1) {
Py_DECREF(zero);
Py_DECREF(*next);
*next = NULL;
return -1;
}
val = PyNumber_TrueDivide(*next, step);
Py_DECREF(*next);
*next = NULL;
Expand All @@ -3116,6 +3122,10 @@ _calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, i

val_is_zero = PyObject_RichCompareBool(val, zero, Py_EQ);
Copy link
Member

Choose a reason for hiding this comment

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

Should be an int, not an intp.

Copy link
Member
@eric-wieser eric-wieser May 3, 2018

Choose a reason for hiding this comment

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

You need to check that this doesn't return -1, indicating an error occurred. Same above.

Py_DECREF(zero);
if (val_is_zero == -1) {
Py_DECREF(val);
return -1;
}

if (cmplx && PyComplex_Check(val)) {
Copy link
Member

Choose a reason for hiding this comment

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

Trying to work out if this section needs a fix too, but I can't work out what this is even trying to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eric-wieser Me too. I don't know why the complex case exists. This is none-sense as math.

Copy link
Member

Choose a reason for hiding this comment

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

See #10332.

value = PyComplex_RealAsDouble(val);
Expand Down
0