Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<CTYPE_IN>(),
Expand Down
71 changes: 17 additions & 54 deletions kernels/test/op_isinf_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScalarType::Float> tf;
TensorFactory<ScalarType::Bool> tfb;

Tensor in = tf.make(
{1, 5}, {-1.0, 0.0, 1.0, NAN, std::numeric_limits<float>::infinity()});
Tensor out = tfb.zeros({1, 5});
Tensor expected = tfb.make({1, 5}, {false, false, false, false, true});
template <ScalarType DTYPE>
void test_sanity_check() {
TensorFactory<DTYPE> tf;
TensorFactory<ScalarType::Bool> tfb;

Tensor ret = op_isinf_out(in, out);
using CTYPE = typename TensorFactory<DTYPE>::ctype;
Tensor in = tf.make(
{1, 5}, {-1, 0, 1, NAN, std::numeric_limits<CTYPE>::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<ScalarType::Half> tf;
TensorFactory<ScalarType::Bool> tfb;

Tensor in = tf.make(
{1, 5}, {-1.0, 0.0, 1.0, NAN, std::numeric_limits<float>::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<ScalarType::Byte> tf;
TensorFactory<ScalarType::Bool> 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<ScalarType::Bool> 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<ScalarType::dtype>();
ET_FORALL_FLOATHBF16_TYPES(TEST_ENTRY);
#undef TEST_ENTRY
}

TEST_F(OpIsInfTest, SanityCheckOutDtype) {
Expand Down
71 changes: 17 additions & 54 deletions kernels/test/op_isnan_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScalarType::Float> tf;
TensorFactory<ScalarType::Bool> tfb;

Tensor in = tf.make(
{1, 5}, {-1.0, 0.0, 1.0, NAN, std::numeric_limits<float>::infinity()});
Tensor out = tfb.zeros({1, 5});
Tensor expected = tfb.make({1, 5}, {false, false, false, true, false});
template <ScalarType DTYPE>
void test_sanity_check() {
TensorFactory<DTYPE> tf;
TensorFactory<ScalarType::Bool> tfb;

Tensor ret = op_isnan_out(in, out);
using CTYPE = typename TensorFactory<DTYPE>::ctype;
Tensor in = tf.make(
{1, 5}, {-1, 0, 1, NAN, std::numeric_limits<CTYPE>::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<ScalarType::Float> tf;
TensorFactory<ScalarType::Bool> tfb;

Tensor in = tf.make(
{1, 5}, {-1.0, 0.0, 1.0, NAN, std::numeric_limits<float>::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<ScalarType::Byte> tf;
TensorFactory<ScalarType::Bool> 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<ScalarType::Bool> 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<ScalarType::dtype>();
ET_FORALL_FLOATHBF16_TYPES(TEST_ENTRY);
#undef TEST_ENTRY
}

TEST_F(OpIsNanTest, SanityCheckOutDtype) {
Expand Down
Loading