ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Concatenation.h File Reference
#include "Shape.h"
#include <vector>
#include <cstdint>

Go to the source code of this file.

Functions

bool concatenationPrepare (const std::vector< Shape > &inputShapes, int32_t axis, Shape *output)
 

Function Documentation

◆ concatenationPrepare()

bool concatenationPrepare ( const std::vector< Shape > &  inputShapes,
int32_t  axis,
Shape output 
)

Definition at line 21 of file Concatenation.cpp.

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
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540
Option< std::vector< int > > inputShapes(optname("--input-shape"), overview("Shape of caffe2 input"), std::vector< int >{}, optional(false), optvalues(""), nullptr, separators(""), showopt(false), IOption::Group::caffe2)
Definition Options.h:32

References ASSERT, getNumberOfDimensions(), getSizeOfDimension(), and offset().