Repository navigation
Add constant lowering support for SliceTypes - #6996
Conversation
|
I noticed an issue with import numpy as np
import numba
ts = slice(None, None, None)
@numba.njit
def test():
return np.array([[1, 2], [3, 4]])[ts]
test_array = np.array([[1, 2], [3, 4]])
# Succeeds
assert np.array_equal(test(), test_array[ts])
ts2 = slice(1, None, None)
@numba.njit
def test2():
return np.array([[1, 2], [3, 4]])[ts2]
# Fails
assert np.array_equal(test2(), test_array[ts2])This doesn't appear to be caused by an obvious problem with import numpy as np
import numba
ts = slice(None, None, None)
@numba.njit
def test():
return ts.start, ts.stop, ts.step
test()
# (0, 9223372036854775807, 1)
ts = slice(1, None, None)
@numba.njit
def test2():
return ts.start, ts.stop, ts.step
test2()
# (1, 9223372036854775807, 1)Any ideas? |
|
I noticed this line in the # $22load_global.10 = global(ts: slice(1, None, None)) :: Literal[slice](slice(None, None, None))I further traced the discrepancy implied by the comment above to the |
|
The issue is that the |
3d68529 to
6b7c9fd
Compare
|
All right, the issue with |
|
Thanks very much for the PR, I've queued it for review. |
|
I've added another commit relocating the tests and removing the unnecessary asserts. Tell me if you want me to squash/rebase these commits. |
55ee398 to
09f66f6
Compare
stuartarchibald
left a comment
There was a problem hiding this comment.
Thanks for the patch! There's a few minor things to resolve but otherwise looks good. Thanks again!
09f66f6 to
d5e3702
Compare
|
I'm assuming that someone will squash these commits; otherwise, adding commits that only fix earlier commits is quite painful. |
6203d79 to
1e781fe
Compare
1e781fe to
a1c6c60
Compare
|
@brandonwillard thank you for updating. |
| else: | ||
| typ = ty |
There was a problem hiding this comment.
I didn't notice this before... but is this branch dead or maybe it should raise? Is it possible to get a slice type that is constant and not literal?
There was a problem hiding this comment.
From OOB discussion with @sklam, it shouldn't be possible to hit this from user defined input but synthetic IR might.
stuartarchibald
left a comment
There was a problem hiding this comment.
Thanks for the patch and fixes.
This PR adds constant lowering support for
SliceTypes.The approach used here is largely taken from existing implementations throughout the codebase (and some guess work), so someone will need to tell me if there's a newer/more preferable way to do this.
Closes #6744.