Suzhou-Tongyuan / jnumpy

Writing Python C extensions in Julia within 5 minutes.
MIT License
234 stars 8 forks source link

Support conversion of numpy 0-D array #35

Closed songjhaha closed 2 years ago

songjhaha commented 2 years ago

We could create a 0-D array in numpy like:

julia> a = np.array(py_cast(Py,1.0))
Py(array(1.))

julia> a.shape
Py(())

Conversion fails in typeassert of ShapeType:

https://github.com/Suzhou-Tongyuan/jnumpy/blob/7e1b5c61148049433ef6ffdb6c89da120df9d878/TyPython/src/CPython.NumPy.jl#L50

https://github.com/Suzhou-Tongyuan/jnumpy/blob/7e1b5c61148049433ef6ffdb6c89da120df9d878/TyPython/src/CPython.NumPy.jl#L97-L98

could fix it with:

const ShapeType = Union{(Tuple{repeat([Py_intptr_t], i)...} for i = 0:SupportedNDim)...}