Skip to content

Commit 307e801

Browse files
authored
Merge pull request #14 from tkoolen/fix-broadcast-ambiguity
Fix broadcast ambiguity issue.
2 parents 84ba361 + 8b95e96 commit 307e801

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/TypeSortedCollections.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ end
198198
Base.Broadcast._containertype(::Type{<:TypeSortedCollection}) = TypeSortedCollection
199199
Base.Broadcast.promote_containertype(::Type{TypeSortedCollection}, _) = TypeSortedCollection
200200
Base.Broadcast.promote_containertype(_, ::Type{TypeSortedCollection}) = TypeSortedCollection
201+
Base.Broadcast.promote_containertype(::Type{TypeSortedCollection}, ::Type{TypeSortedCollection}) = TypeSortedCollection
201202
Base.Broadcast.promote_containertype(::Type{TypeSortedCollection}, ::Type{Array}) = TypeSortedCollection # handle ambiguities with `Array`
202203
Base.Broadcast.promote_containertype(::Type{Array}, ::Type{TypeSortedCollection}) = TypeSortedCollection # handle ambiguities with `Array`
203204

test/runtests.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,21 @@ end
150150
@test all(x .== results)
151151
end
152152

153-
@testset "broadcast!" begin
153+
@testset "broadcast! consecutive TypeSortedCollections" begin
154+
# strangely, having this test set appear later in the code results in different behavior
155+
# see https://github.com/JuliaLang/julia/pull/23800
156+
x = Number[3.; 4; 5]
157+
sortedx = TypeSortedCollection(x)
158+
y = [7.; 8.; 9.]
159+
sortedy = TypeSortedCollection(y, indices(sortedx))
160+
z = 3
161+
results = similar(y, Float64)
162+
broadcast!(M.g, results, sortedx, sortedy, z)
163+
@test all(results .== M.g.(x, y, z))
164+
@test (@allocated broadcast!(M.g, results, sortedx, sortedy, z)) == 0
165+
end
166+
167+
@testset "broadcast! TSC Vec Number" begin
154168
x = Number[3.; 4; 5]
155169
sortedx = TypeSortedCollection(x)
156170
y1 = rand(length(x))

0 commit comments

Comments
 (0)