diff --git a/Project.toml b/Project.toml index ce5c48d1c..0a1fa489e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Zygote" uuid = "e88e6eb3-aa80-5325-afca-941959d7151f" -version = "0.6.35" +version = "0.6.36" [deps] AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c" diff --git a/src/lib/broadcast.jl b/src/lib/broadcast.jl index 78816e4f7..f2b0e0709 100644 --- a/src/lib/broadcast.jl +++ b/src/lib/broadcast.jl @@ -144,7 +144,7 @@ end end end -@adjoint broadcasted(::Type{T}, x::Numeric) where T = +@adjoint broadcasted(::Type{T}, x::Numeric) where {T<:Number} = T.(x), ȳ -> (nothing, _project(x, ȳ),) # General Fallback diff --git a/test/gradcheck.jl b/test/gradcheck.jl index 7c45d26d2..b3b1e2969 100644 --- a/test/gradcheck.jl +++ b/test/gradcheck.jl @@ -1407,9 +1407,17 @@ end @test all(gradient((x,y) -> sum(x .* y), [1,2], [3 4 5]) .≈ ([12, 12], [3 3 3])) @test all(gradient((x,y) -> sum(x ./ y), [1,2], 5) .≈ ([0.2, 0.2], -0.12)) + # https://github.com/FluxML/Zygote.jl/pull/1171 sm = sprand(5, 5, 0.5) @test gradient(x -> sum(abs2, Float32.(x)), sm)[1] ≈ gradient(x -> sum(abs2, x), Matrix{Float32}(sm))[1] @test gradient(x -> real(sum(ComplexF32.(x) .+ 1 .+ im)), sm)[1] isa SparseMatrixCSC{Float64} + + # https://github.com/FluxML/Zygote.jl/issues/1178 + function f1179(x) + fs = Ref.(x) + getindex.(fs) + end + @test gradient(sum∘f1179, ones(2)) == ([2.0, 2.0],) end using Zygote: Buffer