aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/core/Helpers.inl
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2017-09-07 17:29:16 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:35:24 +0000
commit5ee66eae5dff60f615dfe9427cf1c4116d95f478 (patch)
treef2922f584deb20e92404edcd6fba14f6df59c0d8 /arm_compute/core/Helpers.inl
parentce54b56e0d91a8e73f3ecfede6a2b2aa323aa1fd (diff)
downloadComputeLibrary-5ee66eae5dff60f615dfe9427cf1c4116d95f478.tar.gz
COMPMID-462: Implement TensorReshape for NEON and CL.
Change-Id: I11b39c2ceca26ade73822e29a384ef866ae05729 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/87707 Reviewed-by: Pablo Tello <pablo.tello@arm.com> Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com>
Diffstat (limited to 'arm_compute/core/Helpers.inl')
-rw-r--r--arm_compute/core/Helpers.inl37
1 files changed, 37 insertions, 0 deletions
diff --git a/arm_compute/core/Helpers.inl b/arm_compute/core/Helpers.inl
index e20bdb58a1..c2ca3b44b3 100644
--- a/arm_compute/core/Helpers.inl
+++ b/arm_compute/core/Helpers.inl
@@ -333,4 +333,41 @@ inline ValidRegion calculate_valid_region_scale(const ITensorInfo &src_info, con
return ValidRegion(std::move(anchor), std::move(new_dst_shape));
}
+
+inline Coordinates index2coords(const TensorShape &shape, int index)
+{
+ int num_elements = shape.total_size();
+
+ ARM_COMPUTE_ERROR_ON_MSG(index < 0 || index >= num_elements, "Index has to be in [0, num_elements]!");
+ ARM_COMPUTE_ERROR_ON_MSG(num_elements == 0, "Cannot create coordinate from empty shape!");
+
+ Coordinates coord{ 0 };
+
+ for(int d = shape.num_dimensions() - 1; d >= 0; --d)
+ {
+ num_elements /= shape[d];
+ coord.set(d, index / num_elements);
+ index %= num_elements;
+ }
+
+ return coord;
+}
+
+inline int coords2index(const TensorShape &shape, const Coordinates &coord)
+{
+ int num_elements = shape.total_size();
+ ARM_COMPUTE_UNUSED(num_elements);
+ ARM_COMPUTE_ERROR_ON_MSG(num_elements == 0, "Cannot create linear index from empty shape!");
+
+ int index = 0;
+ int stride = 1;
+
+ for(unsigned int d = 0; d < coord.num_dimensions(); ++d)
+ {
+ index += coord[d] * stride;
+ stride *= shape[d];
+ }
+
+ return index;
+}
} // namespace arm_compute