File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -425,6 +425,18 @@ for f in (:(Base.:^), :(NaNMath.pow))
425
425
end
426
426
end
427
427
428
+ @inline Base. literal_pow (:: typeof (^ ), x:: Dual{T} , :: Type{Val{0}} ) where {T} =
429
+ Dual {T} (one (value (x)), zero (partials (x)))
430
+
431
+ for y in 1 : 3
432
+ @eval @inline function Base. literal_pow (:: typeof (^ ), x:: Dual{T} , :: Val{$y} ) where {T}
433
+ v = value (x)
434
+ expv = v^ $ y
435
+ deriv = $ y * v^ $ (y - 1 )
436
+ return Dual {T} (expv, deriv * partials (x))
437
+ end
438
+ end
439
+
428
440
# hypot #
429
441
# -------#
430
442
Original file line number Diff line number Diff line change 460
460
x1 = Dual {:t1} (x0, 1.0 )
461
461
x2 = Dual {:t2} (x1, 1.0 )
462
462
x3 = Dual {:t3} (x2, 1.0 )
463
- @test x3^ 2 === x3 * x3
464
- @test x2^ 1 === x2
465
- @test x1^ 0 === Dual {:t1} (1.0 , 0.0 )
463
+ pow = ^ # to call non-literal power
464
+ @test pow (x3, 2 ) === x3^ 2 === x3 * x3
465
+ @test pow (x2, 1 ) === x2^ 1 === x2
466
+ @test pow (x1, 0 ) === x1^ 0 === Dual {:t1} (1.0 , 0.0 )
466
467
end
467
468
468
469
end # module
You can’t perform that action at this time.
0 commit comments