Fix stride computation for dimensions with shape 0 in ndarray - #68
Open
cgarling wants to merge 1 commit into
Open
Fix stride computation for dimensions with shape 0 in ndarray#68cgarling wants to merge 1 commit into
cgarling wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #68 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 583 587 +4
=========================================
+ Hits 583 587 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some STScI Roman L2
.asdffiles produced with romanisim contain!core/ndarraynodes with a zero-length shape (e.g. thechisq/dumoarrays, shape[0, 0]) and no explicitstrideskey. ASDF.jl's implicit C-order stride formula (stride[i] = itemsize * prod(shape[i+1:])) collapses to zero for any outer dimension whose product includes a zero-length axis, which then failed the constructor's "strides must be positive" check.NumPy avoids this by treating zero-length dimensions as length 1 only within the running product when computing default C-contiguous strides (
PyArray_NewFromDescr). The Pythonasdfpackage relies on this. Here I reproduce that convention, and have verified it against NumPy's actual output for several representative shapes/dtypes.I also relax the post-materialization stride sanity check in
getindex: Julia'sreshape/reinterpretdon't preserve stride values along size-0 or size-1 axes (no adjacent elements to space apart), so the check now only compares strides for dimensions with more than one element.I verified this patch on my local L2
.asdffiles: all arrays materialize with correct shapes/dtypes, and pixel values match Python'sasdfexactly (accounting for Julia's column-major vs. NumPy's row-major indexing convention).I added regression tests in test/test-ndarray.jl covering the implicit stride computation for zero-length dimensions and materialization of a zero-size block-backed array. The rest of the tests also pass for me locally.
The comments are somewhat verbose so I'm happy if you want to cut them down to size.