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 base/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ end
# Convert to full indices here, to avoid needing multiple conversions in
# the loop in _getindex_ra
inds = _to_subscript_indices(a, i)
isempty(inds) ? _getindex_ra(a, 1, ()) : _getindex_ra(a, inds[1], tail(inds))
isempty(inds) ? _getindex_ra(a, firstindex(a), ()) : _getindex_ra(a, inds[1], tail(inds))
end

@propagate_inbounds function getindex(a::ReshapedReinterpretArray{T,N,S}, ind::SCartesianIndex2) where {T,N,S}
Expand Down Expand Up @@ -556,7 +556,7 @@ end
return _setindex_ra!(a, v, i, ())
end
inds = _to_subscript_indices(a, i)
_setindex_ra!(a, v, inds[1], tail(inds))
isempty(inds) ? _setindex_ra!(a, v, firstindex(a), ()) : _setindex_ra!(a, v, inds[1], tail(inds))
end

@propagate_inbounds function setindex!(a::ReshapedReinterpretArray{T,N,S}, v, ind::SCartesianIndex2) where {T,N,S}
Expand Down
10 changes: 10 additions & 0 deletions test/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ test_many_wrappers(A3) do A3_
@test A3[2,1,2] == 400
end

test_many_wrappers(C) do Cr
r = reinterpret(reshape, Tuple{Int, Int}, Cr)
r[] = (2,2)
@test r[] === (2,2)
r[1] = (3,3)
@test r[1] === (3,3)
r[1,1] = (4,4)
@test r[1,1] === (4,4)
end

# same-size reinterpret where one of the types is non-primitive
let a = NTuple{4,UInt8}[(0x01,0x02,0x03,0x04)]
test_many_wrappers(a, (identity, wrapper, fcviews)) do a_
Expand Down