From b6f87af2fcf88beb9e195788fe630e0150ea665c Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Fri, 6 Dec 2024 18:49:43 +0530 Subject: [PATCH] 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. --- src/structuredbroadcast.jl | 1 + test/structuredbroadcast.jl | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/structuredbroadcast.jl b/src/structuredbroadcast.jl index 9a4d55fd..2c1e7bfa 100644 --- a/src/structuredbroadcast.jl +++ b/src/structuredbroadcast.jl @@ -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 diff --git a/test/structuredbroadcast.jl b/test/structuredbroadcast.jl index 71494aed..5b5cc0cd 100644 --- a/test/structuredbroadcast.jl +++ b/test/structuredbroadcast.jl @@ -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