serge-sans-paille / pythran

Ahead of Time compiler for numeric kernels
https://pythran.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2k stars 193 forks source link

structured numpy array signature? #1912

Open guzuomuse opened 3 years ago

guzuomuse commented 3 years ago
import numpy as np

dt = np.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))])
x = np.array([('Sarah', (8.0, 7.0)), ('John', (6.0, 7.0))], dtype=dt)

# pythran export fn(signatures of x <----how ?????)
def fn(x):
    print(x)

how to organize the signatures? is it possible like numba does from numpy dtype?

serge-sans-paille commented 3 years ago

Unfortunately, Pythran currently doesn't supports structured array. Let's take this issue as an opportunity to discuss the would-be signature:

# (1)
#pythran export fn((char[16], (float64, float64))[:]
# (2)
#pythran export fn((np.str_[16], (float64, float64))[:]

I tend to prefer (1) but I don't have a lot of background with that feature, so I'm really open to suggestions.

cycomanic commented 3 years ago

I'm not a big user of structured arrays, but I would avoid using the np namespace in pythran signatures, as it's inconsistent with other syntax (we don't say np.float64 either). I'm also a bit vary of adding char, considering that str and str_ are equivalent for numpy dtypes, does anything speak against

#pythran export fn((str[15], (float64, float64))[:])

?