Skip to content

Commit 4f28b24

Browse files
authored
Fix portable is[inf|nan|_out compilation on older Linux
By wrapping a potentially non-compliant `isinf`/`isnan` implementations into a lambda with a defined return type Compiler should be able to optimize it out into direct function call, see https://godbolt.org/z/bqYGd47Mx
1 parent b7b40ac commit 4f28b24

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernels/portable/cpu/op_isnan.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ namespace executor {
1515
namespace native {
1616

1717
Tensor& isnan_out(RuntimeContext& ctx, const Tensor& in, Tensor& out) {
18+
// Lambda is syntactic sugar needed to workaround compilation on some older non-compatible distros
19+
// where isnan is not defined for double, but either for float or for long double
1820
return internal::unary_ufunc_realhb_to_bool(
19-
static_cast<bool (*)(double)>(std::isnan), ctx, in, out);
21+
[](double x) -> bool { return std::isnan(x); }, ctx, in, out);
2022
}
2123

2224
} // namespace native

0 commit comments

Comments
 (0)