Skip to content

Commit 2b79873

Browse files
manuelcandalesfacebook-github-bot
authored andcommitted
Add bool input tests for unary realb to float ops
Reviewed By: digantdesai Differential Revision: D47118017 fbshipit-source-id: 9ec8f819b577f15fc2758353f43deedc582c3ad8
1 parent 4fa8212 commit 2b79873

16 files changed

+208
-0
lines changed

kernels/test/op_acos_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ Tensor& _acos_out(const Tensor& self, Tensor& out) {
2020
return torch::executor::aten::acos_outf(context, self, out);
2121
}
2222

23+
TEST(OpAcosOutKernelTest, HandleBoolInput) {
24+
TensorFactory<ScalarType::Bool> tf_bool;
25+
TensorFactory<ScalarType::Float> tf_float;
26+
27+
const std::vector<int32_t> sizes = {1, 2};
28+
29+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
30+
Tensor out = tf_float.zeros(sizes);
31+
Tensor res = tf_float.make(sizes, /*data=*/{1.570796, 0.000000});
32+
33+
EXPECT_TENSOR_CLOSE(_acos_out(a, out), res);
34+
}
35+
2336
// Common testing for acos operator and all kinds of supported input types
2437
template <ScalarType IN_DTYPE, ScalarType OUT_DTYPE>
2538
void test_floating_point_acos_out(

kernels/test/op_acosh_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ Tensor& _acosh_out(const Tensor& self, Tensor& out) {
2020
return torch::executor::aten::acosh_outf(context, self, out);
2121
}
2222

23+
TEST(OpAcoshOutKernelTest, HandleBoolInput) {
24+
TensorFactory<ScalarType::Bool> tf_bool;
25+
TensorFactory<ScalarType::Float> tf_float;
26+
27+
const std::vector<int32_t> sizes = {1, 2};
28+
29+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
30+
Tensor out = tf_float.zeros(sizes);
31+
Tensor res = tf_float.make(sizes, /*data=*/{NAN, 0.000000});
32+
33+
EXPECT_TENSOR_CLOSE(_acosh_out(a, out), res);
34+
}
35+
2336
// Common testing for acosh operator and all kinds of supported input types
2437
template <ScalarType IN_DTYPE, ScalarType OUT_DTYPE>
2538
void test_floating_point_acosh_out(

kernels/test/op_asin_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ Tensor& _asin_out(const Tensor& self, Tensor& out) {
2020
return torch::executor::aten::asin_outf(context, self, out);
2121
}
2222

23+
TEST(OpAsinOutKernelTest, HandleBoolInput) {
24+
TensorFactory<ScalarType::Bool> tf_bool;
25+
TensorFactory<ScalarType::Float> tf_float;
26+
27+
const std::vector<int32_t> sizes = {1, 2};
28+
29+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
30+
Tensor out = tf_float.zeros(sizes);
31+
Tensor res = tf_float.make(sizes, /*data=*/{0.000000, 1.5707960});
32+
33+
EXPECT_TENSOR_CLOSE(_asin_out(a, out), res);
34+
}
35+
2336
// Common testing for asin operator and all kinds of supported input types
2437
template <ScalarType IN_DTYPE, ScalarType OUT_DTYPE>
2538
void test_floating_point_asin_out(

kernels/test/op_asinh_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ Tensor& _asinh_out(const Tensor& self, Tensor& out) {
2020
return torch::executor::aten::asinh_outf(context, self, out);
2121
}
2222

23+
TEST(OpAsinhOutKernelTest, HandleBoolInput) {
24+
TensorFactory<ScalarType::Bool> tf_bool;
25+
TensorFactory<ScalarType::Float> tf_float;
26+
27+
const std::vector<int32_t> sizes = {1, 2};
28+
29+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
30+
Tensor out = tf_float.zeros(sizes);
31+
Tensor res = tf_float.make(sizes, /*data=*/{0.000000, 0.881374});
32+
33+
EXPECT_TENSOR_CLOSE(_asinh_out(a, out), res);
34+
}
35+
2336
// Common testing for asinh operator and all kinds of supported input types
2437
template <ScalarType IN_DTYPE, ScalarType OUT_DTYPE>
2538
void test_floating_point_asinh_out(

kernels/test/op_atan_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ Tensor& _atan_out(const Tensor& self, Tensor& out) {
2020
return torch::executor::aten::atan_outf(context, self, out);
2121
}
2222

23+
TEST(OpAtanOutKernelTest, HandleBoolInput) {
24+
TensorFactory<ScalarType::Bool> tf_bool;
25+
TensorFactory<ScalarType::Float> tf_float;
26+
27+
const std::vector<int32_t> sizes = {1, 2};
28+
29+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
30+
Tensor out = tf_float.zeros(sizes);
31+
Tensor res = tf_float.make(sizes, /*data=*/{0.000000, 0.785398});
32+
33+
EXPECT_TENSOR_CLOSE(_atan_out(a, out), res);
34+
}
35+
2336
// Common testing for atan operator and all kinds of supported input types
2437
template <ScalarType IN_DTYPE, ScalarType OUT_DTYPE>
2538
void test_floating_point_atan_out(

kernels/test/op_atanh_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ Tensor& _atanh_out(const Tensor& self, Tensor& out) {
2020
return torch::executor::aten::atanh_outf(context, self, out);
2121
}
2222

23+
TEST(OpAtanhOutKernelTest, HandleBoolInput) {
24+
TensorFactory<ScalarType::Bool> tf_bool;
25+
TensorFactory<ScalarType::Float> tf_float;
26+
27+
const std::vector<int32_t> sizes = {1, 2};
28+
29+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
30+
Tensor out = tf_float.zeros(sizes);
31+
Tensor res = tf_float.make(sizes, /*data=*/{0.000000, INFINITY});
32+
33+
EXPECT_TENSOR_CLOSE(_atanh_out(a, out), res);
34+
}
35+
2336
// Common testing for atanh operator and all kinds of supported input types
2437
template <ScalarType IN_DTYPE, ScalarType OUT_DTYPE>
2538
void test_floating_point_atanh_out(

kernels/test/op_cos_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ Tensor& _cos_out(const Tensor& self, Tensor& out) {
2020
return torch::executor::aten::cos_outf(context, self, out);
2121
}
2222

23+
TEST(OpCosOutKernelTest, HandleBoolInput) {
24+
TensorFactory<ScalarType::Bool> tf_bool;
25+
TensorFactory<ScalarType::Float> tf_float;
26+
27+
const std::vector<int32_t> sizes = {1, 2};
28+
29+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
30+
Tensor out = tf_float.zeros(sizes);
31+
Tensor res = tf_float.make(sizes, /*data=*/{1.000000, 0.540302});
32+
33+
EXPECT_TENSOR_CLOSE(_cos_out(a, out), res);
34+
}
35+
2336
// Common testing for cos operator and all kinds of supported input types
2437
template <ScalarType IN_DTYPE, ScalarType OUT_DTYPE>
2538
void test_floating_point_cos_out(

kernels/test/op_cosh_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ Tensor& _cosh_out(const Tensor& self, Tensor& out) {
2020
return torch::executor::aten::cosh_outf(context, self, out);
2121
}
2222

23+
TEST(OpCoshOutKernelTest, HandleBoolInput) {
24+
TensorFactory<ScalarType::Bool> tf_bool;
25+
TensorFactory<ScalarType::Float> tf_float;
26+
27+
const std::vector<int32_t> sizes = {1, 2};
28+
29+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
30+
Tensor out = tf_float.zeros(sizes);
31+
Tensor res = tf_float.make(sizes, /*data=*/{1.000000, 1.543081});
32+
33+
EXPECT_TENSOR_CLOSE(_cosh_out(a, out), res);
34+
}
35+
2336
// Common testing for cosh operator and all kinds of supported input types
2437
template <ScalarType IN_DTYPE, ScalarType OUT_DTYPE>
2538
void test_floating_point_cosh_out(

kernels/test/op_erf_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,16 @@ TEST(OpErfTest, SanityCheck) {
3232
EXPECT_TENSOR_EQ(out, ret);
3333
EXPECT_TENSOR_CLOSE(out, expected);
3434
}
35+
36+
TEST(OpErfTest, HandleBoolInput) {
37+
TensorFactory<ScalarType::Bool> tf_bool;
38+
TensorFactory<ScalarType::Float> tf_float;
39+
40+
const std::vector<int32_t> sizes = {1, 2};
41+
42+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
43+
Tensor out = tf_float.zeros(sizes);
44+
Tensor res = tf_float.make(sizes, /*data=*/{0.000000, 0.842701});
45+
46+
EXPECT_TENSOR_CLOSE(_erf_out(a, out), res);
47+
}

kernels/test/op_reciprocal_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,16 @@ TEST(OpReciprocalTest, SanityCheck) {
3232
EXPECT_TENSOR_EQ(out, ret);
3333
EXPECT_TENSOR_CLOSE(out, expected);
3434
}
35+
36+
TEST(OpReciprocalTest, HandleBoolInput) {
37+
TensorFactory<ScalarType::Bool> tf_bool;
38+
TensorFactory<ScalarType::Float> tf_float;
39+
40+
const std::vector<int32_t> sizes = {1, 2};
41+
42+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
43+
Tensor out = tf_float.zeros(sizes);
44+
Tensor res = tf_float.make(sizes, /*data=*/{INFINITY, 1.0});
45+
46+
EXPECT_TENSOR_CLOSE(_reciprocal_out(a, out), res);
47+
}

kernels/test/op_rsqrt_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,16 @@ TEST(OpRsqrtTest, SanityCheck) {
3232
EXPECT_TENSOR_EQ(out, ret);
3333
EXPECT_TENSOR_CLOSE(out, expected);
3434
}
35+
36+
TEST(OpRsqrtTest, HandleBoolInput) {
37+
TensorFactory<ScalarType::Bool> tf_bool;
38+
TensorFactory<ScalarType::Float> tf_float;
39+
40+
const std::vector<int32_t> sizes = {1, 2};
41+
42+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
43+
Tensor out = tf_float.zeros(sizes);
44+
Tensor res = tf_float.make(sizes, /*data=*/{INFINITY, 1.0});
45+
46+
EXPECT_TENSOR_CLOSE(_rsqrt_out(a, out), res);
47+
}

kernels/test/op_sin_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ Tensor& _sin_out(const Tensor& self, Tensor& out) {
2020
return torch::executor::aten::sin_outf(context, self, out);
2121
}
2222

23+
TEST(OpSinOutKernelTest, HandleBoolInput) {
24+
TensorFactory<ScalarType::Bool> tf_bool;
25+
TensorFactory<ScalarType::Float> tf_float;
26+
27+
const std::vector<int32_t> sizes = {1, 2};
28+
29+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
30+
Tensor out = tf_float.zeros(sizes);
31+
Tensor res = tf_float.make(sizes, /*data=*/{0.000000, 0.841471});
32+
33+
EXPECT_TENSOR_CLOSE(_sin_out(a, out), res);
34+
}
35+
2336
// Common testing for sin operator and all kinds of supported input types
2437
template <ScalarType IN_DTYPE, ScalarType OUT_DTYPE>
2538
void test_floating_point_sin_out(

kernels/test/op_sinh_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ Tensor& _sinh_out(const Tensor& self, Tensor& out) {
2020
return torch::executor::aten::sinh_outf(context, self, out);
2121
}
2222

23+
TEST(OpSinhOutKernelTest, HandleBoolInput) {
24+
TensorFactory<ScalarType::Bool> tf_bool;
25+
TensorFactory<ScalarType::Float> tf_float;
26+
27+
const std::vector<int32_t> sizes = {1, 2};
28+
29+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
30+
Tensor out = tf_float.zeros(sizes);
31+
Tensor res = tf_float.make(sizes, /*data=*/{0.000000, 1.175201});
32+
33+
EXPECT_TENSOR_CLOSE(_sinh_out(a, out), res);
34+
}
35+
2336
// Common testing for sinh operator and all kinds of supported input types
2437
template <ScalarType IN_DTYPE, ScalarType OUT_DTYPE>
2538
void test_floating_point_sinh_out(

kernels/test/op_sqrt_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,16 @@ TEST(OpSqrtTest, SanityCheck) {
3232
EXPECT_TENSOR_EQ(out, ret);
3333
EXPECT_TENSOR_CLOSE(out, expected);
3434
}
35+
36+
TEST(OpSqrtTest, HandleBoolInput) {
37+
TensorFactory<ScalarType::Bool> tf_bool;
38+
TensorFactory<ScalarType::Float> tf_float;
39+
40+
const std::vector<int32_t> sizes = {1, 2};
41+
42+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
43+
Tensor out = tf_float.zeros(sizes);
44+
Tensor res = tf_float.make(sizes, /*data=*/{0.0, 1.0});
45+
46+
EXPECT_TENSOR_CLOSE(_sqrt_out(a, out), res);
47+
}

kernels/test/op_tan_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ Tensor& _tan_out(const Tensor& self, Tensor& out) {
2020
return torch::executor::aten::tan_outf(context, self, out);
2121
}
2222

23+
TEST(OpTanOutKernelTest, HandleBoolInput) {
24+
TensorFactory<ScalarType::Bool> tf_bool;
25+
TensorFactory<ScalarType::Float> tf_float;
26+
27+
const std::vector<int32_t> sizes = {1, 2};
28+
29+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
30+
Tensor out = tf_float.zeros(sizes);
31+
Tensor res = tf_float.make(sizes, /*data=*/{0.000000, 1.557408});
32+
33+
EXPECT_TENSOR_CLOSE(_tan_out(a, out), res);
34+
}
35+
2336
// Common testing for tan operator and all kinds of supported input types
2437
template <ScalarType IN_DTYPE, ScalarType OUT_DTYPE>
2538
void test_floating_point_tan_out(

kernels/test/op_tanh_test.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ Tensor& _tanh_out(const Tensor& self, Tensor& out) {
1919
return torch::executor::aten::tanh_outf(context, self, out);
2020
}
2121

22+
TEST(OpTanhOutKernelTest, HandleBoolInput) {
23+
TensorFactory<ScalarType::Bool> tf_bool;
24+
TensorFactory<ScalarType::Float> tf_float;
25+
26+
const std::vector<int32_t> sizes = {1, 2};
27+
28+
Tensor a = tf_bool.make(sizes, /*data=*/{false, true});
29+
Tensor out = tf_float.zeros(sizes);
30+
Tensor res = tf_float.make(sizes, /*data=*/{0.000000, 0.761594});
31+
32+
EXPECT_TENSOR_CLOSE(_tanh_out(a, out), res);
33+
}
34+
2235
// Common testing for tanh operator and all kinds of supported input types
2336
template <ScalarType IN_DTYPE, ScalarType OUT_DTYPE>
2437
void test_floating_point_tanh_out() {

0 commit comments

Comments
 (0)