Skip to content

Commit 638433f

Browse files
committed
Wrap std::isnan/std::isinf in the portable operators
Passing the `std::` functions directory to unary_ufunc_realhb_to_bool can cause "error: cannot resolve overloaded function ‘isinf’ based on conversion to type ‘torch::executor::FunctionRef<bool(double)>’" in some compilation environments. Might be because these functions can be templatized, or because they became constexpr in C++23.
1 parent dc1ca98 commit 638433f

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

kernels/portable/cpu/op_isinf.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,18 @@ namespace torch {
1414
namespace executor {
1515
namespace native {
1616

17+
namespace {
18+
// Passing std::isinf directly to unary_ufunc_realhb_to_bool can cause "error:
19+
// cannot resolve overloaded function ‘isinf’ based on conversion to type
20+
// ‘torch::executor::FunctionRef<bool(double)>’" in some compilation
21+
// environments.
22+
bool isinf_wrapper(double num) {
23+
return std::isinf(num);
24+
}
25+
} // namespace
26+
1727
Tensor& isinf_out(RuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
return internal::unary_ufunc_realhb_to_bool(std::isinf, ctx, in, out);
28+
return internal::unary_ufunc_realhb_to_bool(isinf_wrapper, ctx, in, out);
1929
}
2030

2131
} // namespace native

kernels/portable/cpu/op_isnan.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,18 @@ namespace torch {
1414
namespace executor {
1515
namespace native {
1616

17+
namespace {
18+
// Passing std::isnan directly to unary_ufunc_realhb_to_bool can cause "error:
19+
// cannot resolve overloaded function ‘isnan’ based on conversion to type
20+
// ‘torch::executor::FunctionRef<bool(double)>’" in some compilation
21+
// environments.
22+
bool isnan_wrapper(double num) {
23+
return std::isnan(num);
24+
}
25+
} // namespace
26+
1727
Tensor& isnan_out(RuntimeContext& ctx, const Tensor& in, Tensor& out) {
18-
return internal::unary_ufunc_realhb_to_bool(std::isnan, ctx, in, out);
28+
return internal::unary_ufunc_realhb_to_bool(isnan_wrapper, ctx, in, out);
1929
}
2030

2131
} // namespace native

0 commit comments

Comments
 (0)