• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OpHardTanhTest : public OperatorTest {
24  protected:
op_hardtanh_out(const Tensor & self,const Scalar & min_val,const Scalar & max_val,Tensor & out)25   Tensor& op_hardtanh_out(
26       const Tensor& self,
27       const Scalar& min_val,
28       const Scalar& max_val,
29       Tensor& out) {
30     return torch::executor::aten::hardtanh_outf(
31         context_, self, min_val, max_val, out);
32   }
33 };
34 
TEST_F(OpHardTanhTest,SanityCheck)35 TEST_F(OpHardTanhTest, SanityCheck) {
36   TensorFactory<ScalarType::Float> tf;
37   Tensor in = tf.ones({2, 2});
38   Tensor out = tf.zeros({2, 2});
39 
40   Tensor ret = op_hardtanh_out(in, -2, 2, out);
41 
42   EXPECT_TENSOR_EQ(out, ret);
43   EXPECT_TENSOR_EQ(out, tf.ones({2, 2}));
44 }
45