MCPcopy Create free account
hub / github.com/numpy/numpy / test_rounding

Method test_rounding

numpy/core/tests/test_simd.py:438–482  ·  view source on GitHub ↗

Test intrinsics: npyv_rint_##SFX npyv_ceil_##SFX npyv_trunc_##SFX npyv_floor##SFX

(self, intrin, func)

Source from the content-addressed store, hash-verified

436 @pytest.mark.parametrize("intrin, func", [("ceil", math.ceil),
437 ("trunc", math.trunc), ("floor", math.floor), ("rint", round)])
438 def test_rounding(self, intrin, func):
439 """
440 Test intrinsics:
441 npyv_rint_##SFX
442 npyv_ceil_##SFX
443 npyv_trunc_##SFX
444 npyv_floor##SFX
445 """
446 intrin_name = intrin
447 intrin = getattr(self, intrin)
448 pinf, ninf, nan = self._pinfinity(), self._ninfinity(), self._nan()
449 # special cases
450 round_cases = ((nan, nan), (pinf, pinf), (ninf, ninf))
451 for case, desired in round_cases:
452 data_round = [desired]*self.nlanes
453 _round = intrin(self.setall(case))
454 assert _round == pytest.approx(data_round, nan_ok=True)
455
456 for x in range(0, 2**20, 256**2):
457 for w in (-1.05, -1.10, -1.15, 1.05, 1.10, 1.15):
458 data = self.load([(x+a)*w for a in range(self.nlanes)])
459 data_round = [func(x) for x in data]
460 _round = intrin(data)
461 assert _round == data_round
462
463 # test large numbers
464 for i in (
465 1.1529215045988576e+18, 4.6116860183954304e+18,
466 5.902958103546122e+20, 2.3611832414184488e+21
467 ):
468 x = self.setall(i)
469 y = intrin(x)
470 data_round = [func(n) for n in x]
471 assert y == data_round
472
473 # signed zero
474 if intrin_name == "floor":
475 data_szero = (-0.0,)
476 else:
477 data_szero = (-0.0, -0.25, -0.30, -0.45, -0.5)
478
479 for w in data_szero:
480 _round = self._to_unsigned(intrin(self.setall(w)))
481 data_round = self._to_unsigned(self.setall(-0.0))
482 assert _round == data_round
483
484 @pytest.mark.parametrize("intrin", [
485 "max", "maxp", "maxn", "min", "minp", "minn"

Callers

nothing calls this directly

Calls 5

_pinfinityMethod · 0.80
_ninfinityMethod · 0.80
_nanMethod · 0.80
_to_unsignedMethod · 0.80
funcFunction · 0.50

Tested by

no test coverage detected