-
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
Added is identity comparison for numpy records and added tests as is_comparison_tests.py #9384
base: main
Are you sure you want to change the base?
Conversation
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.
Many thanks for the PR. I've posted some initial feedback to address - once that's addressed, we may need an additional round of review on the tests (I haven't gone further commenting on the test cases as there already some issues there).
numba/np/arrayobj.py
Outdated
def test_kernel(a, b) -> None: | ||
print(int(a is a)) | ||
print(int(a is b)) | ||
print(int(b is a)) | ||
print(int(b is b)) | ||
|
||
|
||
a = np.zeros(1, dtype=[("a", "i4"), ("b", "i4")])[0] | ||
b = a.copy() | ||
njit(test_kernel)(a, b) | ||
cuda.jit(test_kernel)[1, 1](a, b) | ||
cuda.synchronize() | ||
|
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.
The workaround is the lowering implementation record_is
, not all the code that went with it to demonstrate that it worked correctly.
def test_kernel(a, b) -> None: | |
print(int(a is a)) | |
print(int(a is b)) | |
print(int(b is a)) | |
print(int(b is b)) | |
a = np.zeros(1, dtype=[("a", "i4"), ("b", "i4")])[0] | |
b = a.copy() | |
njit(test_kernel)(a, b) | |
cuda.jit(test_kernel)[1, 1](a, b) | |
cuda.synchronize() |
numba/np/arrayobj.py
Outdated
@@ -41,6 +41,28 @@ | |||
_choose_concatenation_layout) | |||
|
|||
|
|||
@lower_builtin(operator.is_, types.Record, types.Record) |
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.
Rather than inserting this lowering right at the top of the file, the natural place for it would be in the Comparisons
section, next to the implementation of array_is
.
numba/np/arrayobj.py
Outdated
@@ -29,7 +29,7 @@ | |||
from numba.core.typing import signature | |||
from numba.core.types import StringLiteral | |||
from numba.core.extending import (register_jitable, overload, overload_method, | |||
intrinsic, overload_attribute) | |||
intrinsic, overload_attribute, lower_builtin) |
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.
lower_builtin
was already imported.
intrinsic, overload_attribute, lower_builtin) | |
intrinsic, overload_attribute) |
numba/np/arrayobj.py
Outdated
@@ -12,7 +12,7 @@ | |||
|
|||
import numpy as np | |||
|
|||
from numba import pndindex, literal_unroll | |||
from numba import pndindex, literal_unroll, cuda, njit, types #type : ignore |
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.
types
was already imported. cuda
cannot be imported in Numba outside of the numba.cuda
module in general.
from numba import pndindex, literal_unroll, cuda, njit, types #type : ignore | |
from numba import pndindex, literal_unroll |
numba/np/is_comparison_tests.py
Outdated
@@ -0,0 +1,75 @@ | |||
import numpy as np |
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.
Whilst it's good to have added tests, they should be in the numba.tests
module, and should fit in with the existing unit test framework.
numba/np/is_comparison_tests.py
Outdated
a = np.zeros(1, dtype=[("a", "i4"), ("b", "i4")])[0] | ||
b = a.copy() | ||
|
||
result = cuda.jit(test_kernel)[1, 1](a, b) |
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.
CUDA kernels cannot return values.
numba/np/is_comparison_tests.py
Outdated
a = np.zeros(1, dtype=[("a", "i4"), ("b", "i4")])[0] | ||
b = a.copy() | ||
|
||
result = test_kernel(a, b) |
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.
test_kernel
returns None
in its present implementation (which needs removing from numba.np.arrayobj
also).
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.
Hey ...thank you for the feedback! I have incorporated changes mentioned by you . If anything else still needs to be done please let me know 🙂
a746223
to
c114da6
Compare
Thanks for making changes. For future changes - please could you avoid force-pushing as this tends to confuse the Github review interface - many thanks in advance! |
Having skimmed over the latest revision, I'm not going to be able to spend more time reviewing this PR in its current form - I think it would be helpful for you to receive additional mentorship to fill in some of the conceptual gaps here, and that's not something I have enough time to do. If you'd like to proceed with the PR, I would suggest making a post on the Numba Discourse (https://numba.discourse.group) describing what you're trying to achieve with the PR, and requesting if there's anyone with sufficient time and experience to help shepherd the PR closer to completion and being ready for another round of review. |
Hey, |
I have made the corrections as pointed out by @guilhermeleobas . Sorry for the delay 🙂 |
Thanks for the help @guilhermeleobas . |
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.
Thanks for the contributions, @Kamakshi8104. Code still needs some work to be done.
Thanks @guilhermeleobas ! I have tried a different approach for record_is_impl function. I hope this works!! Please update me on any needed changes🙂 |
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.
Hi @Kamakshi8104, I made a mistake while reviewing your PR. The code you had originally should work.
Thanks, @gmarkall, for pointing that out.
@guilhermeleobas I have changed it back as requested. Please take a look....let me know If anything else is required |
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.
Thanks for the effort @Kamakshi8104. Have a few more comments, but we're getting there.
numba/tests/test_array_methods.py
Outdated
@@ -11,6 +11,7 @@ | |||
from numba.core.errors import TypingError, NumbaValueError | |||
from numba.np.numpy_support import as_dtype, numpy_version | |||
from numba.tests.support import TestCase, MemoryLeakMixin, needs_blas | |||
#from np.arrayobj import record_is |
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.
Delete this import as it is not needed
numba/tests/test_array_methods.py
Outdated
def test_record_is(self): | ||
def check(a, b, expected): | ||
pyfunc = identity_usecase | ||
cfunc=njit(pyfunc) | ||
|
||
|
||
result = cfunc(a, b) | ||
self.assertEqual(result, expected) | ||
|
||
record_type = np.dtype([("a", "i4"), ("b", "i4")]) | ||
|
||
# Test case: Same records | ||
a = np.zeros(1, dtype=record_type)[0] | ||
b = a.copy() | ||
check(a, b, True) | ||
|
||
# Test case: Different records | ||
c = np.ones(1, dtype=record_type)[0] | ||
check(a, c, False) | ||
|
||
# Test case: Same records with different values | ||
d = np.zeros(1, dtype=record_type)[0] | ||
d['a'] = 42 | ||
check(a, d, False) |
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.
Rather than give the expected result as an argument, compute it by calling pyfunc(a, b)
. This should fix the CI issue.
def test_record_is(self): | |
def check(a, b, expected): | |
pyfunc = identity_usecase | |
cfunc=njit(pyfunc) | |
result = cfunc(a, b) | |
self.assertEqual(result, expected) | |
record_type = np.dtype([("a", "i4"), ("b", "i4")]) | |
# Test case: Same records | |
a = np.zeros(1, dtype=record_type)[0] | |
b = a.copy() | |
check(a, b, True) | |
# Test case: Different records | |
c = np.ones(1, dtype=record_type)[0] | |
check(a, c, False) | |
# Test case: Same records with different values | |
d = np.zeros(1, dtype=record_type)[0] | |
d['a'] = 42 | |
check(a, d, False) | |
def test_record_is(self): | |
def check(a, b): | |
pyfunc = identity_usecase | |
cfunc = njit(pyfunc) | |
result = cfunc(a, b) | |
expected = pyfunc(a, b) | |
self.assertEqual(result, expected) | |
record_type = np.dtype([("a", "i4"), ("b", "i4")]) | |
# Test case: Same records | |
a = np.zeros(1, dtype=record_type)[0] | |
b = a.copy() | |
check(a, b) | |
# Test case: Different records | |
c = np.ones(1, dtype=record_type)[0] | |
check(a, c) | |
# Test case: Same records with different values | |
d = np.zeros(1, dtype=record_type)[0] | |
d['a'] = 42 | |
check(a, d) |
numba/tests/test_array_methods.py
Outdated
|
||
|
||
|
||
# tests for record comparison | ||
|
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.
Do you plan to add any other tests? If not, remove the empty lines.
Thank you @guilhermeleobas and @gmarkall for all your help!! All the tests have successfully passed. I hope this fixes the issue🙂 |
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.
Oh, you need to also write a release notes document. Please, see:
https://github.com/numba/numba/blob/main/docs/upcoming_changes/README.rst
@gmarkall and @guilhermeleobas I have made all changes as well as added documentation. Please let me know if anything else I required further since the PR hasn't been merged yet. 🙂 |
Co-authored-by: Guilherme Leobas <guilhermeleobas@gmail.com>
Co-authored-by: Guilherme Leobas <guilhermeleobas@gmail.com>
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.
If @gmarkall does not have any other comments, we can merge this one for 0.61
I have added the workaround to numba/np/arrayobj.py and have created test cases for the same.
Please let me know if any more changes are required
regards,
Kamakshi