Skip to content

Commit e166f9f

Browse files
authored
[core]Coverity fix of dead code in (pr)elu reference implementation (#28407)
### Details: - Fix Coverity issue in reference implementation of `ELU`, `PReLU` operators of dead code for unsigned types. ### Tickets: - N/A Signed-off-by: Raasz, Pawel <[email protected]>
1 parent 7391a66 commit e166f9f

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/core/reference/include/openvino/reference/elu.hpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
#include <cmath>
88
#include <cstddef>
99

10-
namespace ov {
11-
namespace reference {
10+
#include "openvino/reference/copy.hpp"
11+
12+
namespace ov::reference {
1213
template <typename T>
1314
void elu(const T* arg, T* out, size_t count, double alpha) {
14-
for (size_t i = 0; i < count; i++) {
15-
out[i] = arg[i] < T(0) ? T(alpha * (std::exp(arg[i]) - 1.0)) : arg[i];
15+
if constexpr (std::is_unsigned_v<T>) {
16+
copy(arg, out, count);
17+
} else {
18+
for (size_t i = 0; i < count; i++) {
19+
out[i] = arg[i] < T(0) ? T(alpha * (std::exp(arg[i]) - 1.0)) : arg[i];
20+
}
1621
}
1722
}
18-
} // namespace reference
19-
} // namespace ov
23+
} // namespace ov::reference

src/core/reference/include/openvino/reference/prelu.hpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
#include "openvino/op/util/attr_types.hpp"
1212
#include "openvino/reference/autobroadcast_binop.hpp"
1313

14-
namespace ov {
15-
namespace reference {
14+
namespace ov::reference {
1615
namespace func {
1716
// Usage of custom function instead of lambda, gives smaller binary size.
1817
template <class T>
1918
T prelu(const T x, const T y) {
20-
return x < T(0) ? x * y : x;
19+
if constexpr (std::is_unsigned_v<T>) {
20+
return x;
21+
} else {
22+
return x < T(0) ? x * y : x;
23+
}
2124
}
2225
} // namespace func
2326

@@ -32,5 +35,4 @@ void prelu(const T* arg, const T* slope, T* out, const Shape& arg_shape, const S
3235
}
3336
autobroadcast_binop(arg, slope, out, arg_shape, slope_shape_tmp, op::AutoBroadcastType::NUMPY, func::prelu<T>);
3437
}
35-
} // namespace reference
36-
} // namespace ov
38+
} // namespace ov::reference

0 commit comments

Comments
 (0)