MCPcopy Index your code
hub / github.com/numpy/numpy / test_rounding

Method test_rounding

numpy/_core/tests/test_simd.py:445–489  ·  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

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

Tested by

no test coverage detected