ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Reverse.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2017 The TensorFlow Authors. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef __NNFW_CKER_REVERSE_H__
19#define __NNFW_CKER_REVERSE_H__
20
21#include "cker/Shape.h"
22#include "cker/Types.h"
23#include "cker/Utils.h"
24
25namespace nnfw
26{
27namespace cker
28{
29
30template <typename Scalar>
31void Reverse(int axis, const Shape &input_shape, const Scalar *input_data, const Shape &,
32 Scalar *output_data)
33{
34 int outer_size = 1;
35 for (int i = 0; i < axis; ++i)
36 {
37 outer_size *= input_shape.Dims(i);
38 }
39
40 int copy_size = 1;
41 for (int i = axis + 1; i < input_shape.DimensionsCount(); ++i)
42 {
43 copy_size *= input_shape.Dims(i);
44 }
45
46 const int dims_at_axis = input_shape.Dims(axis);
47 for (int i = 0; i < outer_size; ++i)
48 {
49 for (int j = 0; j < dims_at_axis; ++j)
50 {
51 const int start_pos = (i * dims_at_axis + j) * copy_size;
52 Scalar *output_ptr = output_data + start_pos;
53 int loc = (i * dims_at_axis + dims_at_axis - j - 1) * copy_size;
54 memcpy(output_ptr, input_data + loc, copy_size * sizeof(Scalar));
55 }
56 }
57}
58
59} // namespace cker
60} // namespace nnfw
61
62#endif // __NNFW_CKER_REVERSE_H__
int32_t DimensionsCount() const
Definition Shape.h:91
int32_t Dims(int i) const
Definition Shape.h:92
void Reverse(int axis, const Shape &input_shape, const Scalar *input_data, const Shape &, Scalar *output_data)
Definition Reverse.h:31
Definition topk_v2.h:30