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

Ralf Gommers via NumPy-Discussion <[email protected]> Fri, 12 Jun 2026 21:31:37 +0200
Newsgroups gmane.comp.python.numeric.general
Message-ID <CABL7CQiTxPUSF+-BArRNL75gwQkkPopff1wVvzZrW_YCBv+fCA@mail.gmail.com>
--===============3552225574674448542==
Content-Type: multipart/alternative; boundary="000000000000276e8a06541387d2"

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

On Fri, Jun 12, 2026 at 2:33=E2=80=AFPM Nathan via NumPy-Discussion <
[email protected]> wrote:

> 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 surfac=
e.
> 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 gaini=
ng
> widespread adoption.
>
> That said, has this come up in any array API discussions?
>

It hasn't - and since no other array library in Python seems to have it,
that's fairly premature to bring up I'd say.


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

C23, Fortran 2023, IEEE754-2019, Julia, Matlab and R all have it, which is
pretty solid prior art.

In addition to the RFC Lucas linked, there's a stalled open PR to add it to
scipy.special that might be useful:
https://github.com/scipy/scipy/pull/21398. I'll note that it also covers
complex dtypes (as it should), and that C23 et al. are real-valued only. So
NumPy wouldn't be able to count on `libm` support for many years, probably
never, and it'd have to handle more dtypes than `scipy.special` (e.g.,
float16, longdouble). There's also the amount of functions: is it
sinpi/cospi/tanpi, or also their inverses? And the SciPy PR has cotpi as
well (not sure if that makes sense to add there, but almost certainly not
to NumPy). Given all that, I'd be inclined to put it in `xsf` and
`scipy.special`, supporting only float32/float64/complex64/complex128. The
xsf implementation could then also support CuPy.

Cheers,
Ralf



>
> 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 wrot=
e:
>>
>> There was a proposal to add these to `scipy.special`:
>> https://discuss.scientific-python.org/t/rfc-add-sinpi-cospi-tanpi-and-co=
tpi-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#L3=
94-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 =
are
>> 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 th=
e
>> 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
>> these functions for when the underling platform library does not provide
>> it. These implementations work by performing special case handling & ran=
ge
>> reduction, followed by a call to the standard trig function with a scale=
d
>> 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 wo=
uld
>> 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]
>>
> _______________________________________________
> 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]
>

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

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote g=
mail_quote_container"><div dir=3D"ltr" class=3D"gmail_attr">On Fri, Jun 12,=
 2026 at 2:33=E2=80=AFPM Nathan via NumPy-Discussion &lt;<a href=3D"mailto:=
