Skip to content

Commit

Permalink
Fix broadcast ambiguities with AbstractFill (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub authored Dec 4, 2023
1 parent 96d130a commit 6c3d030
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "FillArrays"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "1.9.0"
version = "1.9.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
4 changes: 2 additions & 2 deletions src/fillbroadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ broadcasted(::DefaultArrayStyle, ::typeof(*), a::AbstractZeros, b::AbstractZeros
for op in (:*, :/)
@eval begin
broadcasted(::DefaultArrayStyle, ::typeof($op), a::AbstractZeros, b::AbstractOnes) = _broadcasted_zeros($op, a, b)
broadcasted(::DefaultArrayStyle, ::typeof($op), a::AbstractZeros, b::Fill{<:Number}) = _broadcasted_zeros($op, a, b)
broadcasted(::DefaultArrayStyle, ::typeof($op), a::AbstractZeros, b::AbstractFill{<:Number}) = _broadcasted_zeros($op, a, b)
broadcasted(::DefaultArrayStyle, ::typeof($op), a::AbstractZeros, b::Number) = _broadcasted_zeros($op, a, b)
broadcasted(::DefaultArrayStyle, ::typeof($op), a::AbstractZeros, b::AbstractRange) = _broadcasted_zeros($op, a, b)
broadcasted(::DefaultArrayStyle, ::typeof($op), a::AbstractZeros, b::AbstractArray{<:Number}) = _broadcasted_zeros($op, a, b)
Expand All @@ -157,7 +157,7 @@ end
for op in (:*, :\)
@eval begin
broadcasted(::DefaultArrayStyle, ::typeof($op), a::AbstractOnes, b::AbstractZeros) = _broadcasted_zeros($op, a, b)
broadcasted(::DefaultArrayStyle, ::typeof($op), a::Fill{<:Number}, b::AbstractZeros) = _broadcasted_zeros($op, a, b)
broadcasted(::DefaultArrayStyle, ::typeof($op), a::AbstractFill{<:Number}, b::AbstractZeros) = _broadcasted_zeros($op, a, b)
broadcasted(::DefaultArrayStyle, ::typeof($op), a::Number, b::AbstractZeros) = _broadcasted_zeros($op, a, b)
broadcasted(::DefaultArrayStyle, ::typeof($op), a::AbstractRange, b::AbstractZeros) = _broadcasted_zeros($op, a, b)
broadcasted(::DefaultArrayStyle, ::typeof($op), a::AbstractArray{<:Number}, b::AbstractZeros) = _broadcasted_zeros($op, a, b)
Expand Down
20 changes: 20 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,26 @@ oneton(sz...) = oneton(Float64, sz...)
end
end

@testset "interface" begin
struct Twos{T,N} <: FillArrays.AbstractFill{T,N,NTuple{N,Base.OneTo{Int}}}
sz :: NTuple{N,Int}
end
Twos{T}(sz::NTuple{N,Int}) where {T,N} = Twos{T,N}(sz)
Twos{T}(sz::Vararg{Int,N}) where {T,N} = Twos{T,N}(sz)
Base.size(A::Twos) = A.sz
FillArrays.getindex_value(A::Twos{T}) where {T} = oneunit(T) + oneunit(T)

@testset "broadcasting ambiguities" begin
A = Twos{Int}(3)
B = Zeros{Int}(size(A))
@test A .* B === B
@test B .* A === B
@test B ./ A === Zeros{Float64}(size(A))
@test A .\ B === Zeros{Float64}(size(A))
@test A ./ B === Fill(Inf, size(A))
end
end

@testset "indexing" begin
A = Fill(3.0,5)
@test A[1:3] Fill(3.0,3)
Expand Down

2 comments on commit 6c3d030

@dlfivefifty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/96475

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.9.1 -m "<description of version>" 6c3d030f56f6a1056200b29f604aeaaafb2dab10
git push origin v1.9.1

Please sign in to comment.