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

Method test_operators_logical

numpy/core/tests/test_simd.py:142–183  ·  view source on GitHub ↗

Logical operations for boolean types. Test intrinsics: npyv_xor_##SFX, npyv_and_##SFX, npyv_or_##SFX, npyv_not_##SFX, npyv_andc_b8, npvy_orc_b8, nvpy_xnor_b8

(self)

Source from the content-addressed store, hash-verified

140 return cvt(load(data))
141
142 def test_operators_logical(self):
143 """
144 Logical operations for boolean types.
145 Test intrinsics:
146 npyv_xor_##SFX, npyv_and_##SFX, npyv_or_##SFX, npyv_not_##SFX,
147 npyv_andc_b8, npvy_orc_b8, nvpy_xnor_b8
148 """
149 data_a = self._data()
150 data_b = self._data(reverse=True)
151 vdata_a = self._load_b(data_a)
152 vdata_b = self._load_b(data_b)
153
154 data_and = [a & b for a, b in zip(data_a, data_b)]
155 vand = getattr(self, "and")(vdata_a, vdata_b)
156 assert vand == data_and
157
158 data_or = [a | b for a, b in zip(data_a, data_b)]
159 vor = getattr(self, "or")(vdata_a, vdata_b)
160 assert vor == data_or
161
162 data_xor = [a ^ b for a, b in zip(data_a, data_b)]
163 vxor = getattr(self, "xor")(vdata_a, vdata_b)
164 assert vxor == data_xor
165
166 vnot = getattr(self, "not")(vdata_a)
167 assert vnot == data_b
168
169 # among the boolean types, andc, orc and xnor only support b8
170 if self.sfx not in ("b8"):
171 return
172
173 data_andc = [(a & ~b) & 0xFF for a, b in zip(data_a, data_b)]
174 vandc = getattr(self, "andc")(vdata_a, vdata_b)
175 assert data_andc == vandc
176
177 data_orc = [(a | ~b) & 0xFF for a, b in zip(data_a, data_b)]
178 vorc = getattr(self, "orc")(vdata_a, vdata_b)
179 assert data_orc == vorc
180
181 data_xnor = [~(a ^ b) & 0xFF for a, b in zip(data_a, data_b)]
182 vxnor = getattr(self, "xnor")(vdata_a, vdata_b)
183 assert data_xnor == vxnor
184
185 def test_tobits(self):
186 data2bits = lambda data: sum([int(x != 0) << i for i, x in enumerate(data, 0)])

Callers

nothing calls this directly

Calls 2

_dataMethod · 0.95
_load_bMethod · 0.95

Tested by

no test coverage detected