Repository navigation
Support FillArrays.OffDiagonal and remove sublayout piracy for DiagonalLayout (require ArrayLayouts v1.15) - #511
Merged
Merged
Conversation
…alLayout Require ArrayLayouts v1.15, which adds OffDiagonalLayout and returns it for views of a DiagonalLayout matrix by unit ranges. Remove the pirated sublayout(::DiagonalLayout, ...) methods, which would otherwise overwrite ArrayLayouts' method, and add bandwidths, inbands_getindex/inbands_setindex! and BandedMatrix conversion for OffDiagonalLayout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #511 +/- ##
==========================================
+ Coverage 90.69% 90.74% +0.05%
==========================================
Files 27 27
Lines 3784 3805 +21
==========================================
+ Hits 3432 3453 +21
Misses 352 352 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Keeps BandedMatrix .+ OffDiagonal banded once OffDiagonal has its own broadcast style (JuliaArrays/FillArrays.jl#458). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
Added |
dlfivefifty
added a commit
to JuliaArrays/FillArrays.jl
that referenced
this pull request
Oct 13, 2026
`OffDiagonal` now has `BroadcastStyle`
`LinearAlgebra.StructuredMatrixStyle{OffDiagonal}`, so zero-preserving
broadcasts keep the single-band structure:
```julia
julia> sin.(Eye(5)[2:end,:])
4×5 FillArrays.OffDiagonal{Float64, Fill{Float64, 1, Tuple{Base.OneTo{Int64}}}, …}
```
- Zero preservation is detected with LinearAlgebra's `fzeropreserving`,
as for `Diagonal` etc. (`fzero(::OffDiagonal)` is defined like for
`RectDiagonal`).
- The result is an `OffDiagonal` only if every `OffDiagonal` argument
lies on the same band and has the same axes as the result. Otherwise
(different bands, a 1×1 `OffDiagonal` broadcast out, non-scalar
non-`OffDiagonal` arguments, or non-zero-preserving functions such as
`cos` or `.+ 1`) it falls back to a dense `Matrix`.
- `copy` broadcasts over the bands themselves, so lazy bands stay lazy:
`sin.(Eye(5)[2:end,:]) ≡ OffDiagonal(Fill(sin(1.0), 4), 1, 4, 5)`.
- In-place `dest .= f.(A)` with `dest::OffDiagonal` on the same band
only writes the band. Other cases fall back to the generic `copyto!`,
which throws when writing a non-zero entry off the band.
- `structured_broadcast_alloc` is defined so that `similar(bc, T)` also
gives an `OffDiagonal`.
Tests cover zero-preserving functions (`sin`, `abs`, scaling, `.^2`, `A
.+ A`, `A .* A`, `round.(Int, A)`, nested broadcasts), dense fallbacks,
mismatched bands, in-place broadcasting and lazy bands. They pass on
Julia 1.10 and 1.13. On 1.11 the only failure is Aqua's `ambiguities`
check being an unexpected pass, which also happens on `master`.
**Downstream:** with this change `BandedMatrix .+ OffDiagonal` would
become a dense `Matrix` instead of a `BandedMatrix`, as BandedMatrices
only defines `BroadcastStyle` rules between `BandedStyle` and the
`StructuredMatrixStyle`s of specific types. Adding `:OffDiagonal` to
that list in `src/interfaceimpl.jl` (e.g. in
JuliaLinearAlgebra/BandedMatrices.jl#511) restores a `BandedMatrix`
result. ArrayLayouts, LazyArrays and BandedMatrices (#511 plus that
one-line change) test suites pass with this PR.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Depends on JuliaLinearAlgebra/ArrayLayouts.jl#285, which adds
OffDiagonalLayoutand will be released as ArrayLayouts v1.15. CI will fail until that version is registered.Changes
FillArrays.OffDiagonal). Bump to v1.14.0.sublayout(::DiagonalLayout, ...)methods. ArrayLayouts v1.15 definessublayout(::DiagonalLayout, ::Type{<:Tuple{AbstractUnitRange{<:Integer},AbstractUnitRange{<:Integer}}})returningOffDiagonalLayout. That method has to be broader than the pirated one here, which takesAbstractUnitRange{Int}, so that loading BandedMatrices v1.13 with ArrayLayouts v1.15 does not trigger method overwriting.OffDiagonalLayout, which coversOffDiagonal, its transpose and adjoint, and views ofDiagonal/OffDiagonalby unit ranges:bandwidths(::OffDiagonalLayout, A) = (-k, k)inbands_getindexandinbands_setindex!forOffDiagonalBandedMatrix(A)copies the band directly viaoffdiagonaldata.Behaviour changes
view(D::Diagonal, kr, jr)with unit ranges now hasOffDiagonalLayoutinstead ofBandedColumns, andlayout_getindex(D, kr, jr)returns aFillArrays.OffDiagonalinstead of aBandedMatrix. The same applies toEye. The tests are updated to match.Diagonalby non-unit-range indices (e.g.view(D, :, 1)orview(D, [1,2], 1:2)) now get ArrayLayouts' defaultsublayoutrather than aBandedColumns-derived one.🤖 Generated with Claude Code