[email protected]">[email protected]</a>&gt; wrote:<br>=
</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;b=
order-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"auto">T=
here 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 compa=
tible 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 standard to consider:=
=C2=A0<div style=3D"font-size:inherit"><a href=3D"https://data-apis.org/arr=
ay-api/latest/" style=3D"font-size:inherit" target=3D"_blank">https://data-=
apis.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 =
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 gainin=
g widespread adoption.</div><div style=3D"font-size:inherit" dir=3D"auto"><=
br></div><div style=3D"font-size:inherit" dir=3D"auto">That said, has this =
come up in any array API discussions?</div></div></blockquote><div><br></di=
v><div>It hasn&#39;t - and since no other array library in Python seems to =
have it, that&#39;s fairly premature to bring up I&#39;d say.</div><div>=C2=
=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e=
x;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"auto=
"><div style=3D"font-size:inherit" dir=3D"auto">Also, do other array or ten=
sor libraries implement it? Increasing interoperability and making it easie=
r=C2=A0for thesame Python function to be used regardless of the underlying =
array type is a core project goal.</div></div></blockquote><div><br></div><=
div>C23, Fortran 2023,=C2=A0IEEE754-2019, Julia, Matlab and R all have it, =
which is pretty solid prior art.</div><div><br></div><div>In addition to th=
e RFC Lucas linked, there&#39;s a stalled open PR to add it to scipy.specia=
l that might be useful:=C2=A0<a href=3D"https://github.com/scipy/scipy/pull=
/21398">https://github.com/scipy/scipy/pull/21398</a>. I&#39;ll note that i=
t also covers complex dtypes (as it should), and that C23 et al. are real-v=
alued only. So NumPy wouldn&#39;t be able to count on `libm` support for ma=
ny years, probably never, and it&#39;d have to handle more dtypes than `sci=
py.special` (e.g., float16, longdouble). There&#39;s also the amount of fun=
ctions: is it sinpi/cospi/tanpi, or also their inverses? And the SciPy PR h=
as cotpi as well (not sure if that makes sense to add there, but almost cer=
tainly not to NumPy). Given all that, I&#39;d be inclined to put it in `xsf=
` and `scipy.special`, supporting only float32/float64/complex64/complex128=
. The xsf implementation could then also support CuPy.</div><div><br></div>=
<div>Cheers,<br></div><div>Ralf</div><div><br></div><div>=C2=A0</div><block=
quote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1=
px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"auto"><br><div clas=
s=3D"gmail_quote" 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:jepler@u=
npythonic.net" target=3D"_blank">[email protected]</a>&gt; wrote:<br></=
div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bor=
der-left:1px solid rgb(204,204,204);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:08 AM, Luca=
s Colley via NumPy-Discussion wrote:</div></div><div><blockquote type=3D"ci=
te" id=3D"m_-5443073061049654567m_4942541049634496217qt"></blockquote></div=
><div><blockquote type=3D"cite" id=3D"m_-5443073061049654567m_4942541049634=
496217qt"><div>There was a proposal to add these to `scipy.special`:=C2=A0<=
a href=3D"https://discuss.scientific-python.org/t/rfc-add-sinpi-cospi-tanpi=
-and-cotpi-functions-to-special/1193" target=3D"_blank">https://discuss.sci=
entific-python.org/t/rfc-add-sinpi-cospi-tanpi-and-cotpi-functions-to-speci=
al/1193</a>. There are existing implementations at=C2=A0<a href=3D"https://=
github.com/scipy/xsf/blob/main/include/xsf/trig.h" target=3D"_blank">https:=
//github.com/scipy/xsf/blob/main/include/xsf/trig.h</a>=C2=A0, with `sinpi`=
 and `cospi` exposed to SciPy (privately) at=C2=A0<a href=3D"https://github=
.com/scipy/scipy/blob/main/scipy/special/xsf_wrappers.h#L394-L396" target=
=3D"_blank">https://github.com/scipy/scipy/blob/main/scipy/special/xsf_wrap=
pers.h#L394-L396</a>.</div><div><br></div><div><div>We should probably deci=
de whether these best belong in `numpy` or `scipy.special`, and only expose=
 them in one of the two.</div><div><br></div><div>Cheers,</div><div><div>Lu=
cas</div><div><div><br></div><blockquote type=3D"cite"><div>On 9 Jun 2026, =
at 16:23, Jerome Kieffer &lt;<a href=3D"mailto:[email protected]" targ=
et=3D"_blank">[email protected]</a>&gt; wrote:</div><div><br></div><di=
v><div><span style=3D"font-style:normal;font-variant-caps:normal;font-weigh=
t:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform=
:none;word-spacing:0px;text-decoration-color:currentcolor;text-decoration-l=
ine:none;text-decoration-style:solid;float:none;display:inline"><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: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;text-decorat=
ion-color:currentcolor;text-decoration-line:none;text-decoration-style:soli=
d;float:none;display:inline"><span style=3D"font-family:Helvetica"><span st=
yle=3D"font-size:12px">On Mon, 08 Jun 2026 08:59:24 -0500</span></span></sp=
an></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"><spa=
n style=3D"font-family:Helvetica"><span style=3D"font-size:12px">&quot;Jeff=
 Epler&quot; &lt;</span></span></span><a href=3D"mailto:[email protected]=
et" 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" target=3D"_blank">jeple=
[email protected]</a><span style=3D"font-style:normal;font-variant-caps:norm=
al;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;t=
ext-transform:none;word-spacing:0px;text-decoration-color:currentcolor;text=
-decoration-line:none;text-decoration-style:solid;float:none;display:inline=
"><span style=3D"font-family:Helvetica"><span style=3D"font-size:12px">&gt;=
 wrote:</span></span></span></div><div><br></div><blockquote type=3D"cite" =
style=3D"font-family:Helvetica;font-size:12px;font-style:normal;font-varian=
t-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-i=
ndent:0px;text-transform:none;word-spacing:0px;text-decoration-line:none;te=
xt-decoration-style:solid"><div>In a recently merged PR (<a href=3D"https:/=
/github.com/python/cpython/pull/150555" target=3D"_blank">https://github.co=
m/python/cpython/pull/150555</a>), CPython has added a family of &quot;*pi&=
quot; functions to the math module, which take half-turn arguments instead =
of radians. One reason these functions are advantageous is that it&#39;s ea=
sy to provide the property that `sinpi(n/2)` is exact for all integers n, w=
hile `sin(pi*n)` is never exactly equal to the mathematical ideal except fo=
r n=3D0.</div><div><br></div><div>These functions are recommended by IEEE75=
4-2019 and standardized in C23 Annex G. (note: I&#39;m reading C23 draft re=
vised 2023-01-24, not the final standard document; and I do not have IEEE75=
4-2019).</div><div><br></div><div>C23 and CPython only added the real-value=
d versions of these functions, but C23 &quot;future library directions&quot=
; notes that identifiers like `csinpi` are &quot;potentially reserved ident=
ifiers.&quot;</div><div><br></div><div>Since CPython only requires C11, CPy=
thon includes implementations of these functions for when the underling pla=
tform library does not provide it. These implementations work by performing=
 special case handling &amp; range reduction, followed by a call to the sta=
ndard trig function with a scaled argument (in the case of forward function=
s) or scaling of the result (in the case of inverse/arc functions).</div><d=
iv><br></div><div>I am interested in doing the numpy implementation, howeve=
r I have never done core numpy work before. If there is interest from the p=
roject, I would like to initially offer a PR containing a single function s=
uch as `sinpi` and then complete the others following numpy core developer =
feedback.</div><div><br></div><div>Thanks,</div><div>Jeff</div><div>PS I no=
tice 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 style=3D=
"font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:=
normal;text-align:start;text-indent:0px;text-transform:none;word-spacing:0p=
x;text-decoration-color:currentcolor;text-decoration-line:none;text-decorat=
ion-style:solid;float:none;display:inline"><span style=3D"font-family:Helve=
tica"><span style=3D"font-size:12px">--<span>=C2=A0</span></span></span></s=
pan></div><div><span style=3D"font-style:normal;font-variant-caps:normal;fo=
nt-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-t=
ransform:none;word-spacing:0px;text-decoration-color:currentcolor;text-deco=
ration-line:none;text-decoration-style:solid;float:none;display:inline"><sp=
an style=3D"font-family:Helvetica"><span style=3D"font-size:12px">J=C3=A9r=
=C3=B4me Kieffer</span></span></span></div><div><span style=3D"font-style:n=
ormal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-a=
lign:start;text-indent:0px;text-transform:none;word-spacing:0px;text-decora=
tion-color:currentcolor;text-decoration-line:none;text-decoration-style:sol=
id;float:none;display:inline"><span style=3D"font-family:Helvetica"><span s=
tyle=3D"font-size:12px">tel +33 476 882 445</span></span></span></div><div>=
<span style=3D"font-style:normal;font-variant-caps:normal;font-weight:400;l=
etter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;w=
ord-spacing:0px;text-decoration-color:currentcolor;text-decoration-line:non=
e;text-decoration-style:solid;float:none;display:inline"><span style=3D"fon=
t-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:0px;text-transform:none;word-spacing:0px;text=
-decoration-color:currentcolor;text-decoration-line:none;text-decoration-st=
yle:solid;float:none;display:inline"><span style=3D"font-family:Helvetica">=
<span style=3D"font-size: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-varian=
t-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-i=
ndent:0px;text-transform:none;word-spacing:0px" target=3D"_blank">numpy-dis=
[email protected]</a></div><div><span style=3D"font-style:normal;font-vari=
ant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text=
-indent:0px;text-transform:none;word-spacing:0px;text-decoration-color:curr=
entcolor;text-decoration-line:none;text-decoration-style:solid;float:none;d=
isplay:inline"><span style=3D"font-family:Helvetica"><span style=3D"font-si=
ze:12px">To unsubscribe send an email to<span>=C2=A0</span></span></span></=
span><a href=3D"mailto:[email protected]" style=3D"font-fam=
ily:Helvetica;font-size:12px;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" target=3D"_blank">numpy-discussion-leave@pyt=
hon.org</a></div><div><a href=3D"https://mail.python.org/mailman3//lists/nu=
mpy-discussion.python.org" style=3D"font-family:Helvetica;font-size:12px;fo=
nt-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:nor=
mal;text-align: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;font-weight:400;letter-spacing:normal;text-align:start;text-indent:=
0px;text-transform:none;word-spacing:0px;text-decoration-color:currentcolor=
;text-decoration-line:none;text-decoration-style:solid;float:none;display:i=
nline"><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:l=
[email protected]" style=3D"font-family:Helvetica;font-size:12px;font-=
style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal=
;text-align:start;text-indent:0px;text-transform:none;word-spacing:0px" tar=
get=3D"_blank">[email protected]</a></div></div></blockquote></div></=
div></div><div>_______________________________________________</div><div>Nu=
mPy-Discussion mailing list --=C2=A0<a href=3D"mailto:numpy-discussion@pyth=
on.org" target=3D"_blank">[email protected]</a></div><div>To unsu=
bscribe send an email to=C2=A0<a href=3D"mailto:numpy-discussion-leave@pyth=
on.org" target=3D"_blank">[email protected]</a></div><div><=
a href=3D"https://mail.python.org/mailman3//lists/numpy-discussion.python.o=
rg" target=3D"_blank">https://mail.python.org/mailman3//lists/numpy-discuss=
ion.python.org</a></div></blockquote></div><div><blockquote type=3D"cite" i=
d=3D"m_-5443073061049654567m_4942541049634496217qt"><div>Member address:=C2=
=A0<a href=3D"mailto:[email protected]" target=3D"_blank">jepler@unpyth=
onic.net</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>
_______________________________________________<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"_b=
lank">[email protected]</a><br>
</blockquote></div></div>

--000000000000276e8a06541387d2--

--===============3552225574674448542==
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]

--===============3552225574674448542==--