From a2611815f278334c801094d095901d36e111c3f9 Mon Sep 17 00:00:00 2001 From: Giorgio Arena Date: Fri, 21 Jul 2017 10:08:48 +0100 Subject: COMPMID-417 NEON/CL MeanStdDev bugfix using FillBorderKernel Change-Id: Ic48ba7f69783d0e1e80611264e2bc67d1732436e Reviewed-on: http://mpd-gerrit.cambridge.arm.com/81293 Reviewed-by: Anthony Barbier Tested-by: Kaizen --- tests/AssetsLibrary.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/AssetsLibrary.h') diff --git a/tests/AssetsLibrary.h b/tests/AssetsLibrary.h index 3dd30e7629..18ffd773c8 100644 --- a/tests/AssetsLibrary.h +++ b/tests/AssetsLibrary.h @@ -150,6 +150,15 @@ public: */ RawTensor get(const std::string &name, Format format, Channel channel); + /** Puts garbage values all around the tensor for testing purposes + * + * @param[in, out] tensor To be filled tensor. + * @param[in] distribution Distribution used to fill the tensor's surroundings. + * @param[in] seed_offset The offset will be added to the global seed before initialising the random generator. + */ + template + void fill_borders_with_garbage(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const; + /** Fills the specified @p tensor with random values drawn from @p * distribution. * @@ -347,6 +356,32 @@ private: std::random_device::result_type _seed; }; +template +void AssetsLibrary::fill_borders_with_garbage(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const +{ + const PaddingSize padding_size = tensor.padding(); + + Window window; + window.set(0, Window::Dimension(-padding_size.left, tensor.shape()[0] + padding_size.right, 1)); + window.set(1, Window::Dimension(-padding_size.top, tensor.shape()[1] + padding_size.bottom, 1)); + + std::mt19937 gen(_seed); + + execute_window_loop(window, [&](const Coordinates & id) + { + TensorShape shape = tensor.shape(); + + // If outside of valid region + if(id.x() < 0 || id.x() >= static_cast(shape.x()) || id.y() < 0 || id.y() >= static_cast(shape.y())) + { + using ResultType = typename std::remove_reference::type::result_type; + const ResultType value = distribution(gen); + void *const out_ptr = tensor(id); + store_value_with_data_type(out_ptr, value, tensor.data_type()); + } + }); +} + template void AssetsLibrary::fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const { @@ -366,6 +401,8 @@ void AssetsLibrary::fill(T &&tensor, D &&distribution, std::random_device::resul void *const out_ptr = tensor(id); store_value_with_data_type(out_ptr, value, tensor.data_type()); }); + + fill_borders_with_garbage(tensor, distribution, seed_offset); } template -- cgit v1.2.1