Re: ENH: Add np.sinpi et al following CPython core, C23 & IEEE754-2019

Nathan via NumPy-Discussion <[email protected]> Fri, 12 Jun 2026 06:31:38 -0600
Newsgroups gmane.comp.python.numeric.general
Message-ID <CAJXewOmfwqQWVBV0oYZjqZjrLB1w_1HiGM_g4hOUifyJxtNtww@mail.gmail.com>
--===============1041305320562155677==
Content-Type: multipart/alternative; boundary="0000000000003bb98906540da985"

--0000000000003bb98906540da985
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

There is no hard-and-fast rule, besides that changing the NumPy API surface
has a much larger blast radius than changing the SciPy API surface. Adding
ufuncs to the NumPy API forces downstream projects that attempt to be
compatible with the full NumPy API to add support.

There=E2=80=99s the array API standard to consider:
https://data-apis.org/array-api/latest/

I=E2=80=99m not saying to go to them and ask them to standardize it. That=
=E2=80=99s not how
it=E2=80=99s supposed to work: things become standardized after gaining wid=
espread
adoption.

That said, has this come up in any array API discussions?

Also, do other array or tensor libraries implement it? Increasing
interoperability and making it easier for the same Python function to be
used regardless of the underlying array type is a core project goal.

On Fri, Jun 12, 2026 at 6:25=E2=80=AFAM Jeff Epler <[email protected]> =
wrote:

