|
7 | 7 | */ |
8 | 8 |
|
9 | 9 | #include <executorch/kernels/test/FunctionHeaderWrapper.h> // Declares the operator |
10 | | -#include <executorch/kernels/test/TestUtil.h> |
11 | | -#include <executorch/kernels/test/supported_features.h> |
12 | | -#include <executorch/runtime/core/exec_aten/exec_aten.h> |
13 | | -#include <executorch/runtime/core/exec_aten/testing_util/tensor_factory.h> |
14 | | -#include <executorch/runtime/core/exec_aten/testing_util/tensor_util.h> |
| 10 | +#include <executorch/kernels/test/UnaryUfuncRealHBToFloatHTest.h> |
15 | 11 |
|
16 | 12 | #include <gtest/gtest.h> |
17 | 13 |
|
18 | | -using namespace ::testing; |
19 | | -using exec_aten::ScalarType; |
20 | | -using exec_aten::Tensor; |
21 | | -using exec_aten::TensorShapeDynamism; |
22 | | -using torch::executor::testing::TensorFactory; |
| 14 | +#include <cmath> |
23 | 15 |
|
24 | | -class OpAsinOutTest : public OperatorTest { |
| 16 | +using exec_aten::Tensor; |
| 17 | +class OpAsinOutTest |
| 18 | + : public torch::executor::testing::UnaryUfuncRealHBToFloatHTest { |
25 | 19 | protected: |
26 | | - Tensor& op_asin_out(const Tensor& self, Tensor& out) { |
| 20 | + Tensor& op_out(const Tensor& self, Tensor& out) override { |
27 | 21 | return torch::executor::aten::asin_outf(context_, self, out); |
28 | 22 | } |
29 | 23 |
|
30 | | - // Common testing for asin operator and all kinds of supported input types |
31 | | - template <ScalarType IN_DTYPE, ScalarType OUT_DTYPE> |
32 | | - void test_floating_point_asin_out( |
33 | | - const std::vector<int32_t>& out_shape = {1, 6}, |
34 | | - TensorShapeDynamism dynamism = TensorShapeDynamism::STATIC) { |
35 | | - TensorFactory<IN_DTYPE> tf_in; |
36 | | - TensorFactory<OUT_DTYPE> tf_out; |
37 | | - |
38 | | - // Destination for the asin operator. |
39 | | - Tensor out = tf_out.zeros(out_shape, dynamism); |
40 | | - |
41 | | - // clang-format off |
42 | | - op_asin_out(tf_in.make({1, 6}, { 0, 1, 3, 5, 10, 100 }), out); |
43 | | - |
44 | | - // Check that it matches (or close to) the expected output. |
45 | | - EXPECT_TENSOR_CLOSE( |
46 | | - out, |
47 | | - tf_out.make({1, 6}, { 0.000000, 1.570796, NAN, NAN, NAN, NAN })); |
48 | | - // clang-format on |
| 24 | + double op_reference(double x) const override { |
| 25 | + return std::asin(x); |
49 | 26 | } |
50 | 27 |
|
51 | | - // Unhandled output dtypes. |
52 | | - template <ScalarType INPUT_DTYPE, ScalarType OUTPUT_DTYPE> |
53 | | - void test_asin_invalid_output_dtype_dies() { |
54 | | - TensorFactory<INPUT_DTYPE> tf; |
55 | | - TensorFactory<OUTPUT_DTYPE> tf_out; |
56 | | - |
57 | | - const std::vector<int32_t> sizes = {2, 5}; |
58 | | - |
59 | | - Tensor in = tf.ones(sizes); |
60 | | - Tensor out = tf_out.zeros(sizes); |
61 | | - |
62 | | - ET_EXPECT_KERNEL_FAILURE(context_, op_asin_out(in, out)); |
63 | | - } |
| 28 | + torch::executor::testing::SupportedFeatures* get_supported_features() |
| 29 | + const override; |
64 | 30 | }; |
65 | 31 |
|
66 | | -TEST_F(OpAsinOutTest, HandleBoolInput) { |
67 | | - TensorFactory<ScalarType::Bool> tf_bool; |
68 | | - TensorFactory<ScalarType::Float> tf_float; |
69 | | - |
70 | | - const std::vector<int32_t> sizes = {1, 2}; |
71 | | - |
72 | | - Tensor a = tf_bool.make(sizes, /*data=*/{false, true}); |
73 | | - Tensor out = tf_float.zeros(sizes); |
74 | | - Tensor res = tf_float.make(sizes, /*data=*/{0.000000, 1.5707960}); |
75 | | - |
76 | | - EXPECT_TENSOR_CLOSE(op_asin_out(a, out), res); |
77 | | -} |
78 | | - |
79 | | -TEST_F(OpAsinOutTest, AllRealInputHalfOutputStaticDynamismSupport) { |
80 | | - if (torch::executor::testing::SupportedFeatures::get()->is_aten) { |
81 | | - GTEST_SKIP() << "Test Half support only for ExecuTorch mode"; |
82 | | - } |
83 | | -#define TEST_ENTRY(ctype, dtype) \ |
84 | | - test_floating_point_asin_out<ScalarType::dtype, ScalarType::Float>(); |
85 | | - ET_FORALL_REALH_TYPES(TEST_ENTRY); |
86 | | -#undef TEST_ENTRY |
87 | | -} |
88 | | - |
89 | | -TEST_F(OpAsinOutTest, AllRealInputFloatOutputStaticDynamismSupport) { |
90 | | -#define TEST_ENTRY(ctype, dtype) \ |
91 | | - test_floating_point_asin_out<ScalarType::dtype, ScalarType::Float>(); |
92 | | - ET_FORALL_REAL_TYPES(TEST_ENTRY); |
93 | | -#undef TEST_ENTRY |
94 | | -} |
95 | | - |
96 | | -TEST_F(OpAsinOutTest, AllRealInputDoubleOutputStaticDynamismSupport) { |
97 | | -#define TEST_ENTRY(ctype, dtype) \ |
98 | | - test_floating_point_asin_out<ScalarType::dtype, ScalarType::Double>(); |
99 | | - ET_FORALL_REAL_TYPES(TEST_ENTRY); |
100 | | -#undef TEST_ENTRY |
101 | | -} |
102 | | - |
103 | | -TEST_F(OpAsinOutTest, AllRealInputHalfOutputBoundDynamismSupport) { |
104 | | - if (torch::executor::testing::SupportedFeatures::get()->is_aten) { |
105 | | - GTEST_SKIP() << "Test Half support only for ExecuTorch mode"; |
106 | | - } |
107 | | -#define TEST_ENTRY(ctype, dtype) \ |
108 | | - test_floating_point_asin_out<ScalarType::dtype, ScalarType::Float>( \ |
109 | | - {10, 10}, TensorShapeDynamism::DYNAMIC_BOUND); |
110 | | - ET_FORALL_REALH_TYPES(TEST_ENTRY); |
111 | | -#undef TEST_ENTRY |
112 | | -} |
113 | | - |
114 | | -TEST_F(OpAsinOutTest, AllRealInputFloatOutputBoundDynamismSupport) { |
115 | | -#define TEST_ENTRY(ctype, dtype) \ |
116 | | - test_floating_point_asin_out<ScalarType::dtype, ScalarType::Float>( \ |
117 | | - {10, 10}, TensorShapeDynamism::DYNAMIC_BOUND); |
118 | | - ET_FORALL_REAL_TYPES(TEST_ENTRY); |
119 | | -#undef TEST_ENTRY |
120 | | -} |
121 | | - |
122 | | -TEST_F(OpAsinOutTest, AllRealInputDoubleOutputBoundDynamismSupport) { |
123 | | -#define TEST_ENTRY(ctype, dtype) \ |
124 | | - test_floating_point_asin_out<ScalarType::dtype, ScalarType::Double>( \ |
125 | | - {10, 10}, TensorShapeDynamism::DYNAMIC_BOUND); |
126 | | - ET_FORALL_REAL_TYPES(TEST_ENTRY); |
127 | | -#undef TEST_ENTRY |
128 | | -} |
129 | | - |
130 | | -TEST_F(OpAsinOutTest, AllRealInputFloatOutputUnboundDynamismSupport) { |
131 | | - if (!torch::executor::testing::SupportedFeatures::get()->is_aten) { |
132 | | - GTEST_SKIP() << "Dynamic shape unbound not supported"; |
133 | | - } |
134 | | -#define TEST_ENTRY(ctype, dtype) \ |
135 | | - test_floating_point_asin_out<ScalarType::dtype, ScalarType::Float>( \ |
136 | | - {1, 1}, TensorShapeDynamism::DYNAMIC_UNBOUND); |
137 | | - ET_FORALL_REAL_TYPES(TEST_ENTRY); |
138 | | -#undef TEST_ENTRY |
139 | | -} |
140 | | - |
141 | | -TEST_F(OpAsinOutTest, AllRealInputDoubleOutputUnboundDynamismSupport) { |
142 | | - if (!torch::executor::testing::SupportedFeatures::get()->is_aten) { |
143 | | - GTEST_SKIP() << "Dynamic shape unbound not supported"; |
144 | | - } |
145 | | -#define TEST_ENTRY(ctype, dtype) \ |
146 | | - test_floating_point_asin_out<ScalarType::dtype, ScalarType::Double>( \ |
147 | | - {1, 1}, TensorShapeDynamism::DYNAMIC_UNBOUND); |
148 | | - ET_FORALL_REAL_TYPES(TEST_ENTRY); |
149 | | -#undef TEST_ENTRY |
150 | | -} |
151 | | - |
152 | | -TEST_F(OpAsinOutTest, AllNonFloatOutputDTypeDies) { |
153 | | -#define TEST_ENTRY(ctype, dtype) \ |
154 | | - test_asin_invalid_output_dtype_dies<ScalarType::Float, ScalarType::dtype>(); |
155 | | - ET_FORALL_INT_TYPES(TEST_ENTRY); |
156 | | -#undef TEST_ENTRY |
157 | | -} |
158 | | - |
159 | | -// Mismatched shape tests. |
160 | | -TEST_F(OpAsinOutTest, MismatchedInputShapesDies) { |
161 | | - if (torch::executor::testing::SupportedFeatures::get()->is_aten) { |
162 | | - GTEST_SKIP() << "ATen kernel can handle mismatched input shapes"; |
163 | | - } |
164 | | - TensorFactory<ScalarType::Float> tf; |
165 | | - |
166 | | - Tensor a = tf.ones(/*sizes=*/{4}); |
167 | | - Tensor out = tf.ones(/*sizes=*/{2, 2}); |
168 | | - |
169 | | - ET_EXPECT_KERNEL_FAILURE(context_, op_asin_out(a, out)); |
170 | | -} |
| 32 | +IMPLEMENT_UNARY_UFUNC_REALHB_TO_FLOATH_TEST(OpAsinOutTest) |
0 commit comments