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 May 15, 2023
1 parent e2d7839 commit 3e1847d
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 3e1847d

Please sign in to comment.