Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Base.elsize not implemented for PyArray #579

Closed
nhz2 opened this issue Dec 10, 2024 · 1 comment · Fixed by #593
Closed

Base.elsize not implemented for PyArray #579

nhz2 opened this issue Dec 10, 2024 · 1 comment · Fixed by #593
Labels
bug Something isn't working

Comments

@nhz2
Copy link

nhz2 commented Dec 10, 2024

Affects: PythonCall

Describe the bug
I would like to get a pointer to a view of a PyArray

julia> using PythonCall

julia> x = view(PyArray(UInt8[1,2,3]), 1:2)
2-element view(::PyArray{UInt8, 1}, 1:2) with eltype UInt8:
 0x01
 0x02

julia> y = Base.cconvert(Ptr{UInt8}, x)
2-element view(::PyArray{UInt8, 1}, 1:2) with eltype UInt8:
 0x01
 0x02

julia> Base.unsafe_convert(Ptr{UInt8}, y)
ERROR: MethodError: no method matching elsize(::Type{PyArray{UInt8, 1, true, true, UInt8}})
The function `elsize` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  elsize(::Type{Union{}}, Any...)
   @ Base array.jl:233
  elsize(::Type{<:LinearAlgebra.Adjoint{<:Real, P}}) where P<:(AbstractVecOrMat)
   @ LinearAlgebra ~/.julia/juliaup/julia-1.11.2+0.x64.linux.gnu/share/julia/stdlib/v1.11/LinearAlgebra/src/adjtrans.jl:355
  elsize(::Type{A}) where {T, A<:(Array{T})}
   @ Base array.jl:225
  ...

Stacktrace:
 [1] elsize(A::PyArray{UInt8, 1, true, true, UInt8})
   @ Base ./abstractarray.jl:257
 [2] _memory_offset(x::PyArray{UInt8, 1, true, true, UInt8}, I::Int64)
   @ Base ./abstractarray.jl:1239
 [3] unsafe_convert(::Type{Ptr{…}}, V::SubArray{UInt8, 1, PyArray{…}, Tuple{…}, true})
   @ Base ./reshapedarray.jl:329
 [4] top-level scope
   @ REPL[71]:1
Some type information was truncated. Use `show(err)` to see complete types.

Your system

Julia Version 1.11.2
Commit 5e9a32e7af2 (2024-12-01 20:02 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × Intel(R) Core(TM) i7-10700KF CPU @ 3.80GHz
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)

PythonCall v0.9.23
@nhz2
Copy link
Author

nhz2 commented Feb 23, 2025

I can confirm that this is fixed for me. Thank you!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant