blob: 56f65d0ba837cd204d8422fbc5bda45a95daa1a5 [file] [log] [blame]
Georgios Pinitas358ca202017-12-07 16:47:52 +00001/*
Gian Marco36a0a462018-01-12 10:21:40 +00002 * Copyright (c) 2017-2018 ARM Limited.
Georgios Pinitas358ca202017-12-07 16:47:52 +00003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef __ARM_COMPUTE_MISC_SHAPE_CALCULATOR_H__
25#define __ARM_COMPUTE_MISC_SHAPE_CALCULATOR_H__
26
Georgios Pinitas9be0c5a2018-02-19 12:46:29 +000027#include "arm_compute/core/Helpers.h"
Georgios Pinitas358ca202017-12-07 16:47:52 +000028#include "arm_compute/core/ITensorInfo.h"
Georgios Pinitas1250a5a2018-01-02 13:27:37 +000029#include "arm_compute/core/Utils.h"
Georgios Pinitas358ca202017-12-07 16:47:52 +000030
Georgios Pinitas77589b52018-08-21 14:41:35 +010031#include "arm_compute/core/utils/helpers/tensor_transform.h"
32
Gian Marco Iodiced2fab732018-03-02 11:18:12 +000033#include <cmath>
34
Georgios Pinitas358ca202017-12-07 16:47:52 +000035namespace arm_compute
36{
37namespace misc
38{
39namespace shape_calculator
40{
Abe Mbise7784c832018-05-31 16:48:41 +010041inline TensorShape compute_vector_to_tensor_output_shape(const TensorShape &input, size_t conv_w, size_t conv_h, const DataLayout &data_layout)
42{
43 const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
44 const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
45 const size_t idx_c = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
46
47 TensorShape output_shape(input);
48 output_shape.set(idx_w, conv_w);
49 output_shape.set(idx_h, conv_h);
50 output_shape.set(idx_c, input.x() / (conv_w * conv_h));
51
52 return output_shape;
53}
Georgios Pinitase1a352c2018-09-03 12:42:19 +010054
Pablo Tello00afd112018-01-04 10:34:24 +000055inline TensorShape compute_permutation_output_shape(const ITensorInfo &input, const PermutationVector &perm)
56{
57 TensorShape output_shape = input.tensor_shape();
58 permute(output_shape, perm);
59 return output_shape;
60}
Georgios Pinitase1a352c2018-09-03 12:42:19 +010061
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +010062inline TensorShape compute_reorg_output_shape(const ITensorInfo &input, int32_t stride)
63{
Gian Marco Iodice477531c2018-08-21 17:53:38 +010064 const size_t idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
65 const size_t idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
66 const size_t idx_channel = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL);
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +010067
Gian Marco Iodice477531c2018-08-21 17:53:38 +010068 ARM_COMPUTE_ERROR_ON(stride <= 0);
69 ARM_COMPUTE_ERROR_ON_MSG((input.tensor_shape()[idx_width] % stride != 0), "The width of the input tensor must be a multiple of stride");
70 ARM_COMPUTE_ERROR_ON_MSG((input.tensor_shape()[idx_height] % stride != 0), "The height of the input tensor must be a multiple of stride");
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +010071
72 TensorShape output_shape{ input.tensor_shape() };
Gian Marco Iodice477531c2018-08-21 17:53:38 +010073
74 output_shape.set(idx_width, output_shape[idx_width] / stride);
75 output_shape.set(idx_height, output_shape[idx_height] / stride);
76 output_shape.set(idx_channel, output_shape[idx_channel] * stride * stride);
Georgios Pinitasaa6a04a2018-08-29 12:53:41 +010077
78 return output_shape;
79}
Georgios Pinitase1a352c2018-09-03 12:42:19 +010080
Gian Marco Iodice916d1bc2018-08-13 11:20:41 +010081inline TensorShape compute_weights_reshaped_shape(const ITensorInfo &weights, bool has_bias = false, unsigned int num_groups = 1)
Georgios Pinitas78c00902018-01-09 17:33:11 +000082{
Giorgio Arena088c2b02018-08-07 16:59:05 +010083 // Number of groups greater than one are only supported for NCHW data layout, and the number of weights must be a multiple of it.
Giorgio Arenac6aa49b2018-08-07 11:53:30 +010084 ARM_COMPUTE_ERROR_ON(num_groups == 0);
Giorgio Arenac6aa49b2018-08-07 11:53:30 +010085 ARM_COMPUTE_ERROR_ON(weights.data_layout() == DataLayout::NHWC && num_groups > 1);
Gian Marco Iodice916d1bc2018-08-13 11:20:41 +010086 ARM_COMPUTE_ERROR_ON((weights.dimension(3) % num_groups) != 0);
Giorgio Arenac6aa49b2018-08-07 11:53:30 +010087
Georgios Pinitas78c00902018-01-09 17:33:11 +000088 // Calculate output shape
89 TensorShape weights_reshaped{ weights.tensor_shape() };
Gian Marco Iodice916d1bc2018-08-13 11:20:41 +010090 weights_reshaped.set(3, weights_reshaped[3] / num_groups);
91
Georgios Pinitas78c00902018-01-09 17:33:11 +000092 weights_reshaped.collapse(3);
93 const size_t tmp_dim = weights_reshaped[0];
Gian Marco Iodice916d1bc2018-08-13 11:20:41 +010094 weights_reshaped.set(0, weights_reshaped[1]);
Georgios Pinitas78c00902018-01-09 17:33:11 +000095 weights_reshaped.set(1, tmp_dim + (has_bias ? 1 : 0));
Giorgio Arenac6aa49b2018-08-07 11:53:30 +010096 if(weights.num_dimensions() < 5)
97 {
98 weights_reshaped.set(2, num_groups);
99 }
Georgios Pinitas78c00902018-01-09 17:33:11 +0000100
101 return weights_reshaped;
102}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100103
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100104inline TensorShape compute_interleaved_shape(const ITensorInfo &a, int mult_interleave4x4_height = 1, bool reinterpret_input_as_3d = false)
Georgios Pinitas358ca202017-12-07 16:47:52 +0000105{
Gian Marco36a0a462018-01-12 10:21:40 +0000106 // The interleaved output matrix will have the following shape: [ a_height * W, ceil(a_width / W) ] where W = 4 * mult_interleave4x4_height
107 ARM_COMPUTE_ERROR_ON(mult_interleave4x4_height < 1);
108 const int interleave_width = 4 * mult_interleave4x4_height;
Georgios Pinitas358ca202017-12-07 16:47:52 +0000109 TensorShape shape_interleaved_a{ a.tensor_shape() };
Gian Marco36a0a462018-01-12 10:21:40 +0000110 shape_interleaved_a.set(0, a.dimension(0) * interleave_width);
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100111 if(reinterpret_input_as_3d)
112 {
113 const int M = a.dimension(1) * a.dimension(2);
114 const int height = std::ceil(M / static_cast<float>(interleave_width));
115 shape_interleaved_a.set(1, height);
Isabella Gottardi089695f2018-10-17 18:04:15 +0100116
117 // When the data format is NHWC and the shapes are Nx1x1
118 // the tensor shape num_dimensions is automatically set to 1 instead of 3.
119 // To avoid failures by removing a dimension that doesn't exist
120 // check if the number of dimensions is greater than 2.
121 if(shape_interleaved_a.num_dimensions() > 2)
122 {
123 shape_interleaved_a.remove_dimension(2);
124 }
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100125 }
126 else
127 {
128 shape_interleaved_a.set(1, std::ceil(a.dimension(1) / static_cast<float>(interleave_width)));
129 }
Georgios Pinitas358ca202017-12-07 16:47:52 +0000130
131 return shape_interleaved_a;
132}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100133
Georgios Pinitas358ca202017-12-07 16:47:52 +0000134inline TensorShape compute_transpose1xW_shape(const ITensorInfo &b)
135{
136 // The transpose1xW output matrix will have the following shape: [ b_height * 16, ceil(b_width / 16.0f) ]
137 TensorShape shape_transposed1xW_b{ b.tensor_shape() };
138 shape_transposed1xW_b.set(0, b.dimension(1) * 16);
139 shape_transposed1xW_b.set(1, std::ceil(b.dimension(0) / 16.f));
140
141 return shape_transposed1xW_b;
142}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100143
Gian Marco36a0a462018-01-12 10:21:40 +0000144inline TensorShape compute_transpose1xW_with_element_size_shape(const ITensorInfo &b, int mult_transpose1xW_width = 1)
Georgios Pinitas358ca202017-12-07 16:47:52 +0000145{
Gian Marco36a0a462018-01-12 10:21:40 +0000146 // Note: mult_transpose1xW_width expresses the number of chunks with size 1x(W) we want to store on the same row
147 // The transpose1xW output matrix will have the following shape:
148 // [ b_height * W, ceil(b_width / W) ] where W = (16 / element size of the tensor) * mult_transpose1xW_width
149 ARM_COMPUTE_ERROR_ON(mult_transpose1xW_width < 1);
Georgios Pinitas358ca202017-12-07 16:47:52 +0000150 TensorShape shape_transposed1xW_b{ b.tensor_shape() };
Gian Marco36a0a462018-01-12 10:21:40 +0000151 const size_t transpose_width = (16 / b.element_size()) * mult_transpose1xW_width;
Georgios Pinitas358ca202017-12-07 16:47:52 +0000152 shape_transposed1xW_b.set(0, b.dimension(1) * transpose_width);
153 shape_transposed1xW_b.set(1, static_cast<size_t>(std::ceil(b.dimension(0) / static_cast<float>(transpose_width))));
154
155 return shape_transposed1xW_b;
156}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100157
Georgios Pinitas358ca202017-12-07 16:47:52 +0000158inline TensorShape compute_reductionA_shape(const ITensorInfo &b)
159{
160 TensorShape shape_vector_sum_col{ b.tensor_shape() };
161 if(shape_vector_sum_col.num_dimensions() > 1)
162 {
163 shape_vector_sum_col.remove_dimension(1);
164 }
165
166 return shape_vector_sum_col;
167}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100168
Georgios Pinitas358ca202017-12-07 16:47:52 +0000169inline TensorShape compute_reductionB_shape(const ITensorInfo &a)
170{
171 TensorShape shape_vector_sum_row{ a.tensor_shape() };
172 shape_vector_sum_row.set(Window::DimX, a.dimension(1));
Georgios Pinitas932491f2018-09-21 16:33:15 +0100173 if(shape_vector_sum_row.num_dimensions() > 1)
Georgios Pinitas358ca202017-12-07 16:47:52 +0000174 {
175 shape_vector_sum_row.remove_dimension(1);
176 }
177
178 return shape_vector_sum_row;
179}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100180
Giorgio Arena226e4b92018-08-23 12:00:02 +0100181inline TensorShape compute_col2im_shape(const ITensorInfo &input, const Size2D &convolved_dims, bool batch_size_on_z, unsigned int num_groups = 1)
Georgios Pinitas78c00902018-01-09 17:33:11 +0000182{
Michele Di Giorgio980002b2018-08-08 09:25:51 +0100183 ARM_COMPUTE_ERROR_ON(num_groups == 0);
Giorgio Arena226e4b92018-08-23 12:00:02 +0100184 ARM_COMPUTE_ERROR_ON(input.tensor_shape()[1] != (convolved_dims.area()));
Michele Di Giorgio980002b2018-08-08 09:25:51 +0100185 ARM_COMPUTE_ERROR_ON((num_groups > 1) && input.tensor_shape()[2] != num_groups);
186
Georgios Pinitase55b40a2018-09-13 17:20:04 +0100187 const DataLayout data_layout = input.data_layout();
188 const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
189 const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
190 const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
Michele Di Giorgio980002b2018-08-08 09:25:51 +0100191
Georgios Pinitase55b40a2018-09-13 17:20:04 +0100192 TensorShape col2im_shape{ input.tensor_shape() };
193 // If batches start on 3rd dimension shift dimensions right by 1 to retain upper tensor shape,
194 // as first three will be override by H,W,C data
195 if(batch_size_on_z && num_groups == 1)
196 {
197 col2im_shape.shift_right(1);
198 }
199 col2im_shape.set(width_idx, convolved_dims.width);
200 col2im_shape.set(height_idx, convolved_dims.height);
201 col2im_shape.set(channel_idx, input.tensor_shape()[0] * num_groups);
Georgios Pinitas78c00902018-01-09 17:33:11 +0000202
203 return col2im_shape;
204}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100205
Georgios Pinitas358ca202017-12-07 16:47:52 +0000206inline TensorShape compute_transposed_shape(const ITensorInfo &input)
207{
208 TensorShape shape_transposed{ input.tensor_shape() };
209
210 shape_transposed.set(0, input.dimension(1));
211 shape_transposed.set(1, input.dimension(0));
212
213 return shape_transposed;
214}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100215
Giorgio Arena76572242018-04-04 17:44:26 +0100216inline TensorShape compute_depthwise_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, PadStrideInfo conv_info, unsigned int depth_multiplier)
Georgios Pinitas1250a5a2018-01-02 13:27:37 +0000217{
218 const TensorShape input_shape{ input.tensor_shape() };
219 const TensorShape weights_shape{ weights.tensor_shape() };
220
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000221 const DataLayout data_layout = input.data_layout();
222 const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
223 const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
Giorgio Arena76572242018-04-04 17:44:26 +0100224 const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000225
Georgios Pinitas1250a5a2018-01-02 13:27:37 +0000226 unsigned int output_width = 0;
227 unsigned int output_height = 0;
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000228 std::tie(output_width, output_height) = scaled_dimensions(input_shape[width_idx], input_shape[height_idx],
229 weights_shape[width_idx], weights_shape[height_idx],
Georgios Pinitasd05dce42018-01-22 16:29:17 +0000230 conv_info);
Georgios Pinitas1250a5a2018-01-02 13:27:37 +0000231
232 TensorShape output_shape{ input_shape };
Giorgio Arenadfca60b2018-01-31 10:30:59 +0000233 output_shape.set(width_idx, output_width);
234 output_shape.set(height_idx, output_height);
Giorgio Arena76572242018-04-04 17:44:26 +0100235 output_shape.set(channel_idx, input_shape[channel_idx] * depth_multiplier);
Georgios Pinitas1250a5a2018-01-02 13:27:37 +0000236
237 return output_shape;
238}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100239
Michele Di Giorgioed5a4922018-09-13 16:22:01 +0100240inline TensorShape compute_deconvolution_upsampled_shape(const ITensorInfo &input, const ITensorInfo &weights, unsigned int sx, unsigned int sy, unsigned int inner_border_right,
241 unsigned int inner_border_top,
242 std::pair<unsigned int, unsigned int> &out_dims, unsigned int &padx, unsigned int &pady)
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000243{
Michele Di Giorgioed5a4922018-09-13 16:22:01 +0100244 const DataLayout data_layout = input.data_layout();
245 const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
246 const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
247
Michalis Spyrouafbc5ff2018-10-03 14:18:19 +0100248 // Find the upsampled dimensions
Michele Di Giorgioed5a4922018-09-13 16:22:01 +0100249 unsigned int out_x = (input.dimension(idx_w) - 1) * sx + inner_border_right + 1;
250 unsigned int out_y = (input.dimension(idx_h) - 1) * sy + inner_border_top + 1;
Michalis Spyrouafbc5ff2018-10-03 14:18:19 +0100251
252 // Find the padding needed for the convolution with stride 1 in order to match output shape
Michele Di Giorgioed5a4922018-09-13 16:22:01 +0100253 padx = out_dims.first - (out_x - weights.dimension(idx_w) + 1);
254 pady = out_dims.second - (out_y - weights.dimension(idx_h) + 1);
Michalis Spyrouafbc5ff2018-10-03 14:18:19 +0100255 out_x += padx;
256 out_y += pady;
257
258 TensorShape scale_out_shape(input.tensor_shape());
Michele Di Giorgioed5a4922018-09-13 16:22:01 +0100259 scale_out_shape.set(idx_w, out_x);
260 scale_out_shape.set(idx_h, out_y);
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000261
262 return scale_out_shape;
263}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100264
Michele Di Giorgioed5a4922018-09-13 16:22:01 +0100265inline TensorShape compute_deconvolution_output_shape(const std::pair<unsigned int, unsigned int> &out_dims, const ITensorInfo &input, const ITensorInfo &weights)
266{
267 const TensorShape input_shape{ input.tensor_shape() };
268 const TensorShape weights_shape{ weights.tensor_shape() };
269
270 const DataLayout data_layout = input.data_layout();
271 const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
272 const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
273 const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
274 const int batch_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
275
276 TensorShape out_shape{ input_shape };
277 out_shape.set(width_idx, out_dims.first);
278 out_shape.set(height_idx, out_dims.second);
279 out_shape.set(channel_idx, weights_shape[batch_idx]);
280 return out_shape;
281}
282
Giorgio Arena0f170392018-07-18 16:13:12 +0100283inline TensorShape compute_im2col_conv_shape(const ITensorInfo *input, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation, bool batch_size_on_z,
284 unsigned int num_groups = 1)
Giorgio Arena156fcf32018-03-09 15:30:43 +0000285{
Giorgio Arena0f170392018-07-18 16:13:12 +0100286 // The output shape will be the 3D shape [ out_channels * kernel_area, num_elems_per_out_channel, batches ] if batch_size_on_z == true
287 // or the 4D shape [ out_channels * kernel_area / num_groups, num_elems_per_out_channel, num_groups, batches ] if batch_size_on_z == false
288
289 ARM_COMPUTE_ERROR_ON(num_groups == 0);
290 ARM_COMPUTE_ERROR_ON(num_groups > 1 && input->data_layout() != DataLayout::NCHW);
291 ARM_COMPUTE_ERROR_ON(num_groups > 1 && batch_size_on_z);
Giorgio Arena156fcf32018-03-09 15:30:43 +0000292
293 TensorShape output_shape{ input->tensor_shape() };
294
295 const DataLayout data_layout = input->data_layout();
296 const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
297 const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
298 const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
299
300 std::pair<unsigned int, unsigned int> out_dims = scaled_dimensions(output_shape[width_idx], output_shape[height_idx], kernel_dims.width, kernel_dims.height, conv_info, dilation);
Giorgio Arena0f170392018-07-18 16:13:12 +0100301 output_shape.set(0, (output_shape[channel_idx] / num_groups * kernel_dims.area() + (has_bias ? 1 : 0))); // NOLINT
Giorgio Arenaf485a102018-04-20 16:06:21 +0100302 output_shape.set(1, (out_dims.first * out_dims.second));
Gian Marco Iodice597a8562018-08-01 15:06:06 +0100303 if(batch_size_on_z && output_shape.num_dimensions() >= 3)
304 {
305 output_shape.remove_dimension(2);
306 }
307 else
308 {
Giorgio Arena0f170392018-07-18 16:13:12 +0100309 output_shape.set(2, num_groups);
Gian Marco Iodice597a8562018-08-01 15:06:06 +0100310 }
Giorgio Arena156fcf32018-03-09 15:30:43 +0000311
312 return output_shape;
313}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100314
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100315inline TensorShape compute_flatten_shape(const ITensorInfo *input)
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000316{
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100317 // The output shape will be the flatten version of the input (i.e. [ width * height * channels, num_batches, ... ] ). Used for FlattenLayer and FullyConnectedLayer.
318
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000319 TensorShape output_shape{ input->tensor_shape() };
320
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100321 output_shape.collapse(3);
Giorgio Arena156fcf32018-03-09 15:30:43 +0000322
323 return output_shape;
324}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100325
giuros01efbf6c82018-09-03 09:53:53 +0100326inline TensorShape compute_softmax_shape(const ITensorInfo *input, size_t axis = 1)
327{
328 // The output shape will be a 2D version of the input. For instance:
329 // - [x,y,z] and axis 1 will return [x, y*z]
330 // - [x,y,z,w] and axis 2 will return [x*y, w*z]
331 // - [x,y,z,w] and axis 3 will return [x*y*z, w]
332 TensorShape shape2D = input->tensor_shape();
333
334 if(axis < input->num_dimensions())
335 {
336 // Collapse from axis onward (this changes the shape)
337 shape2D.collapse_from(axis);
338
339 // Collapse the rest (collapse is inclusive)
340 shape2D.collapse(shape2D.num_dimensions() - 1);
341 }
342 else
343 {
344 // Collapse everything
345 shape2D.collapse(shape2D.num_dimensions());
346 }
347
348 if(axis == 0)
349 {
350 // If axis is zero the first dim should be one. Since
351 // collapse is an inclusive operation we need to shift
352 shape2D.shift_right(1);
353 }
354
355 return shape2D;
356}
357
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000358inline TensorShape compute_interleave_custom_shape(const TensorShape &input, const int x_interleave, const int y_interleave)
359{
360 TensorShape output_shape{ input };
361
362 output_shape.set(0, output_shape.x() * x_interleave);
363 output_shape.set(1, std::ceil(output_shape.y() / static_cast<float>(y_interleave)));
364
365 return output_shape;
366}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100367
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000368inline TensorShape compute_fully_connected_reshaped_weights_shape(const ITensorInfo *input, bool transpose_weights, bool is_batched_fc_layer, const int interleave)
369{
370 TensorShape output_shape{ input->tensor_shape() };
371
372 // Transpose weights if the user hasn't done it
373 if(transpose_weights)
374 {
375 output_shape = compute_transposed_shape(*input);
376 }
377
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000378 // If we run multiple batches we need 1xW transpose, too.
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +0000379 if(is_batched_fc_layer)
380 {
381 output_shape = compute_transposed_shape(input->clone()->set_tensor_shape(output_shape));
382 output_shape = compute_interleave_custom_shape(output_shape, interleave, interleave);
383 }
384
385 return output_shape;
386}
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000387
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000388inline TensorShape compute_winograd_filter_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info)
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000389{
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000390 TensorShape tensor_shape{ input.tensor_shape() };
391
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000392 const Size2D kernel_size = winograd_info.kernel_size;
393 const Size2D output_tile_size = winograd_info.output_tile_size;
394 const Size2D input_tile_size = Size2D(output_tile_size.width + kernel_size.width - 1, output_tile_size.height + kernel_size.height - 1);
Giorgio Arena2d9de0a2018-03-15 17:58:20 +0000395
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000396 tensor_shape.remove_dimension(get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH));
397 tensor_shape.set(Window::DimX, input.dimension(3));
398 tensor_shape.set(Window::DimY, input.dimension(get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL)));
399 tensor_shape.set(Window::DimZ, input_tile_size.area());
Gian Marco Iodice7e4b2392018-02-22 16:17:20 +0000400
401 return tensor_shape;
402}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100403
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000404inline TensorShape compute_winograd_input_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info)
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000405{
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000406 const PadStrideInfo conv_info = winograd_info.convolution_info;
407 const Size2D kernel_size = winograd_info.kernel_size;
408 const Size2D output_tile_size = winograd_info.output_tile_size;
409 const Size2D input_tile_size = Size2D(output_tile_size.width + kernel_size.width - 1, output_tile_size.height + kernel_size.height - 1);
410
Giorgio Arenac42f28d2018-04-26 11:33:05 +0100411 const size_t idx_w = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
412 const size_t idx_h = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
413 const size_t idx_c = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL);
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000414
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +0100415 // Compute the number of output tiles along the x and y direction of size "output_tile_size"
416 const Size2D num_tiles = compute_winograd_convolution_tiles(Size2D(input.tensor_shape()[idx_w], input.tensor_shape()[idx_h]),
417 kernel_size,
418 output_tile_size,
419 conv_info);
Giorgio Arenac42f28d2018-04-26 11:33:05 +0100420
421 const unsigned int width = input.tensor_shape()[idx_c];
Gian Marco Iodicef1c2bf02018-06-13 14:05:54 +0100422 const unsigned int height = num_tiles.area();
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000423 const unsigned int depth = input_tile_size.area();
Giorgio Arena1f9ca1d2018-03-01 11:13:45 +0000424
425 TensorShape output_shape{ input.tensor_shape() };
426 output_shape.set(0, width);
427 output_shape.set(1, height);
428 output_shape.set(2, depth);
429
430 return output_shape;
431}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100432
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000433inline TensorShape compute_winograd_output_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info)
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000434{
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000435 const PadStrideInfo conv_info = winograd_info.convolution_info;
436 const Size2D kernel_size = winograd_info.kernel_size;
437 const Size2D input_dimensions = winograd_info.input_dimensions;
438 const DataLayout data_layout = winograd_info.output_data_layout;
439
440 // Compute output shape
441 unsigned int output_width = 0;
442 unsigned int output_height = 0;
443 std::tie(output_width, output_height) = scaled_dimensions(input_dimensions.width, input_dimensions.height,
444 kernel_size.width, kernel_size.height, conv_info);
445
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000446 TensorShape tensor_shape{ input.tensor_shape() };
447
448 // Output dimension
Gian Marco Iodice247f52c2018-03-22 11:24:56 +0000449 const unsigned int out_w = output_width;
450 const unsigned int out_h = output_height;
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000451 const unsigned int out_c = input.dimension(0);
452
453 tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH), out_w);
454 tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT), out_h);
455 tensor_shape.set(get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL), out_c);
456
457 return tensor_shape;
458}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100459
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000460inline TensorShape compute_deep_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, PadStrideInfo conv_info)
461{
462 const TensorShape input_shape{ input.tensor_shape() };
463 const TensorShape weights_shape{ weights.tensor_shape() };
464
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000465 const size_t idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
466 const size_t idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
467 const size_t idx_channel = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::CHANNEL);
468
Giorgio Arenac0f54432018-03-16 14:02:34 +0000469 const unsigned int input_width = input_shape[idx_width];
470 const unsigned int input_height = input_shape[idx_height];
471 const unsigned int weights_width = weights_shape[idx_width];
472 const unsigned int weights_height = weights_shape[idx_height];
473 const unsigned int weights_out_channel = weights_shape[3];
474 unsigned int output_width = 0;
475 unsigned int output_height = 0;
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000476 std::tie(output_width, output_height) = scaled_dimensions(input_width, input_height, weights_width, weights_height, conv_info);
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000477
478 TensorShape output_shape{ input_shape };
Gian Marco Iodiced2fab732018-03-02 11:18:12 +0000479 output_shape.set(idx_width, output_width);
480 output_shape.set(idx_height, output_height);
Giorgio Arenac0f54432018-03-16 14:02:34 +0000481 output_shape.set(idx_channel, weights_out_channel);
Georgios Pinitasd8734b52017-12-22 15:27:52 +0000482
483 return output_shape;
484}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100485
Alex Gilday60954c62018-03-05 16:22:48 +0000486inline TensorShape compute_min_max_shape(const ITensorInfo *input)
487{
488 TensorShape output_shape{ input->tensor_shape() };
489 output_shape.set(Window::DimX, 2);
490 output_shape.remove_dimension(1);
491 output_shape.remove_dimension(1);
492
493 return output_shape;
494}
495
Michalis Spyroue74b2012018-04-18 09:49:16 +0100496inline TensorShape compute_pool_shape(const ITensorInfo &input, PoolingLayerInfo pool_info)
497{
498 unsigned int pooled_w = 0;
499 unsigned int pooled_h = 0;
500
Giorgio Arena3c520c52018-05-01 11:47:24 +0100501 TensorShape output_shape{ input.tensor_shape() };
Michalis Spyroue74b2012018-04-18 09:49:16 +0100502
Giorgio Arena3c520c52018-05-01 11:47:24 +0100503 const bool is_global_pooling = pool_info.is_global_pooling();
504 const unsigned int idx_width = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::WIDTH);
505 const unsigned int idx_height = get_data_layout_dimension_index(input.data_layout(), DataLayoutDimension::HEIGHT);
506 const unsigned int pool_size_x = is_global_pooling ? output_shape[idx_width] : pool_info.pool_size().width;
507 const unsigned int pool_size_y = is_global_pooling ? output_shape[idx_height] : pool_info.pool_size().height;
508
509 std::tie(pooled_w, pooled_h) = scaled_dimensions(output_shape[idx_width],
510 output_shape[idx_height],
Michalis Spyroue74b2012018-04-18 09:49:16 +0100511 pool_size_x,
512 pool_size_y,
513 pool_info.pad_stride_info());
514
Giorgio Arena3c520c52018-05-01 11:47:24 +0100515 output_shape.set(idx_width, pooled_w);
516 output_shape.set(idx_height, pooled_h);
Michalis Spyroue74b2012018-04-18 09:49:16 +0100517
518 return output_shape;
519}
520
Michalis Spyrou36a559e2018-03-20 10:30:58 +0000521inline TensorShape compute_rnn_shape(const ITensorInfo *input, const unsigned int batch_size)
522{
523 TensorShape output_shape{ input->tensor_shape() };
524 output_shape.set(1, batch_size);
525
526 return output_shape;
527}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100528
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100529inline TensorShape compute_mm_shape(const ITensorInfo &input0, const ITensorInfo &input1, bool is_interleaved_transposed, const GEMMReshapeInfo &reshape_info)
530{
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000531 ARM_COMPUTE_ERROR_ON_MSG(input0.num_dimensions() > 4, "The number of dimensions for the matrix A must be <= 4");
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100532 ARM_COMPUTE_ERROR_ON_MSG(is_interleaved_transposed && reshape_info.reinterpret_input_as_3d(), "The first input tensor cannot be reinterpreted as 3D if is_interleaved_transposed is true");
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100533
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100534 const bool reinterpret_input_as_3d = reshape_info.reinterpret_input_as_3d();
535 const bool reinterpret_output_as_3d = reshape_info.depth_output_gemm3d() != 1;
536 const int m = reshape_info.reinterpret_input_as_3d() ? input0.dimension(1) * input0.dimension(2) : input0.dimension(1);
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000537
538 // If the output of GEMM has to be reinterpreted as 3D, the number of input0 rows (M) is obtained collapsing the second and third
539 // dimension of the output tensor
540 const int dim0 = is_interleaved_transposed ? reshape_info.n() : input1.dimension(0);
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100541 const int dim1 = is_interleaved_transposed ? reshape_info.m() / reshape_info.depth_output_gemm3d() : m / reshape_info.depth_output_gemm3d();
542 const int dim2 = reinterpret_input_as_3d ? input0.tensor_shape()[3] : input0.tensor_shape()[2];
543 const int dim3 = reinterpret_input_as_3d ? 1 : input0.tensor_shape()[3];
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000544
545 TensorShape output_shape{ input0.tensor_shape() };
546
547 output_shape.set(0, dim0);
548 output_shape.set(1, dim1);
Gian Marco Iodice68a3f562018-07-26 11:44:03 +0100549 output_shape.set(2, reinterpret_output_as_3d ? reshape_info.depth_output_gemm3d() : dim2);
550 output_shape.set(3, reinterpret_output_as_3d ? dim2 : dim3);
551 output_shape.set(4, reinterpret_output_as_3d ? dim3 : 1);
Isabella Gottardi8e74f442018-03-01 16:42:00 +0000552
553 return output_shape;
Gian Marco Iodice750641d2018-05-08 12:01:57 +0100554}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100555
Georgios Pinitas932491f2018-09-21 16:33:15 +0100556inline TensorShape compute_output_stage_shape(const ITensorInfo &input, unsigned int gemm_3d_depth = 1, bool batch_size_on_z = false)
Georgios Pinitas041f36d2018-09-18 18:38:37 +0100557{
558 ARM_COMPUTE_ERROR_ON(input.data_layout() != DataLayout::NHWC && gemm_3d_depth > 1);
559
560 TensorShape output_shape = input.tensor_shape();
561 if(gemm_3d_depth > 1)
562 {
Georgios Pinitas932491f2018-09-21 16:33:15 +0100563 if(batch_size_on_z)
564 {
565 output_shape.shift_right(1);
566 }
Georgios Pinitas041f36d2018-09-18 18:38:37 +0100567 output_shape.set(0, input.tensor_shape().x());
568 output_shape.set(1, input.tensor_shape().y() / gemm_3d_depth);
569 output_shape.set(2, gemm_3d_depth);
570 }
571
572 return output_shape;
573}
574
Georgios Pinitas77589b52018-08-21 14:41:35 +0100575inline TensorShape compute_strided_slice_shape(const ITensorInfo &input,
576 const Coordinates &starts, const Coordinates &ends, const Coordinates &strides,
577 int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask)
578{
579 using namespace arm_compute::helpers::tensor_transform;
580
581 const TensorShape &input_shape = input.tensor_shape();
582
583 // Get actual start, end coordinates and strides
584 const Coordinates final_strides = strided_slice_strides(input_shape, strides);
585 const Coordinates starts_abs = strided_slice_absolute_start_coords(input_shape, starts, final_strides, begin_mask);
586 const Coordinates ends_abs = strided_slice_absolute_end_coords(input_shape, starts_abs, ends, final_strides, end_mask, shrink_axis_mask);
587
588 return compute_strided_slice_output_shape(input_shape, starts_abs, ends_abs, final_strides);
589}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100590
Michalis Spyrou6a8d3b62018-08-31 10:07:09 +0100591inline TensorShape compute_batch_to_space_shape(const ITensorInfo *input, const int block_x, const int block_y)
592{
593 ARM_COMPUTE_ERROR_ON(block_x <= 0 || block_y <= 0);
Michalis Spyrouf1addb62018-09-11 11:16:47 +0100594
595 const DataLayout data_layout = input->data_layout();
596 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
597 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
Michalis Spyrou13a51e12018-09-18 13:09:30 +0100598 const int idx_batch = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
Michalis Spyrouf1addb62018-09-11 11:16:47 +0100599
Michalis Spyrou6a8d3b62018-08-31 10:07:09 +0100600 TensorShape output_shape{ input->tensor_shape() };
Michalis Spyrouf1addb62018-09-11 11:16:47 +0100601 output_shape.set(idx_width, input->tensor_shape()[idx_width] * block_x);
602 output_shape.set(idx_height, input->tensor_shape()[idx_height] * block_y);
Michalis Spyrou13a51e12018-09-18 13:09:30 +0100603 output_shape.set(idx_batch, input->tensor_shape()[idx_batch] / (block_x * block_y));
Michalis Spyrou6a8d3b62018-08-31 10:07:09 +0100604
605 return output_shape;
606}
Georgios Pinitas77589b52018-08-21 14:41:35 +0100607
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100608inline TensorShape compute_split_shape(const ITensorInfo *input, unsigned int axis, unsigned int num_splits)
609{
610 TensorShape empty_shape;
611 empty_shape.set(0, 0);
612
613 TensorShape out_shape{ input->tensor_shape() };
614
615 // Return empty shape if axis is invalid
616 if(axis > input->tensor_shape().num_dimensions())
617 {
618 return empty_shape;
619 }
620
621 size_t axis_size = out_shape[axis];
622
623 // Return empty shape if num_split is not valid
624 if(axis_size % num_splits)
625 {
626 return empty_shape;
627 }
628
629 out_shape[axis] = axis_size / num_splits;
630 return out_shape;
631}
632
Michalis Spyrou16934a52018-08-21 18:03:58 +0100633inline TensorShape compute_space_to_batch_shape(const ITensorInfo *input, const int block_x, const int block_y, const Size2D &padding_left, const Size2D &padding_right)
634{
635 TensorShape output_shape{ input->tensor_shape() };
Michalis Spyrou13a51e12018-09-18 13:09:30 +0100636
637 const DataLayout data_layout = input->data_layout();
638 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
639 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
640 const int idx_batch = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
641
642 output_shape.set(idx_width, input->tensor_shape()[idx_width] * block_x + padding_left.x() + padding_right.x());
643 output_shape.set(idx_height, input->tensor_shape()[idx_height] * block_y + padding_left.y() + padding_right.y());
644 output_shape.set(idx_batch, input->tensor_shape()[idx_batch] / (block_x * block_y));
Michalis Spyrou16934a52018-08-21 18:03:58 +0100645
646 return output_shape;
647}
648
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100649inline TensorShape compute_padded_shape(const TensorShape &input_shape, const PaddingList &padding)
650{
651 TensorShape padded_shape = input_shape;
652 for(size_t dim = 0; dim < padding.size(); ++dim)
653 {
654 padded_shape.set(dim, padding[dim].first + input_shape[dim] + padding[dim].second);
655 }
656 return padded_shape;
657}
658
Michalis Spyrouceb889e2018-09-17 18:24:41 +0100659inline TensorShape compute_upsample_shape(const ITensorInfo &input, const Size2D &info)
660{
661 const DataLayout data_layout = input.data_layout();
662 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
663 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
664
665 TensorShape scale_out_shape(input.tensor_shape());
666 const unsigned int out_x = input.dimension(idx_width) * info.x();
667 const unsigned int out_y = input.dimension(idx_height) * info.y();
668 scale_out_shape.set(idx_width, out_x);
669 scale_out_shape.set(idx_height, out_y);
670
671 return scale_out_shape;
672}
673
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100674template <typename T>
Georgios Pinitase2220552018-07-20 13:23:44 +0100675inline TensorShape extract_shape(T *data)
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100676{
Georgios Pinitase2220552018-07-20 13:23:44 +0100677 return data->info()->tensor_shape();
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100678}
679
Georgios Pinitase2220552018-07-20 13:23:44 +0100680inline TensorShape extract_shape(ITensorInfo *data)
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100681{
Georgios Pinitase2220552018-07-20 13:23:44 +0100682 return data->tensor_shape();
683}
684
685inline TensorShape extract_shape(const TensorShape *data)
686{
687 return *data;
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100688}
689
690template <typename T>
Georgios Pinitase29acf12018-07-16 14:40:09 +0100691inline TensorShape calculate_depth_concatenate_shape(const std::vector<T *> &inputs_vector)
692{
Georgios Pinitase2220552018-07-20 13:23:44 +0100693 TensorShape out_shape = extract_shape(inputs_vector[0]);
Georgios Pinitase29acf12018-07-16 14:40:09 +0100694
695 size_t max_x = 0;
696 size_t max_y = 0;
697 size_t depth = 0;
698
699 for(const auto &tensor : inputs_vector)
700 {
701 ARM_COMPUTE_ERROR_ON(tensor == nullptr);
Georgios Pinitase2220552018-07-20 13:23:44 +0100702 const TensorShape shape = extract_shape(tensor);
Georgios Pinitase29acf12018-07-16 14:40:09 +0100703 max_x = std::max(shape.x(), max_x);
704 max_y = std::max(shape.y(), max_y);
705 depth += shape.z();
706 }
707
708 out_shape.set(0, max_x);
709 out_shape.set(1, max_y);
710 out_shape.set(2, depth);
711
712 return out_shape;
713}
714
715template <typename T>
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100716inline TensorShape calculate_width_concatenate_shape(const std::vector<T *> &inputs_vector)
717{
Georgios Pinitase2220552018-07-20 13:23:44 +0100718 TensorShape out_shape = extract_shape(inputs_vector[0]);
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100719
720 size_t width = 0;
721 for(const auto &tensor : inputs_vector)
722 {
723 ARM_COMPUTE_ERROR_ON(tensor == nullptr);
Georgios Pinitase2220552018-07-20 13:23:44 +0100724 const TensorShape shape = extract_shape(tensor);
Michalis Spyrou55b3d122018-05-09 09:59:23 +0100725 width += shape.x();
726 }
727
728 out_shape.set(0, width);
729
730 return out_shape;
731}
Georgios Pinitas358ca202017-12-07 16:47:52 +0000732} // namespace shape_calculator
733} // namespace misc
734} // namespace arm_compute
735#endif /* __ARM_COMPUTE_MISC_SHAPE_CALCULATOR_H__ */