Skip to content

Commit

Permalink
Fallback newindex method with a BandIndex (#1143)
Browse files Browse the repository at this point in the history
Currently, `Broadcast.newindex` with a `BandIndex` is specialized for
structured broadcasting, but this incorrectly assumed that all the
matrices involved in a structured broadcast operation will be structured
matrices. This PR adds a fallback that simply converts the `BandIndex`
to a `CartesianIndex` before computing the `newindex`.

This PR gets the tests for `FillArrays` working on julia nightly.
  • Loading branch information
jishnub authored Dec 6, 2024
1 parent d1e267f commit b6f87af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/structuredbroadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ isvalidstructbc(dest::Bidiagonal, bc::Broadcasted{StructuredMatrixStyle{Bidiagon
@inbounds Broadcast._broadcast_getindex(bc, b)
end

Broadcast.newindex(A, b::BandIndex) = Broadcast.newindex(A, _cartinds(b))
function Broadcast.newindex(A::StructuredMatrix, b::BandIndex)
# we use the fact that a StructuredMatrix is square,
# and we apply newindex to both the axes at once to obtain the result
Expand Down
5 changes: 5 additions & 0 deletions test/structuredbroadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,9 @@ end
end
end

@testset "newindex with BandIndex" begin
ind = Broadcast.newindex(rand(2,2),LinearAlgebra.BandIndex(0,1))
@test ind == CartesianIndex(1,1)
end

end

0 comments on commit b6f87af

Please sign in to comment.