1313from __future__ import annotations
1414
1515import typing
16- from math import inf
16+ from math import inf , nan
1717
1818import numpy
1919
3030)
3131
3232
33- # TODO: https://github.com/scikit-hep/vector/issues/615
34- # revert back to `nan_to_num` implementation once
35- # https://github.com/cupy/cupy/issues/9143 is fixed.
36- # `lib.where` works but there is no SymPy equivalent for the function.
3733def xy_z (lib , x , y , z ):
38- return (
39- lib .where (
40- z != 0 , lib .arcsinh ( lib . where (z != 0 , z / lib . sqrt ( x ** 2 + y ** 2 ), z )), z
41- )
42- * 1
34+ return lib . nan_to_num (
35+ lib .arcsinh ( z / lib . sqrt ( x ** 2 + y ** 2 )),
36+ nan = lib .nan_to_num ( (z != 0 ) * inf , posinf = nan ),
37+ posinf = inf ,
38+ neginf = - inf ,
4339 )
4440
4541
@@ -56,12 +52,13 @@ def xy_eta(lib, x, y, eta):
5652xy_eta .__awkward_transform_allowed__ = False # type:ignore[attr-defined]
5753
5854
59- # TODO: https://github.com/scikit-hep/vector/issues/615
60- # revert back to `nan_to_num` implementation once
61- # https://github.com/cupy/cupy/issues/9143 is fixed.
62- # `lib.where` works but there is no SymPy equivalent for the function.
6355def rhophi_z (lib , rho , phi , z ):
64- return lib .where (z != 0 , lib .arcsinh (lib .where (z != 0 , z / rho , z )), z ) * 1
56+ return lib .nan_to_num (
57+ lib .arcsinh (z / rho ),
58+ nan = lib .nan_to_num ((z != 0 ) * inf , posinf = nan ),
59+ posinf = inf ,
60+ neginf = - inf ,
61+ )
6562
6663
6764def rhophi_theta (lib , rho , phi , theta ):
0 commit comments