Skip to content

Commit 29c52b4

Browse files
Addressed coverity issue about handling bools in floor_divide
1 parent 1993eae commit 29c52b4

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

dpctl/tensor/libtensor/include/kernels/elementwise_functions/floor_divide.hpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ struct FloorDivideFunctor
5757

5858
resT operator()(const argT1 &in1, const argT2 &in2)
5959
{
60-
if constexpr (std::is_integral_v<argT1> || std::is_integral_v<argT2>) {
60+
if constexpr (std::is_same_v<argT1, bool> &&
61+
std::is_same_v<argT2, bool>) {
62+
return (in2) ? static_cast<resT>(in1) : resT(0);
63+
}
64+
else if constexpr (std::is_integral_v<argT1> ||
65+
std::is_integral_v<argT2>) {
6166
if (in2 == argT2(0)) {
6267
return resT(0);
6368
}
@@ -81,7 +86,16 @@ struct FloorDivideFunctor
8186
sycl::vec<resT, vec_sz> operator()(const sycl::vec<argT1, vec_sz> &in1,
8287
const sycl::vec<argT2, vec_sz> &in2)
8388
{
84-
if constexpr (std::is_integral_v<resT>) {
89+
if constexpr (std::is_same_v<argT1, bool> &&
90+
std::is_same_v<argT2, bool>) {
91+
sycl::vec<resT, vec_sz> res;
92+
#pragma unroll
93+
for (int i = 0; i < vec_sz; ++i) {
94+
res[i] = (in2[i]) ? static_cast<resT>(in1[i]) : resT(0);
95+
}
96+
return res;
97+
}
98+
else if constexpr (std::is_integral_v<resT>) {
8599
sycl::vec<resT, vec_sz> res;
86100
#pragma unroll
87101
for (int i = 0; i < vec_sz; ++i) {

0 commit comments

Comments
 (0)