Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG, SIMD: Fix the bitmask of the boolean comparison #22848

Merged
merged 1 commit into from Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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