From 3237874ef078ae73c64eb6618f1c542a70fbcbb6 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Sun, 4 Jul 2021 20:30:50 -0400 Subject: [PATCH 1/7] Revert "comment out trinary rules" This reverts commit ead820dfd4dcac0264a2f927ce5d91c10f74bb23. --- src/rules.jl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/rules.jl b/src/rules.jl index e1a1726..f3528ce 100644 --- a/src/rules.jl +++ b/src/rules.jl @@ -103,15 +103,11 @@ end # trinary # #---------# -#= - @define_diffrule Base.muladd(x, y, z) = :($y), :($x), :(one($z)) @define_diffrule Base.fma(x, y, z) = :($y), :($x), :(one($z)) @define_diffrule Base.ifelse(p, x, y) = false, :($p), :(!$p) -=# - #################### # SpecialFunctions # #################### From 750591b5e0045a19853cd52457b409c639c875fb Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Sun, 4 Jul 2021 20:32:07 -0400 Subject: [PATCH 2/7] v1.4.0 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 28f4607..88671e2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DiffRules" uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" -version = "1.3.0" +version = "1.4.0" [deps] NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" From 660dc041ac8497ee9c0340013bb1195851461891 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Sun, 4 Jul 2021 20:32:54 -0400 Subject: [PATCH 3/7] Revert "also comment out trinary tests" This reverts commit 148b29c20d4724bb897076d17765db8a47f73e2d. --- test/runtests.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index e3da95f..c41c29e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -47,7 +47,6 @@ for (M, f, arity) in DiffRules.diffrules() end end elseif arity == 3 - #= @test DiffRules.hasdiffrule(M, f, 3) derivs = DiffRules.diffrule(M, f, :foo, :bar, :goo) @eval begin @@ -63,7 +62,6 @@ for (M, f, arity) in DiffRules.diffrules() @test isapprox(dz, finitediff(z -> $M.$f(foo, bar, z), goo), rtol=0.05) end end - =# end end @@ -82,7 +80,6 @@ for xtype in [:Float64, :BigFloat, :Int64] end # Test ifelse separately as first argument is boolean -#= @test DiffRules.hasdiffrule(:Base, :ifelse, 3) derivs = DiffRules.diffrule(:Base, :ifelse, :foo, :bar, :goo) for cond in [true, false] @@ -94,4 +91,4 @@ for cond in [true, false] @test isapprox(dz, finitediff(z -> ifelse(foo, bar, z), goo), rtol=0.05) end end -=# + From c6c68efb6d463c6d345050906ed4c1be58c65e59 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Tue, 21 Sep 2021 16:04:27 -0400 Subject: [PATCH 4/7] Apply 2 suggestions Co-authored-by: David Widmann --- src/rules.jl | 2 +- test/runtests.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rules.jl b/src/rules.jl index 26adf0c..b038f75 100644 --- a/src/rules.jl +++ b/src/rules.jl @@ -103,7 +103,7 @@ end @define_diffrule Base.muladd(x, y, z) = :($y), :($x), :(one($z)) @define_diffrule Base.fma(x, y, z) = :($y), :($x), :(one($z)) -@define_diffrule Base.ifelse(p, x, y) = false, :($p), :(!$p) +@define_diffrule Base.ifelse(p, x, y) = NaN, :($p), :(!$p) #################### # SpecialFunctions # diff --git a/test/runtests.jl b/test/runtests.jl index c41c29e..686b679 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -82,7 +82,7 @@ end # Test ifelse separately as first argument is boolean @test DiffRules.hasdiffrule(:Base, :ifelse, 3) derivs = DiffRules.diffrule(:Base, :ifelse, :foo, :bar, :goo) -for cond in [true, false] +for cond in (true, false) @eval begin foo = $cond bar, gee = randn(2) From 7256e9ed5e46c35cac9149213d9c578f1729b2d4 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Tue, 21 Sep 2021 17:19:16 -0400 Subject: [PATCH 5/7] Update test/runtests.jl --- test/runtests.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/runtests.jl b/test/runtests.jl index 686b679..dfda529 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -89,6 +89,7 @@ for cond in (true, false) dx, dy, dz = $(derivs[1]), $(derivs[2]), $(derivs[3]) @test isapprox(dy, finitediff(y -> ifelse(foo, y, goo), bar), rtol=0.05) @test isapprox(dz, finitediff(z -> ifelse(foo, bar, z), goo), rtol=0.05) + @test isnan(dx) end end From db8d4eb3b604fa88b2a317c07379d802fd957b05 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Thu, 27 Apr 2023 12:17:06 +0200 Subject: [PATCH 6/7] Fix test --- test/runtests.jl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index fd1fa21..c6c8780 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -211,12 +211,14 @@ end derivs = DiffRules.diffrule(:Base, :ifelse, :foo, :bar, :goo) for cond in (true, false) @eval begin - foo = $cond - bar, gee = randn(2) - dx, dy, dz = $(derivs[1]), $(derivs[2]), $(derivs[3]) - @test isapprox(dy, finitediff(y -> ifelse(foo, y, goo), bar), rtol=0.05) - @test isapprox(dz, finitediff(z -> ifelse(foo, bar, z), goo), rtol=0.05) - @test isnan(dx) + let + foo = $cond + bar, goo = randn(2) + dx, dy, dz = $(derivs[1]), $(derivs[2]), $(derivs[3]) + @test isnan(dx) + @test dy ≈ finitediff(y -> ifelse(foo, y, goo), bar) rtol=0.05 + @test dz ≈ finitediff(z -> ifelse(foo, bar, z), goo) rtol=0.05 + end end end From 6a7aeefa73fd7b6e78c1f3d9bb81877cfb9276b5 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Thu, 27 Apr 2023 12:27:34 +0200 Subject: [PATCH 7/7] Change tolerances --- test/runtests.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index c6c8780..a1bb486 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -95,17 +95,17 @@ non_diffeable_arg_functions = [(:Base, :rem2pi, 2), (:Base, :ldexp, 2), (:Base, foo, bar, goo = randn($T, 3) dx, dy, dz = $(derivs[1]), $(derivs[2]), $(derivs[3]) if !isnan(dx) - @test dx ≈ finitediff(x -> $M.$f(x, bar, goo), foo) rtol=0.05 + @test dx ≈ finitediff(x -> $M.$f(x, bar, goo), foo) rtol=1e-2 # Check type, if applicable. @test promote_type(typeof(real(dx)), $T) === $T end if !isnan(dy) - @test dy ≈ finitediff(y -> $M.$f(foo, y, goo), bar) rtol=0.05 + @test dy ≈ finitediff(y -> $M.$f(foo, y, goo), bar) rtol=1e-2 # Check type, if applicable. @test promote_type(typeof(real(dy)), $T) === $T end if !isnan(dz) - @test dz ≈ finitediff(z -> $M.$f(foo, bar, z), goo) rtol=0.05 + @test dz ≈ finitediff(z -> $M.$f(foo, bar, z), goo) rtol=1e-2 # Check type, if applicable. @test promote_type(typeof(real(dz)), $T) === $T end @@ -216,8 +216,8 @@ for cond in (true, false) bar, goo = randn(2) dx, dy, dz = $(derivs[1]), $(derivs[2]), $(derivs[3]) @test isnan(dx) - @test dy ≈ finitediff(y -> ifelse(foo, y, goo), bar) rtol=0.05 - @test dz ≈ finitediff(z -> ifelse(foo, bar, z), goo) rtol=0.05 + @test dy ≈ finitediff(y -> ifelse(foo, y, goo), bar) rtol=1e-2 atol=1e-9 + @test dz ≈ finitediff(z -> ifelse(foo, bar, z), goo) rtol=1e-2 atol=1e-9 end end end