[Numpy-discussion] sinc always returns double precision
Paul Woodford
pwoodford at keywcorp.com
Thu May 10 14:27:00 EDT 2018
Ah, I see. That rationale makes sense.
Paul
From: NumPy-Discussion <numpy-discussion-bounces+pwoodford=keywcorp.com at python.org> on behalf of Marten van Kerkwijk <m.h.vankerkwijk at gmail.com>
Reply-To: Discussion of Numerical Python <numpy-discussion at python.org>
Date: Tuesday, May 8, 2018 at 2:40 PM
To: Discussion of Numerical Python <numpy-discussion at python.org>
Subject: Re: [Numpy-discussion] sinc always returns double precision
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://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_numpy_numpy_issues_10322&d=DwICAg&c=31nHN1tvZeuWBT6LwDN4Ngk1qezfsYHyolgGeY2ZhlU&r=pWejSe2R2_qRF_nJUoy-IChkOn_Jf3D9EMavoc-oxtw&m=JujDdD-etvHDgctd0xXmVffN19AAT7Q9yD3Ryb71tnI&s=H4tN00ZUcDUwYLPau1NUGBTZbZ2HRfvFvzA0S8PB_Wc&e=)
All that said, the implementation of `np.sinc` is not super - really
could do with a few more in-place operations!
-- Marten
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion at python.org
https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_numpy-2Ddiscussion&d=DwICAg&c=31nHN1tvZeuWBT6LwDN4Ngk1qezfsYHyolgGeY2ZhlU&r=pWejSe2R2_qRF_nJUoy-IChkOn_Jf3D9EMavoc-oxtw&m=JujDdD-etvHDgctd0xXmVffN19AAT7Q9yD3Ryb71tnI&s=z-fzi6OPNJPWvVe8bgcB49TVJoosQJyusXcabEXXP0k&e=
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180510/30122d99/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5202 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180510/30122d99/attachment.bin>
More information about the NumPy-Discussion
mailing list