> How is it typically decided whether some array function goes in numpy or
> scipy?
>
> On Tue, Jun 9, 2026, at 11:08 AM, Lucas Colley via NumPy-Discussion wrote=
:
>
> There was a proposal to add these to `scipy.special`:
> https://discuss.scientific-python.org/t/rfc-add-sinpi-cospi-tanpi-and-cot=
pi-functions-to-special/1193.
> There are existing implementations at
> https://github.com/scipy/xsf/blob/main/include/xsf/trig.h , with `sinpi`
> and `cospi` exposed to SciPy (privately) at
> https://github.com/scipy/scipy/blob/main/scipy/special/xsf_wrappers.h#L39=
4-L396
> .
>
> We should probably decide whether these best belong in `numpy` or
> `scipy.special`, and only expose them in one of the two.
>
> Cheers,
> Lucas
>
> On 9 Jun 2026, at 16:23, Jerome Kieffer <[email protected]> wrote:
>
> I like the idea !
>
> On Mon, 08 Jun 2026 08:59:24 -0500
> "Jeff Epler" <[email protected]> wrote:
>
> In a recently merged PR (https://github.com/python/cpython/pull/150555),
> CPython has added a family of "*pi" functions to the math module, which
> take half-turn arguments instead of radians. One reason these functions a=
re
> advantageous is that it's easy to provide the property that `sinpi(n/2)` =
is
> exact for all integers n, while `sin(pi*n)` is never exactly equal to the
> mathematical ideal except for n=3D0.
>
> These functions are recommended by IEEE754-2019 and standardized in C23
> Annex G. (note: I'm reading C23 draft revised 2023-01-24, not the final
> standard document; and I do not have IEEE754-2019).
>
> C23 and CPython only added the real-valued versions of these functions,
> but C23 "future library directions" notes that identifiers like `csinpi`
> are "potentially reserved identifiers."
>
> Since CPython only requires C11, CPython includes implementations of thes=
e
> functions for when the underling platform library does not provide it.
> These implementations work by performing special case handling & range
> reduction, followed by a call to the standard trig function with a scaled
> argument (in the case of forward functions) or scaling of the result (in
> the case of inverse/arc functions).
>
> I am interested in doing the numpy implementation, however I have never
> done core numpy work before. If there is interest from the project, I wou=
ld
> like to initially offer a PR containing a single function such as `sinpi`
> and then complete the others following numpy core developer feedback.
>
> Thanks,
> Jeff
> PS I notice via the archives that there are occasional "New Contributors'
> Hour" meetings. Is the next one scheduled yet?
>
>
>
>
>
> --
> J=C3=A9r=C3=B4me Kieffer
> tel +33 476 882 445
> _______________________________________________
> NumPy-Discussion mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3//lists/numpy-discussion.python.org
> Member address: [email protected]
>
> _______________________________________________
> NumPy-Discussion mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3//lists/numpy-discussion.python.org
>
> Member address: [email protected]
>
>
> _______________________________________________
> NumPy-Discussion mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3//lists/numpy-discussion.python.org
> Member address: [email protected]
>

--0000000000003bb98906540da985
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">There is no hard-and-fast rule, besides that changing the=
 NumPy API surface has a much larger blast radius than changing the SciPy A=
PI surface. Adding ufuncs to the NumPy API forces downstream projects that =
attempt to be compatible with the full NumPy API to add support.</div><div =
dir=3D"auto"><br></div><div dir=3D"auto">There=E2=80=99s the array API stan=
dard to consider:=C2=A0<div style=3D"font-size:inherit"><a href=3D"https://=
data-apis.org/array-api/latest/" style=3D"font-size:inherit">https://data-a=
pis.org/array-api/latest/</a></div><div style=3D"font-size:inherit" dir=3D"=
auto"><br></div><div style=3D"font-size:inherit" dir=3D"auto">I=E2=80=99m n=
ot saying to go to them and ask them to standardize it. That=E2=80=99s not =
how it=E2=80=99s supposed to work: things become standardized after gaining=
 widespread adoption.</div><div style=3D"font-size:inherit" dir=3D"auto"><b=
r></div><div style=3D"font-size:inherit" dir=3D"auto">That said, has this c=
ome up in any array API discussions?</div><div style=3D"font-size:inherit" =
dir=3D"auto"><br></div><div style=3D"font-size:inherit" dir=3D"auto">Also, =
do other array or tensor libraries implement it? Increasing interoperabilit=
y and making it easier=C2=A0for the same Python function to be used regardl=
ess of the underlying array type is a core project goal.</div></div><div di=
r=3D"auto"><br><div class=3D"gmail_quote gmail_quote_container" dir=3D"auto=
"><div dir=3D"ltr" class=3D"gmail_attr">On Fri, Jun 12, 2026 at 6:25=E2=80=
=AFAM Jeff Epler &lt;<a href=3D"mailto:[email protected]">jepler@unpyth=
onic.net</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D=
"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u><div=
><div>How is it typically decided whether some array function goes in numpy=
 or scipy?</div></div><div><div><br></div><div>On Tue, Jun 9, 2026, at 11:0=
8 AM, Lucas Colley via NumPy-Discussion wrote:</div></div><div><blockquote =
type=3D"cite" id=3D"m_4942541049634496217qt"></blockquote></div><div><block=
quote type=3D"cite" id=3D"m_4942541049634496217qt"><div>There was a proposa=
l to add these to `scipy.special`:=C2=A0<a href=3D"https://discuss.scientif=
ic-python.org/t/rfc-add-sinpi-cospi-tanpi-and-cotpi-functions-to-special/11=
93" target=3D"_blank">https://discuss.scientific-python.org/t/rfc-add-sinpi=
-cospi-tanpi-and-cotpi-functions-to-special/1193</a>. There are existing im=
plementations at=C2=A0<a href=3D"https://github.com/scipy/xsf/blob/main/inc=
lude/xsf/trig.h" target=3D"_blank">https://github.com/scipy/xsf/blob/main/i=
nclude/xsf/trig.h</a>=C2=A0, with `sinpi` and `cospi` exposed to SciPy (pri=
vately) at=C2=A0<a href=3D"https://github.com/scipy/scipy/blob/main/scipy/s=
pecial/xsf_wrappers.h#L394-L396" target=3D"_blank">https://github.com/scipy=
/scipy/blob/main/scipy/special/xsf_wrappers.h#L394-L396</a>.</div><div><br>=
</div><div><div>We should probably decide whether these best belong in `num=
py` or `scipy.special`, and only expose them in one of the two.</div><div><=
br></div><div>Cheers,</div><div><div>Lucas</div><div><div><br></div><blockq=
uote type=3D"cite"><div>On 9 Jun 2026, at 16:23, Jerome Kieffer &lt;<a href=
=3D"mailto:[email protected]" target=3D"_blank">[email protected]=
</a>&gt; wrote:</div><div><br></div><div><div><span style=3D"font-style:nor=
mal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-ali=
gn:start;text-indent:0px;text-transform:none;word-spacing:0px;text-decorati=
on-color:currentcolor;text-decoration-line:none;text-decoration-style:solid=
;float:none;display:inline!important"><span style=3D"font-family:Helvetica"=
><span style=3D"font-size:12px">I like the idea !</span></span></span></div=
><div><br></div><div><span style=3D"font-style:normal;font-variant-caps:nor=
mal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;=
text-transform:none;word-spacing:0px;text-decoration-color:currentcolor;tex=
t-decoration-line:none;text-decoration-style:solid;float:none;display:inlin=
e!important"><span style=3D"font-family:Helvetica"><span style=3D"font-size=
:12px">On Mon, 08 Jun 2026 08:59:24 -0500</span></span></span></div><div><s=
pan style=3D"font-style:normal;font-variant-caps:normal;font-weight:400;let=
ter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;wor=
d-spacing:0px;text-decoration-color:currentcolor;text-decoration-line:none;=
text-decoration-style:solid;float:none;display:inline!important"><span styl=
e=3D"font-family:Helvetica"><span style=3D"font-size:12px">&quot;Jeff Epler=
&quot; &lt;</span></span></span><a href=3D"mailto:[email protected]" st=
yle=3D"font-family:Helvetica;font-size:12px;font-style:normal;font-variant-=
caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-ind=
ent:0px;text-transform:none;word-spacing:0px" target=3D"_blank">jepler@unpy=
thonic.net</a><span style=3D"font-style:normal;font-variant-caps:normal;fon=
t-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-tr=
ansform:none;word-spacing:0px;text-decoration-color:currentcolor;text-decor=
ation-line:none;text-decoration-style:solid;float:none;display:inline!impor=
tant"><span style=3D"font-family:Helvetica"><span style=3D"font-size:12px">=
&gt; wrote:</span></span></span></div><div><br></div><blockquote type=3D"ci=
te" style=3D"font-family:Helvetica;font-size:12px;font-style:normal;font-va=
riant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;te=
xt-indent:0px;text-transform:none;word-spacing:0px;text-decoration-line:non=
e;text-decoration-style:solid"><div>In a recently merged PR (<a href=3D"htt=
ps://github.com/python/cpython/pull/150555" target=3D"_blank">https://githu=
b.com/python/cpython/pull/150555</a>), CPython has added a family of &quot;=
*pi&quot; functions to the math module, which take half-turn arguments inst=
ead of radians. One reason these functions are advantageous is that it&#39;=
s easy to provide the property that `sinpi(n/2)` is exact for all integers =
n, while `sin(pi*n)` is never exactly equal to the mathematical ideal excep=
t for n=3D0.</div><div><br></div><div>These functions are recommended by IE=
EE754-2019 and standardized in C23 Annex G. (note: I&#39;m reading C23 draf=
t revised 2023-01-24, not the final standard document; and I do not have IE=
EE754-2019).</div><div><br></div><div>C23 and CPython only added the real-v=
alued versions of these functions, but C23 &quot;future library directions&=
quot; notes that identifiers like `csinpi` are &quot;potentially reserved i=
dentifiers.&quot;</div><div><br></div><div>Since CPython only requires C11,=
 CPython includes implementations of these functions for when the underling=
 platform library does not provide it. These implementations work by perfor=
