Updated Windows base Computations to be Safer#1297
Updated Windows base Computations to be Safer#1297nilgoyette merged 1 commit intorust-ndarray:masterfrom
base Computations to be Safer#1297Conversation
I don't want to ask too much of a generous contributor, but if you can, could you please add a test that would have failed before the fix in this PR? (a test with negative strides) |
No worries! But I am not totally sure if this is possible, |
|
If it's impossible to pass an array with negative strides, then I don't understand the point of this PR. Can't you call If I understand bluss comment correctly, it should create negative strides. |
|
Ah sorry there are two strides here, the parameter and the offset, I was thinking about the parameter. I believe there's already a |
Transpose just changes order of axes, it doesn't modify their lengths or strides. "Axis 0 and 1 become axis 1 and 0". Use instead ndarray's method Example on matrix with dimensions (n1, n2) and strides (s1, s2):
(*) slicing with negative step is equivalent to using invert axis. As seen in that test code: |
I agree with this one. @LazaroHurtado We need a negative axis input array. The window strides (your feature) still just needs to be anything that's not just (1, 1, 1), for example something with a stride of 2 on the same axis that is inverted. I agree no negative window strides should be possible to be used. |
base Computations to be Saferbase Computations to be Safer
67723af to
5bcc73e
Compare
|
Thank you for adding some more context! I included a test that asserts the proper strided (the parameter) windows are returned when a single and all axis are inverted. I also verified that this test failed before the work introduced in this PR. |
|
Excellent, thank you @LazaroHurtado for the test, and @bluss for the technical details. Now I feel much more confident merging this branch! I tested with numpy and I get the same results. |
Please refer to #1249 for context and discussions, specifically this comment.
The assertion verifying a window's size dimension or axis' stride is non-zero has been removed and outsourced to
Slice, which will error when:end>ax_desc.len, which can only happen whenwsz == 0step == 0, which can only happen when an axis' stride is zeroThus, we maintain the same functionality as before