diff --git a/kernels/portable/cpu/pattern/unary_ufunc_realhb_to_bool.cpp b/kernels/portable/cpu/pattern/unary_ufunc_realhb_to_bool.cpp index 76bef5fe021..3be4b258cc4 100644 --- a/kernels/portable/cpu/pattern/unary_ufunc_realhb_to_bool.cpp +++ b/kernels/portable/cpu/pattern/unary_ufunc_realhb_to_bool.cpp @@ -43,7 +43,7 @@ Tensor& unary_ufunc_realhb_to_bool( const auto in_type = in.scalar_type(); - ET_SWITCH_REALHB_TYPES(in_type, ctx, __func__, CTYPE_IN, [&] { + ET_SWITCH_REALHBBF16_TYPES(in_type, ctx, __func__, CTYPE_IN, [&] { apply_unary_map_fn( [fn](const CTYPE_IN val_in) { return fn(val_in); }, in.const_data_ptr(), diff --git a/kernels/test/op_isinf_test.cpp b/kernels/test/op_isinf_test.cpp index 3b544dc65f0..d7916984371 100644 --- a/kernels/test/op_isinf_test.cpp +++ b/kernels/test/op_isinf_test.cpp @@ -25,66 +25,29 @@ class OpIsInfTest : public OperatorTest { Tensor& op_isinf_out(const Tensor& self, Tensor& out) { return torch::executor::aten::isinf_outf(context_, self, out); } -}; - -TEST_F(OpIsInfTest, SanityCheckFloat) { - TensorFactory tf; - TensorFactory tfb; - Tensor in = tf.make( - {1, 5}, {-1.0, 0.0, 1.0, NAN, std::numeric_limits::infinity()}); - Tensor out = tfb.zeros({1, 5}); - Tensor expected = tfb.make({1, 5}, {false, false, false, false, true}); + template + void test_sanity_check() { + TensorFactory tf; + TensorFactory tfb; - Tensor ret = op_isinf_out(in, out); + using CTYPE = typename TensorFactory::ctype; + Tensor in = tf.make( + {1, 5}, {-1, 0, 1, NAN, std::numeric_limits::infinity()}); + Tensor out = tfb.zeros({1, 5}); + Tensor expected = tfb.make({1, 5}, {false, false, false, false, true}); - EXPECT_TENSOR_EQ(out, ret); - EXPECT_TENSOR_EQ(out, expected); -} + Tensor ret = op_isinf_out(in, out); -TEST_F(OpIsInfTest, SanityCheckHalf) { - if (torch::executor::testing::SupportedFeatures::get()->is_aten) { - GTEST_SKIP() << "Test Half support only for ExecuTorch mode"; + EXPECT_TENSOR_EQ(out, ret); + EXPECT_TENSOR_EQ(out, expected); } - TensorFactory tf; - TensorFactory tfb; - - Tensor in = tf.make( - {1, 5}, {-1.0, 0.0, 1.0, NAN, std::numeric_limits::infinity()}); - Tensor out = tfb.zeros({1, 5}); - Tensor expected = tfb.make({1, 5}, {false, false, false, false, true}); - - Tensor ret = op_isinf_out(in, out); - - EXPECT_TENSOR_EQ(out, ret); - EXPECT_TENSOR_EQ(out, expected); -} - -TEST_F(OpIsInfTest, SanityCheckByte) { - TensorFactory tf; - TensorFactory tfb; - - Tensor in = tf.make({1, 5}, {1, 2, 3, 4, 5}); - Tensor out = tfb.zeros({1, 5}); - Tensor expected = tfb.make({1, 5}, {false, false, false, false, false}); - - Tensor ret = op_isinf_out(in, out); - - EXPECT_TENSOR_EQ(out, ret); - EXPECT_TENSOR_EQ(out, expected); -} - -TEST_F(OpIsInfTest, SanityCheckBool) { - TensorFactory tfb; - - Tensor in = tfb.make({1, 5}, {true, false, true, true, false}); - Tensor out = tfb.zeros({1, 5}); - Tensor expected = tfb.make({1, 5}, {false, false, false, false, false}); - - Tensor ret = op_isinf_out(in, out); +}; - EXPECT_TENSOR_EQ(out, ret); - EXPECT_TENSOR_EQ(out, expected); +TEST_F(OpIsInfTest, SanityCheck) { +#define TEST_ENTRY(ctype, dtype) test_sanity_check(); + ET_FORALL_FLOATHBF16_TYPES(TEST_ENTRY); +#undef TEST_ENTRY } TEST_F(OpIsInfTest, SanityCheckOutDtype) { diff --git a/kernels/test/op_isnan_test.cpp b/kernels/test/op_isnan_test.cpp index 2894fc88ccf..c63fc838eae 100644 --- a/kernels/test/op_isnan_test.cpp +++ b/kernels/test/op_isnan_test.cpp @@ -25,66 +25,29 @@ class OpIsNanTest : public OperatorTest { Tensor& op_isnan_out(const Tensor& self, Tensor& out) { return torch::executor::aten::isnan_outf(context_, self, out); } -}; - -TEST_F(OpIsNanTest, SanityCheckFloat) { - TensorFactory tf; - TensorFactory tfb; - Tensor in = tf.make( - {1, 5}, {-1.0, 0.0, 1.0, NAN, std::numeric_limits::infinity()}); - Tensor out = tfb.zeros({1, 5}); - Tensor expected = tfb.make({1, 5}, {false, false, false, true, false}); + template + void test_sanity_check() { + TensorFactory tf; + TensorFactory tfb; - Tensor ret = op_isnan_out(in, out); + using CTYPE = typename TensorFactory::ctype; + Tensor in = tf.make( + {1, 5}, {-1, 0, 1, NAN, std::numeric_limits::infinity()}); + Tensor out = tfb.zeros({1, 5}); + Tensor expected = tfb.make({1, 5}, {false, false, false, true, false}); - EXPECT_TENSOR_EQ(out, ret); - EXPECT_TENSOR_EQ(out, expected); -} + Tensor ret = op_isnan_out(in, out); -TEST_F(OpIsNanTest, SanityCheckHalf) { - if (torch::executor::testing::SupportedFeatures::get()->is_aten) { - GTEST_SKIP() << "Test Half support only for ExecuTorch mode"; + EXPECT_TENSOR_EQ(out, ret); + EXPECT_TENSOR_EQ(out, expected); } - TensorFactory tf; - TensorFactory tfb; - - Tensor in = tf.make( - {1, 5}, {-1.0, 0.0, 1.0, NAN, std::numeric_limits::infinity()}); - Tensor out = tfb.zeros({1, 5}); - Tensor expected = tfb.make({1, 5}, {false, false, false, true, false}); - - Tensor ret = op_isnan_out(in, out); - - EXPECT_TENSOR_EQ(out, ret); - EXPECT_TENSOR_EQ(out, expected); -} - -TEST_F(OpIsNanTest, SanityCheckByte) { - TensorFactory tf; - TensorFactory tfb; - - Tensor in = tf.make({1, 5}, {1, 2, 3, 4, 5}); - Tensor out = tfb.zeros({1, 5}); - Tensor expected = tfb.make({1, 5}, {false, false, false, false, false}); - - Tensor ret = op_isnan_out(in, out); - - EXPECT_TENSOR_EQ(out, ret); - EXPECT_TENSOR_EQ(out, expected); -} - -TEST_F(OpIsNanTest, SanityCheckBool) { - TensorFactory tfb; - - Tensor in = tfb.make({1, 5}, {true, false, true, true, false}); - Tensor out = tfb.zeros({1, 5}); - Tensor expected = tfb.make({1, 5}, {false, false, false, false, false}); - - Tensor ret = op_isnan_out(in, out); +}; - EXPECT_TENSOR_EQ(out, ret); - EXPECT_TENSOR_EQ(out, expected); +TEST_F(OpIsNanTest, SanityCheck) { +#define TEST_ENTRY(ctype, dtype) test_sanity_check(); + ET_FORALL_FLOATHBF16_TYPES(TEST_ENTRY); +#undef TEST_ENTRY } TEST_F(OpIsNanTest, SanityCheckOutDtype) {