From 17a5673bdfd7d8fcdf27454b75b15efdb6477c9e Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Sun, 14 Aug 2022 20:33:17 -0700 Subject: [PATCH] broadcast adjoint for unary minus (#1287) --- src/lib/broadcast.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/broadcast.jl b/src/lib/broadcast.jl index 8c0d3c54c..98124bd03 100644 --- a/src/lib/broadcast.jl +++ b/src/lib/broadcast.jl @@ -80,6 +80,8 @@ unbroadcast(x::AbstractArray, x̄::Nothing) = nothing @adjoint broadcasted(::typeof(-), x::Numeric, y::Numeric) = x .- y, Δ -> (nothing, unbroadcast(x, Δ), _minus(unbroadcast(y, Δ))) +@adjoint broadcasted(::typeof(-), x::Numeric) = .-x, + Δ -> (nothing, _minus(Δ)) _minus(Δ) = -Δ _minus(::Nothing) = nothing