From 94d33531f32ec3d28651990e378d718e175c09a3 Mon Sep 17 00:00:00 2001 From: cossio Date: Sat, 11 Dec 2021 16:34:21 +0100 Subject: [PATCH 1/2] fix mod CI test --- test/runtests.jl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 533cf93..00f7e52 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -13,7 +13,7 @@ end @testset "DiffRules" begin @testset "check rules" begin -non_numeric_arg_functions = [(:Base, :rem2pi, 2), (:Base, :ifelse, 3)] +non_numeric_arg_functions = [(:Base, :rem2pi, 2), (:Base, :ifelse, 3), (:Base, :mod, 2)] for (M, f, arity) in DiffRules.diffrules(; filter_modules=nothing) (M, f, arity) ∈ non_numeric_arg_functions && continue @@ -91,6 +91,18 @@ for xtype in [:Float64, :BigFloat, :Int64] end end end + +# Treat mod separately because of discontinuities at integers +derivs = DiffRules.diffrule(:Base, :mod, :x, :y) +@eval begin + let + x = randn() + y = randn() + dx, dy = $(derivs[1]), $(derivs[2]) + @test isapprox(dx, finitediff(z -> mod(z, y), float(x)), rtol=0.05) + @test isapprox(dy, finitediff(z -> mod(x, z), float(y)), rtol=0.05) + end +end end @testset "diffrules" begin From f9d70df3bffffa40761f1cff59e0778c2139e6a3 Mon Sep 17 00:00:00 2001 From: cossio Date: Sat, 11 Dec 2021 18:53:26 +0100 Subject: [PATCH 2/2] devmotion suggestion --- test/runtests.jl | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 00f7e52..c27fdd0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -13,7 +13,7 @@ end @testset "DiffRules" begin @testset "check rules" begin -non_numeric_arg_functions = [(:Base, :rem2pi, 2), (:Base, :ifelse, 3), (:Base, :mod, 2)] +non_numeric_arg_functions = [(:Base, :rem2pi, 2), (:Base, :ifelse, 3)] for (M, f, arity) in DiffRules.diffrules(; filter_modules=nothing) (M, f, arity) ∈ non_numeric_arg_functions && continue @@ -45,7 +45,11 @@ for (M, f, arity) in DiffRules.diffrules(; filter_modules=nothing) derivs = DiffRules.diffrule(M, f, :foo, :bar) @eval begin let - foo, bar = rand(1:10), rand() + if "mod" == string($M.$f) + foo, bar = rand() + 13, rand() + 5 # make sure x/y is not integer + else + foo, bar = rand(1:10), rand() + end dx, dy = $(derivs[1]), $(derivs[2]) if !(isnan(dx)) @test isapprox(dx, finitediff(z -> $M.$f(z, bar), float(foo)), rtol=0.05) @@ -91,18 +95,6 @@ for xtype in [:Float64, :BigFloat, :Int64] end end end - -# Treat mod separately because of discontinuities at integers -derivs = DiffRules.diffrule(:Base, :mod, :x, :y) -@eval begin - let - x = randn() - y = randn() - dx, dy = $(derivs[1]), $(derivs[2]) - @test isapprox(dx, finitediff(z -> mod(z, y), float(x)), rtol=0.05) - @test isapprox(dy, finitediff(z -> mod(x, z), float(y)), rtol=0.05) - end -end end @testset "diffrules" begin