|
|
|
|
|
by aschreyer
4788 days ago
|
|
It is a bit unfortunate that you have to "unroll" your code to get the most out of Numba. Hopefully at some point it will be able to translate NumPy functions such as np.abs(X - y).sum(axis=1)) efficiently into LLVM. Those extreme performance improvements are misleading though; in my experience the speed up compared to concise, optimal NumPy code is more in the range 50-100%. |
|
If you never are resorting to using C/C++ or Fortran, then Numba is not necessarily going to be helpful for you.
I don't think we are trying to mislead. We are simply showing examples that illustrate what Numba can be used for. Of course your code does not have many for-loops in it because you never could write code like that and have it be fast in Python. The big-deal about Numba is that now you can. You don't have to rely on a C/C++ library that either write or get someone else to write for you. You can just use Python.
I agree with you about the "unrolling". I don't recommend adding for-loops when good vectorized expressions work. Keep using them as we will be able to do a better job of parallelizing that code in the future. However, when you can't vectorize and for-loops are all you have, Numba is great.
We have spent some time on optimizing NumPy expressions like you describe and some array expressions can be translated down to equivalent LLVM loops. But most of the effort in that direction has been happening in the Blaze project which is generalizing NumPy so it can deal with much larger data but still produce optimized code from those vector expressions. This actually requires a re-thinking of how NumPy is implemented from the ground up.