KieranWynn / pyquaternion

A fully featured, pythonic library for representing and using quaternions
http://kieranwynn.github.io/pyquaternion/
MIT License
339 stars 68 forks source link

Got a bit carried away adding preliminary support for numba =) #70

Open alexpyattaev opened 3 years ago

alexpyattaev commented 3 years ago

Hi, hope you will find these changes useful/helpful. I'm looking for a speedup of pyquaternion code, primarily targeting numba jit compiler. I've added basic support for numba into pyquaternion, as well as did some other cleanup of the code in some places. For now the code should pass pretty much all of the original unittests with minimal side effects. Few notes:

  1. Is Quaternion intended to be subclassed? If not, we could potentially make several optimizations to get rid of classmethods.
  2. Is it really useful to be able to initialize Quaternions from string literals? Feels like unnecessary complication in init that is not really making anyone's life easier (probably it is the reverse). I've disabled it in my version, not sure what you'd think about it.
  3. Can Quaternions really have a hash? We are not protecting the internal .q variable in any way from mutation, which could make hash invalid. Feels like Quaternion class is not currently properly hashable, and it might be tough to make it hashable.
  4. Numba support is optional, i.e. code will run fine without it present. Original intent was to use @jitclass optimization but Quaternion is too bulky for that, especially the magic in constructor. Maybe we could consider simplifying it a bit?