-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Implementation and test updates to support NumPy 1.25 #9011
Changes from 7 commits
614a1cb
7db7e99
b11bafb
ac919ca
d7162f5
e338e22
5e3ff5e
0ef226b
6d779e5
bde1ec5
e8fe800
47550a5
ccbb814
ca6de9e
1a3b8af
3925a82
7336691
0596c21
1a1c7c1
56d1da0
f4cfb3f
93ac652
55855d7
8f47d8c
989e81d
eb74738
3f46ed1
443c2ff
0c086cf
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 |
---|---|---|
|
@@ -361,6 +361,39 @@ def int_ne_impl(context, builder, sig, args): | |
return impl_ret_untracked(context, builder, sig.return_type, res) | ||
|
||
|
||
def int_signed_unsigned_cmp(op): | ||
def impl(context, builder, sig, args): | ||
(left, right) = args | ||
# This code is entirely too clever. It's taken from the NumPy source. | ||
gmarkall marked this conversation as resolved.
Show resolved
Hide resolved
apmasell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# What we're going to do is divide the range of a signed value at zero. | ||
# If the signed value is less than zero, then we can treat zero as the | ||
# unsigned value since the unsigned value is necessarily zero or larger | ||
# and any signed comparison between a negative value and zero/infinity | ||
# will yield the same result. If the signed value is greater than or | ||
# equal to zero, then we can safely cast it to an unsigned value and do | ||
# the expected unsigned-unsigned comparison operation. | ||
# Original: https://github.com/numpy/numpy/pull/23713 | ||
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. Thanks for adding this link - I appreciate the link to the PR because it also gives the context for the addition to NumPy, which is nice. |
||
cmp_zero = builder.icmp_signed('<', left, Constant(left.type, 0)) | ||
lt_zero = builder.icmp_signed(op, left, Constant(left.type, 0)) | ||
ge_zero = builder.icmp_unsigned(op, left, right) | ||
res = builder.select(cmp_zero, lt_zero, ge_zero) | ||
return impl_ret_untracked(context, builder, sig.return_type, res) | ||
return impl | ||
|
||
|
||
def int_unsigned_signed_cmp(op): | ||
def impl(context, builder, sig, args): | ||
(left, right) = args | ||
# This code is entirely too clever. See the sister implementation for | ||
# details | ||
apmasell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cmp_zero = builder.icmp_signed('<', right, Constant(right.type, 0)) | ||
lt_zero = builder.icmp_signed(op, Constant(right.type, 0), right) | ||
ge_zero = builder.icmp_unsigned(op, left, right) | ||
res = builder.select(cmp_zero, lt_zero, ge_zero) | ||
return impl_ret_untracked(context, builder, sig.return_type, res) | ||
return impl | ||
|
||
|
||
def int_abs_impl(context, builder, sig, args): | ||
[x] = args | ||
ZERO = Constant(x.type, None) | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -620,6 +620,10 @@ def _fill_ufunc_db(ufunc_db): | |||||||||||||||||||
'FF->?': npyfuncs.np_complex_gt_impl, | ||||||||||||||||||||
'DD->?': npyfuncs.np_complex_gt_impl, | ||||||||||||||||||||
} | ||||||||||||||||||||
if numpy_version >= (1, 25): | ||||||||||||||||||||
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. Note: these functions are automatically tested by 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. I'm not sure this is happening - there don't appear to be any tests generated that involve
(i.e. no tests with signed / unsigned are generated). 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. Additionally, numba/numba/tests/test_ufuncs.py Lines 176 to 184 in 766f6d9
(there is only one 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. My "egrep" check earlier was run erroneously because I didn't have NumPy 1.25 in my environment. The I tried experimenting with adding testing of these types to the 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. Cherry-picked. |
||||||||||||||||||||
ufunc_db[np.greater].update({ | ||||||||||||||||||||
'qQ->?': numbers.int_signed_unsigned_cmp('>'), | ||||||||||||||||||||
'Qq->?': numbers.int_unsigned_signed_cmp('>')}) | ||||||||||||||||||||
|
||||||||||||||||||||
ufunc_db[np.greater_equal] = { | ||||||||||||||||||||
'??->?': numbers.int_uge_impl, | ||||||||||||||||||||
|
@@ -638,6 +642,10 @@ def _fill_ufunc_db(ufunc_db): | |||||||||||||||||||
'FF->?': npyfuncs.np_complex_ge_impl, | ||||||||||||||||||||
'DD->?': npyfuncs.np_complex_ge_impl, | ||||||||||||||||||||
} | ||||||||||||||||||||
if numpy_version >= (1, 25): | ||||||||||||||||||||
ufunc_db[np.greater_equal].update({ | ||||||||||||||||||||
'qQ->?': numbers.int_signed_unsigned_cmp('>='), | ||||||||||||||||||||
'Qq->?': numbers.int_unsigned_signed_cmp('>=')}) | ||||||||||||||||||||
|
||||||||||||||||||||
ufunc_db[np.less] = { | ||||||||||||||||||||
'??->?': numbers.int_ult_impl, | ||||||||||||||||||||
|
@@ -656,6 +664,10 @@ def _fill_ufunc_db(ufunc_db): | |||||||||||||||||||
'FF->?': npyfuncs.np_complex_lt_impl, | ||||||||||||||||||||
'DD->?': npyfuncs.np_complex_lt_impl, | ||||||||||||||||||||
} | ||||||||||||||||||||
if numpy_version >= (1, 25): | ||||||||||||||||||||
ufunc_db[np.less].update({ | ||||||||||||||||||||
'qQ->?': numbers.int_signed_unsigned_cmp('<'), | ||||||||||||||||||||
'Qq->?': numbers.int_unsigned_signed_cmp('<')}) | ||||||||||||||||||||
|
||||||||||||||||||||
ufunc_db[np.less_equal] = { | ||||||||||||||||||||
'??->?': numbers.int_ule_impl, | ||||||||||||||||||||
|
@@ -674,6 +686,10 @@ def _fill_ufunc_db(ufunc_db): | |||||||||||||||||||
'FF->?': npyfuncs.np_complex_le_impl, | ||||||||||||||||||||
'DD->?': npyfuncs.np_complex_le_impl, | ||||||||||||||||||||
} | ||||||||||||||||||||
if numpy_version >= (1, 25): | ||||||||||||||||||||
ufunc_db[np.less_equal].update({ | ||||||||||||||||||||
'qQ->?': numbers.int_signed_unsigned_cmp('<='), | ||||||||||||||||||||
'Qq->?': numbers.int_unsigned_signed_cmp('<=')}) | ||||||||||||||||||||
|
||||||||||||||||||||
ufunc_db[np.not_equal] = { | ||||||||||||||||||||
'??->?': numbers.int_ne_impl, | ||||||||||||||||||||
|
@@ -692,6 +708,10 @@ def _fill_ufunc_db(ufunc_db): | |||||||||||||||||||
'FF->?': npyfuncs.np_complex_ne_impl, | ||||||||||||||||||||
'DD->?': npyfuncs.np_complex_ne_impl, | ||||||||||||||||||||
} | ||||||||||||||||||||
if numpy_version >= (1, 25): | ||||||||||||||||||||
ufunc_db[np.not_equal].update({ | ||||||||||||||||||||
'qQ->?': numbers.int_signed_unsigned_cmp('!='), | ||||||||||||||||||||
'Qq->?': numbers.int_unsigned_signed_cmp('!=')}) | ||||||||||||||||||||
|
||||||||||||||||||||
ufunc_db[np.equal] = { | ||||||||||||||||||||
'??->?': numbers.int_eq_impl, | ||||||||||||||||||||
|
@@ -710,6 +730,10 @@ def _fill_ufunc_db(ufunc_db): | |||||||||||||||||||
'FF->?': npyfuncs.np_complex_eq_impl, | ||||||||||||||||||||
'DD->?': npyfuncs.np_complex_eq_impl, | ||||||||||||||||||||
} | ||||||||||||||||||||
if numpy_version >= (1, 25): | ||||||||||||||||||||
ufunc_db[np.equal].update({ | ||||||||||||||||||||
'qQ->?': numbers.int_signed_unsigned_cmp('=='), | ||||||||||||||||||||
'Qq->?': numbers.int_unsigned_signed_cmp('==')}) | ||||||||||||||||||||
|
||||||||||||||||||||
ufunc_db[np.logical_and] = { | ||||||||||||||||||||
'??->?': npyfuncs.np_logical_and_impl, | ||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this accidentally added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Yes.