ming special case handling &amp; range reduction, followed by a call to the=
 standard trig function with a scaled argument (in the case of forward func=
tions) or scaling of the result (in the case of inverse/arc functions).</di=
v><div><br></div><div>I am interested in doing the numpy implementation, ho=
wever I have never done core numpy work before. If there is interest from t=
he project, I would like to initially offer a PR containing a single functi=
on such as `sinpi` and then complete the others following numpy core develo=
per feedback.</div><div><br></div><div>Thanks,</div><div>Jeff</div><div>PS =
I notice via the archives that there are occasional &quot;New Contributors&=
#39; Hour&quot; meetings. Is the next one scheduled yet?</div></blockquote>=
<div><br></div><div><br></div><div><br></div><div><br></div><div><span styl=
e=3D"font-style:normal;font-variant-caps:normal;font-weight:400;letter-spac=
ing:normal;text-align:start;text-indent:0px;text-transform:none;word-spacin=
g:0px;text-decoration-color:currentcolor;text-decoration-line:none;text-dec=
oration-style:solid;float:none;display:inline!important"><span style=3D"fon=
t-family:Helvetica"><span style=3D"font-size:12px">--<span>=C2=A0</span></s=
pan></span></span></div><div><span style=3D"font-style:normal;font-variant-=
caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-ind=
ent:0px;text-transform:none;word-spacing:0px;text-decoration-color:currentc=
olor;text-decoration-line:none;text-decoration-style:solid;float:none;displ=
ay:inline!important"><span style=3D"font-family:Helvetica"><span style=3D"f=
ont-size:12px">J=C3=A9r=C3=B4me Kieffer</span></span></span></div><div><spa=
n style=3D"font-style:normal;font-variant-caps:normal;font-weight:400;lette=
r-spacing:normal;text-align:start;text-indent:0px;text-transform:none;word-=
spacing:0px;text-decoration-color:currentcolor;text-decoration-line:none;te=
xt-decoration-style:solid;float:none;display:inline!important"><span style=
=3D"font-family:Helvetica"><span style=3D"font-size:12px">tel +33 476 882 4=
45</span></span></span></div><div><span style=3D"font-style:normal;font-var=
iant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;tex=
t-indent:0px;text-transform:none;word-spacing:0px;text-decoration-color:cur=
rentcolor;text-decoration-line:none;text-decoration-style:solid;float:none;=
display:inline!important"><span style=3D"font-family:Helvetica"><span style=
=3D"font-size:12px">_______________________________________________</span><=
/span></span></div><div><span style=3D"font-style:normal;font-variant-caps:=
normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0=
px;text-transform:none;word-spacing:0px;text-decoration-color:currentcolor;=
text-decoration-line:none;text-decoration-style:solid;float:none;display:in=
line!important"><span style=3D"font-family:Helvetica"><span style=3D"font-s=
ize:12px">NumPy-Discussion mailing list --<span>=C2=A0</span></span></span>=
</span><a href=3D"mailto:[email protected]" style=3D"font-family:=
Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-we=
ight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transf=
orm:none;word-spacing:0px" target=3D"_blank">[email protected]</a=
></div><div><span style=3D"font-style:normal;font-variant-caps:normal;font-=
weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-tran=
sform:none;word-spacing:0px;text-decoration-color:currentcolor;text-decorat=
ion-line:none;text-decoration-style:solid;float:none;display:inline!importa=
nt"><span style=3D"font-family:Helvetica"><span style=3D"font-size:12px">To=
 unsubscribe send an email to<span>=C2=A0</span></span></span></span><a hre=
