@@ -200,6 +200,7 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
200
200
201
201
# Predicates #
202
202
# ------------#
203
+ @testset " Predicates" begin
203
204
204
205
@test ForwardDiff. isconstant (zero (FDNUM))
205
206
@test ForwardDiff. isconstant (one (FDNUM))
@@ -212,10 +213,13 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
212
213
@test isequal (FDNUM, Dual {TestTag()} (PRIMAL, PARTIALS2)) == (N == 0 )
213
214
@test isequal (PRIMAL, PRIMAL2) == isequal (FDNUM, FDNUM2)
214
215
215
- @test isequal (NESTED_FDNUM, Dual {TestTag()} (Dual {TestTag()} (PRIMAL, M_PARTIALS2), NESTED_PARTIALS2)) == (N == M == 0 )
216
- # @test isequal(PRIMAL, PRIMAL2) == isequal(NESTED_FDNUM, NESTED_FDNUM2)
216
+ # Recall that FDNUM = Dual{TestTag()}(PRIMAL, PARTIALS) has N partials,
217
+ # and FDNUM2 has everything with a 2, and all random numbers nonzero.
218
+ # M is the length of M_PARTIALS, which affects:
219
+ # NESTED_FDNUM = Dual{TestTag()}(Dual{TestTag()}(PRIMAL, M_PARTIALS), NESTED_PARTIALS)
217
220
218
- @info " Predicates" N M V PRIMAL PRIMAL2 NESTED_FDNUM NESTED_FDNUM2
221
+ @test isequal (NESTED_FDNUM, Dual {TestTag()} (Dual {TestTag()} (PRIMAL, M_PARTIALS2), NESTED_PARTIALS2)) == (N == M == 0 )
222
+ @test isequal (NESTED_FDNUM, NESTED_FDNUM2) == isequal (PRIMAL, PRIMAL2) && (N == M == 0 )
219
223
220
224
@test (FDNUM == Dual {TestTag()} (PRIMAL, PARTIALS2)) == (N == 0 )
221
225
@test (PRIMAL == PRIMAL2) == (FDNUM == FDNUM2)
@@ -300,6 +304,7 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
300
304
@test isodd (Dual {TestTag()} (Dual {TestTag()} (1 )))
301
305
@test ! (isodd (Dual {TestTag()} (Dual {TestTag()} (2 ))))
302
306
307
+ end
303
308
# #######################
304
309
# Promotion/Conversion #
305
310
# #######################
@@ -373,8 +378,11 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
373
378
374
379
# Division #
375
380
# ----------#
381
+ @testset " Division" begin
376
382
377
383
if M > 0 && N > 0
384
+ # Recall that FDNUM = Dual{TestTag()}(PRIMAL, PARTIALS) has N partials,
385
+ # all random numbers nonzero, and FDNUM2 another draw. M only affects NESTED_FDNUM.
378
386
@test Dual {1} (FDNUM) / Dual {1} (PRIMAL) === Dual {1} (FDNUM / PRIMAL)
379
387
@test Dual {1} (PRIMAL) / Dual {1} (FDNUM) === Dual {1} (PRIMAL / FDNUM)
380
388
@test_broken Dual {1} (FDNUM) / FDNUM2 === Dual {1} (FDNUM / FDNUM2)
@@ -391,8 +399,12 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
391
399
@test dual_isapprox (NESTED_FDNUM / PRIMAL, Dual {TestTag()} (value (NESTED_FDNUM) / PRIMAL, partials (NESTED_FDNUM) / PRIMAL))
392
400
@test dual_isapprox (PRIMAL / NESTED_FDNUM, Dual {TestTag()} (PRIMAL / value (NESTED_FDNUM), (- (PRIMAL) / value (NESTED_FDNUM)^ 2 ) * partials (NESTED_FDNUM)))
393
401
402
+ end
403
+
394
404
# Exponentiation #
395
405
# ----------------#
406
+ @testset " Exponentiation" begin
407
+
396
408
# If V == Int, the LHS terms are Int's. Large inputs cause integer overflow
397
409
# within the generic fallback of `isapprox`, resulting in a DomainError.
398
410
# Promote to Float64 to avoid issues.
@@ -406,6 +418,7 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
406
418
407
419
@test partials (NaNMath. pow (Dual {TestTag()} (- 2.0 , 1.0 ), Dual {TestTag()} (2.0 , 0.0 )), 1 ) == - 4.0
408
420
421
+ end
409
422
# ##################################
410
423
# General Mathematical Operations #
411
424
# ##################################
@@ -461,6 +474,7 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
461
474
462
475
# Special Cases #
463
476
# ---------------#
477
+ @testset " Special Cases" begin
464
478
465
479
@test_broken dual_isapprox (hypot (FDNUM, FDNUM2, FDNUM), sqrt (2 * (FDNUM^ 2 ) + FDNUM2^ 2 ))
466
480
@test_broken dual_isapprox (hypot (FDNUM, FDNUM2, FDNUM3), sqrt (FDNUM^ 2 + FDNUM2^ 2 + FDNUM3^ 2 ))
@@ -485,8 +499,14 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
485
499
@test dual_isapprox (f (FDNUM, PRIMAL2, PRIMAL3), Dual {TestTag()} (f (PRIMAL, PRIMAL2, PRIMAL3), PRIMAL2* PARTIALS))
486
500
@test dual_isapprox (f (PRIMAL, PRIMAL2, FDNUM3), Dual {TestTag()} (f (PRIMAL, PRIMAL2, PRIMAL3), PARTIALS3))
487
501
end
502
+
503
+ end # testset
488
504
end
489
505
506
+ # ############
507
+ # bug fixes #
508
+ # ############
509
+
490
510
@testset " Exponentiation of zero" begin
491
511
x0 = 0.0
492
512
x1 = Dual {:t1} (x0, 1.0 )
0 commit comments