-
Notifications
You must be signed in to change notification settings - Fork 372
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
Properly Generate ExtSlice #1492
Comments
Does this distinction matter at all in Python 3, or is it effectively a Python 2 issue? |
Possibly related to #1481. If the distinction matters, Hy will have to have special forms for either case, which means |
@Kodiologist as far as I can tell, yes, but we get away with it because we never emit multidimensional slices anywhere with As far as I can tell, only |
And for what its worth, its probably worth implementing - even if its an optimization when we notice In [1]: class Demo:
...: def __getitem__(self, key):
...: return key
...:
In [2]: demo = Demo()
In [3]: %timeit demo[1:2]
183 ns ± 0.666 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
In [4]: %timeit demo[slice(1, 2)]
266 ns ± 2.23 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each) |
On second thought, we could have a |
I don't know how you could properly disambiguate it without using Say we chose to represent |
I think I'll experiment with addressing this by trying to peek into contents of Index AST expression and start by trying to transforming I don't think there's any real need to "fix" this by looking at how we approach representation, and instead look at it as a optimization instead. I think |
@vodik The reason why class Demo:
def __getitem__(self, item):
return item
demo = Demo()
s = slice(1, 2)
%timeit demo[1:2]
137 ns ± 0.564 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
%timeit demo[s]
130 ns ± 0.7 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
def test():
s = slice(1, 2)
demo = Demo()
def test1():
demo[1:2]
def test2():
demo[s]
return test1, test2
test1, test2 = test()
%timeit test1()
203 ns ± 4.77 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
%timeit test2()
190 ns ± 4.65 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each) |
More to fetch at serhiy-storchaka's PR. |
Hy has dropped support for python2 and |
So to summarize, this seems to make neither a semantic difference nor a performance difference in practice, and it's going to be obsolete anyway as older Pythons die off. I think we probably don't need to worry about it. |
Multi-dimensional lookup should emit
ast.ExtSlice
instead of a normal lookup withast.Tuple
.Basically any time we'd generate this:
But if any of the elements of that tuple is an instance of
ast.slice
(ast.Slice
and, on Python 2,ast.Ellipsis
), it should be constructed asslice=ExtSlice(dims[...])
instead.Related to #1491 if we want to add Python 2 support for Ellipsis. Otherwise its not too pressing since we don't have anything that emits
ast.Slice
directly, its always done as a function call. But if we where to add something, this issue would have to be resolved first.The text was updated successfully, but these errors were encountered: