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 OpLeakyReluTest : public OperatorTest {
24 protected:
op_leaky_relu_out(const Tensor & in,const Scalar & negative_slope,Tensor & out)25 Tensor& op_leaky_relu_out(
26 const Tensor& in,
27 const Scalar& negative_slope,
28 Tensor& out) {
29 return torch::executor::aten::leaky_relu_outf(
30 context_, in, negative_slope, out);
31 }
32 };
33
TEST_F(OpLeakyReluTest,SanityCheck)34 TEST_F(OpLeakyReluTest, SanityCheck) {
35 TensorFactory<ScalarType::Float> tf;
36 Tensor in = tf.ones({2, 2});
37 Tensor out = tf.zeros({2, 2});
38
39 Tensor ret = op_leaky_relu_out(in, -0.01, out);
40
41 EXPECT_TENSOR_EQ(out, ret);
42 EXPECT_TENSOR_EQ(out, tf.ones({2, 2}));
43 }
44