f=3D"mailto:[email protected]" style=3D"font-family:Helveti=
ca;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:40=
0;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:non=
e;word-spacing:0px" target=3D"_blank">[email protected]</a>=
</div><div><a href=3D"https://mail.python.org/mailman3//lists/numpy-discuss=
ion.python.org" style=3D"font-family:Helvetica;font-size:12px;font-style:no=
rmal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-al=
ign:start;text-indent:0px;text-transform:none;word-spacing:0px" target=3D"_=
blank">https://mail.python.org/mailman3//lists/numpy-discussion.python.org<=
/a></div><div><span style=3D"font-style:normal;font-variant-caps:normal;fon=
t-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-tr=
ansform:none;word-spacing:0px;text-decoration-color:currentcolor;text-decor=
ation-line:none;text-decoration-style:solid;float:none;display:inline!impor=
tant"><span style=3D"font-family:Helvetica"><span style=3D"font-size:12px">=
Member address:<span>=C2=A0</span></span></span></span><a href=3D"mailto:lu=
[email protected]" style=3D"font-family:Helvetica;font-size:12px;font-s=
tyle:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;=
text-align:start;text-indent:0px;text-transform:none;word-spacing:0px" targ=
et=3D"_blank">[email protected]</a></div></div></blockquote></div></d=
iv></div><div>_______________________________________________</div><div>Num=
Py-Discussion mailing list --=C2=A0<a href=3D"mailto:numpy-discussion@pytho=
n.org" target=3D"_blank">[email protected]</a></div><div>To unsub=
scribe send an email to=C2=A0<a href=3D"mailto:numpy-discussion-leave@pytho=
n.org" target=3D"_blank">[email protected]</a></div><div><a=
 href=3D"https://mail.python.org/mailman3//lists/numpy-discussion.python.or=
g" target=3D"_blank">https://mail.python.org/mailman3//lists/numpy-discussi=
on.python.org</a></div></blockquote></div><div><blockquote type=3D"cite" id=
=3D"m_4942541049634496217qt"><div>Member address:=C2=A0<a href=3D"mailto:je=
[email protected]" target=3D"_blank">[email protected]</a></div><div>=
<br></div></blockquote><div><br></div></div>_______________________________=
________________<br>
NumPy-Discussion mailing list -- <a href=3D"mailto:numpy-discussion@python.=
org" target=3D"_blank">[email protected]</a><br>
To unsubscribe send an email to <a href=3D"mailto:numpy-discussion-leave@py=
thon.org" target=3D"_blank">[email protected]</a><br>
<a href=3D"https://mail.python.org/mailman3//lists/numpy-discussion.python.=
org" rel=3D"noreferrer" target=3D"_blank">https://mail.python.org/mailman3/=
/lists/numpy-discussion.python.org</a><br>
Member address: <a href=3D"mailto:[email protected]" target=3D"_blank">=
[email protected]</a><br>
</blockquote></div></div>

--0000000000003bb98906540da985--

--===============1041305320562155677==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
NumPy-Discussion mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/numpy-discussion.python.org
Member address: [email protected]

--===============1041305320562155677==--