[Numpy-discussion] sinc always returns double precision

Marten van Kerkwijk m.h.vankerkwijk at gmail.com
Tue May 8 14:34:11 EDT 2018


It is actually a bit more subtle (annoyingly so), the reason you get a
float64 is that you pass in a scalar, and for scalars, the dtype of
`pi` indeed "wins", as there is little reason to possibly loose
precision.  If you pass in an array instead, then you do get
`float32`:
```
np.sinc(np.array([1.], dtype=np.float32)).dtype
dtype('float32')
```
The rationale here is that for an array you generally do not want to
just blow up the memory usage, so its dtype has precedent (as long as
it is float). So, there is a reason, but it certainly leads to a lot
of confusion (e.g., https://github.com/numpy/numpy/issues/10322)

All that said, the implementation of `np.sinc` is not super - really
could do with a few more in-place operations!

-- Marten


More information about the NumPy-Discussion mailing list