From 5a99ddf2dcf3a5eb49ea85cb8bcc6a43f1496e5e Mon Sep 17 00:00:00 2001 From: Ioan-Cristian Szabo Date: Thu, 26 Oct 2017 16:46:04 +0100 Subject: COMPMID-590: Add transpose_validation to the test framework. Change-Id: I9d7b7b34a742b62278d26503ae81a517c883b373 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/92078 Tested-by: Kaizen Reviewed-by: Pablo Tello --- tests/validation/CPP/Transpose.cpp | 66 ++++++++++++++++++++++++++++++++++++++ tests/validation/CPP/Transpose.h | 43 +++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 tests/validation/CPP/Transpose.cpp create mode 100644 tests/validation/CPP/Transpose.h (limited to 'tests/validation/CPP') diff --git a/tests/validation/CPP/Transpose.cpp b/tests/validation/CPP/Transpose.cpp new file mode 100644 index 0000000000..9f2e62e1aa --- /dev/null +++ b/tests/validation/CPP/Transpose.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "Transpose.h" + +#include "arm_compute/core/Types.h" +#include "tests/validation/FixedPoint.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor transpose(const SimpleTensor &src) +{ + // Make rows the columns of the original shape + TensorShape dst_shape{ src.shape().y(), src.shape().x() }; + + // Create reference + SimpleTensor dst{ dst_shape, src.data_type() }; + + // Compute reference + for(int i = 0; i < src.num_elements(); ++i) + { + const Coordinates coord = index2coord(src.shape(), i); + const Coordinates dst_coord{ coord.y(), coord.x() }; + const size_t dst_index = coord2index(dst.shape(), dst_coord); + + dst[dst_index] = src[i]; + } + + return dst; +} + +template SimpleTensor transpose(const SimpleTensor &src); +template SimpleTensor transpose(const SimpleTensor &src); +template SimpleTensor transpose(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute diff --git a/tests/validation/CPP/Transpose.h b/tests/validation/CPP/Transpose.h new file mode 100644 index 0000000000..3f42f41253 --- /dev/null +++ b/tests/validation/CPP/Transpose.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_TEST_TRANSPOSE_H__ +#define __ARM_COMPUTE_TEST_TRANSPOSE_H__ + +#include "tests/SimpleTensor.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor transpose(const SimpleTensor &src); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_TRANSPOSE_H__ */ -- cgit v1.2.1