I want to find an alternative for weave in Python 2 since weave is not available anymore in Python 3.
More specifically I need to have an alternative way of writing:
from scipy import weave
from scipy.weave import converters
code = """ C-code1 """
support_code = """ C-code2 """
weave.inline(code, ['a', 'b', 'c'], support_code=support_code, type_converters=converters.blitz, compiler='gcc', verbose=0)
You can use the Cython library as it's recommended by weave developers here. It's a little more complex in using but increases the performance of your code too. You can find some example here.
Another alternative can be Numba. It's more user-friendly but doesn't cache the compiled code.
Have a look at numba. Chances are, you can migrate all your codebase into plain python, and still preserve the same speed that you're used to from C code. You even gain some features like throwing clear python errors right from your inner loops, which was to my knowledge not easily possible from weave. As an example how fast you get with numba, you might check the benchmarks of numpy_groupies
, which offers implementations as well in numba as with weave. If you got rid of your C code once, you'll never look back.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With