Skip to content

Commit 502eee4

Browse files
committed
Remove scalar_getindex hack for Tuple; make tests more precise
Tests now check: * That single element tuple broadcast with SA still works * That expected things are inferred * That the return types of these broadcasts are precisely as expected
1 parent ce0d5f3 commit 502eee4

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/broadcast.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ end
9595

9696
scalar_getindex(x) = x
9797
scalar_getindex(x::Ref) = x[]
98-
scalar_getindex(x::Tuple{<: Any}) = x[1]
9998

10099
@generated function _broadcast(f, ::Size{newsize}, s::Tuple{Vararg{Size}}, a...) where newsize
101100
first_staticarray = 0

test/broadcast.jl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,18 @@ end
216216

217217
@testset "broadcasting with tuples" begin
218218
# issue 485
219-
v = SVector(1,2,3)
220-
@test v .+ (10, 20, 30) == SVector(11, 22, 33)
221-
vm = MVector(1,2,3)
222-
vm .+= (10, 20, 30)
223-
@test vm == SVector(11, 22, 33)
224-
@test (1,2) .+ (@SMatrix [10 20; 30 40]) == @SMatrix [11 21; 32 42]
225-
@test (@SMatrix [10 20; 30 40]) .+ (1,2) == @SMatrix [11 21; 32 42]
226-
mm = @MMatrix [10 20; 30 40]
227-
mm .+= (1,2)
228-
@test mm == @SMatrix [11 21; 32 42]
219+
@test @inferred(SA[1,2,3] .+ (1,)) === SA{Int}[2, 3, 4]
220+
@test @inferred(SA[1,2,3] .+ (10, 20, 30)) === SA{Int}[11, 22, 33]
221+
@test @inferred((1,2) .+ (SA[10 20; 30 40])) === SA{Int}[11 21; 32 42]
222+
@test @inferred((SA[10 20; 30 40]) .+ (1,2)) === SA{Int}[11 21; 32 42]
223+
224+
add_bc!(m, v) = m .+= v # Helper function; @inferred gets confused by .+= syntax
225+
@test @inferred(add_bc!(MVector((1,2,3)), (10, 20, 30))) ::MVector{3,Int} == SA[11, 22, 33]
226+
@test @inferred(add_bc!(MMatrix(SA[10 20; 30 40]), (1,2))) ::MMatrix{2,2,Int} == SA[11 21; 32 42]
227+
228+
# Tuples of SA
229+
@test SA[1,2,3] .* (SA[1,0],) === SVector{3,SVector{2,Int}}(((1,0), (2,0), (3,0)))
230+
# Unfortunately this case of nested broadcasting is not inferred
231+
@test_broken @inferred(SA[1,2,3] .* (SA[1,0],))
229232
end
230233
end

0 commit comments

Comments
 (0)