moble/quaternion

Numpy version

gareins opened this issue · 3 comments

I am currently using this package with default numpy 1.12 on RPi (debian stretch) and this seems to work for what I need (from_rotation_matrix, rotate_vectors). What are 1.13 specific features, that could cause an error?

moble commented

Unfortunately, the problem is a silent killer: everything will run, but you could get incorrect results that are might be very hard to notice. Numpy 1.12 and earlier had a bug in conjugation that was fixed in 1.13. See issue #1 for details. In 1.12 and earlier, you should see this incorrect behavior:

>>> import numpy as np
>>> import quaternion
>>> a = np.array([quaternion.one, quaternion.x, quaternion.y, quaternion.z])
>>> np.conjugate(a)  # This gives the correct output
array([quaternion(1, -0, -0, -0), quaternion(0, -1, -0, -0),
       quaternion(0, -0, -1, -0), quaternion(0, -0, -0, -1)], dtype=quaternion)
>>> a.conjugate()  # This does not
array([quaternion(1, 0, 0, 0), quaternion(0, 1, 0, 0),
       quaternion(0, 0, 1, 0), quaternion(0, 0, 0, 1)], dtype=quaternion)

For numpy versions where the bug has been fixed, the correct result from that last line would look like this:

>>> a.conjugate()  # Correct result in np version >= 1.13
array([quaternion(1, 0, 0, 0), quaternion(0, 1, 0, 0),
       quaternion(0, 0, 1, 0), quaternion(0, 0, 0, 1)], dtype=quaternion)

Last time I tried, I couldn't really find any reasonably new packages for ARM on conda, but if at all possible, I would suggest that you use some sort of environment manager to get more recent versions. If you're confident that none of your code uses conjugation in this way, I suppose you could continue to use it, but don't blame me when your robot runs amok. ;) It looks like the only place in my code that uses it seems to be minimal_rotation, so unless you're using that fairly obscure function, you might just get away with it. (And even if you need to use old versions, you could just alter minimal_rotation to use np.conjugate.)

That was way too good of an answer, thanks mate!

moble commented

FYI, conda-forge has started supplying AArch64 builds of numpy, and it looks like it may be possible for me to select it as an option for the conda-forge build of quaternion in the near future. It looks like RPi 2B v1.2 and higher could use AArch64 (except that it looks like Raspbian comes with a 32-bit kernel by default at the moment, so it might not work out of the box for everyone). If you want to try that now, I think something like conda install -c conda-forge numpy should work as long as you're on python 2.7, 3.6, or 3.7 (currently). As of this writing, that should get you the latest release: numpy 1.16.4. Then, just download this package and run python setup.py install from the top directory. This package compiles pretty easily, so it should work without any more hassle as long as you run it in the same conda env as that numpy installed into.

There's also some talk of conda-forge starting to support AArch32, and this is all a very active topic, so to anyone who's looking for RPi support, don't give up hope.