Skip to content

Commit

Permalink
Allow single indexing of arrays of GPU arrays (#760)
Browse files Browse the repository at this point in the history
* Allow single indexing of arrays of GPU arrays

* bump version
  • Loading branch information
ToucheSir authored Dec 14, 2023
1 parent 40b9058 commit ae37562
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRules"
uuid = "082447d4-558c-5d27-93f4-14fc19e9eca2"
version = "1.58.0"
version = "1.58.1"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
2 changes: 1 addition & 1 deletion src/rulesets/Base/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ end
ChainRules.@non_differentiable _setindex_zero(x::AbstractArray, dy::Any, inds::Any...)

function ∇getindex!(dx::AbstractArray, dy, inds::Integer...)
view(dx, inds...) .+= Ref(dy)
@views dx[inds...] += dy
return dx
end
function ∇getindex!(dx::AbstractArray, dy, inds...)
Expand Down
8 changes: 8 additions & 0 deletions test/rulesets/Base/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ end
@test Array(y3) == Array(x_23_gpu)[1, [1,1,2]]
@test unthunk(bk3(jl(ones(3)))[2]) == jl([2 1 0; 0 0 0])
end

@testset "getindex(::Array{<:AbstractGPUArray})" begin
x_gpu = jl(rand(1))
y, back = rrule(getindex, [x_gpu], 1)
@test y === x_gpu
dxs_gpu = unthunk(back(jl([1.0]))[2])
@test dxs_gpu == [jl([1.0])]
end
end

# first & tail handled by getfield rules
Expand Down

2 comments on commit ae37562

@oxinabox
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/97081

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.58.1 -m "<description of version>" ae37562ea1f16816a0d8fff24e0aca6cd594a40f
git push origin v1.58.1

Please sign in to comment.