xref: /aosp_15_r20/external/executorch/kernels/test/op_neg_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::ScalarType;
19 using exec_aten::Tensor;
20 using torch::executor::testing::TensorFactory;
21 
22 class OpNegTest : public OperatorTest {
23  protected:
op_neg_out(const Tensor & self,Tensor & out)24   Tensor& op_neg_out(const Tensor& self, Tensor& out) {
25     return torch::executor::aten::neg_outf(context_, self, out);
26   }
27 };
28 
TEST_F(OpNegTest,SanityCheck)29 TEST_F(OpNegTest, SanityCheck) {
30   TensorFactory<ScalarType::Float> tf;
31 
32   Tensor in = tf.make({1, 7}, {-3.0, -2.5, -1.01, 0.0, 1.01, 2.5, 3.0});
33   Tensor out = tf.zeros({1, 7});
34   Tensor expected = tf.make({1, 7}, {3.0, 2.5, 1.01, 0.0, -1.01, -2.5, -3.0});
35 
36   Tensor ret = op_neg_out(in, out);
37 
38   EXPECT_TENSOR_EQ(out, ret);
39   EXPECT_TENSOR_EQ(out, expected);
40 }
41