Skip to content

Commit 29a856b

Browse files
committed
rename to value_and_pullback
1 parent 9a764c9 commit 29a856b

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

test/gradcheck.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jacobicheck(f, dims...) = jacobicheck(f, randn.(Float64, dims)...)
4747
isZero(x) = x isa AbstractZero
4848

4949
# Zygote's misnamed hobbit function:
50-
function pullback(f, x...)
50+
function value_and_pullback(f, x...)
5151
y, b = Diffractor.∂⃖{1}()(f, x...)
5252
back(dy) = map(unthunk, Base.tail(b(dy)))
5353
y, back
@@ -171,7 +171,7 @@ end
171171

172172
# https://github.com/FluxML/Zygote.jl/issues/376
173173

174-
_, back = pullback(x->x[1]*im, randn(2))
174+
_, back = value_and_pullback(x->x[1]*im, randn(2))
175175
@test back(1.0)[1] == real([-im, 0]) == [0, 0]
176176

177177
# _droplike
@@ -187,10 +187,10 @@ end
187187
@test_broken gradient(x -> sum(Float32[1, x] .+ x), 4) == (3.0f0,)
188188

189189
# Ensure that nothings work with numeric types.
190-
_, back = pullback(getindex, randn(4), [1])
190+
_, back = value_and_pullback(getindex, randn(4), [1])
191191
@test back([ZeroTangent()]) == (zeros(4), NoTangent())
192192
# Ensure that nothings work with non-numeric types.
193-
_, back = pullback(getindex, [randn(2) for _ in 1:3], [1])
193+
_, back = value_and_pullback(getindex, [randn(2) for _ in 1:3], [1])
194194
@test back([ZeroTangent()]) == (NoTangent(), NoTangent())
195195
end
196196

@@ -246,7 +246,7 @@ end
246246
@test jacobicheck(x -> permutedims(x, [3,1,2]), rand(4,5,6))
247247
@test jacobicheck(x -> PermutedDimsArray(x, (3,1,2)), rand(4,5,6))
248248
let
249-
y, back = pullback(permutedims, randn(3))
249+
y, back = value_and_pullback(permutedims, randn(3))
250250
@test first(back(randn(1, 3))) isa Vector
251251
end
252252
end
@@ -311,36 +311,36 @@ end
311311

312312
@testset "Tuple adjoint" begin
313313
x = randn(3)
314-
_, pb = pullback(x -> map(abs2, x), x)
314+
_, pb = value_and_pullback(x -> map(abs2, x), x)
315315
Δy = randn(3)
316316
@test first(pb((Δy..., ))) first(pb(Δy))
317317
end
318318

319319
@testset "empty tuples" begin
320-
out, pb = pullback(map, -, ())
320+
out, pb = value_and_pullback(map, -, ())
321321
@test pb(out) === (NoTangent(), NoTangent())
322322

323-
out, pb = pullback(map, +, (), ())
324-
# MethodError: reducing over an empty collection is not allowed, ChainRules.var"#map_pullback#1234"{typeof(+), Tuple{Tuple{}, Tuple{}},
323+
out, pb = value_and_pullback(map, +, (), ())
324+
# MethodError: reducing over an empty collection is not allowed, ChainRules.var"#map_value_and_pullback#1234"{typeof(+), Tuple{Tuple{}, Tuple{}},
325325
@test_broken pb(()) === (ZeroTangent(), ZeroTangent(), ZeroTangent())
326326

327327
function build_foo(z)
328328
foo(x) = x * z
329329
return foo
330330
end
331-
out, pb = pullback(map, build_foo(5.0), ())
331+
out, pb = value_and_pullback(map, build_foo(5.0), ())
332332
@test pb(()) === (NoTangent(), NoTangent())
333333
end
334334

335335
@testset "Vector{Nothing} cotangent" begin
336336
Δ = fill(ZeroTangent(), 5)
337337

338338
# Unary stateless
339-
out, pb = pullback(map, -, randn(5))
339+
out, pb = value_and_pullback(map, -, randn(5))
340340
@test pb(Δ)[2] isa Vector{ZeroTangent}
341341

342342
# Binary stateless
343-
out, pb = pullback(map, +, randn(5), randn(5))
343+
out, pb = value_and_pullback(map, +, randn(5), randn(5))
344344
@test pb(Δ)[2] isa Vector{ZeroTangent}
345345
@test pb(Δ)[3] isa Vector{ZeroTangent}
346346

@@ -350,7 +350,7 @@ end
350350
return foo
351351
end
352352
# AssertionError: Base.issingletontype(typeof(f))
353-
@test_broken out, pb = pullback(map, build_foo(5.0), randn(5))
353+
@test_broken out, pb = value_and_pullback(map, build_foo(5.0), randn(5))
354354
@test_skip pb(Δ)[2] isa Vector{ZeroTangent}
355355
end
356356

@@ -364,8 +364,8 @@ end
364364
("binary empty vector", +, Float64[], (Float64[], Float64[])),
365365
("binary vector", +, randn(2), (randn(2), randn(2))),
366366
]
367-
@inferred pullback(map, f, xs...)
368-
y, pb = pullback(map, f, xs...)
367+
@inferred value_and_pullback(map, f, xs...)
368+
y, pb = value_and_pullback(map, f, xs...)
369369
@inferred pb(ȳ)
370370
end
371371

@@ -377,8 +377,8 @@ end
377377
# return type Tuple{NoTangent, {Union{NoTangent, Tangent{...}}}}
378378
("binary tuple", +, (randn(), randn()), ((randn(), randn()), (randn(), randn()))),
379379
]
380-
@inferred pullback(map, f, xs...)
381-
y, pb = pullback(map, f, xs...)
380+
@inferred value_and_pullback(map, f, xs...)
381+
y, pb = value_and_pullback(map, f, xs...)
382382
@inferred pb(ȳ)
383383
end
384384
end

0 commit comments

Comments
 (0)