Skip to content

Commit

Permalink
Excise getindex adjoint
Browse files Browse the repository at this point in the history
We have a better rule in Chainrules now
  • Loading branch information
ToucheSir committed Sep 8, 2023
1 parent 415ec0a commit 6edfce9
Showing 1 changed file with 0 additions and 18 deletions.
18 changes: 0 additions & 18 deletions src/lib/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,6 @@ end
@adjoint (::Type{T})(sz) where {T<:Zeros} = T(sz), Δ->(nothing,)
@adjoint (::Type{T})(sz) where {T<:Ones} = T(sz), Δ->(nothing,)

@adjoint getindex(x::AbstractArray, inds...) = x[inds...], ∇getindex(x, inds)

@adjoint view(x::AbstractArray, inds...) = view(x, inds...), ∇getindex(x, inds)

∇getindex(x::AbstractArray{T,N}, inds) where {T,N} = dy -> begin
if inds isa NTuple{N,Int} && T <: Number
dx = OneElement(dy, inds, axes(x))
elseif inds isa NTuple{<:Any, Integer}
dx = _zero(x, typeof(dy))
dx[inds...] = dy
else
dx = _zero(x, eltype(dy))
dxv = view(dx, inds...)
dxv .= accum.(dxv, _droplike(dy, dxv))
end
return (_project(x, dx), map(_->nothing, inds)...)
end

"""
OneElement(val, ind, axes) <: AbstractArray
Expand Down

0 comments on commit 6edfce9

Please sign in to comment.