From ecdeb432b6e3f16040f77531aef8a75d169abcc9 Mon Sep 17 00:00:00 2001 From: nhz2 Date: Tue, 19 May 2026 14:08:29 -0400 Subject: [PATCH] Implement try_strides --- src/Wrap/PyArray.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Wrap/PyArray.jl b/src/Wrap/PyArray.jl index 7b1dc8d3..37d9aca4 100644 --- a/src/Wrap/PyArray.jl +++ b/src/Wrap/PyArray.jl @@ -636,6 +636,17 @@ Base.strides(x::PyArray{T,N,M,L,R}) where {T,N,M,L,R} = error("strides are not a multiple of element size") end +@static if isdefined(Base, :try_strides) + Base.try_strides(x::PyArray{T,N,M,L,T}) where {T,N,M,L} = + if all(mod.(x.strides, sizeof(T)) .== 0) + div.(x.strides, sizeof(T)) + else + nothing + end + Base.is_ptr_loadable(x::PyArray{T,N,M,L,T}) where {T,N,M,L} = true + Base.is_ptr_storable(x::PyArray{T,N,M,L,T}) where {T,N,M,L} = Utils.ismutablearray(x) +end + function Base.showarg(io::IO, x::PyArray{T,N}, toplevel::Bool) where {T,N} toplevel || print(io, "::") print(io, "PyArray{")