ONE - On-device Neural Engine
Loading...
Searching...
No Matches
SplitV.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_SPLIT_V_H__
19#define __NNFW_CKER_SPLIT_V_H__
20
21#include "cker/Shape.h"
22#include "cker/Types.h"
23
24namespace nnfw
25{
26namespace cker
27{
28
29template <typename Scalar>
30void SplitV(const SplitVParams &params, const Shape &input_shape, const Scalar *input_data,
31 std::vector<nnfw::cker::Shape> &output_shapes, Scalar *const *output_data)
32{
33 const int split_dimensions = input_shape.DimensionsCount();
34 int axis = params.axis < 0 ? params.axis + split_dimensions : params.axis;
35 int outputs_count = params.num_split;
36
37 for (int i = 0; i < outputs_count; i++)
38 {
39 // TFLITE_DCHECK_EQ(output_shapes[i]->DimensionsCount(), split_dimensions);
40 for (int j = 0; j < split_dimensions; j++)
41 {
42 if (j != axis)
43 {
44 MatchingDim(output_shapes[i], j, input_shape, j);
45 }
46 }
47 }
48
49 int64_t outer_size = 1;
50 for (int i = 0; i < axis; ++i)
51 {
52 outer_size *= input_shape.Dims(i);
53 }
54 // For all output arrays,
55 // FlatSize() = outer_size * Dims(axis) * base_inner_size;
56 int64_t base_inner_size = 1;
57 for (int i = axis + 1; i < split_dimensions; ++i)
58 {
59 base_inner_size *= input_shape.Dims(i);
60 }
61
62 const Scalar *input_ptr = input_data;
63 int copy_size = 0;
64 for (int k = 0; k < outer_size; k++)
65 {
66 for (int i = 0; i < outputs_count; ++i)
67 {
68 copy_size = output_shapes[i].Dims(axis) * base_inner_size;
69 memcpy(output_data[i] + k * copy_size, input_ptr, copy_size * sizeof(Scalar));
70 input_ptr += copy_size;
71 }
72 }
73}
74
75} // namespace cker
76} // namespace nnfw
77
78#endif // __NNFW_CKER_SPLIT_V_H__
int32_t DimensionsCount() const
Definition Shape.h:91
int32_t Dims(int i) const
Definition Shape.h:92
void SplitV(const SplitVParams &params, const Shape &input_shape, const Scalar *input_data, std::vector< nnfw::cker::Shape > &output_shapes, Scalar *const *output_data)
Definition SplitV.h:30
int MatchingDim(const Shape &shape1, int index1, const Shape &shape2, int index2)
Definition Shape.h:220
Definition topk_v2.h:30