From dc4a9e39dfb13aecb61d955445538838fbb2233d Mon Sep 17 00:00:00 2001 From: Rafael CF Sousa Date: Fri, 27 May 2022 12:34:43 -0300 Subject: [PATCH] TST: Add test for andc (u8) This commit also rewrite the tests andc, orc and xnor --- numpy/core/tests/test_simd.py | 67 +++++++++++++---------------------- 1 file changed, 24 insertions(+), 43 deletions(-) diff --git a/numpy/core/tests/test_simd.py b/numpy/core/tests/test_simd.py index 81d759ad42ea..f33db95fc415 100644 --- a/numpy/core/tests/test_simd.py +++ b/numpy/core/tests/test_simd.py @@ -126,7 +126,8 @@ def test_operators_logical(self): """ Logical operations for boolean types. Test intrinsics: - npyv_xor_##SFX, npyv_and_##SFX, npyv_or_##SFX, npyv_not_##SFX + npyv_xor_##SFX, npyv_and_##SFX, npyv_or_##SFX, npyv_not_##SFX, + npyv_andc_b8, npvy_orc_b8, nvpy_xnor_b8 """ data_a = self._data() data_b = self._data(reverse=True) @@ -148,6 +149,22 @@ def test_operators_logical(self): vnot = getattr(self, "not")(vdata_a) assert vnot == data_b + # among the boolean types, andc, orc and xnor only support b8 + if self.sfx not in ("b8"): + return + + data_andc = [(a & ~b) & 0xFF for a, b in zip(data_a, data_b)] + vandc = getattr(self, "andc")(vdata_a, vdata_b) + assert data_andc == vandc + + data_orc = [(a | ~b) & 0xFF for a, b in zip(data_a, data_b)] + vorc = getattr(self, "orc")(vdata_a, vdata_b) + assert data_orc == vorc + + data_xnor = [~(a ^ b) & 0xFF for a, b in zip(data_a, data_b)] + vxnor = getattr(self, "xnor")(vdata_a, vdata_b) + assert data_xnor == vxnor + def test_tobits(self): data2bits = lambda data: sum([int(x != 0) << i for i, x in enumerate(data, 0)]) for data in (self._data(), self._data(reverse=True)): @@ -156,48 +173,6 @@ def test_tobits(self): tobits = bin(self.tobits(vdata)) assert tobits == bin(data_bits) - def test_andc(self): - if self.sfx not in ("b8"): - return - andc_simd = getattr(self.npyv, f"andc_b8") - # create the vectors - data = self._data() - rdata = self._data(reverse=True) - vdata = self._load_b(data) - vrdata = self._load_b(rdata) - # check andc - sandc = [(~x & y) & 0xFF for x, y in zip(rdata, data)] - vandc = andc_simd(vrdata, vdata) - assert sandc == vandc - - def test_orc(self): - if self.sfx not in ("b8"): - return - orc_simd = getattr(self.npyv, f"orc_b8") - # create the vectors - data = self._data() - rdata = self._data(reverse=True) - vdata = self._load_b(data) - vrdata = self._load_b(rdata) - # check orc - sorc = [(~x | y) & 0xFF for x, y in zip(rdata, data)] - vorc = orc_simd(vrdata, vdata) - assert sorc == vorc - - def test_xnor(self): - if self.sfx not in ("b8"): - return - xnor_simd = getattr(self.npyv, f"xnor_b8") - # create the vectors - data = self._data() - rdata = self._data(reverse=True) - vdata = self._load_b(data) - vrdata = self._load_b(rdata) - # check orc - sxnor = [~(x ^ y) & 0xFF for x, y in zip(rdata, data)] - vxnor = xnor_simd(vrdata, vdata) - assert sxnor == vxnor - def test_pack(self): """ Pack multiple vectors into one @@ -865,6 +840,12 @@ def test_operators_logical(self): vnot = cast(getattr(self, "not")(vdata_a)) assert vnot == data_not + if self.sfx not in ("u8"): + return + data_andc = [a & ~b for a, b in zip(data_cast_a, data_cast_b)] + vandc = cast(getattr(self, "andc")(vdata_a, vdata_b)) + assert vandc == data_andc + def test_conversion_boolean(self): bsfx = "b" + self.sfx[1:] to_boolean = getattr(self.npyv, "cvt_%s_%s" % (bsfx, self.sfx))