Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Wrap/PyArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,8 @@ function pyarray_offset(x::PyArray{T,N,F}, i::Int) where {T,N,F}
end

function pyarray_offset(x::PyArray{T,N,F}, i::Vararg{Int,N}) where {T,N,F}
sum((i .- 1) .* x.strides)
# `init` covers 0-d arrays indexed as `x[]`, where `i` is empty
sum((i .- 1) .* x.strides; init=0)
end

function pyarray_load(::Type{T}, p::Ptr{R}) where {T,R}
Expand Down
10 changes: 10 additions & 0 deletions test/Wrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@
)
@test_throws Exception PyArray(nd; array = false, buffer = true)
end
@testset "0-d" begin
tb = pyimport("_testbuffer")
nd = tb.ndarray(5, shape = pylist(), flags = tb.ND_WRITABLE)
a = PyArray(nd; array = false, buffer = true)
@test ndims(a) == 0
@test a[] == 5
a[] = 6
@test a[] == 6
@test pyconvert(Int, nd.tolist()) == 6
end
end

@testitem "PyDict" begin
Expand Down
Loading