Skip to content

Commit 62e0bd8

Browse files
authored
Specialize Base.cconvert for OffsetArrays (#344)
* Specialize Base.cconvert for OffsetArrays * Don't test for adjoint
1 parent e83d167 commit 62e0bd8

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/OffsetArrays.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,10 @@ Base.copy(A::OffsetArray) = parent_call(copy, A)
461461

462462
Base.strides(A::OffsetArray) = strides(parent(A))
463463
Base.elsize(::Type{OffsetArray{T,N,A}}) where {T,N,A} = Base.elsize(A)
464-
@inline Base.unsafe_convert(::Type{Ptr{T}}, A::OffsetArray{T}) where {T} = Base.unsafe_convert(Ptr{T}, parent(A))
464+
Base.cconvert(P::Type{Ptr{T}}, A::OffsetArray{T}) where {T} = Base.cconvert(P, parent(A))
465+
if VERSION < v"1.11-"
466+
@inline Base.unsafe_convert(::Type{Ptr{T}}, A::OffsetArray{T}) where {T} = Base.unsafe_convert(Ptr{T}, parent(A))
467+
end
465468

466469
# For fast broadcasting: ref https://discourse.julialang.org/t/why-is-there-a-performance-hit-on-broadcasting-with-offsetarrays/32194
467470
Base.dataids(A::OffsetArray) = Base.dataids(parent(A))

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,6 +2481,8 @@ end
24812481
@test pointer(a', 5) === pointer(parent(a), 5)
24822482
@test pointer(A', 15) === pointer(parent(A)', 15)
24832483
end
2484+
2485+
@test Base.cconvert(Ptr{eltype(A)}, A) == Base.cconvert(Ptr{eltype(A)}, parent(A))
24842486
end
24852487

24862488
# issue 171

0 commit comments

Comments
 (0)