moble / quaternionic

Interpret numpy arrays as quaternionic arrays with numba acceleration
MIT License
84 stars 7 forks source link

Quaternionic to power 0.0 raises TypeError #11

Closed moble closed 2 years ago

moble commented 4 years ago

Presumably because numpy is taking a shortcut and trying to return ones, we get this:

>>> import quaternionic
>>> quaternionic.x ** 0.0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: operand type(s) all returned NotImplemented from __array_ufunc__(<ufunc '_ones_like'>, '__call__', quaternionic.array([0., 1., 0., 0.])): 'QArray'

On the other hand, it works as expected as long as the exponent is not precisely 0.0:

>>> quaternionic.x ** 1e-323
quaternionic.array([1., 0., 0., 0.])

I also can't find any way to access <ufunc '_ones_like'>; it's different from np.ones_like, for example. I think I'll have to find some way to override this shortcut.

moble commented 4 years ago

A workaround for this is to explicitly call np.float_power or even np.power:

>>> import numpy as np
>>> import quaternionic
>>> np.float_power(quaternionic.x, 0.0)
quaternionic.array([1., 0., 0., 0.])
>>> np.power(quaternionic.x, 0.0)
quaternionic.array([1., 0., 0., 0.])