autodiff.Dual.__pow__¶
- Dual.__pow__(other)¶
Return
self
to the power ofother
.- Parameters
- selfDual
- otherint, float
- Returns
- outDual
Notes
If
other
is a non-integer scalar andself.val
is less than zero, the derivative is a complex number. This will raise a ValueError. Only integer powers are supported if the base is negative.If
self.val
is equal to zero andother
is less than one, we cannot compute the derivative of the result due to a ZeroDivisionError.If
other
is a Dual andself.val
is less than or equal to zero, we cannot compute the derivative of the result since the log of a negative number is not defined. This will raise a ValueError.Examples
Dual number and scalar:
>>> ad.Dual(2) ** 5 Dual(32, array([80]))
Two dual numbers (univariate):
>>> ad.Dual(2, [1]) ** ad.Dual(3, [2]) Dual(8, array([23.09035489]))
Two dual numbers (multivariate):
>>> ad.Dual(3, [1, 2]) ** ad.Dual(2, [3, 4]) Dual(9, array([35.66253179, 51.55004239]))
Example of errors raised (see notes above):
>>> ad.Dual(-1) ** 1.2 Traceback (most recent call last): ... ValueError: -1 cannot be raised to the power of 1.2; only integer powers are allowed if base is negative
>>> ad.Dual(0) ** -2 Traceback (most recent call last): ... ZeroDivisionError: 0.0 cannot be raised to a negative power
>>> ad.Dual(0) ** ad.Dual(1) Traceback (most recent call last): ... ValueError: 0 cannot be raised to the power of 1; log is undefined for x = 0