Skip to content

Commit

Permalink
Merge pull request #22848 from charris/backport-22846
Browse files Browse the repository at this point in the history
BUG, SIMD: Fix the bitmask of the boolean comparison
  • Loading branch information
charris committed Dec 21, 2022
2 parents d6dbe36 + 50242d1 commit 0f1ad5a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions numpy/core/src/umath/loops_comparison.dispatch.c.src
Expand Up @@ -234,7 +234,7 @@ static void simd_binary_@kind@_b8(char **args, npy_intp len)
npyv_b8 a = npyv_cmpeq_u8(npyv_load_u8(src1), vzero);
npyv_b8 b = npyv_cmpeq_u8(npyv_load_u8(src2), vzero);
npyv_b8 c = npyv_@VOP@_b8(a, b);
npyv_store_u8(dst, npyv_andc_u8(npyv_cvt_u8_b8(c), truemask));
npyv_store_u8(dst, npyv_and_u8(npyv_cvt_u8_b8(c), truemask));
}

for (; len > 0; --len, ++src1, ++src2, ++dst) {
Expand All @@ -258,7 +258,7 @@ static void simd_binary_scalar1_@kind@_b8(char **args, npy_intp len)
for (; len >= vstep; len -= vstep, src += vstep, dst += vstep) {
npyv_b8 b = npyv_cmpeq_u8(npyv_load_u8(src), vzero);
npyv_b8 c = npyv_@VOP@_b8(a, b);
npyv_store_u8(dst, npyv_andc_u8(npyv_cvt_u8_b8(c), truemask));
npyv_store_u8(dst, npyv_and_u8(npyv_cvt_u8_b8(c), truemask));
}

for (; len > 0; --len, ++src, ++dst) {
Expand All @@ -281,7 +281,7 @@ static void simd_binary_scalar2_@kind@_b8(char **args, npy_intp len)
for (; len >= vstep; len -= vstep, src += vstep, dst += vstep) {
npyv_b8 a = npyv_cmpeq_u8(npyv_load_u8(src), vzero);
npyv_b8 c = npyv_@VOP@_b8(a, b);
npyv_store_u8(dst, npyv_andc_u8(npyv_cvt_u8_b8(c), truemask));
npyv_store_u8(dst, npyv_and_u8(npyv_cvt_u8_b8(c), truemask));
}

for (; len > 0; --len, ++src, ++dst) {
Expand Down
12 changes: 6 additions & 6 deletions numpy/core/tests/test_umath.py
Expand Up @@ -284,16 +284,16 @@ def test_comparison_functions(self, dtype, py_comp, np_comp):
b_lst = b.tolist()

# (Binary) Comparison (x1=array, x2=array)
comp_b = np_comp(a, b)
comp_b_list = [py_comp(x, y) for x, y in zip(a_lst, b_lst)]
comp_b = np_comp(a, b).view(np.uint8)
comp_b_list = [int(py_comp(x, y)) for x, y in zip(a_lst, b_lst)]

# (Scalar1) Comparison (x1=scalar, x2=array)
comp_s1 = np_comp(np_scalar, b)
comp_s1_list = [py_comp(scalar, x) for x in b_lst]
comp_s1 = np_comp(np_scalar, b).view(np.uint8)
comp_s1_list = [int(py_comp(scalar, x)) for x in b_lst]

# (Scalar2) Comparison (x1=array, x2=scalar)
comp_s2 = np_comp(a, np_scalar)
comp_s2_list = [py_comp(x, scalar) for x in a_lst]
comp_s2 = np_comp(a, np_scalar).view(np.uint8)
comp_s2_list = [int(py_comp(x, scalar)) for x in a_lst]

# Sequence: Binary, Scalar1 and Scalar2
assert_(comp_b.tolist() == comp_b_list,
Expand Down

0 comments on commit 0f1ad5a

Please sign in to comment.