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 #include <executorch/runtime/platform/runtime.h>
15
16 #include <gtest/gtest.h>
17
18 using namespace ::testing;
19 using exec_aten::ArrayRef;
20 using exec_aten::ScalarType;
21 using exec_aten::Tensor;
22 using torch::executor::testing::TensorFactory;
23
op_roll_out(const Tensor & input,ArrayRef<int64_t> shifts,ArrayRef<int64_t> dims,Tensor & out)24 Tensor& op_roll_out(
25 const Tensor& input,
26 ArrayRef<int64_t> shifts,
27 ArrayRef<int64_t> dims,
28 Tensor& out) {
29 executorch::runtime::KernelRuntimeContext context{};
30 return torch::executor::aten::roll_outf(context, input, shifts, dims, out);
31 }
32
33 class OpRollOutTest : public ::testing::Test {
34 protected:
SetUp()35 void SetUp() override {
36 // Since these tests cause ET_LOG to be called, the PAL must be initialized
37 // first.
38 torch::executor::runtime_init();
39 }
40 };
41
TEST_F(OpRollOutTest,SmokeTest)42 TEST_F(OpRollOutTest, SmokeTest) {
43 TensorFactory<ScalarType::Float> tfFloat;
44
45 Tensor input = tfFloat.make({4, 2}, {1, 2, 3, 4, 5, 6, 7, 8});
46 int64_t shifts_data[2] = {2, 1};
47 ArrayRef<int64_t> shifts = ArrayRef<int64_t>(shifts_data, 2);
48 int64_t dims_data[2] = {0, 1};
49 ArrayRef<int64_t> dims = ArrayRef<int64_t>(dims_data, 2);
50 Tensor out = tfFloat.zeros({4, 2});
51 Tensor out_expected = tfFloat.make({4, 2}, {6, 5, 8, 7, 2, 1, 4, 3});
52 op_roll_out(input, shifts, dims, out);
53 EXPECT_TENSOR_CLOSE(out, out_expected);
54 }
55