Skip to content

Commit

Permalink
Make sure StridedArray's pointer is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
N5N3 committed Feb 15, 2022
1 parent 1e4bb11 commit 6341e7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,10 @@ find_extended_inds() = ()
function unsafe_convert(::Type{Ptr{T}}, V::SubArray{T,N,P,<:Tuple{Vararg{RangeIndex}}}) where {T,N,P}
return unsafe_convert(Ptr{T}, V.parent) + _memory_offset(V.parent, map(first, V.indices)...)
end
unsafe_convert(::Type{Ptr{T}}, V::FastContiguousSubArray{T}) where {T} = unsafe_convert(Ptr{T}, V.parent) + V.offset1 * sizeof(T)

pointer(V::FastSubArray, i::Int) = pointer(V.parent, V.offset1 + V.stride1*i)
pointer(V::FastContiguousSubArray, i::Int) = pointer(V.parent, V.offset1 + i)

function pointer(V::SubArray{<:Any,<:Any,<:Array,<:Tuple{Vararg{RangeIndex}}}, is::AbstractCartesianIndex{N}) where {N}
index = first_index(V)
strds = strides(V)
Expand Down
10 changes: 10 additions & 0 deletions test/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,13 @@ end
@test setindex!(x, SomeSingleton(:), 3, 5) == x2
@test_throws MethodError x[2,4] = nothing
end

@testset "pointer for StridedArray" begin
a = rand(Float64, 251)
v = view(a, UInt(2):UInt(251));
A = reshape(v, 25, 10);
@test A isa StridedArray && pointer(A) === pointer(a, 2)
Av = view(A, 1:20, 1:2)
@test Av isa StridedArray && pointer(Av) === pointer(a, 2)
@test Av * Av' isa Array
end

0 comments on commit 6341e7b

Please sign in to comment.