You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The standard does not define bitwise_left_shift or bitwise_right_shift for booleans, but does (strictly speaking) define the operators for boolean input in "Bitwise operators".
Bitwise operators should be defined for arrays having integer and boolean data types.
This may be an oversight, but if not, what should the output dtype be? bool per typical type promotion, or something else? NumPy produces int8, and JAX prefers int32.
Good catch, that looks like an inconsistency indeed. In gh-54, all bitwise_* functions say "integer or bool dtype" except for bitwise_left_shift and bitwise_right_shift. So that was deliberate; there were no review comments on it.
If you look at the NumPy docs, it does also mandate integer dtype for the input arrays. Hence, the acceptance of bool arrays and upcasting them to int8 seems like an accident of implementation. It seems to just follow from the operator implementation, and as soon as the second argument is integer it doesn't matter anymore:
However, does x << x really make any sense to begin with? I don't think so.
The edit that can be made to the standard is for the bitwise operator section to say this I think:
Bitwise operators should be defined for arrays having integer and boolean data types, except << and >> which should be defined only for integer data types.
Activity
rgommers commentedon Mar 3, 2026
Good catch, that looks like an inconsistency indeed. In gh-54, all
bitwise_*functions say "integer or bool dtype" except forbitwise_left_shiftandbitwise_right_shift. So that was deliberate; there were no review comments on it.If you look at the NumPy docs, it does also mandate integer dtype for the input arrays. Hence, the acceptance of
boolarrays and upcasting them toint8seems like an accident of implementation. It seems to just follow from the operator implementation, and as soon as the second argument is integer it doesn't matter anymore:However, does
x << xreally make any sense to begin with? I don't think so.The edit that can be made to the standard is for the bitwise operator section to say this I think:
Bitwise operators should be defined for arrays having integer and boolean data types, except
<<and>>which should be defined only for integer data types.