Skip to content
Merged
Changes from 1 commit
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
14 changes: 13 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down