aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/core/Helpers.h
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2018-02-14 19:23:44 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:47:18 +0000
commit69af6cf5ec6edce564dd5ef97baba5a1325e8763 (patch)
treec8f82cb0f5258b1f2a004631d7fa78b49b34231d /arm_compute/core/Helpers.h
parentb99f00d44b8962c40f1de955831f8b04c15e7386 (diff)
downloadComputeLibrary-69af6cf5ec6edce564dd5ef97baba5a1325e8763.tar.gz
COMPMID-765: Sanitize permutation vector for Permute.
If permutation vector is bigger than the tensorshape to permute then infer dimensions of size one for the extra dimensions. Change-Id: I5addb292f770d925f47f756902e16073039e8f71 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/120473 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Stefana Simion <stefana.simion@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'arm_compute/core/Helpers.h')
-rw-r--r--arm_compute/core/Helpers.h22
1 files changed, 20 insertions, 2 deletions
diff --git a/arm_compute/core/Helpers.h b/arm_compute/core/Helpers.h
index c6a7db4f96..63fad1dcea 100644
--- a/arm_compute/core/Helpers.h
+++ b/arm_compute/core/Helpers.h
@@ -508,10 +508,28 @@ inline Strides compute_strides(const ITensorInfo &info)
template <typename T>
inline void permute(Dimensions<T> &dimensions, const PermutationVector &perm)
{
- auto copy_dimensions = utility::make_array<Dimensions<T>::num_max_dimensions>(dimensions.begin(), dimensions.end());
+ auto dimensions_copy = utility::make_array<Dimensions<T>::num_max_dimensions>(dimensions.begin(), dimensions.end());
for(unsigned int i = 0; i < perm.num_dimensions(); ++i)
{
- dimensions[i] = copy_dimensions[perm[i]];
+ T dimension_val = (perm[i] < dimensions.num_dimensions()) ? dimensions_copy[perm[i]] : 0;
+ dimensions.set(i, dimension_val);
+ }
+}
+
+/** Permutes given TensorShape according to a permutation vector
+ *
+ * @warning Validity of permutation is not checked
+ *
+ * @param[in, out] shape Shape to permute
+ * @param[in] perm Permutation vector
+ */
+inline void permute(TensorShape &shape, const PermutationVector &perm)
+{
+ auto shape_copy = utility::make_array<TensorShape::num_max_dimensions>(shape.begin(), shape.end());
+ for(unsigned int i = 0; i < perm.num_dimensions(); ++i)
+ {
+ size_t dimension_val = (perm[i] < shape.num_dimensions()) ? shape_copy[perm[i]] : 1;
+ shape.set(i, dimension_val);
}
}