8000 BUG: one to any power is still 1. Broken edgecase for int arrays by ewmoore · Pull Request #7651 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: one to any power is still 1. Broken edgecase for int arrays #7651

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 1 commit into from
May 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions numpy/core/src/umath/loops.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,10 @@ NPY_NO_EXPORT void
*((@type@ *)op1) = 1;
continue;
}
if (in1 == 1) {
*((@type@ *)op1) = 1;
continue;
}
if (in2 < 0 || in1 == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

How about drop the previous if and

if (in2 < 0 && (in1 > 1 || in1 < -1)) {

And a special check for divide by zero.

*((@type@ *)op1) = 0;
continue;
Expand Down
4 changes: 4 additions & 0 deletions numpy/core/tests/test_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ def test_integer_power_with_zero_exponent(self):
arr = np.arange(-10, 10)
assert_equal(np.power(arr, 0), np.ones_like(arr))

def test_integer_power_of_1(self):
arr = np.arange(-10, 10)
assert_equal(np.power(1, arr), np.ones_like(arr))


class TestLog2(TestCase):
def test_log2_values(self):
Expand Down
0