1 /*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
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>
15
16 #include <gtest/gtest.h>
17
18 using namespace ::testing;
19 using exec_aten::Scalar;
20 using exec_aten::ScalarType;
21 using exec_aten::Tensor;
22 using torch::executor::testing::SupportedFeatures;
23 using torch::executor::testing::TensorFactory;
24
op_atan2_out(const Tensor & self,const Tensor & other,Tensor & out)25 Tensor& op_atan2_out(const Tensor& self, const Tensor& other, Tensor& out) {
26 executorch::runtime::KernelRuntimeContext context{};
27 return torch::executor::aten::atan2_outf(context, self, other, out);
28 }
29
TEST(OpAtan2OutTest,SmokeTest)30 TEST(OpAtan2OutTest, SmokeTest) {
31 TensorFactory<ScalarType::Double> tfDouble;
32 TensorFactory<ScalarType::Float> tfFloat;
33
34 Tensor self =
35 tfDouble.make({3, 2}, {20.25, 42.5, 51.625, -46.125, 80.375, -35.75});
36 Tensor other = tfDouble.make({2}, {-0.625, -2.25});
37 Tensor out = tfFloat.zeros({3, 2});
38 Tensor out_expected = tfFloat.make(
39 {3, 2},
40 {1.6016507148742676,
41 1.6236881017684937,
42 1.5829023122787476,
43 -1.6195381879806519,
44 1.5785722732543945,
45 -1.633650541305542});
46 op_atan2_out(self, other, out);
47 EXPECT_TENSOR_CLOSE(out, out_expected);
48 }
49