Skip to content

Commit f6ecf92

Browse files
author
Christopher Doris
committed
Add elsize method for PyArray
1 parent 2522a06 commit f6ecf92

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

docs/src/releasenotes.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44
* Added `PYTHON_JULIACALL_HEAP_SIZE_HINT` option to configure initial Julia heap size.
5+
* `Base.elsize` now defined for `PyArray`.
56

67
## 0.9.24 (2025-01-22)
78
* Bug fixes.

src/Wrap/PyArray.jl

+2
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,8 @@ Base.IndexStyle(::Type{PyArray{T,N,M,L,R}}) where {T,N,M,L,R} =
637637

638638
Base.unsafe_convert(::Type{Ptr{T}}, x::PyArray{T,N,M,L,T}) where {T,N,M,L} = x.ptr
639639

640+
Base.elsize(::Type{PyArray{T,N,M,L,T}}) where {T,N,M,L} = sizeof(T)
641+
640642
Base.strides(x::PyArray{T,N,M,L,R}) where {T,N,M,L,R} =
641643
if all(mod.(x.strides, sizeof(R)) .== 0)
642644
div.(x.strides, sizeof(R))

test/Wrap.jl

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
@test strides(y) === (1,)
2727
@test strides(z) === (1,)
2828
end
29+
@testset "elsize" begin
30+
@test Base.elsize(y) === sizeof(Cint)
31+
@test Base.elsize(z) === sizeof(Cint)
32+
@test Base.elsize(PyArray{Cint,1,true,true,Cint}) === sizeof(Cint)
33+
@test Base.elsize(PyArray{Cint,1,false,false,Cint}) === sizeof(Cint)
34+
@test_throws Exception elsize(PyArray{Cint,1,true,false,Cchar})
35+
end
2936
@testset "getindex" begin
3037
@test_throws BoundsError y[0]
3138
@test y[1] == 1

0 commit comments

Comments
 (0)