From 7e58e3effaf0cc549ad5072df6ab87d4bd5e8969 Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Wed, 26 Aug 2020 11:42:19 +0100 Subject: [PATCH] Fix + with degenerate bands --- Project.toml | 2 +- src/generic/broadcast.jl | 5 +++++ test/test_broadcasting.jl | 13 ++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index cfdeef84..249f915e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BandedMatrices" uuid = "aae01518-5342-5314-be14-df237901396f" -version = "0.15.18" +version = "0.15.19" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/generic/broadcast.jl b/src/generic/broadcast.jl index a458dc6d..8cdcbace 100644 --- a/src/generic/broadcast.jl +++ b/src/generic/broadcast.jl @@ -641,6 +641,11 @@ function _banded_broadcast!(dest::AbstractMatrix, f, (A,B)::Tuple{AbstractMatrix # fill extra bands in dest fill!(view(data_d,1:d_u-max(A_u,B_u),:), z) fill!(view(data_d,d_u+max(A_l,B_l)+2:size(data_d,1),:), z) + # between A and B if non-overlapping + bs = max(-d_u,-B_l+1):min(A_u-1,d_l) + fill!(view(data_d, bs .+ d_u .+ 1, :), z) + bs = max(-d_u,-A_l+1):min(B_u-1,d_l) + fill!(view(data_d, bs .+ d_u .+ 1, :), z) # construct where B upper is zero # this is from band A_u:B_u+1 diff --git a/test/test_broadcasting.jl b/test/test_broadcasting.jl index 890b4d17..b3332039 100644 --- a/test/test_broadcasting.jl +++ b/test/test_broadcasting.jl @@ -512,5 +512,16 @@ import BandedMatrices: BandedStyle, BandedRows @test copyto!(similar(bc, Float64), bc) == A .* B == B .* A == BandedMatrix(B, (0,0)) == Matrix(A) .* B - end + end + + @testset "adding degenerate" begin + A = BandedMatrix(1 => 1:9) + B = BandedMatrix(-1 => 1:9) + C = BandedMatrix(Fill(-1,10,10),(1,1)) + C .= A .+ B + @test diag(C) == Zeros{Int}(10) + C = BandedMatrix(Fill(-1,10,10),(1,1)) + C .= A .+ B + @test diag(C) == Zeros{Int}(10) + end end \ No newline at end of file