Skip to content

Commit 483cc87

Browse files
author
Holger Kohr
committed
TST: add test for elemwise with infinity
1 parent f6649ca commit 483cc87

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

pygpu/tests/test_elemwise.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import operator
22
import numpy
3+
from mako.template import Template
34

45
from unittest import TestCase
56
from pygpu import gpuarray, ndgpuarray as elemary
@@ -297,3 +298,37 @@ def broadcast(shapea, shapeb):
297298
rg = ag + bg
298299

299300
check_meta_content(rg, rc)
301+
302+
303+
_inf_preamb_tpl = Template('''
304+
WITHIN_KERNEL ${flt}
305+
infinity() {return INFINITY;}
306+
307+
WITHIN_KERNEL ${flt}
308+
neg_infinity() {return -INFINITY;}
309+
''')
310+
311+
312+
def test_infinity():
313+
for dtype in ['float32', 'float64']:
314+
ac, ag = gen_gpuarray((2,), dtype, ctx=context, cls=elemary)
315+
out_g = ag._empty_like_me()
316+
flt = 'ga_float' if dtype == 'float32' else 'ga_double'
317+
out_arg = arg('out', out_g.dtype, scalar=False, read=False, write=True)
318+
preamble = _inf_preamb_tpl.render(flt=flt)
319+
320+
# +infinity
321+
ac[:] = numpy.inf
322+
expr_inf = 'out = infinity()'
323+
kernel = GpuElemwise(context, expr_inf, [out_arg],
324+
preamble=preamble)
325+
kernel(out_g)
326+
assert numpy.array_equal(ac, numpy.asarray(out_g))
327+
328+
# -infinity
329+
ac[:] = -numpy.inf
330+
expr_neginf = 'out = neg_infinity()'
331+
kernel = GpuElemwise(context, expr_neginf, [out_arg],
332+
preamble=preamble)
333+
kernel(out_g)
334+
assert numpy.array_equal(ac, numpy.asarray(out_g))

0 commit comments

Comments
 (0)