Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special case x^1 #412

Open
dpsanders opened this issue Oct 9, 2019 · 1 comment
Open

Special case x^1 #412

dpsanders opened this issue Oct 9, 2019 · 1 comment

Comments

@dpsanders
Copy link

dpsanders commented Oct 9, 2019

x^0 is special-cased here (see #331)

Could x^1 also be special-cased a couple of lines later?
Currently it instead calculates 1 * x^0. When x == 0 that relies on 0^0 being defined correctly.

(This led to the error in #411.)

@tkf
Copy link
Contributor

tkf commented Oct 12, 2019

I think you need to special case it dynamically here

ForwardDiff.jl/src/dual.jl

Lines 452 to 453 in c374b69

if y == zero(y)
new_partials = zero(partials(x))

by adding elseif y === one(y) branch and also here

ForwardDiff.jl/src/dual.jl

Lines 472 to 473 in c374b69

for y in 1:3
@eval @inline function Base.literal_pow(::typeof(^), x::Dual{T}, ::Val{$y}) where {T}

for the literal case (x^1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants