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

np.logical_xor.accumulate fails on 1.24 on mac #22841

Closed
knutdrand opened this issue Dec 20, 2022 · 3 comments · Fixed by #22851
Closed

np.logical_xor.accumulate fails on 1.24 on mac #22841

knutdrand opened this issue Dec 20, 2022 · 3 comments · Fixed by #22851
Assignees
Labels
00 - Bug 06 - Regression component: SIMD Issues in SIMD (fast instruction sets) code or machinery

Comments

@knutdrand
Copy link

Describe the issue:

.Accumulate on logical_xor gives wrong result on newest version. I suspect the same for bitwise_xor.

Reproduce the code example:

import numpy as np

a = np.array([False, False,  True, False, False, False, False,  True, False, False,  True, False, False,  True, False, False, False, False, False, False])
np.logical_xor.accumulate(a)
array([False, False,  True,  True, False, False, False,  True,  True,
       False,  True,  True, False,  True,  True, False, False, False,
       False, False])
# Should be [False, False,  True,  True, True, True, True, False,,,,]

Error message:

No response

NumPy/Python version information:

numpy=1.24
python 3.8,
mac version 12.5.1

Context for the issue:

No response

@seberg seberg added component: SIMD Issues in SIMD (fast instruction sets) code or machinery 06 - Regression labels Dec 20, 2022
@seberg seberg added this to the 1.24.1 release milestone Dec 20, 2022
@seberg
Copy link
Member

seberg commented Dec 20, 2022

Again ping @seiko2plus and maybe @Developer-Ecosystem-Engineering. This looks like probably the identical issue as gh-22840 (just now slightly different with the reduction). Presumably introduced by gh-22167.

With a view (although I am not sure how important it is directly without digging in):

>>> a = np.array([False, False,  True, False, False, False, False,  True, False, False,  True, False, False,  True, False, False, False, False, False, False])
>>> np.logical_xor.accumulate(a).view(np.uint8)
array([  0,   0, 254, 254,   0,   0,   0, 254, 254,   0, 254, 254,   0,
       254, 254,   0,   0,   0,   0,   0], dtype=uint8)

@seiko2plus seiko2plus self-assigned this Dec 20, 2022
@Developer-Ecosystem-Engineering
Copy link
Contributor

Hi @seberg,

Appears related to #21483. The aliases for BOOL_logical_xor was BOOL_not_equal, which was subsequently changed

@seiko2plus
Copy link
Member

Memory overlaps! The comparison loops of all data types are free of overlap checking:

#define IS_BLOCKABLE_BINARY_BOOL(esize, vsize) \
(steps[0] == (esize) && steps[0] == steps[1] && steps[2] == (1) && \
npy_is_aligned(args[1], (esize)) && \
npy_is_aligned(args[0], (esize)))
#define IS_BLOCKABLE_BINARY_SCALAR1_BOOL(esize, vsize) \
(steps[0] == 0 && steps[1] == (esize) && steps[2] == (1) && \
npy_is_aligned(args[1], (esize)))
#define IS_BLOCKABLE_BINARY_SCALAR2_BOOL(esize, vsize) \
(steps[0] == (esize) && steps[1] == 0 && steps[2] == (1) && \
npy_is_aligned(args[0], (esize)))

/* argument one scalar */
if (IS_BLOCKABLE_BINARY_SCALAR1_BOOL(sizeof(@type@), NPY_SIMD_WIDTH)) {
simd_binary_scalar1_@kind@_@sfx@(args, dimensions[0]);
return;
}
/* argument two scalar */
else if (IS_BLOCKABLE_BINARY_SCALAR2_BOOL(sizeof(@type@), NPY_SIMD_WIDTH)) {
simd_binary_scalar2_@kind@_@sfx@(args, dimensions[0]);
return;
}
else if (IS_BLOCKABLE_BINARY_BOOL(sizeof(@type@), NPY_SIMD_WIDTH)) {
simd_binary_@kind@_@sfx@(args, dimensions[0]);
return;
}

+    // multiply by sizeof(@type@) due to SIMD unroll
     /* argument one scalar */
-    if (IS_BLOCKABLE_BINARY_SCALAR1_BOOL(sizeof(@type@), NPY_SIMD_WIDTH)) {
+    if (IS_BLOCKABLE_BINARY_SCALAR1(sizeof(@type@), NPY_SIMD_WIDTH*sizeof(@type@))) {
         simd_binary_scalar1_@kind@_@sfx@(args, dimensions[0]);
         return;
     }
     /* argument two scalar */
-    else if (IS_BLOCKABLE_BINARY_SCALAR2_BOOL(sizeof(@type@), NPY_SIMD_WIDTH)) {
+    else if (IS_BLOCKABLE_BINARY_SCALAR2(sizeof(@type@), NPY_SIMD_WIDTH*sizeof(@type@))) {
         simd_binary_scalar2_@kind@_@sfx@(args, dimensions[0]);
         return;
     }
-    else if (IS_BLOCKABLE_BINARY_BOOL(sizeof(@type@), NPY_SIMD_WIDTH)) {
+    else if (IS_BLOCKABLE_BINARY(sizeof(@type@), NPY_SIMD_WIDTH*sizeof(@type@))) {
         simd_binary_@kind@_@sfx@(args, dimensions[0]);
         return;
     }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 06 - Regression component: SIMD Issues in SIMD (fast instruction sets) code or machinery
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants