Skip to content

Commit 1b389c0

Browse files
committed
tidy, rm some comments
1 parent 8c718df commit 1b389c0

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

src/rulesets/Base/fastmath_able.jl

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -167,35 +167,16 @@ let
167167
# literal_pow is in base.jl
168168
function frule((_, Δx, Δp), ::typeof(^), x::Number, p::Number)
169169
y = x ^ p
170-
# thegrad = (p * y / x)
171-
# thelog = Δp isa AbstractZero ? Δp : log(oftype(y, x))
172-
# return y, muladd(y * thelog, Δp, thegrad * Δx)
173-
# end
174-
# function frule((_, Δx, Δp), ::typeof(^), x::Real, p::Real)
175-
# y = x ^ p
176170
thegrad = _pow_grad_x(x, p, float(y))
177171
thelog = if Δp isa AbstractZero
178172
# Then don't waste time computing log
179173
Δp
180-
else# if x isa Real && p isa Real
181-
# For positive x we'd like a real answer, including any Δp.
182-
# For negative x, this is a DomainError unless isinteger(p)...
183-
184-
# could decide that implues that p is non-differentiable:
185-
# log(ifelse(x<0, one(x), x))
186-
187-
# or we could match what the rrule with ProjectTo gives:
188-
real(log(complex(x)))
189-
#=
190-
191-
julia> frule((0,0,1), ^, -4, 3.0), unthunk.(rrule(^, -4, 3.0)[2](1))
192-
((-64.0, 0.0), (NoTangent(), 48.0, -88.722839111673))
193-
194-
julia> frule((0,0,1), ^, 4, 3.0), unthunk.(rrule(^, 4, 3.0)[2](1))
195-
((64.0, 88.722839111673), (NoTangent(), 48.0, 88.722839111673))
196-
=#
174+
else
175+
# When x < 0 && isinteger(p), could decide p is non-differentiable,
176+
# isolated points, or could match what the rrule with ProjectTo gives:
177+
_pow_grad_p(x, p, float(y))
197178
end
198-
return y, muladd(y * thelog, Δp, thegrad * Δx)
179+
return y, muladd(thelog, Δp, thegrad * Δx)
199180
end
200181

201182
function rrule(::typeof(^), x::Number, p::Number)
@@ -208,6 +189,7 @@ julia> frule((0,0,1), ^, 4, 3.0), unthunk.(rrule(^, 4, 3.0)[2](1))
208189
end
209190
return y, power_pullback
210191
end
192+
211193
_pow_grad_x(x, p, y) = (p * y / x)
212194
function _pow_grad_x(x::Real, p::Real, y)
213195
return ifelse(!iszero(x) | (p<0), (p * y / x),
@@ -220,7 +202,6 @@ julia> frule((0,0,1), ^, 4, 3.0), unthunk.(rrule(^, 4, 3.0)[2](1))
220202
ifelse(p>0, zero(y), oftype(y, NaN) ))
221203
end
222204

223-
224205
@scalar_rule(
225206
rem(x, y),
226207
@setup((u, nan) = promote(x / y, NaN16), isint = isinteger(x / y)),

0 commit comments

Comments
 (0)