-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
MAINT: simplify power fast path logic #27901
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
Changes from 23 commits
6923108
8196fbb
4090a1c
91dd9dd
c0e88c8
c00489d
1d9f355
4b2920c
dd6e773
c95bff2
084416e
e23423c
7cad24e
c028996
3297309
455407f
df6f54a
d10bce5
21c12a6
c9929ff
ed449e7
ba24783
b5f8a2b
023d55a
efbd6b8
31418e9
a5d0ef4
2e0f6ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,11 +239,30 @@ NPY_NO_EXPORT void NPY_CPU_DISPATCH_CURFX(@TYPE@_@func@) | |
if (stride_zero) { | ||
BINARY_DEFS | ||
const @type@ in2 = *(@type@ *)ip2; | ||
if (in2 == 2.0) { | ||
BINARY_LOOP_SLIDING { | ||
const @type@ in1 = *(@type@ *)ip1; | ||
int fastop_found = 1; | ||
BINARY_LOOP_SLIDING { | ||
const @type@ in1 = *(@type@ *)ip1; | ||
if (in2 == -1.0) { | ||
*(@type@ *)op1 = 1.0 / in1; | ||
} | ||
else if (in2 == 0.0) { | ||
*(@type@ *)op1 = 1.0; | ||
} | ||
else if (in2 == 0.5) { | ||
*(@type@ *)op1 = @sqrt@(in1); | ||
} | ||
else if (in2 == 1.0) { | ||
*(@type@ *)op1 = in1; | ||
} | ||
else if (in2 == 2.0) { | ||
*(@type@ *)op1 = in1 * in1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact, here we also should maybe just call the normal multiply loop (with duplicated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do with the SQRT! |
||
} | ||
else { | ||
fastop_found = 0; | ||
break; | ||
} | ||
} | ||
if (fastop_found) { | ||
return; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,13 +107,13 @@ def test_norm_object_array(self): | |
assert_array_equal(norm, [0, 1]) | ||
assert_(norm.dtype == np.dtype('float64')) | ||
|
||
assert_raises(ValueError, linalg.norm, testvector, ord='fro') | ||
assert_raises(ValueError, linalg.norm, testvector, ord='nuc') | ||
assert_raises(ValueError, linalg.norm, testvector, ord=np.inf) | ||
assert_raises(ValueError, linalg.norm, testvector, ord=-np.inf) | ||
assert_raises(ValueError, linalg.norm, testvector, ord=0) | ||
assert_raises(ValueError, linalg.norm, testvector, ord=-1) | ||
assert_raises(ValueError, linalg.norm, testvector, ord=-2) | ||
for ord in ['fro', 'nuc', np.inf, -np.inf, 0, -1, -2]: | ||
pytest.raises( | ||
(ValueError, ZeroDivisionError, RuntimeWarning), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you maybe say an example of the core operation that changed (i.e. what kind of array to the power of what kind of scalar this ends up at)? I agree those changes are probably fine, but I would feel better seeing an example (I can dig that up myself, but maybe you got it). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that the if not issubclass(x.dtype.type, (inexact, object_)):
x = x.astype(float) As far as I can tell, the regression test checks if this cast works. Probably why there are cases for the arrays being equal and the dtype being With the fast paths, we call I can provide a concrete traceback soon. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you provide that traceback/details (I assume it's quick for you)? The If we don't hit any error in that path, then we need to think about it more carefully. |
||
linalg.norm, | ||
testvector, | ||
ord=ord, | ||
) | ||
|
||
testmatrix = np.array([[np.array([0, 1]), 0, 0], | ||
[0, 0, 0]], dtype=object) | ||
|
@@ -126,15 +126,13 @@ def test_norm_object_array(self): | |
assert_array_equal(norm, [0, 1]) | ||
assert_(norm.dtype == np.dtype('float64')) | ||
|
||
assert_raises(TypeError, linalg.norm, testmatrix, ord='nuc') | ||
assert_raises(ValueError, linalg.norm, testmatrix, ord=np.inf) | ||
assert_raises(ValueError, linalg.norm, testmatrix, ord=-np.inf) | ||
assert_raises(ValueError, linalg.norm, testmatrix, ord=0) | ||
assert_raises(ValueError, linalg.norm, testmatrix, ord=1) | ||
assert_raises(ValueError, linalg.norm, testmatrix, ord=-1) | ||
assert_raises(TypeError, linalg.norm, testmatrix, ord=2) | ||
assert_raises(TypeError, linalg.norm, testmatrix, ord=-2) | ||
assert_raises(ValueError, linalg.norm, testmatrix, ord=3) | ||
for ord in ['nuc', np.inf, -np.inf, 0, 1, -1, 2, -2, 3]: | ||
pytest.raises( | ||
(ValueError, TypeError, ZeroDivisionError, RuntimeWarning), | ||
linalg.norm, | ||
testmatrix, | ||
ord=ord, | ||
) | ||
|
||
def test_lstsq_complex_larger_rhs(self): | ||
# gh-9891 | ||
|
Uh oh!
There was an error while loading. Please reload this page.