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/runtime/core/exec_aten/exec_aten.h>
12 #include <executorch/runtime/core/exec_aten/testing_util/tensor_factory.h>
13 #include <executorch/runtime/core/exec_aten/testing_util/tensor_util.h>
14
15 #include <gtest/gtest.h>
16
17 using namespace ::testing;
18 using exec_aten::Scalar;
19 using exec_aten::ScalarType;
20 using exec_aten::Tensor;
21 using torch::executor::testing::TensorFactory;
22
23 class OpFmodTest : public OperatorTest {
24 protected:
25 Tensor&
op_fmod_tensor_out(const Tensor & self,const Tensor & other,Tensor & out)26 op_fmod_tensor_out(const Tensor& self, const Tensor& other, Tensor& out) {
27 return torch::executor::aten::fmod_outf(context_, self, other, out);
28 }
29
30 Tensor&
op_fmod_scalar_out(const Tensor & self,const Scalar & other,Tensor & out)31 op_fmod_scalar_out(const Tensor& self, const Scalar& other, Tensor& out) {
32 return torch::executor::aten::fmod_outf(context_, self, other, out);
33 }
34 };
35
TEST_F(OpFmodTest,SmokeTest)36 TEST_F(OpFmodTest, SmokeTest) {
37 TensorFactory<ScalarType::Long> tfDouble;
38 TensorFactory<ScalarType::Long> tfLong;
39 TensorFactory<ScalarType::Int> tfInt;
40
41 Tensor self = tfLong.full({2, 2}, 46);
42 Tensor other = tfInt.full({2, 2}, 4);
43 Tensor out = tfDouble.zeros({2, 2});
44 Tensor out_expected = tfDouble.full({2, 2}, 2.0);
45 op_fmod_tensor_out(self, other, out);
46 EXPECT_TENSOR_CLOSE(out, out_expected);
47 }
48