Skip to content

Commit 4b54fd7

Browse files
committed
add RoundingMode to ambiguity list and special case rem2pi in tests
1 parent ee80bbc commit 4b54fd7

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/dual.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ macro define_binary_dual_op(f, xy_body, x_body, y_body)
9898
@inline $(f)(x::Dual{Txy}, y::Dual{Txy}) where {Txy} = $xy_body
9999
@inline $(f)(x::Dual{Tx}, y::Dual{Ty}) where {Tx,Ty} = Ty Tx ? $x_body : $y_body
100100
end
101-
for R in REAL_TYPES
101+
for R in AMBIGUOUS_TYPES
102102
expr = quote
103103
@inline $(f)(x::Dual{Tx}, y::$R) where {Tx} = $x_body
104104
@inline $(f)(x::$R, y::Dual{Ty}) where {Ty} = $y_body
@@ -124,7 +124,7 @@ macro define_ternary_dual_op(f, xyz_body, xy_body, xz_body, yz_body, x_body, y_b
124124
end
125125
end
126126
end
127-
for R in REAL_TYPES
127+
for R in AMBIGUOUS_TYPES
128128
expr = quote
129129
@inline $(f)(x::Dual{Txy}, y::Dual{Txy}, z::$R) where {Txy} = $xy_body
130130
@inline $(f)(x::Dual{Tx}, y::Dual{Ty}, z::$R) where {Tx, Ty} = Ty Tx ? $x_body : $y_body
@@ -134,7 +134,7 @@ macro define_ternary_dual_op(f, xyz_body, xy_body, xz_body, yz_body, x_body, y_b
134134
@inline $(f)(x::$R, y::Dual{Ty}, z::Dual{Tz}) where {Ty,Tz} = Tz Ty ? $y_body : $z_body
135135
end
136136
append!(defs.args, expr.args)
137-
for Q in REAL_TYPES
137+
for Q in AMBIGUOUS_TYPES
138138
Q === R && continue
139139
expr = quote
140140
@inline $(f)(x::Dual{Tx}, y::$R, z::$Q) where {Tx} = $x_body

src/prelude.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const NANSAFE_MODE_ENABLED = false
22

3-
const REAL_TYPES = (AbstractFloat, Irrational, Integer, Rational, Real)
3+
const AMBIGUOUS_TYPES = (AbstractFloat, Irrational, Integer, Rational, Real, RoundingMode)
44

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

test/DualTest.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ samerng() = MersenneTwister(1)
1919
intrand(V) = V == Int ? rand(2:10) : rand(V)
2020

2121
dual_isapprox(a, b) = isapprox(a, b)
22-
dual_isapprox(a::Dual{T,T1,T2}, b::Dual{T,T3,T4}) where {T,T1,T2,T3,T4} =
23-
isapprox(value(a), value(b)) && isapprox(partials(a), partials(b))
24-
dual_isapprox(a::Dual{T,T1,T2}, b::Dual{T3,T4,T5}) where {T,T1,T2,T3,T4,T5} =
25-
error("Tags don't match")
22+
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))
23+
dual_isapprox(a::Dual{T,T1,T2}, b::Dual{T3,T4,T5}) where {T,T1,T2,T3,T4,T5} = error("Tags don't match")
24+
2625
ForwardDiff.:(::Type{TestTag()}, ::Int) = true
2726
ForwardDiff.:(::Int, ::Type{TestTag()}) = false
2827

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

395394
if V != Int
396395
for (M, f, arity) in DiffRules.diffrules()
397-
in(f, (:hankelh1, :hankelh1x, :hankelh2, :hankelh2x, :/)) && continue
396+
in(f, (:hankelh1, :hankelh1x, :hankelh2, :hankelh2x, :/, :rem2pi)) && continue
398397
println(" ...auto-testing $(M).$(f) with $arity arguments")
399398
if arity == 1
400399
deriv = DiffRules.diffrule(M, f, :x)

0 commit comments

Comments
 (0)