Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support in numba njit #167

Closed
alexpyattaev opened this issue Jun 16, 2021 · 2 comments
Closed

Support in numba njit #167

alexpyattaev opened this issue Jun 16, 2021 · 2 comments

Comments

@alexpyattaev
Copy link

Numba is amazing, and it can readily deal with numpy arrays. numpy-quaternion is fast on its own, but functions using it can not be jit-compiled by numba:
@numba.njit() def t(): return np.quaternion(1,0,0,0)
Clearly, it would be amazing to have numba be able to support also cases when dtype=quaternion. I am unsure if there is any way to make it happen, but would be really cool.

In the best case one should be able to just place @njit on functions using quaternions and not care about anything. I am currently using my own implementation of quaternions in python targeting numba njit, and it is fairly fast (but uncomfortable to use).

Let me know what you think.

@moble
Copy link
Owner

moble commented Jun 16, 2021

I agree that numba is pretty great, and I actually use it in a few places in this package. Unfortunately, the maintainers of numba have made it clear that they won't be putting much effort into doing things like supporting custom dtypes, or jitclass "dunder" methods. (I was just searching for this issue about that problem, and see that you wrote the last comment on it, so I see that you're up on it.) The numpy developers are actually gradually working on improvements to the dtype system that could make all of this much easier, but I'm not holding my breath.

For now, and for the foreseeable future, there are only a couple alternatives that I know of:

  1. Convert quaternion arrays to float arrays and back when passing them into and out of numba functions. This is very fast because no memory is copied, but it's annoying to code up.
  2. Use this other quaternion package, which hacks things a bit to make quaternionic arrays subtypes of numpy float arrays (rather than numpy arrays with a different dtype). There are some pitfalls that can't be avoided because of numpy's design, but it's pretty solid.

@moble moble closed this as completed Jun 16, 2021
@alexpyattaev
Copy link
Author

Well the core issue is in both cases the need to convert into plain arrays for numba jitted functions to be able to use quats...
My current solution is just plain procedural code, which is ugly as sin but very fast, FYI here https://github.com/alexpyattaev/python-simulations-library/tree/master/transformations
I've also tried to jitclass pyquaternion, but the code there is just abysmally bad, so no amount of jit can save it=) results here:
https://github.com/alexpyattaev/pyquaternion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants