Skip to content

Return OffDiagonal when slicing Diagonal of LayoutVector (require FillArrays v1.18) - #285

Merged
dlfivefifty merged 4 commits into
masterfrom
dl/offdiagonal
Oct 11, 2026
Merged

dlfivefifty merged 4 commits into
masterfrom
dl/offdiagonal

Conversation

@dlfivefifty

Copy link
Copy Markdown
Member

FillArrays v1.18 adds OffDiagonal and returns it when slicing a Diagonal of an AbstractFill by unit ranges. This PR does the same for a Diagonal whose diagonal is a LayoutVector or a SubArray{<:Any,1,<:LayoutVecOrMat}: before, these slices fell back to Base and returned a dense Matrix.

julia> D = Diagonal(MyVector(randn(5)));

julia> D[2:4, 1:5] isa FillArrays.OffDiagonal
true

Changes:

  • Bump the FillArrays compat to 1.18 and the version to 1.15.
  • Add getindex(::Diagonal{<:Any,<:Union{LayoutVector,SubArray{<:Any,1,<:LayoutVecOrMat}}}, ::Union{AbstractUnitRange,Colon}, ::Union{AbstractUnitRange,Colon}), which calls FillArrays' internal _onebased_index and _singleband_getindex. Offset and infinite index shapes still go to the generic fallback, as they do in FillArrays.
  • Add tests for several range and Colon combinations, empty ranges, out-of-bounds slices, and diagonals backed by views.

Note: the new method relies on FillArrays internals, so a later FillArrays release that renames them would break it.

🤖 Generated with Claude Code

Require FillArrays v1.18 and reuse its single-band slicing so that indexing
a Diagonal whose diagonal is a LayoutVector (or a SubArray of a LayoutArray)
by unit ranges returns a FillArrays.OffDiagonal instead of a dense Matrix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.53%. Comparing base (0d4c00b) to head (036876d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #285      +/-   ##
==========================================
+ Coverage   90.33%   90.53%   +0.19%     
==========================================
  Files          12       12              
  Lines        1987     2028      +41     
==========================================
+ Hits         1795     1836      +41     
  Misses        192      192              

☔ 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.

dlfivefifty and others added 3 commits October 10, 2026 19:46
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This lets downstream packages such as BandedMatrices.jl read the band of a
view of a Diagonal or OffDiagonal without materialising it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant