Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/TracedRArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ function Base.getindex(
end

function Base.getindex(a::WrappedArray{TracedRNumber{T}}, linear_indices) where {T}
return getindex(ancestor(a), TracedUtils.get_ancestor_indices(a, linear_indices))
return getindex(ancestor(a), TracedUtils.get_ancestor_indices(a, linear_indices)...)
end

function Base.getindex(a::WrappedArray{TracedRNumber{T},1}, indices) where {T}
return getindex(ancestor(a), TracedUtils.get_ancestor_indices(a, indices))
return getindex(ancestor(a), TracedUtils.get_ancestor_indices(a, indices)...)
end
function Base.getindex(
a::WrappedArray{TracedRNumber{T},N}, indices::Vararg{Any,N}
Expand Down
11 changes: 8 additions & 3 deletions src/TracedUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,26 @@ end
function get_ancestor_indices_inner(
x::AnyTracedRArray{T,N}, linear_indices::AbstractArray
) where {T,N}
return _get_ancestor_indices_linear(x, linear_indices)
idxs = _get_ancestor_indices_linear(x, linear_indices)
return idxs isa Tuple ? idxs : (idxs,)
end
function get_ancestor_indices_inner(
x::AnyTracedRArray{T,1}, linear_indices::AbstractArray
) where {T}
return _get_ancestor_indices_linear(x, linear_indices)
idxs = _get_ancestor_indices_linear(x, linear_indices)
return idxs isa Tuple ? idxs : (idxs,)
end

function _get_ancestor_indices_linear(x::AnyTracedRArray, indices::AbstractArray)
@show indices
indices = CartesianIndices(x)[indices]
@show indices
pidxs = parentindices(x)
parent_indices = map(indices) do idx
CartesianIndex(Base.reindex(pidxs, (idx.I...,)))
end
return get_ancestor_indices(parent(x), parent_indices)
@show parent_indices
return @show get_ancestor_indices(parent(x), parent_indices)
end

Base.@nospecializeinfer function batch_ty(
Expand Down
11 changes: 11 additions & 0 deletions test/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,14 @@ end

@test parent_ra ≈ parent
end

function test_slice_copy!(x)
@view(x[1, :]) .= 0
return x
end

@testset "slice copy" begin
x = Reactant.to_rarray(rand(2, 10))
@jit test_slice_copy!(x)
@test all(Array(x)[1, :] .== 0)
end
Loading