Skip to content

Commit

Permalink
conversions for dual numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeInnes committed Jan 22, 2019
1 parent 496dbfa commit 152ce4a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/tracker/lib/real.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ import Base:^

^(a::TrackedReal, b::Integer) = track(^, a, b)

# Hack for conversions

using ForwardDiff: Dual

(T::Type{<:Real})(x::Dual) = Dual(T(x.value), map(T, x.partials.values))

# Tuples

struct TrackedTuple{T<:Tuple}
Expand Down
2 changes: 2 additions & 0 deletions test/tracker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ end
@test gradtest(x -> meanpool(x, (2,2)), rand(10, 10, 3, 2))
@test gradtest(x -> meanpool(x, (2,2,2)), rand(5, 5, 5, 3, 2))

@test gradtest(x -> Float64.(x), 5)

@testset "equality & order" begin
# TrackedReal
@test param(2)^2 == param(4)
Expand Down

0 comments on commit 152ce4a

Please sign in to comment.