Fix strides for 0-sized arrays#497
Conversation
8a2f5ba to
a2fd498
Compare
60bbcd7 to
59c65fb
Compare
kaushikcfd
left a comment
There was a problem hiding this comment.
Thanks, could you please also add a tiny regression that fails on current main.
59c65fb to
f0abbd9
Compare
Definitely! Added one in bd5ed02. That fails on |
802f419 to
89f0fa3
Compare
| from pymbolic.primitives import If, Comparison | ||
| new_stride_axis = If( | ||
| Comparison(dim_tag.stride, "<", 1), | ||
| 1, dim_tag.stride) |
There was a problem hiding this comment.
I'm not loving this, on multiple levels.
- If we merge this, the cost of the conditional is incurred on potentially every single array access.
- I'm not sure why this logic needs to live here (and why code in the invokers don't suffice). Could you explain?
- Negative strides are totally fine:
np.arange(10)[::-1].strides->(-8,)(Execution targets don't support negative strides #504) - Zero strides are also, in principle, well-defined.
There was a problem hiding this comment.
I'm not sure why this logic needs to live here (and why code in the invokers don't suffice). Could you explain?
Mostly because this was the direction I went down the rabbit hole. I'll work on putting it in the invokers, since there's no reason that wouldn't work, as far as I can tell.
Negative strides are totally fine: np.arange(10)[::-1].strides -> (-8,) (#504)
Do any of the other targets support them? Haven't really tried that, but agree that in principle there's no reason why they can't work.
Zero strides are also, in principle, well-defined.
When would those come up? Haven't managed to convince numpy to make some, although for 0-sized arrays, just setting ary.strides to something shouldn't break the world, right?
There was a problem hiding this comment.
Do any of the other targets support them?
🤷 No reason they shouldn't, though. :)
When would those come up?
stride_tricks? As intermediates in broadcasting? Not sure.
23f8e7b to
1e02b47
Compare
1e02b47 to
24d254c
Compare
24d254c to
92c9aaf
Compare
|
Superseded by #584. |
Found one last issue with 0-sized arrays in inducer/arraycontext#91.
This was messing up the code generation on the
pytatoside and it would fail in the invoker when checking strides.