From ef4b4ae784f7533ed6d9e7b51827a894c32ed48e Mon Sep 17 00:00:00 2001 From: Michele Di Giorgio Date: Tue, 4 Jul 2017 17:19:43 +0100 Subject: COMPMID-438: Add support for floating point Min-Max Location layer. Change-Id: I84ae564a40fc7320a6f94a84d53906ba51404f51 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/79797 Reviewed-by: Anthony Barbier Tested-by: Kaizen --- tests/validation/TensorOperations.h | 46 +++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 15 deletions(-) (limited to 'tests/validation/TensorOperations.h') diff --git a/tests/validation/TensorOperations.h b/tests/validation/TensorOperations.h index a5039a4641..b472e3d5cf 100644 --- a/tests/validation/TensorOperations.h +++ b/tests/validation/TensorOperations.h @@ -305,34 +305,50 @@ void sobel_5x5(Tensor &in, Tensor &out_x, Tensor &out_y, BorderMode } } -// Min max location -template -void min_max_location(const Tensor &in, int32_t &min, int32_t &max, IArray &min_loc, IArray &max_loc, uint32_t &min_count, uint32_t &max_count) +template +void compute_min_max(const Tensor &in, void *min, void *max) { - // Set min and max to first pixel - min = in[0]; - max = in[0]; - min_count = 0; - max_count = 0; + using type = typename std::conditional::value, float, int32_t>::type; - const size_t width = in.shape().x(); + // Set min and max to first pixel + type tmp_min = static_cast(in[0]); + type tmp_max = static_cast(in[0]); // Look for min and max values for(int i = 1; i < in.num_elements(); ++i) { - if(static_cast(in[i]) < min) + if(static_cast(in[i]) < tmp_min) { - min = in[i]; + tmp_min = static_cast(in[i]); } - if(static_cast(in[i]) > max) + if(static_cast(in[i]) > tmp_max) { - max = in[i]; + tmp_max = static_cast(in[i]); } } + *static_cast(min) = tmp_min; + *static_cast(max) = tmp_max; +} + +// Min max location +template +void min_max_location(const Tensor &in, void *min, void *max, IArray &min_loc, IArray &max_loc, uint32_t &min_count, uint32_t &max_count) +{ + const size_t width = in.shape().x(); + + compute_min_max(in, min, max); + + using type = typename std::conditional::value, float, int32_t>::type; + + type min_value = *static_cast(min); + type max_value = *static_cast(max); + + min_count = 0; + max_count = 0; for(int i = 0; i < in.num_elements(); ++i) { - if(static_cast(in[i]) == min) + if(static_cast(in[i]) == min_value) { Coordinates2D min_coord; min_coord.x = static_cast(i % width); @@ -342,7 +358,7 @@ void min_max_location(const Tensor &in, int32_t &min, int32_t &max, IArray(in[i]) == max) + if(static_cast(in[i]) == max_value) { Coordinates2D max_coord; max_coord.x = static_cast(i % width); -- cgit v1.2.1