Skip to content

Commit

Permalink
Fix + with degenerate bands
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty committed Aug 26, 2020
1 parent 12fbc03 commit 7e58e3e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 5 additions & 0 deletions src/generic/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion test/test_broadcasting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7e58e3e

Please sign in to comment.