Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
Aqua = "0.5"
Aqua = "0.5, 0.6"
julia = "1.6"

[extras]
Expand Down
5 changes: 5 additions & 0 deletions src/fillbroadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,8 @@ broadcasted(::DefaultArrayStyle{N}, ::typeof(Base.literal_pow), ::Base.RefValue{
broadcasted(::DefaultArrayStyle{N}, ::typeof(Base.literal_pow), ::Base.RefValue{typeof(^)}, r::Ones{T,N}, ::Base.RefValue{Val{k}}) where {T,N,k} = Ones{T}(axes(r))
broadcasted(::DefaultArrayStyle{N}, ::typeof(Base.literal_pow), ::Base.RefValue{typeof(^)}, r::Zeros{T,N}, ::Base.RefValue{Val{0}}) where {T,N} = Ones{T}(axes(r))
broadcasted(::DefaultArrayStyle{N}, ::typeof(Base.literal_pow), ::Base.RefValue{typeof(^)}, r::Zeros{T,N}, ::Base.RefValue{Val{k}}) where {T,N,k} = Zeros{T}(axes(r))

# supports structured broadcast
if isdefined(LinearAlgebra, :fzero)
LinearAlgebra.fzero(x::Zeros) = zero(eltype(x))
end
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1469,3 +1469,19 @@ end
@test cor(Fill(3, 4, 5)) ≈ cor(fill(3, 4, 5)) nans=true
@test cor(Fill(3, 4, 5), dims=2) ≈ cor(fill(3, 4, 5), dims=2) nans=true
end

@testset "Structured broadcast" begin
D = Diagonal(1:5)
@test D + Zeros(5,5) isa Diagonal
@test D - Zeros(5,5) isa Diagonal
@test D .+ Zeros(5,5) isa Diagonal
@test D .- Zeros(5,5) isa Diagonal
@test D .* Zeros(5,5) isa Diagonal
@test Zeros(5,5) .* D isa Diagonal
@test Zeros(5,5) - D isa Diagonal
@test Zeros(5,5) + D isa Diagonal
@test Zeros(5,5) .- D isa Diagonal
@test Zeros(5,5) .+ D isa Diagonal
f = (x,y) -> x+1
@test f.(D, Zeros(5,5)) isa Matrix
end