Re: ENH: Add np.sinpi et al following CPython core, C23 & IEEE754-2019
"Jeff Epler" <[email protected]> Thu, 11 Jun 2026 10:09:48 -0500
| Newsgroups | gmane.comp.python.numeric.general |
|---|---|
| Message-ID | <[email protected]> |
--===============7164167014849633119== Content-Type: multipart/alternative; boundary=73a4d0b2c2278ec3bcc2ef418fa5294fa0c2672e --73a4d0b2c2278ec3bcc2ef418fa5294fa0c2672e Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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-cotpi-functions-to= -special/1193. There are existing implementations at https://github.com/= scipy/xsf/blob/main/include/xsf/trig.h , with `sinpi` and `cospi` expose= d to SciPy (privately) at https://github.com/scipy/scipy/blob/main/scipy= /special/xsf_wrappers.h#L394-L396. >=20 > We should probably decide whether these best belong in `numpy` or `sci= py.special`, and only expose them in one of the two. >=20 > Cheers, > Lucas >=20 >> On 9 Jun 2026, at 16:23, Jerome Kieffer <[email protected]> wrot= e: >>=20 >> I like the idea ! >>=20 >> On Mon, 08 Jun 2026 08:59:24 -0500 >> "Jeff Epler" <[email protected]> wrote: >>=20 >>> In a recently merged PR (https://github.com/python/cpython/pull/1505= 55), CPython has added a family of "*pi" functions to the math module, w= hich take half-turn arguments instead of radians. One reason these funct= ions are advantageous is that it's easy to provide the property that `si= npi(n/2)` is exact for all integers n, while `sin(pi*n)` is never exactl= y equal to the mathematical ideal except for n=3D0. >>>=20 >>> 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 fi= nal standard document; and I do not have IEEE754-2019). >>>=20 >>> C23 and CPython only added the real-valued versions of these functio= ns, but C23 "future library directions" notes that identifiers like `csi= npi` are "potentially reserved identifiers." >>>=20 >>> Since CPython only requires C11, CPython includes implementations of= these functions for when the underling platform library does not provid= e it. These implementations work by performing special case handling & r= ange reduction, followed by a call to the standard trig function with a = scaled argument (in the case of forward functions) or scaling of the res= ult (in the case of inverse/arc functions). >>>=20 >>> I am interested in doing the numpy implementation, however I have ne= ver done core numpy work before. If there is interest from the project, = I would like to initially offer a PR containing a single function such a= s `sinpi` and then complete the others following numpy core developer fe= edback. >>>=20 >>> Thanks, >>> Jeff >>> PS I notice via the archives that there are occasional "New Contribu= tors' Hour" meetings. Is the next one scheduled yet? >>=20 >>=20 >>=20 >>=20 >> --=20 >> 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] >=20 --73a4d0b2c2278ec3bcc2ef418fa5294fa0c2672e Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable <!DOCTYPE html><html><head><title></title></head><body><div>How is it ty= pically decided whether some array function goes in numpy or scipy?</div= ><div><br></div><div>On Tue, Jun 9, 2026, at 11:08 AM, Lucas Colley via = NumPy-Discussion wrote:</div><blockquote type=3D"cite" id=3D"qt" style=3D= "overflow-wrap:break-word;"><div>There was a proposal to add these to `s= cipy.special`: <a href=3D"https://discuss.scientific-python.org/t/r= fc-add-sinpi-cospi-tanpi-and-cotpi-functions-to-special/1193">https://di= scuss.scientific-python.org/t/rfc-add-sinpi-cospi-tanpi-and-cotpi-functi= ons-to-special/1193</a>. There are existing implementations at <a h= ref=3D"https://github.com/scipy/xsf/blob/main/include/xsf/trig.h">https:= //github.com/scipy/xsf/blob/main/include/xsf/trig.h</a> , with `sin= pi` and `cospi` exposed to SciPy (privately) at <a href=3D"https://= github.com/scipy/scipy/blob/main/scipy/special/xsf_wrappers.h#L394-L396"= >https://github.com/scipy/scipy/blob/main/scipy/special/xsf_wrappers.h#L= 394-L396</a>.</div><div><br></div><div><div>We should probably decide wh= ether these best belong in `numpy` or `scipy.special`, and only expose t= hem in one of the two.</div><div><br></div><div>Cheers,</div><div><div>L= ucas</div><div><div><br></div><blockquote type=3D"cite"><div>On 9 Jun 20= 26, at 16:23, Jerome Kieffer <[email protected]> wrote:</div>= <div><br></div><div><div><span style=3D"font-style:normal;font-variant-c= aps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-i= ndent:0px;text-transform:none;text-wrap-mode:wrap;white-space-collapse:c= ollapse;word-spacing:0px;-webkit-text-stroke-width:0px;text-decoration-c= olor:currentcolor;text-decoration-line:none;text-decoration-style:solid;= text-decoration-thickness:auto;float:none;display:inline !important;"><s= pan class=3D"font" style=3D"font-family:Helvetica;"><span class=3D"size"= 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:no= rmal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:= 0px;text-transform:none;text-wrap-mode:wrap;white-space-collapse:collaps= e;word-spacing:0px;-webkit-text-stroke-width:0px;text-decoration-color:c= urrentcolor;text-decoration-line:none;text-decoration-style:solid;text-d= ecoration-thickness:auto;float:none;display:inline !important;"><span cl= ass=3D"font" style=3D"font-family:Helvetica;"><span class=3D"size" style= =3D"font-size:12px;">On Mon, 08 Jun 2026 08:59:24 -0500</span></span></s= pan></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;text-wrap-mode:wrap;white-space-collapse:collapse;wo= rd-spacing:0px;-webkit-text-stroke-width:0px;text-decoration-color:curre= ntcolor;text-decoration-line:none;text-decoration-style:solid;text-decor= ation-thickness:auto;float:none;display:inline !important;"><span class=3D= "font" style=3D"font-family:Helvetica;"><span class=3D"size" style=3D"fo= nt-size:12px;">"Jeff Epler" <</span></span></span><a href=3D"mailto:j= [email protected]" style=3D"font-family:Helvetica;font-size:12px;font= -style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:no= rmal;text-align:start;text-indent:0px;text-transform:none;text-wrap-mode= :wrap;white-space-collapse:collapse;word-spacing:0px;-webkit-text-stroke= -width:0px;">[email protected]</a><span style=3D"font-style:normal;f= ont-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align= :start;text-indent:0px;text-transform:none;text-wrap-mode:wrap;white-spa= ce-collapse:collapse;word-spacing:0px;-webkit-text-stroke-width:0px;text= -decoration-color:currentcolor;text-decoration-line:none;text-decoration= -style:solid;text-decoration-thickness:auto;float:none;display:inline !i= mportant;"><span class=3D"font" style=3D"font-family:Helvetica;"><span c= lass=3D"size" style=3D"font-size:12px;">> wrote:</span></span></span>= </div><div><br></div><blockquote type=3D"cite" style=3D"font-family:Helv= etica;font-size:12px;font-style:normal;font-variant-caps:normal;font-wei= ght:400;letter-spacing:normal;text-align:start;text-indent:0px;text-tran= sform:none;text-wrap-mode:wrap;white-space-collapse:collapse;word-spacin= g:0px;-webkit-text-stroke-width:0px;text-decoration-line:none;text-decor= ation-thickness:auto;text-decoration-style:solid;"><div>In a recently me= rged PR (https://github.com/python/cpython/pull/150555), CPython has add= ed a family of "*pi" functions to the math module, which take half-turn = arguments instead of radians. One reason these functions are advantageou= s is that it's easy to provide the property that `sinpi(n/2)` is exact f= or all integers n, while `sin(pi*n)` is never exactly equal to the mathe= matical ideal except for n=3D0.</div><div><br></div><div>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 docume= nt; and I do not have IEEE754-2019).</div><div><br></div><div>C23 and CP= ython only added the real-valued versions of these functions, but C23 "f= uture library directions" notes that identifiers like `csinpi` are "pote= ntially reserved identifiers."</div><div><br></div><div>Since CPython on= ly requires C11, CPython includes implementations of these functions for= when the underling platform library does not provide it. These implemen= tations 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).</div><div><br></div><div>I am interested in = doing the numpy implementation, however I have never done core numpy wor= k before. If there is interest from the project, I would like to initial= ly offer a PR containing a single function such as `sinpi` and then comp= lete the others following numpy core developer feedback.</div><div><br><= /div><div>Thanks,</div><div>Jeff</div><div>PS I notice via the archives = that there are occasional "New Contributors' Hour" 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-var= iant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;= text-indent:0px;text-transform:none;text-wrap-mode:wrap;white-space-coll= apse:collapse;word-spacing:0px;-webkit-text-stroke-width:0px;text-decora= tion-color:currentcolor;text-decoration-line:none;text-decoration-style:= solid;text-decoration-thickness:auto;float:none;display:inline !importan= t;"><span class=3D"font" style=3D"font-family:Helvetica;"><span class=3D= "size" style=3D"font-size:12px;">--<span class=3D"qt-Apple-converted-spa= ce"> </span></span></span></span></div><div><span style=3D"font-sty= le:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal= ;text-align:start;text-indent:0px;text-transform:none;text-wrap-mode:wra= p;white-space-collapse:collapse;word-spacing:0px;-webkit-text-stroke-wid= th:0px;text-decoration-color:currentcolor;text-decoration-line:none;text= -decoration-style:solid;text-decoration-thickness:auto;float:none;displa= y:inline !important;"><span class=3D"font" style=3D"font-family:Helvetic= a;"><span class=3D"size" style=3D"font-size:12px;">J=C3=A9r=C3=B4me Kief= fer</span></span></span></div><div><span style=3D"font-style:normal;font= -variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:st= art;text-indent:0px;text-transform:none;text-wrap-mode:wrap;white-space-= collapse:collapse;word-spacing:0px;-webkit-text-stroke-width:0px;text-de= coration-color:currentcolor;text-decoration-line:none;text-decoration-st= yle:solid;text-decoration-thickness:auto;float:none;display:inline !impo= rtant;"><span class=3D"font" style=3D"font-family:Helvetica;"><span clas= s=3D"size" style=3D"font-size:12px;">tel +33 476 882 445</span></span></= span></div><div><span style=3D"font-style:normal;font-variant-caps:norma= l;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px= ;text-transform:none;text-wrap-mode:wrap;white-space-collapse:collapse;w= ord-spacing:0px;-webkit-text-stroke-width:0px;text-decoration-color:curr= entcolor;text-decoration-line:none;text-decoration-style:solid;text-deco= ration-thickness:auto;float:none;display:inline !important;"><span class= =3D"font" style=3D"font-family:Helvetica;"><span class=3D"size" style=3D= "font-size:12px;">_______________________________________________</span>= </span></span></div><div><span style=3D"font-style:normal;font-variant-c= aps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-i= ndent:0px;text-transform:none;text-wrap-mode:wrap;white-space-collapse:c= ollapse;word-spacing:0px;-webkit-text-stroke-width:0px;text-decoration-c= olor:currentcolor;text-decoration-line:none;text-decoration-style:solid;= text-decoration-thickness:auto;float:none;display:inline !important;"><s= pan class=3D"font" style=3D"font-family:Helvetica;"><span class=3D"size"= style=3D"font-size:12px;">NumPy-Discussion mailing list --<span class=3D= "qt-Apple-converted-space"> </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-weight:400;let= ter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;= text-wrap-mode:wrap;white-space-collapse:collapse;word-spacing:0px;-webk= it-text-stroke-width:0px;">[email protected]</a></div><div><sp= an style=3D"font-style:normal;font-variant-caps:normal;font-weight:400;l= etter-spacing:normal;text-align:start;text-indent:0px;text-transform:non= e;text-wrap-mode:wrap;white-space-collapse:collapse;word-spacing:0px;-we= bkit-text-stroke-width:0px;text-decoration-color:currentcolor;text-decor= ation-line:none;text-decoration-style:solid;text-decoration-thickness:au= to;float:none;display:inline !important;"><span class=3D"font" style=3D"= font-family:Helvetica;"><span class=3D"size" style=3D"font-size:12px;">T= o unsubscribe send an email to<span class=3D"qt-Apple-converted-space">&= nbsp;</span></span></span></span><a href=3D"mailto:numpy-discussion-leav= [email protected]" style=3D"font-family:Helvetica;font-size:12px;font-style:n= ormal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;tex= t-align:start;text-indent:0px;text-transform:none;text-wrap-mode:wrap;wh= ite-space-collapse:collapse;word-spacing:0px;-webkit-text-stroke-width:0= px;">[email protected]</a></div><div><a href=3D"https://= mail.python.org/mailman3//lists/numpy-discussion.python.org" style=3D"fo= nt-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:n= ormal;font-weight:400;letter-spacing:normal;text-align:start;text-indent= :0px;text-transform:none;text-wrap-mode:wrap;white-space-collapse:collap= se;word-spacing:0px;-webkit-text-stroke-width:0px;">https://mail.python.= org/mailman3//lists/numpy-discussion.python.org</a></div><div><span styl= e=3D"font-style:normal;font-variant-caps:normal;font-weight:400;letter-s= pacing:normal;text-align:start;text-indent:0px;text-transform:none;text-= wrap-mode:wrap;white-space-collapse:collapse;word-spacing:0px;-webkit-te= xt-stroke-width:0px;text-decoration-color:currentcolor;text-decoration-l= ine:none;text-decoration-style:solid;text-decoration-thickness:auto;floa= t:none;display:inline !important;"><span class=3D"font" style=3D"font-fa= mily:Helvetica;"><span class=3D"size" style=3D"font-size:12px;">Member a= ddress:<span class=3D"qt-Apple-converted-space"> </span></span></sp= an></span><a href=3D"mailto:[email protected]" style=3D"font-famil= y:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;fo= nt-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;tex= t-transform:none;text-wrap-mode:wrap;white-space-collapse:collapse;word-= spacing:0px;-webkit-text-stroke-width:0px;">[email protected]</a><= /div></div></blockquote></div></div></div><div>_________________________= ______________________</div><div>NumPy-Discussion mailing list -- <= a href=3D"mailto:[email protected]">[email protected]= g</a></div><div>To unsubscribe send an email to <a href=3D"mailto:n= [email protected]">[email protected]</a><= /div><div><a href=3D"https://mail.python.org/mailman3//lists/numpy-discu= ssion.python.org">https://mail.python.org/mailman3//lists/numpy-discussi= on.python.org</a></div><div>Member address: <a href=3D"mailto:jeple= [email protected]">[email protected]</a></div><div><br></div></blockq= uote><div><br></div></body></html> --73a4d0b2c2278ec3bcc2ef418fa5294fa0c2672e-- --===============7164167014849633119== 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] --===============7164167014849633119==--