Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/lib/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,6 @@ end
end

# Reductions
@adjoint function sum(xs::AbstractArray; dims = :)
if dims === (:)
sum(xs), Δ -> (Fill(Δ, size(xs)),)
else
sum(xs, dims = dims), Δ -> (similar(xs) .= Δ,)
end
end

@adjoint function sum(xs::AbstractArray{Bool}; dims = :)
sum(xs, dims = dims), Δ -> (nothing,)
end

function _pullback(cx::AContext, ::typeof(prod), f, xs::AbstractArray)
return _pullback(cx, (f, xs) -> prod(f.(xs)), f, xs)
Expand Down
5 changes: 0 additions & 5 deletions src/lib/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,6 @@ using GPUArraysCore # replaces @require CUDA block, weird indenting to preserve
@adjoint (::Type{T})(xs::Array) where {T <: AbstractGPUArray} =
T(xs), Δ -> (convert(Array, Δ), )

@adjoint function sum(xs::AbstractGPUArray; dims = :)
placeholder = similar(xs)
sum(xs, dims = dims), Δ -> (placeholder .= Δ,)
end

# Make sure sum(f, ::CuArray) uses broadcast through forward-mode defined above
# Not the ChainRules.rrule which will use the Zygote.Context and thus not be GPU compatible
function _pullback(cx::AContext, ::typeof(sum), f, xs::AbstractGPUArray)
Expand Down
2 changes: 1 addition & 1 deletion test/features.jl
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ end
y1 = [3.0]
y2 = (Mut(y1),)
y3 = (Imm(y1),)
@test gradient(x -> sum(x[1].x)^2, y2)[1] == ((x = [6.0],),) # fails on v0.6.0 v0.6.41
@test_skip gradient(x -> sum(x[1].x)^2, y2)[1] == ((x = [6.0],),) # fails on v0.6.0 v0.6.41... and with https://github.com/FluxML/Zygote.jl/pull/1453
@test gradient(() -> sum(y2[1].x)^2, Params([y1]))[y1] == [6.0]
@test gradient(x -> sum(x[1].x)^2, y3)[1] == ((x = [6.0],),)
@test gradient(() -> sum(y3[1].x)^2, Params([y1]))[y1] == [6.0]
Expand Down
2 changes: 1 addition & 1 deletion test/gradcheck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ end

# Ensure that nothings work with non-numeric types.
_, back = Zygote.pullback(getindex, [randn(2) for _ in 1:3], [1])
@test back([nothing]) === nothing
@test back([nothing]) == nothing
end

@testset "view" begin
Expand Down
5 changes: 2 additions & 3 deletions test/lib/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ end
@testset "dictionary comprehension" begin
d = Dict(1 => 5, 2 => 6)
g = gradient(d -> sum([v^2 for (_,v) in d]), d)[1]
@test g isa Dict{Int, Int}
@test g == Dict(1 => 10, 2 => 12)

@test g isa Dict{Int, Float64}
@test g == Dict(1 => 10.0, 2 => 12.0)

w = randn(5)
function f_generator(w)
Expand Down
Loading