Skip to content

Fix deprecation warning introduced by DiffRules v1.4 #553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name = "ForwardDiff"
uuid = "f6369f11-7733-5829-9624-2563aa707210"
version = "0.10.22"
version = "0.10.23"

[deps]
CommonSubexpressions = "bbf7d656-a473-5ed7-a52c-81e309532950"
DiffResults = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Expand All @@ -18,8 +19,9 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Calculus = "0.2, 0.3, 0.4, 0.5"
CommonSubexpressions = "0.3"
DiffResults = "0.0.1, 0.0.2, 0.0.3, 0.0.4, 1.0.1"
DiffRules = "1.2.1"
DiffRules = "1.4.0"
DiffTests = "0.0.1, 0.1"
LogExpFunctions = "0.3"
NaNMath = "0.2.2, 0.3"
Preferences = "1"
SpecialFunctions = "0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 1.0"
Expand Down
1 change: 1 addition & 0 deletions src/ForwardDiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using LinearAlgebra
import Printf
import NaNMath
import SpecialFunctions
import LogExpFunctions
import CommonSubexpressions

include("prelude.jl")
Expand Down
8 changes: 6 additions & 2 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,12 @@ Base.float(d::Dual) = convert(float(typeof(d)), d)
# General Mathematical Operations #
###################################

for (M, f, arity) in DiffRules.diffrules()
in((M, f), ((:Base, :^), (:NaNMath, :pow), (:Base, :/), (:Base, :+), (:Base, :-))) && continue
for (M, f, arity) in DiffRules.diffrules(filter_modules = nothing)
if (M, f) in ((:Base, :^), (:NaNMath, :pow), (:Base, :/), (:Base, :+), (:Base, :-))
continue # Skip methods which we define elsewhere.
elseif !(isdefined(@__MODULE__, M) && isdefined(getfield(@__MODULE__, M), f))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this a reasonable way to check if M and f are defined? Seems a bit clunky.

continue # Skip rules for methods not defined in the current scope
end
if arity == 1
eval(unary_dual_definition(M, f))
elseif arity == 2
Expand Down
18 changes: 14 additions & 4 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Random
using ForwardDiff
using ForwardDiff: Partials, Dual, value, partials

using NaNMath, SpecialFunctions
using NaNMath, SpecialFunctions, LogExpFunctions
using DiffRules

import Calculus
Expand Down Expand Up @@ -420,12 +420,22 @@ for N in (0,3), M in (0,4), V in (Int, Float32)
@test abs(NESTED_FDNUM) === NESTED_FDNUM

if V != Int
for (M, f, arity) in DiffRules.diffrules()
in(f, (:hankelh1, :hankelh1x, :hankelh2, :hankelh2x, :/, :rem2pi)) && continue
for (M, f, arity) in DiffRules.diffrules(filter_modules = nothing)
if f in (:hankelh1, :hankelh1x, :hankelh2, :hankelh2x, :/, :rem2pi)
continue # Skip these rules
elseif !(isdefined(@__MODULE__, M) && isdefined(getfield(@__MODULE__, M), f))
continue # Skip rules for methods not defined in the current scope
end
println(" ...auto-testing $(M).$(f) with $arity arguments")
if arity == 1
deriv = DiffRules.diffrule(M, f, :x)
modifier = in(f, (:asec, :acsc, :asecd, :acscd, :acosh, :acoth)) ? one(V) : zero(V)
modifier = if in(f, (:asec, :acsc, :asecd, :acscd, :acosh, :acoth))
one(V)
elseif in(f, (:log1mexp, :log2mexp))
-one(V)
else
zero(V)
end
@eval begin
x = rand() + $modifier
dx = $M.$f(Dual{TestTag()}(x, one(x)))
Expand Down