Skip to content

Fix stride computation for dimensions with shape 0 in ndarray - #68

Merged
icweaver merged 7 commits into
mainfrom
roman-l2-check
Aug 24, 2026
Merged

icweaver merged 7 commits into
mainfrom
roman-l2-check

Conversation

@cgarling

@cgarling cgarling commented Aug 6, 2026

Copy link
Copy Markdown
Member

Some STScI Roman L2 .asdf files produced with romanisim contain !core/ndarray nodes with a zero-length shape (e.g. the chisq/dumo arrays, shape [0, 0]) and no explicit strides key. 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 Python asdf package 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's reshape/reinterpret don'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 .asdf files: all arrays materialize with correct shapes/dtypes, and pixel values match Python's asdf exactly (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.

@codecov

codecov Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (fd82f70) to head (624570e).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #68   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          583       589    +6     
=========================================
+ Hits           583       589    +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@icweaver
icweaver self-requested a review August 13, 2026 00:41

@icweaver icweaver left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @cgarling! I've left my light review comments for this really nice PR

Comment thread src/ASDF.jl Outdated
Comment thread src/ASDF.jl Outdated
Comment thread src/ASDF.jl Outdated
Comment thread src/ASDF.jl Outdated
Comment thread test/test-ndarray.jl Outdated
Comment thread test/test-ndarray.jl Outdated
cgarling and others added 6 commits August 15, 2026 10:58
Co-authored-by: Ian Weaver <weaveric@gmail.com>
Co-authored-by: Ian Weaver <weaveric@gmail.com>
Co-authored-by: Ian Weaver <weaveric@gmail.com>
Co-authored-by: Ian Weaver <weaveric@gmail.com>
@icweaver

Copy link
Copy Markdown
Member

Thanks!

@icweaver
icweaver merged commit c18e875 into main Aug 24, 2026
14 checks passed
@icweaver
icweaver deleted the roman-l2-check branch August 24, 2026 23:34
@cgarling cgarling mentioned this pull request Sep 19, 2026
icweaver pushed a commit that referenced this pull request Sep 19, 2026
I need a release so that #68
is incorporated in a publicly installable version for collaborators.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants