Skip to content

Commit c9a79db

Browse files
Merge pull request #18 from ChrisRackauckas/fix-formatting
Apply JuliaFormatter to fix code formatting
2 parents 39721c1 + b3f815c commit c9a79db

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

ext/FastPowerEnzymeExt.jl

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,27 @@ function Enzyme.EnzymeRules.forward(config::FwdConfig,
1313
y = _y.val
1414
ret = func.val(x, y)
1515
T = typeof(ret)
16-
if !(_x isa Const)
17-
dxval = _x.dval * y * (fastpower(x,y - 1))
18-
else
16+
if !(_x isa Const)
17+
dxval = _x.dval * y * (fastpower(x, y - 1))
18+
else
1919
dxval = make_zero(_x.val)
2020
end
21-
if !(_y isa Const)
22-
dyval = x isa Real && x<=0 ? Base.oftype(float(x), NaN) : _y.dval*(fastpower(x,y))*log(x)
23-
else
21+
if !(_y isa Const)
22+
dyval = x isa Real && x<=0 ? Base.oftype(float(x), NaN) :
23+
_y.dval*(fastpower(x, y))*log(x)
24+
else
2425
dyval = make_zero(_y.val)
25-
end
26+
end
2627
if RT <: DuplicatedNoNeed
27-
return convert(T,dxval + dyval)
28+
return convert(T, dxval + dyval)
2829
else
2930
return Duplicated(ret, convert(T, dxval + dyval))
3031
end
3132
end
3233

33-
function EnzymeRules.augmented_primal(config::Enzyme.EnzymeRules.RevConfigWidth{1},
34-
func::Const{typeof(fastpower)}, ::Union{Type{<:Active}, Type{<:Const}}, x::Union{Const,Active}, y::Union{Const,Active})
34+
function EnzymeRules.augmented_primal(config::Enzyme.EnzymeRules.RevConfigWidth{1},
35+
func::Const{typeof(fastpower)}, ::Union{Type{<:Active}, Type{<:Const}},
36+
x::Union{Const, Active}, y::Union{Const, Active})
3537
if EnzymeRules.needs_primal(config)
3638
primal = func.val(x.val, y.val)
3739
else
@@ -40,12 +42,15 @@ function EnzymeRules.augmented_primal(config::Enzyme.EnzymeRules.RevConfigWidth{
4042
return EnzymeRules.AugmentedReturn(primal, nothing, nothing)
4143
end
4244

43-
function EnzymeRules.reverse(config::Enzyme.EnzymeRules.RevConfigWidth{1},
44-
func::Const{typeof(fastpower)}, dret, tape, _x::Union{Const,Active}, _y::Union{Const,Active})
45+
function EnzymeRules.reverse(config::Enzyme.EnzymeRules.RevConfigWidth{1},
46+
func::Const{typeof(fastpower)}, dret, tape, _x::Union{Const, Active}, _y::Union{
47+
Const, Active})
4548
x = _x.val
4649
y = _y.val
47-
dxval = _x isa Const ? nothing : dret.val * y * (fastpower(x,y - 1))
48-
dyval = _y isa Const ? nothing : (x isa Real && x<=0 ? Base.oftype(float(x), NaN) : dret.val * (fastpower(x,y))*log(x))
50+
dxval = _x isa Const ? nothing : dret.val * y * (fastpower(x, y - 1))
51+
dyval = _y isa Const ? nothing :
52+
(x isa Real && x<=0 ? Base.oftype(float(x), NaN) :
53+
dret.val * (fastpower(x, y)) * log(x))
4954
return (dxval, dyval)
5055
end
5156

ext/FastPowerMooncakeExt.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module FastPowerMooncakeExt
22

33
using FastPower, Mooncake
4-
Mooncake.@mooncake_overlay FastPower.fastpower(x,y) = x^y
4+
Mooncake.@mooncake_overlay FastPower.fastpower(x, y) = x^y
55

6-
end
6+
end

src/FastPower.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module FastPower
1111
c = 0.523692f0
1212
# IEEE is sgn(1):exp(8):frac(23) representing
1313
# (1+frac)*2^(exp-127). 1+frac is called the significand
14-
14+
1515
# get exponent
1616
ux1i = reinterpret(UInt32, x)
1717
exp = Int32((ux1i & 0x7F800000) >> 23)
@@ -24,7 +24,7 @@ module FastPower
2424
ux2i = (ux1i & 0x007FFFFF) | 0x3f000000
2525
exp -= 0x7e # 126 instead of 127 compensates for division by 2
2626
end
27-
signif = reinterpret(Float32, ux2i)
27+
signif = reinterpret(Float32, ux2i)
2828
quot = muladd(signif, a, b) / (signif + c)
2929
return muladd(signif - 1.0f0, quot, exp)
3030
end

test/runtests.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,23 @@ end
2727
@testset for RT in (Duplicated, DuplicatedNoNeed),
2828
Tx in (Const, Duplicated),
2929
Ty in (Const, Duplicated)
30-
3130
x = 1.0
3231
y = 0.5
33-
test_forward(fastpower, RT, (x, Tx), (y, Ty), atol = 1e-4, rtol=1e-3)
32+
test_forward(fastpower, RT, (x, Tx), (y, Ty), atol = 1e-4, rtol = 1e-3)
3433
end
3534
end
3635

3736
@testset "Fast pow - Enzyme reverse rule" begin
3837
@testset for RT in (Active,), Tx in (Active, Const), Ty in (Active, Const)
3938
x = 1.0
4039
y = 0.5
41-
test_reverse(fastpower, RT, (x, Tx), (y, Ty), atol = 1e-4, rtol=1e-3)
40+
test_reverse(fastpower, RT, (x, Tx), (y, Ty), atol = 1e-4, rtol = 1e-3)
4241
end
4342
end
4443

45-
mooncake_derivative(f,x) = Mooncake.value_and_gradient!!(Mooncake.build_rrule(f, x), f, x)[2][2]
44+
function mooncake_derivative(f, x)
45+
Mooncake.value_and_gradient!!(Mooncake.build_rrule(f, x), f, x)[2][2]
46+
end
4647
@testset "Fast pow - Other AD Engines" begin
4748
x = 1.5123233245141
4849
y = 0.22352354326

0 commit comments

Comments
 (0)