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

Pure Python first pass? #2089

Open Dapid opened 1 year ago

Dapid commented 1 year ago

Sometimes I find a small function missing from Pythran. Implementing it in C++ may be a little bit challenging, but I can often bypass it by copying the source code into my own function.

For example np.fft.fftshift is missing from Pythran, but it is a simple wrapper around np.roll, so simply dropping the definition in my code works:

def fftshift(x):
    shift = x.shape[0] // 2
    return np.roll(x, shift, 0)

[Caveat]

Would it be possible to have Pythran read from a library of Python code? So, if I use np.fft.fftshift, the first pass would translate to the previous function (vendored in Pythran), and the second pass would generate the C++ code. This makes adding more functions and plugging gaps much easier, since it doesn't require to write C++.

serge-sans-paille commented 1 year ago

I like that idea. It would make contributions easier, and would pave the way for external library support.