@@ -421,7 +421,7 @@ for N in (0,3), M in (0,4), V in (Int, Float32)
421421
422422 if V != Int
423423 for (M, f, arity) in DiffRules. diffrules (filter_modules = nothing )
424- if f in (:hankelh1 , :hankelh1x , :hankelh2 , :hankelh2x , : / , :rem2pi )
424+ if f in (:/ , :rem2pi )
425425 continue # Skip these rules
426426 elseif ! (isdefined (@__MODULE__ , M) && isdefined (getfield (@__MODULE__ , M), f))
427427 continue # Skip rules for methods not defined in the current scope
@@ -438,9 +438,20 @@ for N in (0,3), M in (0,4), V in (Int, Float32)
438438 end
439439 @eval begin
440440 x = rand () + $ modifier
441- dx = $ M.$ f (Dual {TestTag()} (x, one (x)))
442- @test value (dx) == $ M.$ f (x)
443- @test partials (dx, 1 ) == $ deriv
441+ dx = @inferred $ M.$ f (Dual {TestTag()} (x, one (x)))
442+ actualval = $ M.$ f (x)
443+ @assert actualval isa Real || actualval isa Complex
444+ if actualval isa Real
445+ @test dx isa Dual{TestTag ()}
446+ @test value (dx) == actualval
447+ @test partials (dx, 1 ) == $ deriv
448+ else
449+ @test dx isa Complex{<: Dual{TestTag()} }
450+ @test value (real (dx)) == real (actualval)
451+ @test value (imag (dx)) == imag (actualval)
452+ @test partials (real (dx), 1 ) == real ($ deriv)
453+ @test partials (imag (dx), 1 ) == imag ($ deriv)
454+ end
444455 end
445456 elseif arity == 2
446457 derivs = DiffRules. diffrule (M, f, :x , :y )
@@ -453,14 +464,31 @@ for N in (0,3), M in (0,4), V in (Int, Float32)
453464 end
454465 @eval begin
455466 x, y = $ x, $ y
456- dx = $ M.$ f (Dual {TestTag()} (x, one (x)), y)
457- dy = $ M.$ f (x, Dual {TestTag()} (y, one (y)))
467+ dx = @inferred $ M.$ f (Dual {TestTag()} (x, one (x)), y)
468+ dy = @inferred $ M.$ f (x, Dual {TestTag()} (y, one (y)))
458469 actualdx = $ (derivs[1 ])
459470 actualdy = $ (derivs[2 ])
460- @test value (dx) == $ M.$ f (x, y)
461- @test value (dy) == value (dx)
462- @test partials (dx, 1 ) ≈ actualdx nans= true
463- @test partials (dy, 1 ) ≈ actualdy nans= true
471+ actualval = $ M.$ f (x, y)
472+ @assert actualval isa Real || actualval isa Complex
473+ if actualval isa Real
474+ @test dx isa Dual{TestTag ()}
475+ @test dy isa Dual{TestTag ()}
476+ @test value (dx) == actualval
477+ @test value (dy) == actualval
478+ @test partials (dx, 1 ) ≈ actualdx nans= true
479+ @test partials (dy, 1 ) ≈ actualdy nans= true
480+ else
481+ @test dx isa Complex{<: Dual{TestTag()} }
482+ @test dy isa Complex{<: Dual{TestTag()} }
483+ @test real (value (dx)) == real (actualval)
484+ @test real (value (dy)) == real (actualval)
485+ @test imag (value (dx)) == imag (actualval)
486+ @test imag (value (dy)) == imag (actualval)
487+ @test partials (real (dx), 1 ) ≈ real (actualdx) nans= true
488+ @test partials (real (dy), 1 ) ≈ real (actualdy) nans= true
489+ @test partials (imag (dx), 1 ) ≈ imag (actualdx) nans= true
490+ @test partials (imag (dy), 1 ) ≈ imag (actualdy) nans= true
491+ end
464492 end
465493 end
466494 end
0 commit comments