Skip to content

Commit e25e5d2

Browse files
malfetfacebook-github-bot
authored andcommitted
Fix portable is[inf|nan|_out compilation on older Linux (#3272)
Summary: 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 Pull Request resolved: #3272 Reviewed By: GregoryComer Differential Revision: D56504717 Pulled By: malfet fbshipit-source-id: 72da456027dbc837c3cfac83b18a5f002fedc3a5
1 parent 5b0030f commit e25e5d2

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

kernels/portable/cpu/op_isinf.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& isinf_out(RuntimeContext& ctx, const Tensor& in, Tensor& out) {
18+
// Lambda is syntactic sugar needed to workaround compilation on some older
19+
// non-compatible distros where isnan is returning int rather than bool
1820
return internal::unary_ufunc_realhb_to_bool(
19-
static_cast<bool (*)(double)>(std::isinf), ctx, in, out);
21+
[](double x) -> bool { return std::isinf(x); }, ctx, in, out);
2022
}
2123

2224
} // namespace native

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
19+
// non-compatible distros where isnan is returning int rather than bool
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)