Skip to content

Commit 6ab3c71

Browse files
committed
Add comment in convert_impl to the branch handling conversion away from bool
1 parent cc0756f commit 6ab3c71

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

dpctl/tensor/libtensor/include/utils/type_utils.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ template <typename dstTy, typename srcTy> dstTy convert_impl(const srcTy &v)
7171
}
7272
}
7373
else if constexpr (std::is_same_v<srcTy, bool>) {
74+
// C++ interprets a byte of storage behind bool by only
75+
// testing is least significant bit, leading to both
76+
// 0x00 and 0x02 interpreted as False, while 0x01 and 0xFF
77+
// interpreted as True. NumPy's interpretation of underlying
78+
// storage is different: any bit set is interpreted as True,
79+
// no bits set as False, see gh-2121
7480
const std::uint8_t &u = sycl::bit_cast<std::uint8_t>(v);
7581
if constexpr (is_complex_v<dstTy>) {
7682
return (u == 0) ? dstTy{} : dstTy{1, 0};

0 commit comments

Comments
 (0)