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
8 changes: 4 additions & 4 deletions base/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,13 @@ end
_maybe_reshape(::IndexSCartesian2, A::ReshapedReinterpretArray, I...) = A

# fallbacks
function _getindex(::IndexSCartesian2, A::AbstractArray{T,N}, I::Vararg{Int, N}) where {T,N}
function _getindex(::IndexSCartesian2, A::AbstractArray, I::Vararg{Int, N}) where {N}
@_propagate_inbounds_meta
getindex(A, I...)
_getindex(IndexCartesian(), A, I...)
end
function _setindex!(::IndexSCartesian2, A::AbstractArray{T,N}, v, I::Vararg{Int, N}) where {T,N}
function _setindex!(::IndexSCartesian2, A::AbstractArray, v, I::Vararg{Int, N}) where {N}
@_propagate_inbounds_meta
setindex!(A, v, I...)
_setindex!(IndexCartesian(), A, v, I...)
end
# fallbacks for array types that use "pass-through" indexing (e.g., `IndexStyle(A) = IndexStyle(parent(A))`)
# but which don't handle SCartesianIndex2
Expand Down
23 changes: 23 additions & 0 deletions test/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,23 @@ test_many_wrappers(fill(1.0, 5, 3), (identity, wrapper)) do a_
@test r[goodinds...] == -5
end
end

let a = rand(ComplexF32, 5)
r = reinterpret(reshape, Float32, a)
ref = Array(r)

@test r[1, :, 1] == ref[1, :]
@test r[1, :, 1, 1, 1] == ref[1, :]
@test r[1, :, UInt8(1)] == ref[1, :]

r[2, :, 1] .= 0f0
ref[2, :] .= 0f0
@test r[2, :, 1] == ref[2, :]

@test r[4] == ref[4]
@test_throws BoundsError r[1, :, 2]
end

let ar = [(1,2), (3,4)]
arr = reinterpret(reshape, Int, ar)
@test @inferred(IndexStyle(arr)) == Base.IndexSCartesian2{2}()
Expand Down Expand Up @@ -612,3 +629,9 @@ let R = reinterpret(reshape, Float32, ComplexF32[1.0f0+2.0f0*im, 4.0f0+3.0f0*im]
@test !isassigned(R, 5)
@test Array(R)::Matrix{Float32} == [1.0f0 4.0f0; 2.0f0 3.0f0]
end

@testset "issue #54623" begin
x = 0xabcdef01234567
@test reinterpret(reshape, UInt8, fill(x)) == [0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab, 0x00]
@test reinterpret(reshape, UInt8, [x]) == [0x67; 0x45; 0x23; 0x01; 0xef; 0xcd; 0xab; 0x00;;]
end