conversions for dual numbers

This commit is contained in:
Mike J Innes 2019-01-22 10:07:42 +00:00
parent 496dbfabd2
commit 152ce4a164
2 changed files with 8 additions and 0 deletions

View File

@ -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}

View File

@ -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)