Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: allow colon indexing of traced **vectors** #664

Merged
merged 2 commits into from
Jan 31, 2025

Conversation

floffy-f
Copy link
Contributor

Description of the problem

In the case in which one wants to set inplace a vector (so its dimension is (N,)) into some target traced vector with the colon-index operator, there is an ambigüity between two function signatures:

Base.setindex!(a::TracedRArray{T,N}, v, ::Colon) where {T,N}

and

const N = 1
Base.setindex!(a::TracedRArray{T,N}, v, indices::Vararg{Any,N}) where {T,N}

MWE

using Reactant

function ipop!(y, x)
    y[:] = x
end
x = Reactant.to_array([1.0, 2.0])
y = similar(x)
@jit ipop!(y, x)

ERROR: MethodError: setindex!(::Reactant.TracedRArray{Float64, 1}, ::Reactant.TracedRArray{Float64, 1}, ::Colon) is ambiguous.

Candidates:
setindex!(a::Reactant.TracedRArray{T, N}, v, ::Colon) where {T, N}
@ Reactant.TracedRArrayOverrides ~/.julia/packages/Reactant/B09Ss/src/TracedRArray.jl:271
setindex!(a::Reactant.TracedRArray{T, N}, v, indices::Vararg{Any, N}) where {T, N}
@ Reactant.TracedRArrayOverrides ~/.julia/packages/Reactant/B09Ss/src/TracedRArray.jl:295

Solution

I tested the solution in test/indexing.jl.
The function from the first signature is removed, and a check is added at the beginning of the second one to execute the same code as the deleted function.

@wsmoses wsmoses merged commit 52b60ad into EnzymeAD:main Jan 31, 2025
36 of 38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants