xref: /aosp_15_r20/external/executorch/kernels/test/op_remainder_test.cpp (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
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 OpRemainderOutTest : public OperatorTest {
24  protected:
op_remainder_tensor_out(const Tensor & self,const Tensor & other,Tensor & out)25   Tensor& op_remainder_tensor_out(
26       const Tensor& self,
27       const Tensor& other,
28       Tensor& out) {
29     return torch::executor::aten::remainder_outf(context_, self, other, out);
30   }
31 
op_remainder_scalar_out(const Tensor & self,const Scalar & other,Tensor & out)32   Tensor& op_remainder_scalar_out(
33       const Tensor& self,
34       const Scalar& other,
35       Tensor& out) {
36     return torch::executor::aten::remainder_outf(context_, self, other, out);
37   }
38 };
39 
TEST_F(OpRemainderOutTest,SmokeTest)40 TEST_F(OpRemainderOutTest, SmokeTest) {
41   TensorFactory<ScalarType::Long> tfDouble;
42   TensorFactory<ScalarType::Long> tfLong;
43   TensorFactory<ScalarType::Int> tfInt;
44 
45   Tensor self = tfLong.full({2, 2}, 46);
46   Tensor other = tfInt.full({2, 2}, 4);
47   Tensor out = tfDouble.zeros({2, 2});
48   Tensor out_expected = tfDouble.full({2, 2}, 2.0);
49   op_remainder_tensor_out(self, other, out);
50   EXPECT_TENSOR_CLOSE(out, out_expected);
51 }
52