Skip to content

Commit 299b46f

Browse files
committed
add isinf function
1 parent 5d61e30 commit 299b46f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pykokkos/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
set_device_id,
1818
)
1919

20-
from pykokkos.lib.ufuncs import _isnan as isnan, _isfinite as isfinite
20+
from pykokkos.lib.ufuncs import _isnan as isnan, _isinf as isinf, _isfinite as isfinite
2121

2222
from pykokkos.lib.info import iinfo, finfo
2323
from pykokkos.lib.create import zeros, zeros_like, ones, ones_like, full, full_like

pykokkos/lib/ufuncs.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def _equal(view1, view2, profiler_name: Optional[str] = None):
146146
)
147147
return out
148148

149+
149150
def _isnan(view, profiler_name: Optional[str] = None):
150151
dtype = view.dtype
151152
ndims = len(view.shape)
@@ -172,6 +173,30 @@ def _isnan(view, profiler_name: Optional[str] = None):
172173
)
173174
return out
174175

176+
177+
def _isinf(view, profiler_name: Optional[str] = None):
178+
dtype = view.dtype
179+
ndims = len(view.shape)
180+
if ndims > 2:
181+
raise NotImplementedError("isinf() ufunc only supports up to 2D views")
182+
out = pk.View([*view.shape], dtype=pk.bool)
183+
if view.shape == ():
184+
tid = 1
185+
else:
186+
tid = view.shape[0]
187+
_ufunc_kernel_dispatcher(
188+
profiler_name=profiler_name,
189+
tid=tid,
190+
dtype=dtype,
191+
ndims=ndims,
192+
op="isinf",
193+
sub_dispatcher=pk.parallel_for,
194+
out=out,
195+
view=view,
196+
)
197+
return out
198+
199+
175200
def _isfinite(view, profiler_name: Optional[str] = None):
176201
dtype = view.dtype
177202
ndims = len(view.shape)

0 commit comments

Comments
 (0)