Skip to content

Commit 0af523a

Browse files
authored
Fix deprecation warning introduced by DiffRules v1.4 (#553)
* Fix deprecation warning introduced by DiffRules v1.4 * Fix typo * Add rules for LogExpFunctions * Update Project.toml
1 parent 8b40834 commit 0af523a

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
name = "ForwardDiff"
22
uuid = "f6369f11-7733-5829-9624-2563aa707210"
3-
version = "0.10.22"
3+
version = "0.10.23"
44

55
[deps]
66
CommonSubexpressions = "bbf7d656-a473-5ed7-a52c-81e309532950"
77
DiffResults = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
88
DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b"
99
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
10+
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
1011
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
1112
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
1213
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
@@ -18,8 +19,9 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1819
Calculus = "0.2, 0.3, 0.4, 0.5"
1920
CommonSubexpressions = "0.3"
2021
DiffResults = "0.0.1, 0.0.2, 0.0.3, 0.0.4, 1.0.1"
21-
DiffRules = "1.2.1"
22+
DiffRules = "1.4.0"
2223
DiffTests = "0.0.1, 0.1"
24+
LogExpFunctions = "0.3"
2325
NaNMath = "0.2.2, 0.3"
2426
Preferences = "1"
2527
SpecialFunctions = "0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 1.0"

src/ForwardDiff.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ using LinearAlgebra
1212
import Printf
1313
import NaNMath
1414
import SpecialFunctions
15+
import LogExpFunctions
1516
import CommonSubexpressions
1617

1718
include("prelude.jl")

src/dual.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,12 @@ Base.float(d::Dual) = convert(float(typeof(d)), d)
392392
# General Mathematical Operations #
393393
###################################
394394

395-
for (M, f, arity) in DiffRules.diffrules()
396-
in((M, f), ((:Base, :^), (:NaNMath, :pow), (:Base, :/), (:Base, :+), (:Base, :-))) && continue
395+
for (M, f, arity) in DiffRules.diffrules(filter_modules = nothing)
396+
if (M, f) in ((:Base, :^), (:NaNMath, :pow), (:Base, :/), (:Base, :+), (:Base, :-))
397+
continue # Skip methods which we define elsewhere.
398+
elseif !(isdefined(@__MODULE__, M) && isdefined(getfield(@__MODULE__, M), f))
399+
continue # Skip rules for methods not defined in the current scope
400+
end
397401
if arity == 1
398402
eval(unary_dual_definition(M, f))
399403
elseif arity == 2

test/DualTest.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ using Random
66
using ForwardDiff
77
using ForwardDiff: Partials, Dual, value, partials
88

9-
using NaNMath, SpecialFunctions
9+
using NaNMath, SpecialFunctions, LogExpFunctions
1010
using DiffRules
1111

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

422422
if V != Int
423-
for (M, f, arity) in DiffRules.diffrules()
424-
in(f, (:hankelh1, :hankelh1x, :hankelh2, :hankelh2x, :/, :rem2pi)) && continue
423+
for (M, f, arity) in DiffRules.diffrules(filter_modules = nothing)
424+
if f in (:hankelh1, :hankelh1x, :hankelh2, :hankelh2x, :/, :rem2pi)
425+
continue # Skip these rules
426+
elseif !(isdefined(@__MODULE__, M) && isdefined(getfield(@__MODULE__, M), f))
427+
continue # Skip rules for methods not defined in the current scope
428+
end
425429
println(" ...auto-testing $(M).$(f) with $arity arguments")
426430
if arity == 1
427431
deriv = DiffRules.diffrule(M, f, :x)
428-
modifier = in(f, (:asec, :acsc, :asecd, :acscd, :acosh, :acoth)) ? one(V) : zero(V)
432+
modifier = if in(f, (:asec, :acsc, :asecd, :acscd, :acosh, :acoth))
433+
one(V)
434+
elseif in(f, (:log1mexp, :log2mexp))
435+
-one(V)
436+
else
437+
zero(V)
438+
end
429439
@eval begin
430440
x = rand() + $modifier
431441
dx = $M.$f(Dual{TestTag()}(x, one(x)))

0 commit comments

Comments
 (0)