COMPMID-2051 Refactor shape_calculator::calculate_concatenate_shape

Change-Id: Ibf316718d11fa975d75f226925747b21c4efd127
Signed-off-by: Michalis Spyrou <michalis.spyrou@arm.com>
Reviewed-on: https://review.mlplatform.org/c/974
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com>
diff --git a/arm_compute/core/CL/kernels/CLDepthConcatenateLayerKernel.h b/arm_compute/core/CL/kernels/CLDepthConcatenateLayerKernel.h
index ff80090..2a18452 100644
--- a/arm_compute/core/CL/kernels/CLDepthConcatenateLayerKernel.h
+++ b/arm_compute/core/CL/kernels/CLDepthConcatenateLayerKernel.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2018 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
  *
  * SPDX-License-Identifier: MIT
  *
@@ -73,13 +73,10 @@
 
     // Inherited methods overridden:
     void run(const Window &window, cl::CommandQueue &queue) override;
-    BorderSize border_size() const override;
 
 private:
     const ICLTensor *_input;
     ICLTensor       *_output;
-    int              _top_bottom;
-    int              _left_right;
     unsigned int     _depth_offset;
 };
 } // namespace arm_compute
diff --git a/arm_compute/core/GLES_COMPUTE/kernels/GCDepthConcatenateLayerKernel.h b/arm_compute/core/GLES_COMPUTE/kernels/GCDepthConcatenateLayerKernel.h
index 06a54dd..6a03170 100644
--- a/arm_compute/core/GLES_COMPUTE/kernels/GCDepthConcatenateLayerKernel.h
+++ b/arm_compute/core/GLES_COMPUTE/kernels/GCDepthConcatenateLayerKernel.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2018 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
  *
  * SPDX-License-Identifier: MIT
  *
@@ -64,13 +64,10 @@
 
     // Inherited methods overridden:
     void run(const Window &window) override;
-    BorderSize border_size() const override;
 
 private:
     const IGCTensor *_input;
     IGCTensor       *_output;
-    int              _top_bottom;
-    int              _left_right;
     int              _depth_offset;
 };
 }
diff --git a/arm_compute/core/NEON/kernels/NEDepthConcatenateLayerKernel.h b/arm_compute/core/NEON/kernels/NEDepthConcatenateLayerKernel.h
index 848d89f..26e23a7 100644
--- a/arm_compute/core/NEON/kernels/NEDepthConcatenateLayerKernel.h
+++ b/arm_compute/core/NEON/kernels/NEDepthConcatenateLayerKernel.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2018 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
  *
  * SPDX-License-Identifier: MIT
  *
@@ -76,17 +76,14 @@
 
     // Inherited methods overridden:
     void run(const Window &window, const ThreadInfo &info) override;
-    BorderSize border_size() const override;
 
 private:
-    using DepthConcatFunction = void(const ITensor *in, ITensor *out, std::pair<int, int> start_xy, int depth_offset, const Window &window);
+    using DepthConcatFunction = void(const ITensor *in, ITensor *out, int depth_offset, const Window &window);
 
 private:
     DepthConcatFunction *_func;
     const ITensor       *_input;
     ITensor             *_output;
-    int                  _top_bottom;
-    int                  _left_right;
     unsigned int         _depth_offset;
 };
 } // namespace arm_compute
diff --git a/arm_compute/core/utils/misc/ShapeCalculator.h b/arm_compute/core/utils/misc/ShapeCalculator.h
index 384bd46..f5058b3 100644
--- a/arm_compute/core/utils/misc/ShapeCalculator.h
+++ b/arm_compute/core/utils/misc/ShapeCalculator.h
@@ -1173,6 +1173,11 @@
     return *data;
 }
 
+inline TensorShape extract_shape(TensorShape *data)
+{
+    return *data;
+}
+
 /** Calculate the unstack shape of a tensor
  *
  * @param[in] input_shape Input tensor shape
@@ -1187,37 +1192,6 @@
     return input_shape;
 }
 
-/** Calculate the depth concatenate output shape of a vector of tensors
- *
- * @param[in] inputs_vector Vector containing the shapes of the inputs
- *
- * @return the calculated shape
- */
-template <typename T>
-inline TensorShape calculate_depth_concatenate_shape(const std::vector<T *> &inputs_vector)
-{
-    TensorShape out_shape = extract_shape(inputs_vector[0]);
-
-    size_t max_x = 0;
-    size_t max_y = 0;
-    size_t depth = 0;
-
-    for(const auto &tensor : inputs_vector)
-    {
-        ARM_COMPUTE_ERROR_ON(tensor == nullptr);
-        const TensorShape shape = extract_shape(tensor);
-        max_x                   = std::max(shape.x(), max_x);
-        max_y                   = std::max(shape.y(), max_y);
-        depth += shape.z();
-    }
-
-    out_shape.set(0, max_x);
-    out_shape.set(1, max_y);
-    out_shape.set(2, depth);
-
-    return out_shape;
-}
-
 /** Calculate the concatenate output shape of the concatenate operation along a single axis
  *
  * @param[in] input Vector containing the shapes of the inputs
@@ -1230,12 +1204,27 @@
 {
     TensorShape out_shape = extract_shape(input[0]);
 
+    // All dimensions must match except the axis one
+    for(unsigned int i = 0; i < MAX_DIMS; ++i)
+    {
+        if(i == axis)
+        {
+            continue;
+        }
+
+        for(const auto &tensor : input)
+        {
+            ARM_COMPUTE_ERROR_ON(tensor == nullptr);
+            const TensorShape shape = extract_shape(tensor);
+            ARM_COMPUTE_ERROR_ON(out_shape[i] != shape[i]);
+        }
+    }
+
+    // Calculate output shape
     size_t new_size = 0;
     for(const auto &tensor : input)
     {
-        ARM_COMPUTE_ERROR_ON(tensor == nullptr);
         const TensorShape shape = extract_shape(tensor);
-        ARM_COMPUTE_ERROR_ON(axis >= shape.num_dimensions());
         new_size += shape[axis];
     }