Skip to content

Commit

Permalink
add RoundingMode to ambiguity list and special case rem2pi in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrevels committed Jan 10, 2018
1 parent ee80bbc commit eb06c54
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ macro define_binary_dual_op(f, xy_body, x_body, y_body)
@inline $(f)(x::Dual{Txy}, y::Dual{Txy}) where {Txy} = $xy_body
@inline $(f)(x::Dual{Tx}, y::Dual{Ty}) where {Tx,Ty} = Ty Tx ? $x_body : $y_body
end
for R in REAL_TYPES
for R in AMBIGUOUS_TYPES
expr = quote
@inline $(f)(x::Dual{Tx}, y::$R) where {Tx} = $x_body
@inline $(f)(x::$R, y::Dual{Ty}) where {Ty} = $y_body
Expand All @@ -124,7 +124,7 @@ macro define_ternary_dual_op(f, xyz_body, xy_body, xz_body, yz_body, x_body, y_b
end
end
end
for R in REAL_TYPES
for R in AMBIGUOUS_TYPES
expr = quote
@inline $(f)(x::Dual{Txy}, y::Dual{Txy}, z::$R) where {Txy} = $xy_body
@inline $(f)(x::Dual{Tx}, y::Dual{Ty}, z::$R) where {Tx, Ty} = Ty Tx ? $x_body : $y_body
Expand All @@ -134,7 +134,7 @@ macro define_ternary_dual_op(f, xyz_body, xy_body, xz_body, yz_body, x_body, y_b
@inline $(f)(x::$R, y::Dual{Ty}, z::Dual{Tz}) where {Ty,Tz} = Tz Ty ? $y_body : $z_body
end
append!(defs.args, expr.args)
for Q in REAL_TYPES
for Q in AMBIGUOUS_TYPES
Q === R && continue
expr = quote
@inline $(f)(x::Dual{Tx}, y::$R, z::$Q) where {Tx} = $x_body
Expand Down
2 changes: 1 addition & 1 deletion src/prelude.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const NANSAFE_MODE_ENABLED = false

const REAL_TYPES = (AbstractFloat, Irrational, Integer, Rational, Real)
const AMBIGUOUS_TYPES = (AbstractFloat, Irrational, Integer, Rational, Real, RoundingMode)

const UNARY_PREDICATES = Symbol[:isinf, :isnan, :isfinite, :iseven, :isodd, :isreal, :isinteger]

Expand Down
9 changes: 4 additions & 5 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ samerng() = MersenneTwister(1)
intrand(V) = V == Int ? rand(2:10) : rand(V)

dual_isapprox(a, b) = isapprox(a, b)
dual_isapprox(a::Dual{T,T1,T2}, b::Dual{T,T3,T4}) where {T,T1,T2,T3,T4} =
isapprox(value(a), value(b)) && isapprox(partials(a), partials(b))
dual_isapprox(a::Dual{T,T1,T2}, b::Dual{T3,T4,T5}) where {T,T1,T2,T3,T4,T5} =
error("Tags don't match")
dual_isapprox(a::Dual{T,T1,T2}, b::Dual{T,T3,T4}) where {T,T1,T2,T3,T4} = isapprox(value(a), value(b)) && isapprox(partials(a), partials(b))
dual_isapprox(a::Dual{T,T1,T2}, b::Dual{T3,T4,T5}) where {T,T1,T2,T3,T4,T5} = error("Tags don't match")

ForwardDiff.:(::Type{TestTag()}, ::Int) = true
ForwardDiff.:(::Int, ::Type{TestTag()}) = false

Expand Down Expand Up @@ -394,7 +393,7 @@ for N in (0,3), M in (0,4), V in (Int, Float32)

if V != Int
for (M, f, arity) in DiffRules.diffrules()
in(f, (:hankelh1, :hankelh1x, :hankelh2, :hankelh2x, :/)) && continue
in(f, (:hankelh1, :hankelh1x, :hankelh2, :hankelh2x, :/, :rem2pi)) && continue
println(" ...auto-testing $(M).$(f) with $arity arguments")
if arity == 1
deriv = DiffRules.diffrule(M, f, :x)
Expand Down

0 comments on commit eb06c54

Please sign in to comment.