Skip to content

Commit 6341e7b

Browse files
committed
Make sure StridedArray's pointer is defined
1 parent 1e4bb11 commit 6341e7b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

base/subarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,10 @@ find_extended_inds() = ()
432432
function unsafe_convert(::Type{Ptr{T}}, V::SubArray{T,N,P,<:Tuple{Vararg{RangeIndex}}}) where {T,N,P}
433433
return unsafe_convert(Ptr{T}, V.parent) + _memory_offset(V.parent, map(first, V.indices)...)
434434
end
435+
unsafe_convert(::Type{Ptr{T}}, V::FastContiguousSubArray{T}) where {T} = unsafe_convert(Ptr{T}, V.parent) + V.offset1 * sizeof(T)
435436

436437
pointer(V::FastSubArray, i::Int) = pointer(V.parent, V.offset1 + V.stride1*i)
437438
pointer(V::FastContiguousSubArray, i::Int) = pointer(V.parent, V.offset1 + i)
438-
439439
function pointer(V::SubArray{<:Any,<:Any,<:Array,<:Tuple{Vararg{RangeIndex}}}, is::AbstractCartesianIndex{N}) where {N}
440440
index = first_index(V)
441441
strds = strides(V)

test/reinterpretarray.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,3 +546,13 @@ end
546546
@test setindex!(x, SomeSingleton(:), 3, 5) == x2
547547
@test_throws MethodError x[2,4] = nothing
548548
end
549+
550+
@testset "pointer for StridedArray" begin
551+
a = rand(Float64, 251)
552+
v = view(a, UInt(2):UInt(251));
553+
A = reshape(v, 25, 10);
554+
@test A isa StridedArray && pointer(A) === pointer(a, 2)
555+
Av = view(A, 1:20, 1:2)
556+
@test Av isa StridedArray && pointer(Av) === pointer(a, 2)
557+
@test Av * Av' isa Array
558+
end

0 commit comments

Comments
 (0)