Skip to content

Commit b507348

Browse files
committed
Fix closures
1 parent 199cac4 commit b507348

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/stage1/forward.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ end
131131
function (::∂☆internal{N})(f::AbstractZeroBundle{N}, args::AbstractZeroBundle{N}...) where {N}
132132
f_v = primal(f)
133133
args_v = map(primal, args)
134-
return ZeroBundle{N}(f_v(args_v...))
134+
return zero_bundle{N}()(f_v(args_v...))
135135
end
136136
function (::∂☆internal{1})(f::AbstractZeroBundle{1}, args::AbstractZeroBundle{1}...)
137137
f_v = primal(f)
138138
args_v = map(primal, args)
139-
return ZeroBundle{1}(f_v(args_v...))
139+
return zero_bundle{1}()(f_v(args_v...))
140140
end
141141

142142
function (::∂☆internal{N})(args::AbstractTangentBundle{N}...) where {N}

test/forward_mutation.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,22 @@ end
6666
@test 🐇[TaylorTangentIndex(2)].x == 2.0 # returns 20
6767
end
6868

69+
@testset "closure" begin
70+
function bar(x)
71+
z = x + 1.0
72+
function foo!(y)
73+
z = z * y
74+
return z
75+
end
76+
77+
foo!(2)
78+
foo!(2)
79+
return z
80+
end
81+
82+
🥯 = ∂☆{1}()(ZeroBundle{1}(bar), TaylorBundle{1}(10.0, (1.0,)))
83+
@test 🥯[TaylorTangentIndex(1)] == 4.0
84+
end
85+
6986

7087
# end # module

0 commit comments

Comments
 (0)