Skip to content

Commit b6f87af

Browse files
authored
Fallback newindex method with a BandIndex (#1143)
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.
1 parent d1e267f commit b6f87af

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/structuredbroadcast.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ isvalidstructbc(dest::Bidiagonal, bc::Broadcasted{StructuredMatrixStyle{Bidiagon
194194
@inbounds Broadcast._broadcast_getindex(bc, b)
195195
end
196196

197+
Broadcast.newindex(A, b::BandIndex) = Broadcast.newindex(A, _cartinds(b))
197198
function Broadcast.newindex(A::StructuredMatrix, b::BandIndex)
198199
# we use the fact that a StructuredMatrix is square,
199200
# and we apply newindex to both the axes at once to obtain the result

test/structuredbroadcast.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,9 @@ end
376376
end
377377
end
378378

379+
@testset "newindex with BandIndex" begin
380+
ind = Broadcast.newindex(rand(2,2),LinearAlgebra.BandIndex(0,1))
381+
@test ind == CartesianIndex(1,1)
382+
end
383+
379384
end

0 commit comments

Comments
 (0)