Skip to content

Commit

Permalink
fix: specialize / on integer types (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal authored Jan 19, 2025
1 parent 32762fb commit 32c9226
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/TracedRNumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ function Base.div(
return Ops.divide(lhs, TracedUtils.promote_to(TracedRNumber{T}, rhs))
end

function Base.:/(
@nospecialize(lhs::TracedRNumber{T}), @nospecialize(rhs::TracedRNumber{T})
) where {T<:Integer}
return float(lhs) / float(rhs)
end

for (jlop, hloop, hlocomp) in (
(:(Base.:(==)), :compare, "EQ"),
(:(Base.:(!=)), :compare, "NE"),
Expand Down
7 changes: 7 additions & 0 deletions test/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1082,3 +1082,10 @@ end

@test @jit(sum(x_ra)) == sum(x)
end

@testset "/ on integers" begin
@test @jit(/(ConcreteRNumber(2), ConcreteRNumber(4))) 0.5
@test @jit(/(ConcreteRNumber(2), 4)) 0.5
@test @jit(/(2, ConcreteRNumber(4))) 0.5
@test @jit(/(2, ConcreteRNumber(Int32(4)))) 0.5
end

2 comments on commit 32c9226

@avik-pal
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register subdir=lib/ReactantCore

@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/123295

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 ReactantCore-v0.1.4 -m "<description of version>" 32c9226e331a72fa874ed3ad532733bb7f33eb5e
git push origin ReactantCore-v0.1.4

Please sign in to comment.