Skip to content

Commit 670b480

Browse files
authored
fix: unwanted promotions in abstractrange (#1677)
1 parent c3d1de9 commit 670b480

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/TracedPromotion.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function promote_to(
4949
end
5050

5151
function promote_to(::Type{TracedRArray{T,1}}, rhs::Base.OneTo) where {T}
52-
return promote_to(TracedRArray{T,1}, 1:last(rhs))
52+
return promote_to(TracedRArray{T,1}, first(rhs):last(rhs))
5353
end
5454

5555
function promote_to(::Type{TracedRArray{T,N}}, rhs::AbstractArray{<:Any,N}) where {T,N}

test/basic.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,3 +1623,20 @@ mapped_sub(xs...) = stack(map(-, xs...))
16231623
end
16241624
end
16251625
end
1626+
1627+
@testset "AbstractRange Unwanted Promotions" begin
1628+
hlo1 = @code_hlo Reactant.promote_to(Reactant.TracedRArray, Base.OneTo(Int32(42)))
1629+
@test !contains(repr(hlo1), "42xi64")
1630+
@test contains(repr(hlo1), "42xi32")
1631+
1632+
hlo2 = @code_hlo Reactant.promote_to(Reactant.TracedRArray, Int32(34):(Int32(42)))
1633+
@test !contains(repr(hlo2), "9xi64")
1634+
@test contains(repr(hlo2), "9xi32")
1635+
1636+
hlo3 = @code_hlo Reactant.promote_to(
1637+
Reactant.TracedRArray, Int16(34):Int16(3):(Int16(42))
1638+
)
1639+
@test !contains(repr(hlo3), "3xi64")
1640+
@test !contains(repr(hlo3), "3xi32")
1641+
@test contains(repr(hlo3), "3xi16")
1642+
end

0 commit comments

Comments
 (0)