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::ScalarType;
20 using exec_aten::Tensor;
21 using torch::executor::testing::TensorFactory;
22
23 class OpFloorTest : public OperatorTest {
24 protected:
op_floor_out(const Tensor & self,Tensor & out)25 Tensor& op_floor_out(const Tensor& self, Tensor& out) {
26 return torch::executor::aten::floor_outf(context_, self, out);
27 }
28 };
29
TEST_F(OpFloorTest,SanityCheck)30 TEST_F(OpFloorTest, SanityCheck) {
31 TensorFactory<ScalarType::Float> tf;
32
33 Tensor in = tf.make({1, 7}, {-3.0, -2.99, -1.01, 0.0, 1.01, 2.99, 3.0});
34 Tensor out = tf.zeros({1, 7});
35 Tensor expected = tf.make({1, 7}, {-3.0, -3.0, -2.0, 0.0, 1.0, 2.0, 3.0});
36
37 Tensor ret = op_floor_out(in, out);
38
39 EXPECT_TENSOR_EQ(out, ret);
40 EXPECT_TENSOR_EQ(out, expected);
41 }
42
TEST_F(OpFloorTest,HalfSupport)43 TEST_F(OpFloorTest, HalfSupport) {
44 if (torch::executor::testing::SupportedFeatures::get()->is_aten) {
45 GTEST_SKIP() << "Test Half support only for ExecuTorch mode";
46 }
47 TensorFactory<ScalarType::Half> tf;
48
49 Tensor in = tf.make({1, 7}, {-3.0, -2.99, -1.01, 0.0, 1.01, 2.99, 3.0});
50 Tensor out = tf.zeros({1, 7});
51 Tensor expected = tf.make({1, 7}, {-3.0, -3.0, -2.0, 0.0, 1.0, 2.0, 3.0});
52
53 Tensor ret = op_floor_out(in, out);
54
55 EXPECT_TENSOR_EQ(out, ret);
56 EXPECT_TENSOR_EQ(out, expected);
57 }
58