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

Method test_conversions

numpy/_core/tests/test_simd.py:333–350  ·  view source on GitHub ↗

Round to nearest even integer, assume CPU control register is set to rounding. Test intrinsics: npyv_round_s32_##SFX

(self)

Source from the content-addressed store, hash-verified

331 To only test single precision
332 """
333 def test_conversions(self):
334 """
335 Round to nearest even integer, assume CPU control register is set to rounding.
336 Test intrinsics:
337 npyv_round_s32_##SFX
338 """
339 features = self._cpu_features()
340 if not self.npyv.simd_f64 and re.match(r".*(NEON|ASIMD)", features):
341 # very costly to emulate nearest even on Armv7
342 # instead we round halves to up. e.g. 0.5 -> 1, -0.5 -> -1
343 _round = lambda v: int(v + (0.5 if v >= 0 else -0.5))
344 else:
345 _round = round
346 vdata_a = self.load(self._data())
347 vdata_a = self.sub(vdata_a, self.setall(0.5))
348 data_round = [_round(x) for x in vdata_a]
349 vround = self.round_s32(vdata_a)
350 assert vround == data_round
351
352class _SIMD_FP64(_Test_Utility):
353 """

Callers

nothing calls this directly

Calls 2

_cpu_featuresMethod · 0.80
_dataMethod · 0.45

Tested by

no test coverage detected