ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Concatenation.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright (C) 2017 The Android Open Source Project
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#include "Concatenation.h"
19#include "Assert.h"
20
21bool concatenationPrepare(const std::vector<Shape> &inputShapes, int32_t axis, Shape *output)
22{
23
24 int num_inputs = inputShapes.size();
25 OperandType input_type = inputShapes[0].type;
26 uint32_t num_dimensions = getNumberOfDimensions(inputShapes[0]);
27
28 ASSERT(axis >= 0);
29 ASSERT(axis < (int32_t)num_dimensions);
30
31 int sum_axis = getSizeOfDimension(inputShapes[0], axis);
32 for (int i = 1; i < num_inputs; ++i)
33 {
34 ASSERT(getNumberOfDimensions(inputShapes[i]) == num_dimensions);
35 ASSERT(inputShapes[i].type == inputShapes[0].type);
36 if (input_type == OperandType::TENSOR_QUANT8_ASYMM)
37 {
38 ASSERT(inputShapes[0].offset == inputShapes[i].offset);
39 ASSERT(inputShapes[0].scale == inputShapes[i].scale);
40 }
41 for (int d = 0; d < (int32_t)num_dimensions; ++d)
42 {
43 if (d == axis)
44 {
45 sum_axis += getSizeOfDimension(inputShapes[i], axis);
46 }
47 else
48 {
49 ASSERT(getSizeOfDimension(inputShapes[0], d) ==
50 getSizeOfDimension(inputShapes[i], d));
51 }
52 }
53 }
54
55 output->type = input_type;
56 output->dimensions = inputShapes[0].dimensions;
57 output->dimensions[axis] = sum_axis;
58
59 if (input_type == OperandType::TENSOR_QUANT8_ASYMM)
60 {
61 ASSERT(inputShapes[0].offset == output->offset);
62 ASSERT(inputShapes[0].scale == output->scale);
63 }
64
65 return true;
66}
OperandType
Definition OperandType.h:24
#define ASSERT(v)
Definition Assert.h:24
uint32_t getSizeOfDimension(const Shape &shape, uint32_t dimensionIdx)
Definition Shape.cpp:60
uint32_t getNumberOfDimensions(const Shape &shape)
Definition Shape.cpp:58
bool concatenationPrepare(const std::vector< Shape > &inputShapes, int32_t axis, Shape *output)
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540
Definition Shape.h:28