aboutsummaryrefslogtreecommitdiff
path: root/tests/validation/reference/BatchToSpaceLayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/validation/reference/BatchToSpaceLayer.cpp')
-rw-r--r--tests/validation/reference/BatchToSpaceLayer.cpp51
1 files changed, 29 insertions, 22 deletions
diff --git a/tests/validation/reference/BatchToSpaceLayer.cpp b/tests/validation/reference/BatchToSpaceLayer.cpp
index 404ee73cac..63d121f59b 100644
--- a/tests/validation/reference/BatchToSpaceLayer.cpp
+++ b/tests/validation/reference/BatchToSpaceLayer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018 Arm Limited.
+ * Copyright (c) 2018, 2023 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -23,8 +23,10 @@
*/
#include "BatchToSpaceLayer.h"
+#include "arm_compute/core/Validate.h"
#include "tests/validation/Helpers.h"
+#include "arm_compute/core/utils/misc/ShapeCalculator.h"
namespace arm_compute
{
namespace test
@@ -35,32 +37,37 @@ namespace reference
{
// Batch to Space
template <typename T>
-SimpleTensor<T> batch_to_space(const SimpleTensor<T> &src, const SimpleTensor<int32_t> &block_shape, const TensorShape &dst_shape)
+SimpleTensor<T> batch_to_space(const SimpleTensor<T> &src, const std::vector<int32_t> &block_shape, const CropInfo &crop_info, const TensorShape &dst_shape)
{
- ARM_COMPUTE_ERROR_ON(block_shape[0] <= 0);
- ARM_COMPUTE_ERROR_ON(block_shape[1] <= 0);
- SimpleTensor<T> result(dst_shape, src.data_type());
+ ARM_COMPUTE_ERROR_ON(block_shape[0] < 1);
+ ARM_COMPUTE_ERROR_ON(block_shape[1] < 1);
+ const auto expected_dst_shape = misc::shape_calculator::compute_batch_to_space_shape(DataLayout::NCHW, src.shape(), block_shape[0], block_shape[1], crop_info);
+ ARM_COMPUTE_ERROR_ON(arm_compute::detail::have_different_dimensions(expected_dst_shape, dst_shape, 0));
+ ARM_COMPUTE_UNUSED(expected_dst_shape);
- int in_pos = 0;
- const auto width_in = static_cast<int>(src.shape()[0]);
- const auto height_in = static_cast<int>(src.shape()[1]);
- const auto z_in = static_cast<int>(src.shape()[2]);
- const auto batch_in = static_cast<int>(src.shape()[3]);
+ SimpleTensor<T> result(dst_shape, src.data_type());
+ int out_pos = 0;
+ const auto width_out = static_cast<int>(dst_shape[0]);
+ const auto height_out = static_cast<int>(dst_shape[1]);
+ const auto z_out = static_cast<int>(dst_shape[2]);
+ const auto batch_out = static_cast<int>(dst_shape[3]);
- for(int batch = 0; batch < batch_in; ++batch)
+ for(int batch = 0; batch < batch_out; ++batch)
{
- for(int z = 0; z < z_in; ++z)
+ for(int z = 0; z < z_out; ++z)
{
- for(int y = 0; y < height_in; ++y)
+ for(int y = 0; y < height_out; ++y)
{
- for(int x = 0; x < width_in; ++x)
+ for(int x = 0; x < width_out; ++x)
{
- const int r = src.shape()[3] / (block_shape[0] * block_shape[1]);
- const int out_x = (block_shape[0] * x + (batch / r) % block_shape[0]);
- const int out_y = (block_shape[1] * y + (batch / r) / block_shape[0]);
- const int out_pos = out_x + dst_shape[0] * out_y + z * dst_shape[0] * dst_shape[1] + (batch % r) * dst_shape[0] * dst_shape[1] * dst_shape[2];
- result[out_pos] = src[in_pos];
- ++in_pos;
+ const int x_c = x + crop_info.left;
+ const int y_c = y + crop_info.top;
+ const int in_batch = batch + ((x_c % block_shape[0]) + (y_c % block_shape[1]) * (block_shape[0])) * dst_shape[3];
+ const int in_x = x_c / block_shape[0];
+ const int in_y = y_c / block_shape[1];
+ const int in_pos = in_x + src.shape()[0] * in_y + z * src.shape()[0] * src.shape()[1] + in_batch * src.shape()[0] * src.shape()[1] * src.shape()[2];
+ result[out_pos] = src[in_pos];
+ ++out_pos;
}
}
}
@@ -68,8 +75,8 @@ SimpleTensor<T> batch_to_space(const SimpleTensor<T> &src, const SimpleTensor<in
return result;
}
-template SimpleTensor<float> batch_to_space(const SimpleTensor<float> &src, const SimpleTensor<int32_t> &block_shape, const TensorShape &dst_shape);
-template SimpleTensor<half> batch_to_space(const SimpleTensor<half> &src, const SimpleTensor<int32_t> &block_shape, const TensorShape &dst_shape);
+template SimpleTensor<float> batch_to_space(const SimpleTensor<float> &src, const std::vector<int32_t> &block_shape, const CropInfo &crop_info, const TensorShape &dst_shape);
+template SimpleTensor<half> batch_to_space(const SimpleTensor<half> &src, const std::vector<int32_t> &block_shape, const CropInfo &crop_info, const TensorShape &dst_shape);
} // namespace reference
} // namespace validation
} // namespace test