Skip to content

Commit ad11cc1

Browse files
authored
Fix stride_rank for equal-dim reinterpretarray (#209)
`reinterpret(reshape, T, A)` preserves the dimensionality (and size) of `A` when `sizeof(T) == sizeof(eltype(A))`.
1 parent 63c86af commit ad11cc1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/stridelayout.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ function stride_rank(::Type{R}) where {T,N,S,A<:Array{S},R<:Base.ReinterpretArra
239239
end
240240
if VERSION v"1.6.0-DEV.1581"
241241
@inline function stride_rank(::Type{A}) where {NB, NA, B <: AbstractArray{<:Any,NB},A<: Base.ReinterpretArray{<:Any, NA, <:Any, B, true}}
242-
_stride_rank_reinterpret(stride_rank(B), gt(StaticInt{NB}(), StaticInt{NA}()))
242+
NA == NB ? stride_rank(B) : _stride_rank_reinterpret(stride_rank(B), gt(StaticInt{NB}(), StaticInt{NA}()))
243243
end
244244
@inline _stride_rank_reinterpret(sr, ::False) = (One(), map(Base.Fix2(+,One()),sr)...)
245245
@inline _stride_rank_reinterpret(sr::Tuple{One,Vararg}, ::True) = map(Base.Fix2(-,One()), tail(sr))

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,13 @@ ArrayInterface.parent_type(::Type{DenseWrapper{T,N,P}}) where {T,N,P} = P
364364
@test @inferred(stride_rank(DummyZeros(3,4)')) === nothing
365365
@test @inferred(stride_rank(PermutedDimsArray(DummyZeros(3,4), (2, 1)))) === nothing
366366
@test @inferred(stride_rank(view(DummyZeros(3,4), 1, :))) === nothing
367+
uA = reinterpret(reshape, UInt64, A)
368+
@test @inferred(stride_rank(uA)) === stride_rank(A)
369+
rA = reinterpret(reshape, SVector{3,Float64}, A)
370+
@test @inferred(stride_rank(rA)) === (static(1), static(2))
371+
cA = copy(rA)
372+
rcA = reinterpret(reshape, Float64, cA)
373+
@test @inferred(stride_rank(rcA)) === stride_rank(A)
367374

368375
#=
369376
@btime ArrayInterface.is_column_major($(PermutedDimsArray(A,(3,1,2))))

0 commit comments

Comments
 (0)