Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ _abs_deriv(x) = signbit(x) ? -one(x) : one(x)
# trinary #
#---------#

@define_diffrule Base.hypot(x, y, z) = :( $x / hypot($x, $y, $z) ), :( $y / hypot($x, $y, $z) ), :( $z / hypot($x, $y, $z) )

#=

@define_diffrule Base.muladd(x, y, z) = :($y), :($x), :(one($z))
Expand Down
33 changes: 21 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,32 @@ non_diffeable_arg_functions = [(:Base, :rem2pi, 2), (:Base, :ldexp, 2), (:Base,
end
end
elseif arity == 3
#=
@test DiffRules.hasdiffrule(M, f, 3)
derivs = DiffRules.diffrule(M, f, :foo, :bar, :goo)
@eval begin
foo, bar, goo = randn(3)
dx, dy, dz = $(derivs[1]), $(derivs[2]), $(derivs[3])
if !(isnan(dx))
@test isapprox(dx, finitediff(x -> $M.$f(x, bar, goo), foo), rtol=0.05)
end
if !(isnan(dy))
@test isapprox(dy, finitediff(y -> $M.$f(foo, y, goo), bar), rtol=0.05)
end
if !(isnan(dz))
@test isapprox(dz, finitediff(z -> $M.$f(foo, bar, z), goo), rtol=0.05)
let
foo, bar, goo = rand($T), rand($T), rand($T)
dx, dy, dz = $(derivs[1]), $(derivs[2]), $(derivs[3])
if !(isnan(dx))
@test dx ≈ finitediff(z -> $M.$f(z, 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(z -> $M.$f(foo, z, 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=1e-2

# Check type, if applicable.
@test promote_type(typeof(real(dz)), $T) === $T
end
end
end
=#
end
end
end
Expand Down
Loading