-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #629 from Kolaru/fowarddiff_pow
ForwardDiff extension for power
- Loading branch information
Showing
4 changed files
with
97 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
name = "IntervalArithmetic" | ||
uuid = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" | ||
repo = "https://github.com/JuliaIntervals/IntervalArithmetic.jl.git" | ||
version = "0.22.7" | ||
version = "0.22.8" | ||
|
||
[deps] | ||
CRlibm_jll = "4e9b3aee-d8a1-5a3d-ad8b-7d824db253f0" | ||
RoundingEmulator = "5eaf0fd0-dfba-4ccb-bf02-d820a40db705" | ||
|
||
[weakdeps] | ||
DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b" | ||
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" | ||
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" | ||
|
||
[extensions] | ||
IntervalArithmeticDiffRulesExt = "DiffRules" | ||
IntervalArithmeticForwardDiffExt = "ForwardDiff" | ||
IntervalArithmeticRecipesBaseExt = "RecipesBase" | ||
|
||
[compat] | ||
CRlibm_jll = "1" | ||
DiffRules = "1" | ||
ForwardDiff = "0.10" | ||
RecipesBase = "1" | ||
RoundingEmulator = "0.2" | ||
julia = "1.9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module IntervalArithmeticForwardDiffExt | ||
|
||
using IntervalArithmetic, ForwardDiff | ||
using ForwardDiff: Dual, ≺, value, partials | ||
|
||
function isconstant_interval(x) | ||
all(isthinzero.(values(partials(x)))) | ||
end | ||
|
||
function Base.:(^)(x::Dual{Txy, <:Interval}, y::Dual{Txy, <:Interval}) where Txy | ||
vx, vy = value(x), value(y) | ||
expv = vx^vy | ||
powval = vy * vx^(vy - interval(1)) | ||
if isconstant_interval(y) | ||
logval = one(expv) | ||
elseif isthinzero(vx) && inf(vy) > 0 | ||
logval = zero(vx) | ||
else | ||
logval = expv * log(vx) | ||
end | ||
new_partials = ForwardDiff._mul_partials(partials(x), partials(y), powval, logval) | ||
return Dual{Txy}(expv, new_partials) | ||
end | ||
|
||
function Base.:(^)(x::Dual{Tx, <:Interval}, y::Dual{Ty, <:Interval}) where {Tx, Ty} | ||
if Ty ≺ Tx | ||
return x^value(y) | ||
else | ||
return value(x)^y | ||
end | ||
end | ||
|
||
function Base.:(^)(x::Dual{Tx, <:Interval}, y::Interval) where Tx | ||
v = value(x) | ||
expv = v^y | ||
if isthinzero(y) || isconstant_interval(x) | ||
new_partials = zero(partials(x)) | ||
else | ||
new_partials = partials(x) * y * v^(y - interval(1)) | ||
end | ||
return Dual{Tx}(expv, new_partials) | ||
end | ||
|
||
function Base.:(^)(x::Interval, y::Dual{Ty, <:Interval}) where Ty | ||
v = value(y) | ||
expv = x^v | ||
deriv = (isthinzero(x) && inf(v) > 0) ? zero(expv) : expv*log(x) | ||
return Dual{Ty}(expv, deriv * partials(y)) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5275e5c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
5275e5c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/101546
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: