aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMoritz Pflanzer <moritz.pflanzer@arm.com>2017-07-18 16:21:16 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-09-17 14:16:42 +0100
commitc7d1503008e74496836f99d64c082d4c9ae8f1ca (patch)
tree0aad8f56fe4c9359b08476bc7e5577fd21c1f6fe /tests
parent81bf196a8ea44be9b42a9f9b6f8eca3f016c36e2 (diff)
downloadComputeLibrary-c7d1503008e74496836f99d64c082d4c9ae8f1ca.tar.gz
COMPMID-415: Build new validation
Change-Id: I7409693f40ba3941b9d90f28c5d292c376e185c5 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/80939 Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/SConscript142
-rw-r--r--tests/main.cpp (renamed from tests/benchmark_new/main.cpp)0
-rw-r--r--tests/validation_new/FixedPoint.h984
-rw-r--r--tests/validation_new/SimpleTensor.h332
-rw-r--r--tests/validation_new/Validation.cpp314
-rw-r--r--tests/validation_new/Validation.h238
6 files changed, 1947 insertions, 63 deletions
diff --git a/tests/SConscript b/tests/SConscript
index 82f95c2099..92a8b59d29 100644
--- a/tests/SConscript
+++ b/tests/SConscript
@@ -42,68 +42,61 @@ for v in variables:
vars.Add(v)
# Clone the environment to make sure we're not polluting the arm_compute one:
-common_env = env.Clone()
-vars.Update(common_env)
+old_validation_env = env.Clone()
+vars.Update(old_validation_env)
-Help(new_options.GenerateHelpText(common_env))
+Help(new_options.GenerateHelpText(old_validation_env))
if env['os'] in ['android', 'bare_metal'] or env['standalone']:
Import('arm_compute_a')
- common_env.Append(LIBS = [arm_compute_a])
+ old_validation_env.Append(LIBS = [arm_compute_a])
arm_compute_lib = arm_compute_a
else:
Import('arm_compute_so')
- common_env.Append(LIBS = ["arm_compute"])
+ old_validation_env.Append(LIBS = ["arm_compute"])
arm_compute_lib = arm_compute_so
#FIXME Delete before release
-if common_env['internal_only']:
- common_env.Append(CPPDEFINES=['INTERNAL_ONLY'])
-
-common_env.Append(CPPPATH = [".", "#3rdparty/include"])
-common_env.Append(LIBPATH = ["#3rdparty/%s/%s" % (env['os'], env['arch'])])
-common_env.Append(LIBPATH = ["#build/%s" % env['build_dir']])
-common_env.Append(LIBPATH = ["#build/%s/opencl-1.2-stubs" % env['build_dir']])
-common_env.Append(LIBS = ['boost_program_options'])
-common_env.Append(CXXFLAGS = ['-Wno-missing-field-initializers'])
-
-validation_env = common_env.Clone()
-
-validation_env.Append(CPPDEFINES=['BOOST'])
-
-files = Glob('*.cpp')
-files = [f for f in files if "DatasetManager" not in os.path.basename(str(f))]
-
-common_objects = [ common_env.StaticObject( f ) for f in files ]
-
-validation_env.Append(LIBS = ['boost_unit_test_framework'])
-
-files_validation = Glob('validation/*.cpp')
+if old_validation_env['internal_only']:
+ old_validation_env.Append(CPPDEFINES=['INTERNAL_ONLY'])
+
+old_validation_env.Append(CPPPATH = [".", "#3rdparty/include"])
+old_validation_env.Append(LIBPATH = ["#3rdparty/%s/%s" % (env['os'], env['arch'])])
+old_validation_env.Append(LIBPATH = ["#build/%s" % env['build_dir']])
+old_validation_env.Append(LIBPATH = ["#build/%s/opencl-1.2-stubs" % env['build_dir']])
+old_validation_env.Append(LIBS = ['boost_program_options'])
+old_validation_env.Append(CXXFLAGS = ['-Wno-missing-field-initializers'])
+old_validation_env.Append(CPPDEFINES=['BOOST'])
+old_validation_env.Append(LIBS = ['boost_unit_test_framework'])
+
+old_files_validation = Glob('*.cpp')
+old_files_validation = [f for f in old_files_validation if "main.cpp" not in os.path.basename(str(f))]
+old_files_validation += Glob('validation/*.cpp')
# Add unit tests
-files_validation += Glob('validation/UNIT/*.cpp')
-files_validation += Glob('validation/UNIT/*/*.cpp')
+old_files_validation += Glob('validation/UNIT/*.cpp')
+old_files_validation += Glob('validation/UNIT/*/*.cpp')
if env['opencl']:
Import('opencl')
- files_validation += Glob('validation/CL/*.cpp')
- files_validation += Glob('validation/CL/*/*.cpp')
- files_validation += Glob('validation/system_tests/CL/*.cpp')
+ old_files_validation += Glob('validation/CL/*.cpp')
+ old_files_validation += Glob('validation/CL/*/*.cpp')
+ old_files_validation += Glob('validation/system_tests/CL/*.cpp')
- validation_env.Append(LIBS = "OpenCL")
+ old_validation_env.Append(LIBS = "OpenCL")
+ old_validation_env.Append(CPPDEFINES=['ARM_COMPUTE_CL'])
if env['neon']:
- files_validation += Glob('validation/NEON/*.cpp')
- files_validation += Glob('validation/NEON/*/*.cpp')
- files_validation += Glob('validation/system_tests/NEON/*.cpp')
+ old_files_validation += Glob('validation/NEON/*.cpp')
+ old_files_validation += Glob('validation/NEON/*/*.cpp')
+ old_files_validation += Glob('validation/system_tests/NEON/*.cpp')
if env['os'] == 'android':
- validation_env.Append(LIBS = ["log"])
+ old_validation_env.Append(LIBS = ["log"])
-if common_env['validation_tests']:
- arm_compute_validation = validation_env.Program('arm_compute_validation',
- files_validation + common_objects)
+if old_validation_env['validation_tests']:
+ arm_compute_validation = old_validation_env.Program('arm_compute_validation', old_files_validation)
Depends(arm_compute_validation, arm_compute_lib)
if env['opencl']:
Depends(arm_compute_validation, opencl)
@@ -115,58 +108,70 @@ if common_env['validation_tests']:
#######################################################################
# Clone the environment to make sure we're not polluting the arm_compute one:
-benchmark_env = env.Clone()
+test_env = env.Clone()
# Workaround to build both test systems in parallel
-benchmark_env.VariantDir("new", ".", duplicate=0)
+test_env.VariantDir("new", ".", duplicate=0)
if env['os'] in ['android', 'bare_metal'] or env['standalone']:
Import("arm_compute_a")
- benchmark_env.Append(LIBS = [arm_compute_a])
+ test_env.Append(LIBS = [arm_compute_a])
arm_compute_lib = arm_compute_a
else:
- Import('arm_compute_so')
- benchmark_env.Append(LIBS = ["arm_compute"])
+ Import("arm_compute_so")
+ test_env.Append(LIBS = ["arm_compute"])
arm_compute_lib = arm_compute_so
#FIXME Delete before release
-if common_env['internal_only']:
- benchmark_env.Append(CPPDEFINES=['INTERNAL_ONLY'])
+if old_validation_env['internal_only']:
+ test_env.Append(CPPDEFINES=['INTERNAL_ONLY'])
-benchmark_env.Append(CPPPATH = [".", "#3rdparty/include"])
-benchmark_env.Append(LIBPATH = ["#3rdparty/%s/%s" % (env['os'], env['arch'])])
-benchmark_env.Append(LIBPATH = ["#build/%s" % env['build_dir']])
-benchmark_env.Append(LIBPATH = ["#build/%s/framework" % env['build_dir']])
-benchmark_env.Append(LIBPATH = ["#build/%s/opencl-1.2-stubs" % env['build_dir']])
+test_env.Append(CPPPATH = [".", "#3rdparty/include"])
+test_env.Append(LIBPATH = ["#3rdparty/%s/%s" % (env['os'], env['arch'])])
+test_env.Append(LIBPATH = ["#build/%s" % env['build_dir']])
+test_env.Append(LIBPATH = ["#build/%s/framework" % env['build_dir']])
+test_env.Append(LIBPATH = ["#build/%s/opencl-1.2-stubs" % env['build_dir']])
Import("arm_compute_test_framework")
-benchmark_env.Append(LIBS = ['arm_compute_test_framework'])
+test_env.Append(LIBS = arm_compute_test_framework)
-files_benchmark = Glob('new/DatasetManager.cpp')
-files_benchmark += Glob('new/AssetsLibrary.cpp')
-files_benchmark += Glob('new/RawTensor.cpp')
-files_benchmark += Glob('new/benchmark_new/*.cpp')
+common_files = Glob('new/AssetsLibrary.cpp')
+common_files += Glob('new/RawTensor.cpp')
+common_files += Glob('new/main.cpp')
+
+common_objects = [test_env.StaticObject(f) for f in common_files]
+
+files_benchmark = Glob('new/benchmark_new/*.cpp')
+files_validation = Glob('new/validation_new/*.cpp')
+
+# Always compile reference for validation
+files_validation += Glob('new/validation_new/CPP/*.cpp')
if env['opencl']:
Import('opencl')
- benchmark_env.Append(CPPDEFINES=['ARM_COMPUTE_CL'])
+ test_env.Append(CPPDEFINES=['ARM_COMPUTE_CL'])
+ test_env.Append(LIBS = ["OpenCL"])
files_benchmark += Glob('new/benchmark_new/CL/*/*.cpp')
files_benchmark += Glob('new/benchmark_new/CL/*.cpp')
- benchmark_env.Append(LIBS = "OpenCL")
+ files_validation += Glob('new/validation_new/CL/*/*.cpp')
+ files_validation += Glob('new/validation_new/CL/*.cpp')
if env['neon']:
files_benchmark += Glob('new/benchmark_new/NEON/*/*.cpp')
files_benchmark += Glob('new/benchmark_new/NEON/*.cpp')
+ files_validation += Glob('new/validation_new/NEON/*/*.cpp')
+ files_validation += Glob('new/validation_new/NEON/*.cpp')
+
if env['os'] == 'android':
- benchmark_env.Append(LIBS = ["log"])
+ test_env.Append(LIBS = ["log"])
else:
- benchmark_env.Append(LIBS = ["rt"])
+ test_env.Append(LIBS = ["rt"])
-if common_env['benchmark_tests']:
- arm_compute_benchmark = benchmark_env.Program('arm_compute_benchmark', files_benchmark)
+if old_validation_env['benchmark_tests']:
+ arm_compute_benchmark = test_env.Program('arm_compute_benchmark', files_benchmark + common_objects)
Depends(arm_compute_benchmark, arm_compute_test_framework)
Depends(arm_compute_benchmark, arm_compute_lib)
@@ -175,3 +180,14 @@ if common_env['benchmark_tests']:
Default(arm_compute_benchmark)
Export('arm_compute_benchmark')
+
+if old_validation_env['validation_tests']:
+ arm_compute_validation_new = test_env.Program('arm_compute_validation_new', files_validation + common_objects)
+ Depends(arm_compute_validation_new, arm_compute_test_framework)
+ Depends(arm_compute_validation_new, arm_compute_lib)
+
+ if env['opencl']:
+ Depends(arm_compute_validation_new, opencl)
+
+ Default(arm_compute_validation_new)
+ Export('arm_compute_validation_new')
diff --git a/tests/benchmark_new/main.cpp b/tests/main.cpp
index 95c2d949cf..95c2d949cf 100644
--- a/tests/benchmark_new/main.cpp
+++ b/tests/main.cpp
diff --git a/tests/validation_new/FixedPoint.h b/tests/validation_new/FixedPoint.h
new file mode 100644
index 0000000000..61d791c54c
--- /dev/null
+++ b/tests/validation_new/FixedPoint.h
@@ -0,0 +1,984 @@
+/*
+ * 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_VALIDATION_FIXEDPOINT_H__
+#define __ARM_COMPUTE_TEST_VALIDATION_FIXEDPOINT_H__
+
+#include "Utils.h"
+#include "support/ToolchainSupport.h"
+
+#include <cassert>
+#include <cstdint>
+#include <cstdlib>
+#include <limits>
+#include <string>
+#include <type_traits>
+
+namespace arm_compute
+{
+namespace test
+{
+namespace fixed_point_arithmetic
+{
+namespace detail
+{
+// Forward declare structs
+struct functions;
+template <typename T>
+struct constant_expr;
+}
+
+/** Fixed point traits */
+namespace traits
+{
+// Promote types
+// *INDENT-OFF*
+// clang-format off
+template <typename T> struct promote { };
+template <> struct promote<uint8_t> { using type = uint16_t; };
+template <> struct promote<int8_t> { using type = int16_t; };
+template <> struct promote<uint16_t> { using type = uint32_t; };
+template <> struct promote<int16_t> { using type = int32_t; };
+template <> struct promote<uint32_t> { using type = uint64_t; };
+template <> struct promote<int32_t> { using type = int64_t; };
+template <> struct promote<uint64_t> { using type = uint64_t; };
+template <> struct promote<int64_t> { using type = int64_t; };
+template <typename T>
+using promote_t = typename promote<T>::type;
+// clang-format on
+// *INDENT-ON*
+}
+
+/** Strongly typed enum class representing the overflow policy */
+enum class OverflowPolicy
+{
+ WRAP, /**< Wrap policy */
+ SATURATE /**< Saturate policy */
+};
+/** Strongly typed enum class representing the rounding policy */
+enum class RoundingPolicy
+{
+ TO_ZERO, /**< Round to zero policy */
+ TO_NEAREST_EVEN /**< Round to nearest even policy */
+};
+
+/** Arbitrary fixed-point arithmetic class */
+template <typename T>
+class fixed_point
+{
+public:
+ // Static Checks
+ static_assert(std::is_integral<T>::value, "Type is not an integer");
+
+ /** Constructor (from different fixed point type)
+ *
+ * @param[in] val Fixed point
+ * @param[in] p Fixed point precision
+ */
+ template <typename U>
+ fixed_point(fixed_point<U> val, uint8_t p)
+ : _value(0), _fixed_point_position(p)
+ {
+ assert(p > 0 && p < std::numeric_limits<T>::digits);
+ T v = 0;
+
+ if(std::numeric_limits<T>::digits < std::numeric_limits<U>::digits)
+ {
+ val.rescale(p);
+ v = detail::constant_expr<T>::saturate_cast(val.raw());
+ }
+ else
+ {
+ auto v_cast = static_cast<fixed_point<T>>(val);
+ v_cast.rescale(p);
+ v = v_cast.raw();
+ }
+ _value = static_cast<T>(v);
+ }
+ /** Constructor (from integer)
+ *
+ * @param[in] val Integer value to be represented as fixed point
+ * @param[in] p Fixed point precision
+ * @param[in] is_raw If true val is a raw fixed point value else an integer
+ */
+ template <typename U, typename = typename std::enable_if<std::is_integral<U>::value>::type>
+ fixed_point(U val, uint8_t p, bool is_raw = false)
+ : _value(val << p), _fixed_point_position(p)
+ {
+ if(is_raw)
+ {
+ _value = val;
+ }
+ }
+ /** Constructor (from float)
+ *
+ * @param[in] val Float value to be represented as fixed point
+ * @param[in] p Fixed point precision
+ */
+ fixed_point(float val, uint8_t p)
+ : _value(detail::constant_expr<T>::to_fixed(val, p)), _fixed_point_position(p)
+ {
+ assert(p > 0 && p < std::numeric_limits<T>::digits);
+ }
+ /** Constructor (from float string)
+ *
+ * @param[in] str Float string to be represented as fixed point
+ * @param[in] p Fixed point precision
+ */
+ fixed_point(std::string str, uint8_t p)
+ : _value(detail::constant_expr<T>::to_fixed(support::cpp11::stof(str), p)), _fixed_point_position(p)
+ {
+ assert(p > 0 && p < std::numeric_limits<T>::digits);
+ }
+ /** Default copy constructor */
+ fixed_point &operator=(const fixed_point &) = default;
+ /** Default move constructor */
+ fixed_point &operator=(fixed_point &&) = default;
+ /** Default copy assignment operator */
+ fixed_point(const fixed_point &) = default;
+ /** Default move assignment operator */
+ fixed_point(fixed_point &&) = default;
+
+ /** Float conversion operator
+ *
+ * @return Float representation of fixed point
+ */
+ operator float() const
+ {
+ return detail::constant_expr<T>::to_float(_value, _fixed_point_position);
+ }
+ /** Integer conversion operator
+ *
+ * @return Integer representation of fixed point
+ */
+ template <typename U, typename = typename std::enable_if<std::is_integral<T>::value>::type>
+ operator U() const
+ {
+ return detail::constant_expr<T>::to_int(_value, _fixed_point_position);
+ }
+ /** Convert to different fixed point of different type but same precision
+ *
+ * @note Down-conversion might fail.
+ */
+ template <typename U>
+ operator fixed_point<U>()
+ {
+ U val = static_cast<U>(_value);
+ if(std::numeric_limits<U>::digits < std::numeric_limits<T>::digits)
+ {
+ val = detail::constant_expr<U>::saturate_cast(_value);
+ }
+ return fixed_point<U>(val, _fixed_point_position, true);
+ }
+
+ /** Arithmetic += assignment operator
+ *
+ * @param[in] rhs Fixed point operand
+ *
+ * @return Reference to this fixed point
+ */
+ template <typename U>
+ fixed_point<T> &operator+=(const fixed_point<U> &rhs)
+ {
+ fixed_point<T> val(rhs, _fixed_point_position);
+ _value += val.raw();
+ return *this;
+ }
+ /** Arithmetic -= assignment operator
+ *
+ * @param[in] rhs Fixed point operand
+ *
+ * @return Reference to this fixed point
+ */
+ template <typename U>
+ fixed_point<T> &operator-=(const fixed_point<U> &rhs)
+ {
+ fixed_point<T> val(rhs, _fixed_point_position);
+ _value -= val.raw();
+ return *this;
+ }
+
+ /** Raw value accessor
+ *
+ * @return Raw fixed point value
+ */
+ T raw() const
+ {
+ return _value;
+ }
+ /** Precision accessor
+ *
+ * @return Precision of fixed point
+ */
+ uint8_t precision() const
+ {
+ return _fixed_point_position;
+ }
+ /** Rescale a fixed point to a new precision
+ *
+ * @param[in] p New fixed point precision
+ */
+ void rescale(uint8_t p)
+ {
+ assert(p > 0 && p < std::numeric_limits<T>::digits);
+
+ using promoted_T = typename traits::promote<T>::type;
+ promoted_T val = _value;
+ if(p > _fixed_point_position)
+ {
+ val <<= (p - _fixed_point_position);
+ }
+ else if(p < _fixed_point_position)
+ {
+ uint8_t pbar = _fixed_point_position - p;
+ val += (pbar != 0) ? (1 << (pbar - 1)) : 0;
+ val >>= pbar;
+ }
+
+ _value = detail::constant_expr<T>::saturate_cast(val);
+ _fixed_point_position = p;
+ }
+
+private:
+ T _value; /**< Fixed point raw value */
+ uint8_t _fixed_point_position; /**< Fixed point precision */
+};
+
+namespace detail
+{
+/** Count the number of leading zero bits in the given value.
+ *
+ * @param[in] value Input value.
+ *
+ * @return Number of leading zero bits.
+ */
+template <typename T>
+constexpr int clz(T value)
+{
+ using unsigned_T = typename std::make_unsigned<T>::type;
+ // __builtin_clz is available for int. Need to correct reported number to
+ // match the original type.
+ return __builtin_clz(value) - (32 - std::numeric_limits<unsigned_T>::digits);
+}
+
+template <typename T>
+struct constant_expr
+{
+ /** Calculate representation of 1 in fixed point given a fixed point precision
+ *
+ * @param[in] p Fixed point precision
+ *
+ * @return Representation of value 1 in fixed point.
+ */
+ static constexpr T fixed_one(uint8_t p)
+ {
+ return (1 << p);
+ }
+ /** Calculate fixed point precision step given a fixed point precision
+ *
+ * @param[in] p Fixed point precision
+ *
+ * @return Fixed point precision step
+ */
+ static constexpr float fixed_step(uint8_t p)
+ {
+ return (1.0f / static_cast<float>(1 << p));
+ }
+
+ /** Convert a fixed point value to float given its precision.
+ *
+ * @param[in] val Fixed point value
+ * @param[in] p Fixed point precision
+ *
+ * @return Float representation of the fixed point number
+ */
+ static constexpr float to_float(T val, uint8_t p)
+ {
+ return static_cast<float>(val * fixed_step(p));
+ }
+ /** Convert a fixed point value to integer given its precision.
+ *
+ * @param[in] val Fixed point value
+ * @param[in] p Fixed point precision
+ *
+ * @return Integer of the fixed point number
+ */
+ static constexpr T to_int(T val, uint8_t p)
+ {
+ return val >> p;
+ }
+ /** Convert a single precision floating point value to a fixed point representation given its precision.
+ *
+ * @param[in] val Floating point value
+ * @param[in] p Fixed point precision
+ *
+ * @return The raw fixed point representation
+ */
+ static constexpr T to_fixed(float val, uint8_t p)
+ {
+ return static_cast<T>(saturate_cast<float>(val * fixed_one(p) + ((val >= 0) ? 0.5 : -0.5)));
+ }
+ /** Clamp value between two ranges
+ *
+ * @param[in] val Value to clamp
+ * @param[in] min Minimum value to clamp to
+ * @param[in] max Maximum value to clamp to
+ *
+ * @return clamped value
+ */
+ static constexpr T clamp(T val, T min, T max)
+ {
+ return std::min(std::max(val, min), max);
+ }
+ /** Saturate given number
+ *
+ * @param[in] val Value to saturate
+ *
+ * @return Saturated value
+ */
+ template <typename U>
+ static constexpr T saturate_cast(U val)
+ {
+ return static_cast<T>(std::min<U>(std::max<U>(val, static_cast<U>(std::numeric_limits<T>::min())), static_cast<U>(std::numeric_limits<T>::max())));
+ }
+};
+struct functions
+{
+ /** Output stream operator
+ *
+ * @param[in] s Output stream
+ * @param[in] x Fixed point value
+ *
+ * @return Reference output to updated stream
+ */
+ template <typename T, typename U, typename traits>
+ static std::basic_ostream<T, traits> &write(std::basic_ostream<T, traits> &s, fixed_point<U> &x)
+ {
+ return s << static_cast<float>(x);
+ }
+ /** Signbit of a fixed point number.
+ *
+ * @param[in] x Fixed point number
+ *
+ * @return True if negative else false.
+ */
+ template <typename T>
+ static bool signbit(fixed_point<T> x)
+ {
+ return ((x.raw() >> std::numeric_limits<T>::digits) != 0);
+ }
+ /** Checks if two fixed point numbers are equal
+ *
+ * @param[in] x First fixed point operand
+ * @param[in] y Second fixed point operand
+ *
+ * @return True if fixed points are equal else false
+ */
+ template <typename T>
+ static bool isequal(fixed_point<T> x, fixed_point<T> y)
+ {
+ uint8_t p = std::min(x.precision(), y.precision());
+ x.rescale(p);
+ y.rescale(p);
+ return (x.raw() == y.raw());
+ }
+ /** Checks if two fixed point number are not equal
+ *
+ * @param[in] x First fixed point operand
+ * @param[in] y Second fixed point operand
+ *
+ * @return True if fixed points are not equal else false
+ */
+ template <typename T>
+ static bool isnotequal(fixed_point<T> x, fixed_point<T> y)
+ {
+ return !isequal(x, y);
+ }
+ /** Checks if one fixed point is greater than the other
+ *
+ * @param[in] x First fixed point operand
+ * @param[in] y Second fixed point operand
+ *
+ * @return True if fixed point is greater than other
+ */
+ template <typename T>
+ static bool isgreater(fixed_point<T> x, fixed_point<T> y)
+ {
+ uint8_t p = std::min(x.precision(), y.precision());
+ x.rescale(p);
+ y.rescale(p);
+ return (x.raw() > y.raw());
+ }
+ /** Checks if one fixed point is greater or equal than the other
+ *
+ * @param[in] x First fixed point operand
+ * @param[in] y Second fixed point operand
+ *
+ * @return True if fixed point is greater or equal than other
+ */
+ template <typename T>
+ static bool isgreaterequal(fixed_point<T> x, fixed_point<T> y)
+ {
+ uint8_t p = std::min(x.precision(), y.precision());
+ x.rescale(p);
+ y.rescale(p);
+ return (x.raw() >= y.raw());
+ }
+ /** Checks if one fixed point is less than the other
+ *
+ * @param[in] x First fixed point operand
+ * @param[in] y Second fixed point operand
+ *
+ * @return True if fixed point is less than other
+ */
+ template <typename T>
+ static bool isless(fixed_point<T> x, fixed_point<T> y)
+ {
+ uint8_t p = std::min(x.precision(), y.precision());
+ x.rescale(p);
+ y.rescale(p);
+ return (x.raw() < y.raw());
+ }
+ /** Checks if one fixed point is less or equal than the other
+ *
+ * @param[in] x First fixed point operand
+ * @param[in] y Second fixed point operand
+ *
+ * @return True if fixed point is less or equal than other
+ */
+ template <typename T>
+ static bool islessequal(fixed_point<T> x, fixed_point<T> y)
+ {
+ uint8_t p = std::min(x.precision(), y.precision());
+ x.rescale(p);
+ y.rescale(p);
+ return (x.raw() <= y.raw());
+ }
+ /** Checks if one fixed point is less or greater than the other
+ *
+ * @param[in] x First fixed point operand
+ * @param[in] y Second fixed point operand
+ *
+ * @return True if fixed point is less or greater than other
+ */
+ template <typename T>
+ static bool islessgreater(fixed_point<T> x, fixed_point<T> y)
+ {
+ return isnotequal(x, y);
+ }
+ /** Clamp fixed point to specific range.
+ *
+ * @param[in] x Fixed point operand
+ * @param[in] min Minimum value to clamp to
+ * @param[in] max Maximum value to clamp to
+ *
+ * @return Clamped result
+ */
+ template <typename T>
+ static fixed_point<T> clamp(fixed_point<T> x, T min, T max)
+ {
+ return fixed_point<T>(constant_expr<T>::clamp(x.raw(), min, max), x.precision(), true);
+ }
+ /** Negate number
+ *
+ * @param[in] x Fixed point operand
+ *
+ * @return Negated fixed point result
+ */
+ template <OverflowPolicy OP = OverflowPolicy::SATURATE, typename T>
+ static fixed_point<T> negate(fixed_point<T> x)
+ {
+ using promoted_T = typename traits::promote<T>::type;
+ promoted_T val = -x.raw();
+ if(OP == OverflowPolicy::SATURATE)
+ {
+ val = constant_expr<T>::saturate_cast(val);
+ }
+ return fixed_point<T>(static_cast<T>(val), x.precision(), true);
+ }
+ /** Perform addition among two fixed point numbers
+ *
+ * @param[in] x First fixed point operand
+ * @param[in] y Second fixed point operand
+ *
+ * @return Result fixed point with precision equal to minimum precision of both operands
+ */
+ template <OverflowPolicy OP = OverflowPolicy::SATURATE, typename T>
+ static fixed_point<T> add(fixed_point<T> x, fixed_point<T> y)
+ {
+ uint8_t p = std::min(x.precision(), y.precision());
+ x.rescale(p);
+ y.rescale(p);
+ if(OP == OverflowPolicy::SATURATE)
+ {
+ using type = typename traits::promote<T>::type;
+ type val = static_cast<type>(x.raw()) + static_cast<type>(y.raw());
+ val = constant_expr<T>::saturate_cast(val);
+ return fixed_point<T>(static_cast<T>(val), p, true);
+ }
+ else
+ {
+ return fixed_point<T>(x.raw() + y.raw(), p, true);
+ }
+ }
+ /** Perform subtraction among two fixed point numbers
+ *
+ * @param[in] x First fixed point operand
+ * @param[in] y Second fixed point operand
+ *
+ * @return Result fixed point with precision equal to minimum precision of both operands
+ */
+ template <OverflowPolicy OP = OverflowPolicy::SATURATE, typename T>
+ static fixed_point<T> sub(fixed_point<T> x, fixed_point<T> y)
+ {
+ uint8_t p = std::min(x.precision(), y.precision());
+ x.rescale(p);
+ y.rescale(p);
+ if(OP == OverflowPolicy::SATURATE)
+ {
+ using type = typename traits::promote<T>::type;
+ type val = static_cast<type>(x.raw()) - static_cast<type>(y.raw());
+ val = constant_expr<T>::saturate_cast(val);
+ return fixed_point<T>(static_cast<T>(val), p, true);
+ }
+ else
+ {
+ return fixed_point<T>(x.raw() - y.raw(), p, true);
+ }
+ }
+ /** Perform multiplication among two fixed point numbers
+ *
+ * @param[in] x First fixed point operand
+ * @param[in] y Second fixed point operand
+ *
+ * @return Result fixed point with precision equal to minimum precision of both operands
+ */
+ template <OverflowPolicy OP = OverflowPolicy::SATURATE, typename T>
+ static fixed_point<T> mul(fixed_point<T> x, fixed_point<T> y)
+ {
+ using promoted_T = typename traits::promote<T>::type;
+ uint8_t p_min = std::min(x.precision(), y.precision());
+ uint8_t p_max = std::max(x.precision(), y.precision());
+ promoted_T round_factor = (1 << (p_max - 1));
+ promoted_T val = ((static_cast<promoted_T>(x.raw()) * static_cast<promoted_T>(y.raw())) + round_factor) >> p_max;
+ if(OP == OverflowPolicy::SATURATE)
+ {
+ val = constant_expr<T>::saturate_cast(val);
+ }
+ return fixed_point<T>(static_cast<T>(val), p_min, true);
+ }
+ /** Perform division among two fixed point numbers
+ *
+ * @param[in] x First fixed point operand
+ * @param[in] y Second fixed point operand
+ *
+ * @return Result fixed point with precision equal to minimum precision of both operands
+ */
+ template <OverflowPolicy OP = OverflowPolicy::SATURATE, typename T>
+ static fixed_point<T> div(fixed_point<T> x, fixed_point<T> y)
+ {
+ using promoted_T = typename traits::promote<T>::type;
+ uint8_t p = std::min(x.precision(), y.precision());
+ promoted_T denom = static_cast<promoted_T>(y.raw());
+ if(denom != 0)
+ {
+ promoted_T val = (static_cast<promoted_T>(x.raw()) << std::max(x.precision(), y.precision())) / denom;
+ if(OP == OverflowPolicy::SATURATE)
+ {
+ val = constant_expr<T>::saturate_cast(val);
+ }
+ return fixed_point<T>(static_cast<T>(val), p, true);
+ }
+ else
+ {
+ T val = (x.raw() < 0) ? std::numeric_limits<T>::min() : std::numeric_limits<T>::max();
+ return fixed_point<T>(val, p, true);
+ }
+ }
+ /** Shift left
+ *
+ * @param[in] x Fixed point operand
+ * @param[in] shift Shift value
+ *
+ * @return Shifted value
+ */
+ template <OverflowPolicy OP = OverflowPolicy::SATURATE, typename T>
+ static fixed_point<T> shift_left(fixed_point<T> x, size_t shift)
+ {
+ using promoted_T = typename traits::promote<T>::type;
+ promoted_T val = static_cast<promoted_T>(x.raw()) << shift;
+ if(OP == OverflowPolicy::SATURATE)
+ {
+ val = constant_expr<T>::saturate_cast(val);
+ }
+ return fixed_point<T>(static_cast<T>(val), x.precision(), true);
+ }
+ /** Shift right
+ *
+ * @param[in] x Fixed point operand
+ * @param[in] shift Shift value
+ *
+ * @return Shifted value
+ */
+ template <typename T>
+ static fixed_point<T> shift_right(fixed_point<T> x, size_t shift)
+ {
+ return fixed_point<T>(x.raw() >> shift, x.precision(), true);
+ }
+ /** Calculate absolute value
+ *
+ * @param[in] x Fixed point operand
+ *
+ * @return Absolute value of operand
+ */
+ template <typename T>
+ static fixed_point<T> abs(fixed_point<T> x)
+ {
+ using promoted_T = typename traits::promote<T>::type;
+ T val = (x.raw() < 0) ? constant_expr<T>::saturate_cast(-static_cast<promoted_T>(x.raw())) : x.raw();
+ return fixed_point<T>(val, x.precision(), true);
+ }
+ /** Calculate the logarithm of a fixed point number
+ *
+ * @param[in] x Fixed point operand
+ *
+ * @return Logarithm value of operand
+ */
+ template <typename T>
+ static fixed_point<T> log(fixed_point<T> x)
+ {
+ uint8_t p = x.precision();
+ auto const_one = fixed_point<T>(static_cast<T>(1), p);
+
+ // Logarithm of 1 is zero and logarithm of negative values is not defined in R, so return 0.
+ // Also, log(x) == -log(1/x) for 0 < x < 1.
+ if(isequal(x, const_one) || islessequal(x, fixed_point<T>(static_cast<T>(0), p)))
+ {
+ return fixed_point<T>(static_cast<T>(0), p, true);
+ }
+ else if(isless(x, const_one))
+ {
+ return mul(log(div(const_one, x)), fixed_point<T>(-1, p));
+ }
+
+ // Remove even powers of 2
+ T shift_val = 31 - __builtin_clz(x.raw() >> p);
+ x = shift_right(x, shift_val);
+ x = sub(x, const_one);
+
+ // Constants
+ auto ln2 = fixed_point<T>(0.6931471, p);
+ auto A = fixed_point<T>(1.4384189, p);
+ auto B = fixed_point<T>(-0.67719, p);
+ auto C = fixed_point<T>(0.3218538, p);
+ auto D = fixed_point<T>(-0.0832229, p);
+
+ // Polynomial expansion
+ auto sum = add(mul(x, D), C);
+ sum = add(mul(x, sum), B);
+ sum = add(mul(x, sum), A);
+ sum = mul(x, sum);
+
+ return mul(add(sum, fixed_point<T>(static_cast<T>(shift_val), p)), ln2);
+ }
+ /** Calculate the exponential of a fixed point number.
+ *
+ * exp(x) = exp(floor(x)) * exp(x - floor(x))
+ * = pow(2, floor(x) / ln(2)) * exp(x - floor(x))
+ * = exp(x - floor(x)) << (floor(x) / ln(2))
+ *
+ * @param[in] x Fixed point operand
+ *
+ * @return Exponential value of operand
+ */
+ template <typename T>
+ static fixed_point<T> exp(fixed_point<T> x)
+ {
+ uint8_t p = x.precision();
+ // Constants
+ auto const_one = fixed_point<T>(1, p);
+ auto ln2 = fixed_point<T>(0.6931471, p);
+ auto inv_ln2 = fixed_point<T>(1.442695, p);
+ auto A = fixed_point<T>(0.9978546, p);
+ auto B = fixed_point<T>(0.4994721, p);
+ auto C = fixed_point<T>(0.1763723, p);
+ auto D = fixed_point<T>(0.0435108, p);
+
+ T scaled_int_part = detail::constant_expr<T>::to_int(mul(x, inv_ln2).raw(), p);
+
+ // Polynomial expansion
+ auto frac_part = sub(x, mul(ln2, fixed_point<T>(scaled_int_part, p)));
+ auto taylor = add(mul(frac_part, D), C);
+ taylor = add(mul(frac_part, taylor), B);
+ taylor = add(mul(frac_part, taylor), A);
+ taylor = mul(frac_part, taylor);
+ taylor = add(taylor, const_one);
+
+ // Saturate value
+ if(static_cast<T>(clz(taylor.raw())) <= scaled_int_part)
+ {
+ return fixed_point<T>(std::numeric_limits<T>::max(), p, true);
+ }
+
+ return (scaled_int_part < 0) ? shift_right(taylor, -scaled_int_part) : shift_left(taylor, scaled_int_part);
+ }
+ /** Calculate the inverse square root of a fixed point number
+ *
+ * @param[in] x Fixed point operand
+ *
+ * @return Inverse square root value of operand
+ */
+ template <typename T>
+ static fixed_point<T> inv_sqrt(fixed_point<T> x)
+ {
+ const uint8_t p = x.precision();
+ int8_t shift = std::numeric_limits<T>::digits - (p + detail::clz(x.raw()));
+
+ shift += std::numeric_limits<T>::is_signed ? 1 : 0;
+
+ // Use volatile to restrict compiler optimizations on shift as compiler reports maybe-uninitialized error on Android
+ volatile int8_t *shift_ptr = &shift;
+
+ auto const_three = fixed_point<T>(3, p);
+ auto a = (*shift_ptr < 0) ? shift_left(x, -(shift)) : shift_right(x, shift);
+ fixed_point<T> x2 = a;
+
+ // We need three iterations to find the result for QS8 and five for QS16
+ constexpr int num_iterations = std::is_same<T, int8_t>::value ? 3 : 5;
+ for(int i = 0; i < num_iterations; ++i)
+ {
+ fixed_point<T> three_minus_dx = sub(const_three, mul(a, mul(x2, x2)));
+ x2 = shift_right(mul(x2, three_minus_dx), 1);
+ }
+
+ return (shift < 0) ? shift_left(x2, (-shift) >> 1) : shift_right(x2, shift >> 1);
+ }
+ /** Calculate the hyperbolic tangent of a fixed point number
+ *
+ * @param[in] x Fixed point operand
+ *
+ * @return Hyperbolic tangent of the operand
+ */
+ template <typename T>
+ static fixed_point<T> tanh(fixed_point<T> x)
+ {
+ uint8_t p = x.precision();
+ // Constants
+ auto const_one = fixed_point<T>(1, p);
+ auto const_two = fixed_point<T>(2, p);
+
+ auto exp2x = exp(const_two * x);
+ auto num = exp2x - const_one;
+ auto den = exp2x + const_one;
+ auto tanh = num / den;
+
+ return tanh;
+ }
+ /** Calculate the a-th power of a fixed point number.
+ *
+ * The power is computed as x^a = e^(log(x) * a)
+ *
+ * @param[in] x Fixed point operand
+ * @param[in] a Fixed point exponent
+ *
+ * @return a-th power of the operand
+ */
+ template <typename T>
+ static fixed_point<T> pow(fixed_point<T> x, fixed_point<T> a)
+ {
+ return exp(log(x) * a);
+ }
+};
+
+template <typename T>
+bool operator==(const fixed_point<T> &lhs, const fixed_point<T> &rhs)
+{
+ return functions::isequal(lhs, rhs);
+}
+template <typename T>
+bool operator!=(const fixed_point<T> &lhs, const fixed_point<T> &rhs)
+{
+ return !operator==(lhs, rhs);
+}
+template <typename T>
+bool operator<(const fixed_point<T> &lhs, const fixed_point<T> &rhs)
+{
+ return functions::isless(lhs, rhs);
+}
+template <typename T>
+bool operator>(const fixed_point<T> &lhs, const fixed_point<T> &rhs)
+{
+ return operator<(rhs, lhs);
+}
+template <typename T>
+bool operator<=(const fixed_point<T> &lhs, const fixed_point<T> &rhs)
+{
+ return !operator>(lhs, rhs);
+}
+template <typename T>
+bool operator>=(const fixed_point<T> &lhs, const fixed_point<T> &rhs)
+{
+ return !operator<(lhs, rhs);
+}
+template <typename T>
+fixed_point<T> operator+(const fixed_point<T> &lhs, const fixed_point<T> &rhs)
+{
+ return functions::add(lhs, rhs);
+}
+template <typename T>
+fixed_point<T> operator-(const fixed_point<T> &lhs, const fixed_point<T> &rhs)
+{
+ return functions::sub(lhs, rhs);
+}
+template <typename T>
+fixed_point<T> operator-(const fixed_point<T> &rhs)
+{
+ return functions::negate(rhs);
+}
+template <typename T>
+fixed_point<T> operator*(fixed_point<T> x, fixed_point<T> y)
+{
+ return functions::mul(x, y);
+}
+template <typename T>
+fixed_point<T> operator/(fixed_point<T> x, fixed_point<T> y)
+{
+ return functions::div(x, y);
+}
+template <typename T>
+fixed_point<T> operator>>(fixed_point<T> x, size_t shift)
+{
+ return functions::shift_right(x, shift);
+}
+template <typename T>
+fixed_point<T> operator<<(fixed_point<T> x, size_t shift)
+{
+ return functions::shift_left(x, shift);
+}
+template <typename T, typename U, typename traits>
+std::basic_ostream<T, traits> &operator<<(std::basic_ostream<T, traits> &s, fixed_point<U> x)
+{
+ return functions::write(s, x);
+}
+template <typename T>
+inline fixed_point<T> min(fixed_point<T> x, fixed_point<T> y)
+{
+ return x > y ? y : x;
+}
+template <typename T>
+inline fixed_point<T> max(fixed_point<T> x, fixed_point<T> y)
+{
+ return x > y ? x : y;
+}
+template <OverflowPolicy OP = OverflowPolicy::SATURATE, typename T>
+inline fixed_point<T> add(fixed_point<T> x, fixed_point<T> y)
+{
+ return functions::add<OP>(x, y);
+}
+template <OverflowPolicy OP = OverflowPolicy::SATURATE, typename T>
+inline fixed_point<T> sub(fixed_point<T> x, fixed_point<T> y)
+{
+ return functions::sub<OP>(x, y);
+}
+template <OverflowPolicy OP = OverflowPolicy::SATURATE, typename T>
+inline fixed_point<T> mul(fixed_point<T> x, fixed_point<T> y)
+{
+ return functions::mul<OP>(x, y);
+}
+template <typename T>
+inline fixed_point<T> div(fixed_point<T> x, fixed_point<T> y)
+{
+ return functions::div(x, y);
+}
+template <typename T>
+inline fixed_point<T> abs(fixed_point<T> x)
+{
+ return functions::abs(x);
+}
+template <typename T>
+inline fixed_point<T> clamp(fixed_point<T> x, T min, T max)
+{
+ return functions::clamp(x, min, max);
+}
+template <typename T>
+inline fixed_point<T> exp(fixed_point<T> x)
+{
+ return functions::exp(x);
+}
+template <typename T>
+inline fixed_point<T> log(fixed_point<T> x)
+{
+ return functions::log(x);
+}
+template <typename T>
+inline fixed_point<T> inv_sqrt(fixed_point<T> x)
+{
+ return functions::inv_sqrt(x);
+}
+template <typename T>
+inline fixed_point<T> tanh(fixed_point<T> x)
+{
+ return functions::tanh(x);
+}
+template <typename T>
+inline fixed_point<T> pow(fixed_point<T> x, fixed_point<T> a)
+{
+ return functions::pow(x, a);
+}
+} // namespace detail
+
+// Expose operators
+using detail::operator==;
+using detail::operator!=;
+using detail::operator<;
+using detail::operator>;
+using detail::operator<=;
+using detail::operator>=;
+using detail::operator+;
+using detail::operator-;
+using detail::operator*;
+using detail::operator/;
+using detail::operator>>;
+using detail::operator<<;
+
+// Expose additional functions
+using detail::min;
+using detail::max;
+using detail::add;
+using detail::sub;
+using detail::mul;
+using detail::div;
+using detail::abs;
+using detail::clamp;
+using detail::exp;
+using detail::log;
+using detail::inv_sqrt;
+using detail::tanh;
+using detail::pow;
+// TODO: floor
+// TODO: ceil
+// TODO: sqrt
+} // namespace fixed_point_arithmetic
+} // namespace test
+} // namespace arm_compute
+#endif /*__ARM_COMPUTE_TEST_VALIDATION_FIXEDPOINT_H__ */
diff --git a/tests/validation_new/SimpleTensor.h b/tests/validation_new/SimpleTensor.h
new file mode 100644
index 0000000000..6392e38e25
--- /dev/null
+++ b/tests/validation_new/SimpleTensor.h
@@ -0,0 +1,332 @@
+/*
+ * 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_SIMPLE_TENSOR_H__
+#define __ARM_COMPUTE_TEST_SIMPLE_TENSOR_H__
+
+#include "arm_compute/core/TensorShape.h"
+#include "arm_compute/core/Types.h"
+#include "arm_compute/core/Utils.h"
+#include "support/ToolchainSupport.h"
+#include "tests/IAccessor.h"
+#include "tests/Utils.h"
+
+#include <algorithm>
+#include <array>
+#include <cstddef>
+#include <cstdint>
+#include <functional>
+#include <memory>
+#include <stdexcept>
+#include <utility>
+
+namespace arm_compute
+{
+namespace test
+{
+/** Simple tensor object that stores elements in a consecutive chunk of memory.
+ *
+ * It can be created by either loading an image from a file which also
+ * initialises the content of the tensor or by explcitly specifying the size.
+ * The latter leaves the content uninitialised.
+ *
+ * Furthermore, the class provides methods to convert the tensor's values into
+ * different image format.
+ */
+template <typename T>
+class SimpleTensor final : public IAccessor
+{
+public:
+ /** Create an uninitialised tensor. */
+ SimpleTensor() = default;
+
+ /** Create an uninitialised tensor of the given @p shape and @p format.
+ *
+ * @param[in] shape Shape of the new raw tensor.
+ * @param[in] format Format of the new raw tensor.
+ * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of the fixed point numbers
+ */
+ SimpleTensor(TensorShape shape, Format format, int fixed_point_position = 0);
+
+ /** Create an uninitialised tensor of the given @p shape and @p data type.
+ *
+ * @param[in] shape Shape of the new raw tensor.
+ * @param[in] data_type Data type of the new raw tensor.
+ * @param[in] num_channels (Optional) Number of channels (default = 1).
+ * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of the fixed point numbers (default = 0).
+ */
+ SimpleTensor(TensorShape shape, DataType data_type, int num_channels = 1, int fixed_point_position = 0);
+
+ /** Create a deep copy of the given @p tensor.
+ *
+ * @param[in] tensor To be copied tensor.
+ */
+ SimpleTensor(const SimpleTensor &tensor);
+
+ /** Create a deep copy of the given @p tensor.
+ *
+ * @param[in] tensor To be copied tensor.
+ */
+ SimpleTensor &operator =(SimpleTensor tensor);
+ SimpleTensor(SimpleTensor &&) = default;
+ ~SimpleTensor() = default;
+
+ using value_type = T;
+ using Buffer = std::unique_ptr<value_type[]>;
+
+ /** Return value at @p offset in the buffer.
+ *
+ * @param[in] offset Offset within the buffer.
+ */
+ T &operator[](size_t offset);
+
+ /** Return constant value at @p offset in the buffer.
+ *
+ * @param[in] offset Offset within the buffer.
+ */
+ const T &operator[](size_t offset) const;
+
+ /** Shape of the tensor. */
+ TensorShape shape() const override;
+
+ /** Size of each element in the tensor in bytes. */
+ size_t element_size() const override;
+
+ /** Total size of the tensor in bytes. */
+ size_t size() const override;
+
+ /** Image format of the tensor. */
+ Format format() const override;
+
+ /** Data type of the tensor. */
+ DataType data_type() const override;
+
+ /** Number of channels of the tensor. */
+ int num_channels() const override;
+
+ /** Number of elements of the tensor. */
+ int num_elements() const override;
+
+ /** The number of bits for the fractional part of the fixed point numbers. */
+ int fixed_point_position() const override;
+
+ /** Constant pointer to the underlying buffer. */
+ const T *data() const;
+
+ /** Pointer to the underlying buffer. */
+ T *data();
+
+ /** Read only access to the specified element.
+ *
+ * @param[in] coord Coordinates of the desired element.
+ *
+ * @return A pointer to the desired element.
+ */
+ const void *operator()(const Coordinates &coord) const override;
+
+ /** Access to the specified element.
+ *
+ * @param[in] coord Coordinates of the desired element.
+ *
+ * @return A pointer to the desired element.
+ */
+ void *operator()(const Coordinates &coord) override;
+
+ /** Swaps the content of the provided tensors.
+ *
+ * @param[in, out] tensor1 Tensor to be swapped.
+ * @param[in, out] tensor2 Tensor to be swapped.
+ */
+ template <typename U>
+ friend void swap(SimpleTensor<U> &tensor1, SimpleTensor<U> &tensor2);
+
+private:
+ Buffer _buffer{ nullptr };
+ TensorShape _shape{};
+ Format _format{ Format::UNKNOWN };
+ DataType _data_type{ DataType::UNKNOWN };
+ int _num_channels{ 0 };
+ int _fixed_point_position{ 0 };
+};
+
+template <typename T>
+SimpleTensor<T>::SimpleTensor(TensorShape shape, Format format, int fixed_point_position)
+ : _buffer(nullptr),
+ _shape(shape),
+ _format(format),
+ _fixed_point_position(fixed_point_position)
+{
+ _buffer = support::cpp14::make_unique<T[]>(num_elements() * num_channels());
+}
+
+template <typename T>
+SimpleTensor<T>::SimpleTensor(TensorShape shape, DataType data_type, int num_channels, int fixed_point_position)
+ : _buffer(nullptr),
+ _shape(shape),
+ _data_type(data_type),
+ _num_channels(num_channels),
+ _fixed_point_position(fixed_point_position)
+{
+ _buffer = support::cpp14::make_unique<T[]>(num_elements() * this->num_channels());
+}
+
+template <typename T>
+SimpleTensor<T>::SimpleTensor(const SimpleTensor &tensor)
+ : _buffer(nullptr),
+ _shape(tensor.shape()),
+ _format(tensor.format()),
+ _fixed_point_position(tensor.fixed_point_position())
+{
+ _buffer = support::cpp14::make_unique<T[]>(tensor.num_elements() * num_channels());
+ std::copy_n(tensor.data(), num_elements() * num_channels(), _buffer.get());
+}
+
+template <typename T>
+SimpleTensor<T> &SimpleTensor<T>::operator=(SimpleTensor tensor)
+{
+ swap(*this, tensor);
+
+ return *this;
+}
+
+template <typename T>
+T &SimpleTensor<T>::operator[](size_t offset)
+{
+ return _buffer[offset];
+}
+
+template <typename T>
+const T &SimpleTensor<T>::operator[](size_t offset) const
+{
+ return _buffer[offset];
+}
+
+template <typename T>
+TensorShape SimpleTensor<T>::shape() const
+{
+ return _shape;
+}
+
+template <typename T>
+size_t SimpleTensor<T>::element_size() const
+{
+ return num_channels() * element_size_from_data_type(data_type());
+}
+
+template <typename T>
+int SimpleTensor<T>::fixed_point_position() const
+{
+ return _fixed_point_position;
+}
+
+template <typename T>
+size_t SimpleTensor<T>::size() const
+{
+ const size_t size = std::accumulate(_shape.cbegin(), _shape.cend(), 1, std::multiplies<size_t>());
+ return size * element_size();
+}
+
+template <typename T>
+Format SimpleTensor<T>::format() const
+{
+ return _format;
+}
+
+template <typename T>
+DataType SimpleTensor<T>::data_type() const
+{
+ if(_format != Format::UNKNOWN)
+ {
+ return data_type_from_format(_format);
+ }
+ else
+ {
+ return _data_type;
+ }
+}
+
+template <typename T>
+int SimpleTensor<T>::num_channels() const
+{
+ switch(_format)
+ {
+ case Format::U8:
+ case Format::S16:
+ case Format::U16:
+ case Format::S32:
+ case Format::U32:
+ return 1;
+ case Format::RGB888:
+ return 3;
+ case Format::UNKNOWN:
+ return _num_channels;
+ default:
+ ARM_COMPUTE_ERROR("NOT SUPPORTED!");
+ }
+}
+
+template <typename T>
+int SimpleTensor<T>::num_elements() const
+{
+ return _shape.total_size();
+}
+
+template <typename T>
+const T *SimpleTensor<T>::data() const
+{
+ return _buffer.get();
+}
+
+template <typename T>
+T *SimpleTensor<T>::data()
+{
+ return _buffer.get();
+}
+
+template <typename T>
+const void *SimpleTensor<T>::operator()(const Coordinates &coord) const
+{
+ return _buffer.get() + coord2index(_shape, coord);
+}
+
+template <typename T>
+void *SimpleTensor<T>::operator()(const Coordinates &coord)
+{
+ return _buffer.get() + coord2index(_shape, coord);
+}
+
+template <typename U>
+void swap(SimpleTensor<U> &tensor1, SimpleTensor<U> &tensor2)
+{
+ // Use unqualified call to swap to enable ADL. But make std::swap available
+ // as backup.
+ using std::swap;
+ swap(tensor1._shape, tensor2._shape);
+ swap(tensor1._format, tensor2._format);
+ swap(tensor1._data_type, tensor2._data_type);
+ swap(tensor1._num_channels, tensor2._num_channels);
+ swap(tensor1._buffer, tensor2._buffer);
+}
+} // namespace test
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_TEST_SIMPLE_TENSOR_H__ */
diff --git a/tests/validation_new/Validation.cpp b/tests/validation_new/Validation.cpp
new file mode 100644
index 0000000000..9daee449c1
--- /dev/null
+++ b/tests/validation_new/Validation.cpp
@@ -0,0 +1,314 @@
+/*
+ * 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 "Validation.h"
+
+#include "arm_compute/core/Coordinates.h"
+#include "arm_compute/core/Error.h"
+#include "arm_compute/core/TensorShape.h"
+#include "arm_compute/runtime/Tensor.h"
+
+#include <array>
+#include <cmath>
+#include <cstddef>
+#include <cstdint>
+
+#ifdef ARM_COMPUTE_ENABLE_FP16
+#include <arm_fp16.h> // needed for float16_t
+#endif /* ARM_COMPUTE_ENABLE_FP16 */
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+namespace
+{
+/** Get the data from *ptr after casting according to @p data_type and then convert the data to double.
+ *
+ * @param[in] ptr Pointer to value.
+ * @param[in] data_type Data type of both values.
+ *
+ * @return The data from the ptr after converted to double.
+ */
+double get_double_data(const void *ptr, DataType data_type)
+{
+ if(ptr == nullptr)
+ {
+ ARM_COMPUTE_ERROR("Can't dereference a null pointer!");
+ }
+
+ switch(data_type)
+ {
+ case DataType::U8:
+ return *reinterpret_cast<const uint8_t *>(ptr);
+ case DataType::S8:
+ return *reinterpret_cast<const int8_t *>(ptr);
+ case DataType::QS8:
+ return *reinterpret_cast<const qint8_t *>(ptr);
+ case DataType::U16:
+ return *reinterpret_cast<const uint16_t *>(ptr);
+ case DataType::S16:
+ return *reinterpret_cast<const int16_t *>(ptr);
+ case DataType::QS16:
+ return *reinterpret_cast<const qint16_t *>(ptr);
+ case DataType::U32:
+ return *reinterpret_cast<const uint32_t *>(ptr);
+ case DataType::S32:
+ return *reinterpret_cast<const int32_t *>(ptr);
+ case DataType::U64:
+ return *reinterpret_cast<const uint64_t *>(ptr);
+ case DataType::S64:
+ return *reinterpret_cast<const int64_t *>(ptr);
+#ifdef ARM_COMPUTE_ENABLE_FP16
+ case DataType::F16:
+ return *reinterpret_cast<const float16_t *>(ptr);
+#endif /* ARM_COMPUTE_ENABLE_FP16 */
+ case DataType::F32:
+ return *reinterpret_cast<const float *>(ptr);
+ case DataType::F64:
+ return *reinterpret_cast<const double *>(ptr);
+ case DataType::SIZET:
+ return *reinterpret_cast<const size_t *>(ptr);
+ default:
+ ARM_COMPUTE_ERROR("NOT SUPPORTED!");
+ }
+}
+
+void check_border_element(const IAccessor &tensor, const Coordinates &id,
+ const BorderMode &border_mode, const void *border_value,
+ int64_t &num_elements, int64_t &num_mismatches)
+{
+ const size_t channel_size = element_size_from_data_type(tensor.data_type());
+ const auto ptr = static_cast<const uint8_t *>(tensor(id));
+
+ if(border_mode == BorderMode::REPLICATE)
+ {
+ Coordinates border_id{ id };
+
+ if(id.x() < 0)
+ {
+ border_id.set(0, 0);
+ }
+ else if(static_cast<size_t>(id.x()) >= tensor.shape().x())
+ {
+ border_id.set(0, tensor.shape().x() - 1);
+ }
+
+ if(id.y() < 0)
+ {
+ border_id.set(1, 0);
+ }
+ else if(static_cast<size_t>(id.y()) >= tensor.shape().y())
+ {
+ border_id.set(1, tensor.shape().y() - 1);
+ }
+
+ border_value = tensor(border_id);
+ }
+
+ // Iterate over all channels within one element
+ for(int channel = 0; channel < tensor.num_channels(); ++channel)
+ {
+ const size_t channel_offset = channel * channel_size;
+ const double target = get_double_data(ptr + channel_offset, tensor.data_type());
+ const double ref = get_double_data(static_cast<const uint8_t *>(border_value) + channel_offset, tensor.data_type());
+ const bool equal = is_equal(target, ref);
+
+ ARM_COMPUTE_TEST_INFO("id = " << id);
+ ARM_COMPUTE_TEST_INFO("channel = " << channel);
+ ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << target);
+ ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << ref);
+ ARM_COMPUTE_EXPECT_EQUAL(target, ref);
+
+ if(!equal)
+ {
+ ++num_mismatches;
+ }
+
+ ++num_elements;
+ }
+}
+} // namespace
+
+void validate(const arm_compute::ValidRegion &region, const arm_compute::ValidRegion &reference)
+{
+ ARM_COMPUTE_EXPECT_EQUAL(region.anchor.num_dimensions(), reference.anchor.num_dimensions());
+ ARM_COMPUTE_EXPECT_EQUAL(region.shape.num_dimensions(), reference.shape.num_dimensions());
+
+ for(unsigned int d = 0; d < region.anchor.num_dimensions(); ++d)
+ {
+ ARM_COMPUTE_EXPECT_EQUAL(region.anchor[d], reference.anchor[d]);
+ }
+
+ for(unsigned int d = 0; d < region.shape.num_dimensions(); ++d)
+ {
+ ARM_COMPUTE_EXPECT_EQUAL(region.shape[d], reference.shape[d]);
+ }
+}
+
+void validate(const arm_compute::PaddingSize &padding, const arm_compute::PaddingSize &reference)
+{
+ ARM_COMPUTE_EXPECT_EQUAL(padding.top, reference.top);
+ ARM_COMPUTE_EXPECT_EQUAL(padding.right, reference.right);
+ ARM_COMPUTE_EXPECT_EQUAL(padding.bottom, reference.bottom);
+ ARM_COMPUTE_EXPECT_EQUAL(padding.left, reference.left);
+}
+
+void validate(const IAccessor &tensor, const void *reference_value)
+{
+ ARM_COMPUTE_ASSERT(reference_value != nullptr);
+
+ int64_t num_mismatches = 0;
+ int64_t num_elements = 0;
+ const size_t channel_size = element_size_from_data_type(tensor.data_type());
+
+ // Iterate over all elements, e.g. U8, S16, RGB888, ...
+ for(int element_idx = 0; element_idx < tensor.num_elements(); ++element_idx)
+ {
+ const Coordinates id = index2coord(tensor.shape(), element_idx);
+
+ const auto ptr = static_cast<const uint8_t *>(tensor(id));
+
+ // Iterate over all channels within one element
+ for(int channel = 0; channel < tensor.num_channels(); ++channel)
+ {
+ const size_t channel_offset = channel * channel_size;
+ const double target = get_double_data(ptr + channel_offset, tensor.data_type());
+ const double ref = get_double_data(reference_value, tensor.data_type());
+ const bool equal = is_equal(target, ref);
+
+ ARM_COMPUTE_TEST_INFO("id = " << id);
+ ARM_COMPUTE_TEST_INFO("channel = " << channel);
+ ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << target);
+ ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << ref);
+ ARM_COMPUTE_EXPECT_EQUAL(target, ref);
+
+ if(!equal)
+ {
+ ++num_mismatches;
+ }
+
+ ++num_elements;
+ }
+ }
+
+ if(num_elements > 0)
+ {
+ const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f;
+
+ ARM_COMPUTE_TEST_INFO(num_mismatches << " values (" << std::setprecision(2) << percent_mismatches << "%) mismatched");
+ ARM_COMPUTE_EXPECT_EQUAL(num_mismatches, 0);
+ }
+}
+
+void validate(const IAccessor &tensor, BorderSize border_size, const BorderMode &border_mode, const void *border_value)
+{
+ if(border_mode == BorderMode::UNDEFINED)
+ {
+ return;
+ }
+ else if(border_mode == BorderMode::CONSTANT)
+ {
+ ARM_COMPUTE_ASSERT(border_value != nullptr);
+ }
+
+ int64_t num_mismatches = 0;
+ int64_t num_elements = 0;
+ const int slice_size = tensor.shape()[0] * tensor.shape()[1];
+
+ for(int element_idx = 0; element_idx < tensor.num_elements(); element_idx += slice_size)
+ {
+ Coordinates id = index2coord(tensor.shape(), element_idx);
+
+ // Top border
+ for(int y = -border_size.top; y < 0; ++y)
+ {
+ id.set(1, y);
+
+ for(int x = -border_size.left; x < static_cast<int>(tensor.shape()[0]) + static_cast<int>(border_size.right); ++x)
+ {
+ id.set(0, x);
+
+ check_border_element(tensor, id, border_mode, border_value, num_elements, num_mismatches);
+ }
+ }
+
+ // Bottom border
+ for(int y = tensor.shape()[1]; y < static_cast<int>(tensor.shape()[1]) + static_cast<int>(border_size.bottom); ++y)
+ {
+ id.set(1, y);
+
+ for(int x = -border_size.left; x < static_cast<int>(tensor.shape()[0]) + static_cast<int>(border_size.right); ++x)
+ {
+ id.set(0, x);
+
+ check_border_element(tensor, id, border_mode, border_value, num_elements, num_mismatches);
+ }
+ }
+
+ // Left/right border
+ for(int y = 0; y < static_cast<int>(tensor.shape()[1]); ++y)
+ {
+ id.set(1, y);
+
+ // Left border
+ for(int x = -border_size.left; x < 0; ++x)
+ {
+ id.set(0, x);
+
+ check_border_element(tensor, id, border_mode, border_value, num_elements, num_mismatches);
+ }
+
+ // Right border
+ for(int x = tensor.shape()[0]; x < static_cast<int>(tensor.shape()[0]) + static_cast<int>(border_size.right); ++x)
+ {
+ id.set(0, x);
+
+ check_border_element(tensor, id, border_mode, border_value, num_elements, num_mismatches);
+ }
+ }
+ }
+
+ if(num_elements > 0)
+ {
+ const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f;
+
+ ARM_COMPUTE_TEST_INFO(num_mismatches << " values (" << std::setprecision(2) << percent_mismatches << "%) mismatched");
+ ARM_COMPUTE_EXPECT_EQUAL(num_mismatches, 0);
+ }
+}
+
+void validate(std::vector<unsigned int> classified_labels, std::vector<unsigned int> expected_labels)
+{
+ ARM_COMPUTE_EXPECT_EQUAL(classified_labels.size(), expected_labels.size());
+
+ for(unsigned int i = 0; i < expected_labels.size(); ++i)
+ {
+ ARM_COMPUTE_EXPECT_EQUAL(classified_labels[i], expected_labels[i]);
+ }
+}
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
diff --git a/tests/validation_new/Validation.h b/tests/validation_new/Validation.h
new file mode 100644
index 0000000000..fd8a79d238
--- /dev/null
+++ b/tests/validation_new/Validation.h
@@ -0,0 +1,238 @@
+/*
+ * 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_VALIDATION_H__
+#define __ARM_COMPUTE_TEST_VALIDATION_H__
+
+#include "SimpleTensor.h"
+#include "arm_compute/core/FixedPoint.h"
+#include "arm_compute/core/Types.h"
+#include "framework/Asserts.h"
+#include "tests/IAccessor.h"
+#include "tests/TypePrinter.h"
+#include "tests/Utils.h"
+
+#include <iomanip>
+#include <vector>
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+template <typename T>
+bool compare_dimensions(const Dimensions<T> &dimensions1, const Dimensions<T> &dimensions2)
+{
+ if(dimensions1.num_dimensions() != dimensions2.num_dimensions())
+ {
+ return false;
+ }
+
+ for(unsigned int i = 0; i < dimensions1.num_dimensions(); ++i)
+ {
+ if(dimensions1[i] != dimensions2[i])
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+/** Validate valid regions.
+ *
+ * - Dimensionality has to be the same.
+ * - Anchors have to match.
+ * - Shapes have to match.
+ */
+void validate(const arm_compute::ValidRegion &region, const arm_compute::ValidRegion &reference);
+
+/** Validate padding.
+ *
+ * Padding on all sides has to be the same.
+ */
+void validate(const arm_compute::PaddingSize &padding, const arm_compute::PaddingSize &reference);
+
+/** Validate tensors.
+ *
+ * - Dimensionality has to be the same.
+ * - All values have to match.
+ *
+ * @note: wrap_range allows cases where reference tensor rounds up to the wrapping point, causing it to wrap around to
+ * zero while the test tensor stays at wrapping point to pass. This may permit true erroneous cases (difference between
+ * reference tensor and test tensor is multiple of wrap_range), but such errors would be detected by
+ * other test cases.
+ */
+template <typename T, typename U>
+void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, U tolerance_value = 0, float tolerance_number = 0.f);
+
+/** Validate tensors with valid region.
+ *
+ * - Dimensionality has to be the same.
+ * - All values have to match.
+ *
+ * @note: wrap_range allows cases where reference tensor rounds up to the wrapping point, causing it to wrap around to
+ * zero while the test tensor stays at wrapping point to pass. This may permit true erroneous cases (difference between
+ * reference tensor and test tensor is multiple of wrap_range), but such errors would be detected by
+ * other test cases.
+ */
+template <typename T, typename U>
+void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, const ValidRegion &valid_region, U tolerance_value = 0, float tolerance_number = 0.f);
+
+/** Validate tensors against constant value.
+ *
+ * - All values have to match.
+ */
+void validate(const IAccessor &tensor, const void *reference_value);
+
+/** Validate border against a constant value.
+ *
+ * - All border values have to match the specified value if mode is CONSTANT.
+ * - All border values have to be replicated if mode is REPLICATE.
+ * - Nothing is validated for mode UNDEFINED.
+ */
+void validate(const IAccessor &tensor, BorderSize border_size, const BorderMode &border_mode, const void *border_value);
+
+/** Validate classified labels against expected ones.
+ *
+ * - All values should match
+ */
+void validate(std::vector<unsigned int> classified_labels, std::vector<unsigned int> expected_labels);
+
+/** Validate float value.
+ *
+ * - All values should match
+ */
+template <typename T, typename U = T>
+void validate(T target, T ref, U tolerance_abs_error = std::numeric_limits<T>::epsilon(), double tolerance_relative_error = 0.0001f);
+
+template <typename T, typename U = T>
+bool is_equal(T target, T ref, U max_absolute_error = std::numeric_limits<T>::epsilon(), double max_relative_error = 0.0001f)
+{
+ if(!std::isfinite(target) || !std::isfinite(ref))
+ {
+ return false;
+ }
+
+ // No need further check if they are equal
+ if(ref == target)
+ {
+ return true;
+ }
+
+ // Need this check for the situation when the two values close to zero but have different sign
+ if(std::abs(std::abs(ref) - std::abs(target)) <= max_absolute_error)
+ {
+ return true;
+ }
+
+ double relative_error = 0;
+
+ if(std::abs(target) > std::abs(ref))
+ {
+ relative_error = std::abs(static_cast<double>(target - ref) / target);
+ }
+ else
+ {
+ relative_error = std::abs(static_cast<double>(ref - target) / ref);
+ }
+
+ return relative_error <= max_relative_error;
+}
+
+template <typename T, typename U>
+void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, U tolerance_value, float tolerance_number)
+{
+ // Validate with valid region covering the entire shape
+ validate(tensor, reference, shape_to_valid_region(tensor.shape()), tolerance_value, tolerance_number);
+}
+
+template <typename T, typename U>
+void validate(const IAccessor &tensor, const SimpleTensor<T> &reference, const ValidRegion &valid_region, U tolerance_value, float tolerance_number)
+{
+ int64_t num_mismatches = 0;
+ int64_t num_elements = 0;
+
+ ARM_COMPUTE_EXPECT_EQUAL(tensor.element_size(), reference.element_size());
+ ARM_COMPUTE_EXPECT_EQUAL(tensor.format(), reference.format());
+ ARM_COMPUTE_EXPECT_EQUAL(tensor.data_type(), reference.data_type());
+ ARM_COMPUTE_EXPECT_EQUAL(tensor.num_channels(), reference.num_channels());
+ ARM_COMPUTE_EXPECT(compare_dimensions(tensor.shape(), reference.shape()));
+
+ const int min_elements = std::min(tensor.num_elements(), reference.num_elements());
+ const int min_channels = std::min(tensor.num_channels(), reference.num_channels());
+
+ // Iterate over all elements within valid region, e.g. U8, S16, RGB888, ...
+ for(int element_idx = 0; element_idx < min_elements; ++element_idx)
+ {
+ const Coordinates id = index2coord(reference.shape(), element_idx);
+
+ if(is_in_valid_region(valid_region, id))
+ {
+ // Iterate over all channels within one element
+ for(int c = 0; c < min_channels; ++c)
+ {
+ const T &target_value = reinterpret_cast<const T *>(tensor(id))[c];
+ const T &reference_value = reinterpret_cast<const T *>(reference(id))[c];
+
+ if(!is_equal(target_value, reference_value, tolerance_value))
+ {
+ ARM_COMPUTE_TEST_INFO("id = " << id);
+ ARM_COMPUTE_TEST_INFO("channel = " << c);
+ ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << target_value);
+ ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << reference_value);
+ ARM_COMPUTE_EXPECT_EQUAL(target_value, reference_value);
+
+ ++num_mismatches;
+ }
+
+ ++num_elements;
+ }
+ }
+ }
+
+ if(num_elements > 0)
+ {
+ const int64_t absolute_tolerance_number = tolerance_number * num_elements;
+ const float percent_mismatches = static_cast<float>(num_mismatches) / num_elements * 100.f;
+
+ ARM_COMPUTE_TEST_INFO(num_mismatches << " values (" << std::setprecision(2) << percent_mismatches
+ << "%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number << "%)");
+ ARM_COMPUTE_EXPECT(num_mismatches <= absolute_tolerance_number);
+ }
+}
+
+template <typename T, typename U>
+void validate(T target, T ref, U tolerance_abs_error, double tolerance_relative_error)
+{
+ const bool equal = is_equal(target, ref, tolerance_abs_error, tolerance_relative_error);
+
+ ARM_COMPUTE_TEST_INFO("reference = " << std::setprecision(5) << ref);
+ ARM_COMPUTE_TEST_INFO("target = " << std::setprecision(5) << target);
+ ARM_COMPUTE_EXPECT(equal);
+}
+} // namespace validation
+} // namespace test
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_TEST_REFERENCE_VALIDATION_H__ */