From 60b2cb26d346c3f2f46aedc5e0663d7252c328e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Podgain=C3=B5i?= Date: Tue, 16 Apr 2024 16:16:01 +0200 Subject: [PATCH 01/12] Handling of returns changed in kleidicv_hal.cpp The other branch related to type conversion doesn't contain a fail-state return. Remove this return to make it uniform. --- adapters/opencv/kleidicv_hal.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/adapters/opencv/kleidicv_hal.cpp b/adapters/opencv/kleidicv_hal.cpp index 7c98dd0fe..cea5dd4af 100644 --- a/adapters/opencv/kleidicv_hal.cpp +++ b/adapters/opencv/kleidicv_hal.cpp @@ -677,7 +677,6 @@ int convertTo(const uchar *src_data, size_t src_step, int src_depth, reinterpret_cast(dst_data), dst_step, width, height, static_cast(scale), static_cast(shift))); } - return CV_HAL_ERROR_NOT_IMPLEMENTED; } // type conversion only -- GitLab From b923b06434485a1ff45ff76b08acbdd35b18f7da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Podgain=C3=B5i?= Date: Tue, 16 Apr 2024 16:20:32 +0200 Subject: [PATCH 02/12] Change "singleton" to "get" in OpenCV conformity tests The term "singleton" here might be confusing and may be assumed to be referring to a class. So change it to "get" and place it at the end of the function names for further readability in the all_tests vector in tests.cpp. --- conformity/opencv/test_float_conv.cpp | 2 +- conformity/opencv/test_float_conv.h | 2 +- conformity/opencv/test_gaussian_blur.cpp | 2 +- conformity/opencv/test_gaussian_blur.h | 2 +- conformity/opencv/test_sobel.cpp | 2 +- conformity/opencv/test_sobel.h | 2 +- conformity/opencv/tests.cpp | 10 +++++----- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/conformity/opencv/test_float_conv.cpp b/conformity/opencv/test_float_conv.cpp index 6b3abfe68..d8385b867 100644 --- a/conformity/opencv/test_float_conv.cpp +++ b/conformity/opencv/test_float_conv.cpp @@ -180,7 +180,7 @@ bool test_int8_to_float32_custom(int index, } #endif -std::vector& float_conversion_tests_singleton() { +std::vector& float_conversion_tests_get() { // clang-format off static std::vector tests = { TEST("Float32 to Signed Int8, fill, 1 channel", (test_float32_to_int8_random), exec_float32_to_int8), diff --git a/conformity/opencv/test_float_conv.h b/conformity/opencv/test_float_conv.h index 1b98d9820..9e4c40be6 100644 --- a/conformity/opencv/test_float_conv.h +++ b/conformity/opencv/test_float_conv.h @@ -9,6 +9,6 @@ #include "tests.h" -std::vector& float_conversion_tests_singleton(); +std::vector& float_conversion_tests_get(); #endif // KLEIDICV_OPENCV_CONFORMITY_TEST_FLOAT_CONV_H_ diff --git a/conformity/opencv/test_gaussian_blur.cpp b/conformity/opencv/test_gaussian_blur.cpp index 27ae51e2d..87dd565dc 100644 --- a/conformity/opencv/test_gaussian_blur.cpp +++ b/conformity/opencv/test_gaussian_blur.cpp @@ -40,7 +40,7 @@ bool test_gaussian_blur(int index, RecreatedMessageQueue& request_queue, } #endif -std::vector& gaussian_blur_tests_singleton() { +std::vector& gaussian_blur_tests_get() { // clang-format off static std::vector tests = { TEST("Gaussian blur 3x3, BORDER_REFLECT_101, 1 channel", (test_gaussian_blur<3, cv::BORDER_REFLECT_101, 1>), (exec_gaussian_blur<3, cv::BORDER_REFLECT_101>)), diff --git a/conformity/opencv/test_gaussian_blur.h b/conformity/opencv/test_gaussian_blur.h index 0756ca4fd..ddc045ed2 100644 --- a/conformity/opencv/test_gaussian_blur.h +++ b/conformity/opencv/test_gaussian_blur.h @@ -9,6 +9,6 @@ #include "tests.h" -std::vector& gaussian_blur_tests_singleton(); +std::vector& gaussian_blur_tests_get(); #endif // KLEIDICV_OPENCV_CONFORMITY_TEST_GAUSSIAN_BLUR_H_ diff --git a/conformity/opencv/test_sobel.cpp b/conformity/opencv/test_sobel.cpp index a87143aa0..473e153a6 100644 --- a/conformity/opencv/test_sobel.cpp +++ b/conformity/opencv/test_sobel.cpp @@ -43,7 +43,7 @@ bool test_sobel(int index, RecreatedMessageQueue& request_queue, } #endif -std::vector& sobel_tests_singleton() { +std::vector& sobel_tests_get() { // clang-format off static std::vector tests = { TEST("Sobel Vertical, 1 channel", (test_sobel), exec_sobel), diff --git a/conformity/opencv/test_sobel.h b/conformity/opencv/test_sobel.h index 6c2bb8b45..131fb3850 100644 --- a/conformity/opencv/test_sobel.h +++ b/conformity/opencv/test_sobel.h @@ -9,6 +9,6 @@ #include "tests.h" -std::vector& sobel_tests_singleton(); +std::vector& sobel_tests_get(); #endif // KLEIDICV_OPENCV_CONFORMITY_TEST_SOBEL_H_ diff --git a/conformity/opencv/tests.cpp b/conformity/opencv/tests.cpp index 596282bfb..c75e653fd 100644 --- a/conformity/opencv/tests.cpp +++ b/conformity/opencv/tests.cpp @@ -46,17 +46,17 @@ template static std::vector merge_tests( std::initializer_list& (*)()> test_groups) { std::vector all_tests; - for (auto singleton : test_groups) { - std::vector& group = singleton(); + for (auto getter : test_groups) { + std::vector& group = getter(); all_tests.insert(all_tests.cend(), group.cbegin(), group.cend()); } return all_tests; } std::vector all_tests = merge_tests({ - sobel_tests_singleton, - gaussian_blur_tests_singleton, - float_conversion_tests_singleton, + sobel_tests_get, + gaussian_blur_tests_get, + float_conversion_tests_get, }); #if MANAGER -- GitLab From 9c5018cc58d1b7fcfd6939590bfcd211a53de251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Podgain=C3=B5i?= Date: Tue, 16 Apr 2024 16:24:44 +0200 Subject: [PATCH 03/12] Remove _ from _floatval and floatval_ Remove the underscore from the beginning and the end of the function name, as it is may not be allowed by the C++ standard. --- conformity/opencv/test_float_conv.cpp | 40 +++++++++++++-------------- test/api/test_float_conv.cpp | 18 ++++++------ 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/conformity/opencv/test_float_conv.cpp b/conformity/opencv/test_float_conv.cpp index d8385b867..bdbca493a 100644 --- a/conformity/opencv/test_float_conv.cpp +++ b/conformity/opencv/test_float_conv.cpp @@ -6,30 +6,30 @@ #include -float floatval_(uint32_t v) { +float floatval(uint32_t v) { static_assert(sizeof(float) == 4); return *reinterpret_cast(&v); } -float quietNaN = floatval_(0x7FC00000); -float signalingNaN = floatval_(0x7FA00000); -float posInfinity = floatval_(0x7F800000); -float negInfinity = floatval_(0xFF800000); - -float minusNaN = floatval_(0xFF800001); -float plusNaN = floatval_(0x7F800001); -float plusZero = floatval_(0x00000000); -float minusZero = floatval_(0x80000000); - -float oneNaN = floatval_(0x7FC00001); -float zeroDivZero = floatval_(0xFFC00000); -float floatMin = floatval_(0x00800000); -float floatMax = floatval_(0x7F7FFFFF); - -float posSubnormalMin = floatval_(0x00000001); -float posSubnormalMax = floatval_(0x007FFFFF); -float negSubnormalMin = floatval_(0x80000001); -float negSubnormalMax = floatval_(0x807FFFFF); +float quietNaN = floatval(0x7FC00000); +float signalingNaN = floatval(0x7FA00000); +float posInfinity = floatval(0x7F800000); +float negInfinity = floatval(0xFF800000); + +float minusNaN = floatval(0xFF800001); +float plusNaN = floatval(0x7F800001); +float plusZero = floatval(0x00000000); +float minusZero = floatval(0x80000000); + +float oneNaN = floatval(0x7FC00001); +float zeroDivZero = floatval(0xFFC00000); +float floatMin = floatval(0x00800000); +float floatMax = floatval(0x7F7FFFFF); + +float posSubnormalMin = floatval(0x00000001); +float posSubnormalMax = floatval(0x007FFFFF); +float negSubnormalMin = floatval(0x80000001); +float negSubnormalMax = floatval(0x807FFFFF); template cv::Mat exec_float32_to_int8(cv::Mat& input) { diff --git a/test/api/test_float_conv.cpp b/test/api/test_float_conv.cpp index 41b60bf49..ed5d571a2 100644 --- a/test/api/test_float_conv.cpp +++ b/test/api/test_float_conv.cpp @@ -75,7 +75,7 @@ class FloatConversionTest final { static constexpr uint32_t negSubnormalMin = 0x80000001; static constexpr uint32_t negSubnormalMax = 0x807FFFFF; - static constexpr float _floatval(uint32_t v) { + static constexpr float floatval(uint32_t v) { static_assert(sizeof(float) == 4); KLEIDICV_NO_STRICT_ALIASING_BEGIN return *reinterpret_cast(&v); @@ -90,10 +90,10 @@ class FloatConversionTest final { // clang-format off 4, 8, {{ - { _floatval(quietNaN), _floatval(signalingNaN), _floatval(posInfinity), _floatval(negInfinity) }, - { _floatval(minusNaN), _floatval(plusNaN), _floatval(plusZero), _floatval(minusZero) }, - { _floatval(oneNaN), _floatval(zeroDivZero), _floatval(floatMin), _floatval(floatMax) }, - { _floatval(posSubnormalMin), _floatval(posSubnormalMax), _floatval(negSubnormalMin), _floatval(negSubnormalMax) }, + { floatval(quietNaN), floatval(signalingNaN), floatval(posInfinity), floatval(negInfinity) }, + { floatval(minusNaN), floatval(plusNaN), floatval(plusZero), floatval(minusZero) }, + { floatval(oneNaN), floatval(zeroDivZero), floatval(floatMin), floatval(floatMax) }, + { floatval(posSubnormalMin), floatval(posSubnormalMax), floatval(negSubnormalMin), floatval(negSubnormalMax) }, { 1111.11, -1112.22, 113.33, 114.44 }, { 111.51, 112.62, 113.73, 114.84 }, { 126.66, 127.11, 128.66, 129.11 }, @@ -122,10 +122,10 @@ class FloatConversionTest final { // clang-format off 4, 8, {{ - { _floatval(quietNaN), _floatval(signalingNaN), _floatval(posInfinity), _floatval(negInfinity) }, - { _floatval(minusNaN), _floatval(plusNaN), _floatval(plusZero), _floatval(minusZero) }, - { _floatval(oneNaN), _floatval(zeroDivZero), _floatval(floatMin), _floatval(floatMax) }, - { _floatval(posSubnormalMin), _floatval(posSubnormalMax), _floatval(negSubnormalMin), _floatval(negSubnormalMax) }, + { floatval(quietNaN), floatval(signalingNaN), floatval(posInfinity), floatval(negInfinity) }, + { floatval(minusNaN), floatval(plusNaN), floatval(plusZero), floatval(minusZero) }, + { floatval(oneNaN), floatval(zeroDivZero), floatval(floatMin), floatval(floatMax) }, + { floatval(posSubnormalMin), floatval(posSubnormalMax), floatval(negSubnormalMin), floatval(negSubnormalMax) }, { 1111.11, -1112.22, 113.33, 114.44 }, { 111.51, 112.62, 113.73, 114.84 }, { 126.66, 127.11, 128.66, 129.11 }, -- GitLab From c387eda74839c3b547021d09dd06e8a5deb4d217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Podgain=C3=B5i?= Date: Tue, 16 Apr 2024 16:31:30 +0200 Subject: [PATCH 04/12] Move merge_tests and all_tests to the top of the file Improve readability, for example, when finding the correct place to add new tests. --- conformity/opencv/tests.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/conformity/opencv/tests.cpp b/conformity/opencv/tests.cpp index c75e653fd..4f38648e0 100644 --- a/conformity/opencv/tests.cpp +++ b/conformity/opencv/tests.cpp @@ -14,6 +14,23 @@ #include "test_gaussian_blur.h" #include "test_sobel.h" +template +static std::vector merge_tests( + std::initializer_list& (*)()> test_groups) { + std::vector all_tests; + for (auto getter : test_groups) { + std::vector& group = getter(); + all_tests.insert(all_tests.cend(), group.cbegin(), group.cend()); + } + return all_tests; +} + +std::vector all_tests = merge_tests({ + sobel_tests_get, + gaussian_blur_tests_get, + float_conversion_tests_get, +}); + #if MANAGER void fail_print_matrices(size_t height, size_t width, cv::Mat& input, cv::Mat& manager_result, cv::Mat& subord_result) { @@ -42,23 +59,6 @@ cv::Mat get_expected_from_subordinate(int index, } #endif -template -static std::vector merge_tests( - std::initializer_list& (*)()> test_groups) { - std::vector all_tests; - for (auto getter : test_groups) { - std::vector& group = getter(); - all_tests.insert(all_tests.cend(), group.cbegin(), group.cend()); - } - return all_tests; -} - -std::vector all_tests = merge_tests({ - sobel_tests_get, - gaussian_blur_tests_get, - float_conversion_tests_get, -}); - #if MANAGER int run_tests(RecreatedMessageQueue& request_queue, RecreatedMessageQueue& reply_queue) { -- GitLab From e79f511e74c3427244284453c6901b325a313cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Podgain=C3=B5i?= Date: Tue, 16 Apr 2024 16:34:29 +0200 Subject: [PATCH 05/12] Adjust the wording of float conversion API's comments * Not all special values are bound to return 0 * Make sure that "width" and "height" are on the same line --- kleidicv/include/kleidicv/kleidicv.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kleidicv/include/kleidicv/kleidicv.h b/kleidicv/include/kleidicv/kleidicv.h index f08c492f9..19297bd0e 100644 --- a/kleidicv/include/kleidicv/kleidicv.h +++ b/kleidicv/include/kleidicv/kleidicv.h @@ -1255,7 +1255,7 @@ KLEIDICV_API_DECLARATION(kleidicv_scale_u8, const uint8_t *src, /// /// Each resulting element is saturated, i.e. it is the smallest/largest /// number of the type of the element if the `src` data type cannot be -/// represented as the `dst` type. In case of special values, such as the +/// represented as the `dst` type. In case of some special values, such as the /// different variations of `NaN`, the result is `0`. Source and destination /// data length is `width` * `height`. Number of elements is limited to @ref /// KLEIDICV_MAX_IMAGE_PIXELS. @@ -1284,8 +1284,8 @@ KLEIDICV_API_DECLARATION(kleidicv_float_conversion_f32_u8, const float *src, /// /// Each resulting element is saturated, i.e. it is the smallest/largest /// number of the type of the element if the `src` data type cannot be -/// represented as the `dst` type. Source and destination data length is `width` -/// * `height`. Number of elements is limited to @ref +/// represented as the `dst` type. Source and destination data length is +/// `width` * `height`. Number of elements is limited to @ref /// KLEIDICV_MAX_IMAGE_PIXELS. /// /// @param src Pointer to the source data. Must be non-null. -- GitLab From f0309a5fe180c86f423fb30ab13c3c87d8e2f56d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Podgain=C3=B5i?= Date: Tue, 16 Apr 2024 16:36:13 +0200 Subject: [PATCH 06/12] Fix "end of class" comments in float_conv_sc.h --- kleidicv/src/conversions/float_conv_sc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kleidicv/src/conversions/float_conv_sc.h b/kleidicv/src/conversions/float_conv_sc.h index fb2b4e85b..e04884112 100644 --- a/kleidicv/src/conversions/float_conv_sc.h +++ b/kleidicv/src/conversions/float_conv_sc.h @@ -90,7 +90,7 @@ class float_conversion_operation { return svcvt_u32_f32_x(pg, src); } -}; // end of class float_conversion_operation +}; // end of class float_conversion_operation template class float_conversion_operation { @@ -142,7 +142,7 @@ class float_conversion_operation { svuint32_t src_vector = svld1ub_u32(pg, src); return svcvt_f32_u32_x(pg, src_vector); } -}; +}; // end of class float_conversion_operation template static kleidicv_error_t float_conversion_sc( -- GitLab From 90b845d86d79cc1104ced4d23e0028362f85b751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Podgain=C3=B5i?= Date: Tue, 16 Apr 2024 16:39:25 +0200 Subject: [PATCH 07/12] Rename KLEIDICV_DIFF_IO_API macro to KLEIDICV_API_DIFFERENT_IO_TYPES This macro seems to be an extension of the normal KLEIDICV_API, so additional words can be added as a suffix. Also, do not shorten words, as it is not an issue for the macro name to be long. --- test/api/test_float_conv.cpp | 18 +++++++++--------- test/framework/utils.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/api/test_float_conv.cpp b/test/api/test_float_conv.cpp index ed5d571a2..0e7fdeb45 100644 --- a/test/api/test_float_conv.cpp +++ b/test/api/test_float_conv.cpp @@ -11,15 +11,15 @@ #include "kleidicv/kleidicv.h" #include "test_config.h" -#define KLEIDICV_float_conversion(I, input_type_name, O, output_type_name) \ - KLEIDICV_DIFF_IO_API( \ - float_conversion, \ - kleidicv_float_conversion_##input_type_name##_##output_type_name, I, O) - -KLEIDICV_float_conversion(float, f32, int8_t, s8); -KLEIDICV_float_conversion(float, f32, uint8_t, u8); -KLEIDICV_float_conversion(int8_t, s8, float, f32); -KLEIDICV_float_conversion(uint8_t, u8, float, f32); +#define KLEIDICV_FLOAT_CONVERSION(itype, itype_name, otype, otype_name) \ + KLEIDICV_API_DIFFERENT_IO_TYPES( \ + float_conversion, kleidicv_float_conversion_##itype_name##_##otype_name, \ + itype, otype) + +KLEIDICV_FLOAT_CONVERSION(float, f32, int8_t, s8); +KLEIDICV_FLOAT_CONVERSION(float, f32, uint8_t, u8); +KLEIDICV_FLOAT_CONVERSION(int8_t, s8, float, f32); +KLEIDICV_FLOAT_CONVERSION(uint8_t, u8, float, f32); template class FloatConversionTest final { diff --git a/test/framework/utils.h b/test/framework/utils.h index 5eefe1fd8..9ee2ea621 100644 --- a/test/framework/utils.h +++ b/test/framework/utils.h @@ -24,7 +24,7 @@ return impl; \ } -#define KLEIDICV_DIFF_IO_API(name, impl, itype, otype) \ +#define KLEIDICV_API_DIFFERENT_IO_TYPES(name, impl, itype, otype) \ template , bool> = true, \ std::enable_if_t, bool> = true> \ -- GitLab From 6e00018fa6bba5701ee7d61a924036983d215702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Podgain=C3=B5i?= Date: Tue, 16 Apr 2024 16:43:56 +0200 Subject: [PATCH 08/12] Adjust spacing in the float conversion test file --- test/api/test_float_conv.cpp | 122 +++++++++++++++++------------------ 1 file changed, 60 insertions(+), 62 deletions(-) diff --git a/test/api/test_float_conv.cpp b/test/api/test_float_conv.cpp index 0e7fdeb45..ed735bcc9 100644 --- a/test/api/test_float_conv.cpp +++ b/test/api/test_float_conv.cpp @@ -88,27 +88,27 @@ class FloatConversionTest final { const Elements& get_custom_elements() { static const Elements kTestElements = { // clang-format off - 4, 8, - {{ - { floatval(quietNaN), floatval(signalingNaN), floatval(posInfinity), floatval(negInfinity) }, - { floatval(minusNaN), floatval(plusNaN), floatval(plusZero), floatval(minusZero) }, - { floatval(oneNaN), floatval(zeroDivZero), floatval(floatMin), floatval(floatMax) }, - { floatval(posSubnormalMin), floatval(posSubnormalMax), floatval(negSubnormalMin), floatval(negSubnormalMax) }, - { 1111.11, -1112.22, 113.33, 114.44 }, - { 111.51, 112.62, 113.73, 114.84 }, - { 126.66, 127.11, 128.66, 129.11 }, - { 11.5, 12.5, -11.5, -12.5 } - }}, - {{ - { 0, 0, 127, -128 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 127 }, - { 0, 0, 0, 0 }, - { 127, -128, 113, 114 }, - { 112, 113, 114, 115 }, - { 127, 127, 127, 127 }, - { 12, 12, -12, -12 } - }} + 4, 8, + {{ + { floatval(quietNaN), floatval(signalingNaN), floatval(posInfinity), floatval(negInfinity) }, + { floatval(minusNaN), floatval(plusNaN), floatval(plusZero), floatval(minusZero) }, + { floatval(oneNaN), floatval(zeroDivZero), floatval(floatMin), floatval(floatMax) }, + { floatval(posSubnormalMin), floatval(posSubnormalMax), floatval(negSubnormalMin), floatval(negSubnormalMax) }, + { 1111.11, -1112.22, 113.33, 114.44 }, + { 111.51, 112.62, 113.73, 114.84 }, + { 126.66, 127.11, 128.66, 129.11 }, + { 11.5, 12.5, -11.5, -12.5 } + }}, + {{ + { 0, 0, 127, -128 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 127 }, + { 0, 0, 0, 0 }, + { 127, -128, 113, 114 }, + { 112, 113, 114, 115 }, + { 127, 127, 127, 127 }, + { 12, 12, -12, -12 } + }} // clang-format on }; return kTestElements; @@ -120,27 +120,27 @@ class FloatConversionTest final { const Elements& get_custom_elements() { static const Elements kTestElements = { // clang-format off - 4, 8, - {{ - { floatval(quietNaN), floatval(signalingNaN), floatval(posInfinity), floatval(negInfinity) }, - { floatval(minusNaN), floatval(plusNaN), floatval(plusZero), floatval(minusZero) }, - { floatval(oneNaN), floatval(zeroDivZero), floatval(floatMin), floatval(floatMax) }, - { floatval(posSubnormalMin), floatval(posSubnormalMax), floatval(negSubnormalMin), floatval(negSubnormalMax) }, - { 1111.11, -1112.22, 113.33, 114.44 }, - { 111.51, 112.62, 113.73, 114.84 }, - { 126.66, 127.11, 128.66, 129.11 }, - { 11.5, 12.5, -11.5, -12.5 } - }}, - {{ - { 0, 0, 255, 0 }, - { 0, 0, 0, 0 }, - { 0, 0, 0, 255 }, - { 0, 0, 0, 0 }, - { 255, 0, 113, 114 }, - { 112, 113, 114, 115 }, - { 127, 127, 129, 129 }, - { 12, 12, 0, 0 } - }} + 4, 8, + {{ + { floatval(quietNaN), floatval(signalingNaN), floatval(posInfinity), floatval(negInfinity) }, + { floatval(minusNaN), floatval(plusNaN), floatval(plusZero), floatval(minusZero) }, + { floatval(oneNaN), floatval(zeroDivZero), floatval(floatMin), floatval(floatMax) }, + { floatval(posSubnormalMin), floatval(posSubnormalMax), floatval(negSubnormalMin), floatval(negSubnormalMax) }, + { 1111.11, -1112.22, 113.33, 114.44 }, + { 111.51, 112.62, 113.73, 114.84 }, + { 126.66, 127.11, 128.66, 129.11 }, + { 11.5, 12.5, -11.5, -12.5 } + }}, + {{ + { 0, 0, 255, 0 }, + { 0, 0, 0, 0 }, + { 0, 0, 0, 255 }, + { 0, 0, 0, 0 }, + { 255, 0, 113, 114 }, + { 112, 113, 114, 115 }, + { 127, 127, 129, 129 }, + { 12, 12, 0, 0 } + }} // clang-format on }; return kTestElements; @@ -151,23 +151,23 @@ class FloatConversionTest final { const Elements& get_custom_elements() { static const Elements kTestElements = { // clang-format off - 4, 6, - {{ - { min(), min(), max() - 1, max() }, - { min(), min(), min(), min() }, - { min(), min(), min(), max() - 1 }, - { max() - 1, max(), 113, 114 }, - { 112, 113, 114, 115 }, - { 12, 12, 12, 12 } - }}, - {{ - { min(), min(), max() - 1.0, max() }, - { min(), min(), min(), min() }, - { min(), min(), min(), max() - 1.0 }, - { max() - 1.0, max(), 113.0, 114.0 }, - { 112.0, 113.0, 114.0, 115.0 }, - { 12.0, 12.0, 12.0, 12.0 } - }} + 4, 6, + {{ + { min(), min(), max() - 1, max() }, + { min(), min(), min(), min() }, + { min(), min(), min(), max() - 1 }, + { max() - 1, max(), 113, 114 }, + { 112, 113, 114, 115 }, + { 12, 12, 12, 12 } + }}, + {{ + { min(), min(), max() - 1.0, max() }, + { min(), min(), min(), min() }, + { min(), min(), min(), max() - 1.0 }, + { max() - 1.0, max(), 113.0, 114.0 }, + { 112.0, 113.0, 114.0, 115.0 }, + { 12.0, 12.0, 12.0, 12.0 } + }} // clang-format on }; return kTestElements; @@ -340,14 +340,12 @@ class FloatConversionTest final { void test_sizes(const size_t width, const size_t height) { auto values_list = get_values(); - test::Array2D source(width, height, 1, 1); + test::Array2D source(width, height, 1, 1); test::Array2D expected(width, height, 1, 1); - test::Array2D actual(width, height, 1, 1); source.fill(values_list.source); - expected.fill(values_list.expected); actual.fill(0); -- GitLab From 22fc96ee16048ca21b69af14a2a851b64c11107c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Podgain=C3=B5i?= Date: Tue, 16 Apr 2024 16:48:24 +0200 Subject: [PATCH 09/12] Add more SFINAE template constraints in float conversion tests --- test/api/test_float_conv.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/api/test_float_conv.cpp b/test/api/test_float_conv.cpp index ed735bcc9..a83e1bc60 100644 --- a/test/api/test_float_conv.cpp +++ b/test/api/test_float_conv.cpp @@ -147,6 +147,7 @@ class FloatConversionTest final { } template , bool> = true, std::enable_if_t, bool> = true> const Elements& get_custom_elements() { static const Elements kTestElements = { @@ -174,7 +175,8 @@ class FloatConversionTest final { } template , bool> = true> + std::enable_if_t, bool> = true, + std::enable_if_t, bool> = true> const Values& get_values() { static const Values kTestValues = { // clang-format off @@ -185,6 +187,7 @@ class FloatConversionTest final { } template , bool> = true, std::enable_if_t, bool> = true> const Values& get_values() { static const Values kTestValues = { -- GitLab From 3db852611668b211ae83674124990df3a34d42a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Podgain=C3=B5i?= Date: Tue, 16 Apr 2024 16:49:47 +0200 Subject: [PATCH 10/12] Use "if constexpr" in some places instead of SFINAE This avoids code duplication. --- test/api/test_float_conv.cpp | 66 +++++++++++------------------------- 1 file changed, 19 insertions(+), 47 deletions(-) diff --git a/test/api/test_float_conv.cpp b/test/api/test_float_conv.cpp index a83e1bc60..7f509b990 100644 --- a/test/api/test_float_conv.cpp +++ b/test/api/test_float_conv.cpp @@ -244,36 +244,22 @@ class FloatConversionTest final { return height; } - template , bool> = true, - std::enable_if_t, bool> = true> - std::tuple, test::Array2D, test::Array2D> - get_linear_arrays(size_t width, size_t height) { - test::Array2D source(width, height, 1, 1); - test::Array2D expected(width, height, 1, 1); - test::Array2D actual(width, height, 1, 1); - - test::GenerateLinearSeries generator(min()); - - source.fill(generator); - - calculate_expected(source, expected); - - return {source, expected, actual}; - } - - template , bool> = true, - std::enable_if_t, bool> = true> + template std::tuple, test::Array2D, test::Array2D> get_linear_arrays(size_t width, size_t height) { test::Array2D source(width, height, 1, 1); test::Array2D expected(width, height, 1, 1); test::Array2D actual(width, height, 1, 1); - test::GenerateLinearSeries generator(min()); - - source.fill(generator); + if constexpr (std::is_same_v && std::is_integral_v) { + test::GenerateLinearSeries generator(min()); + source.fill(generator); + } else if constexpr (std::is_integral_v && std::is_same_v) { + test::GenerateLinearSeries generator(min()); + source.fill(generator); + } else { + static_assert(sizeof(I) == 0 && sizeof(O) == 0, "should never happen"); + } calculate_expected(source, expected); @@ -282,30 +268,16 @@ class FloatConversionTest final { public: // minimum_size set by caller to trigger the 'big' conversion path. - template , bool> = true, - std::enable_if_t, bool> = true> + template void test_linear(size_t width, size_t minimum_size = 1) { - size_t height = get_linear_height(width, minimum_size); - - auto arrays = get_linear_arrays(width, height); - - test::Array2D& source = std::get<0>(arrays); - test::Array2D& expected = std::get<1>(arrays); - test::Array2D& actual = std::get<2>(arrays); - - ASSERT_EQ(KLEIDICV_OK, (float_conversion()( - source.data(), source.stride(), actual.data(), - actual.stride(), width, height))); - - EXPECT_EQ_ARRAY2D(expected, actual); - } - - template , bool> = true, - std::enable_if_t, bool> = true> - void test_linear(size_t width, size_t minimum_size = 1) { - size_t height = get_linear_height(width, minimum_size); + size_t height = 0; + if constexpr (std::is_same_v && std::is_integral_v) { + height = get_linear_height(width, minimum_size); + } else if constexpr (std::is_integral_v && std::is_same_v) { + height = get_linear_height(width, minimum_size); + } else { + static_assert(sizeof(I) == 0 && sizeof(O) == 0, "should never happen"); + } auto arrays = get_linear_arrays(width, height); -- GitLab From 2b15a9c682984fcd5763452c0f3639c01e5a13ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Podgain=C3=B5i?= Date: Tue, 16 Apr 2024 16:53:11 +0200 Subject: [PATCH 11/12] Remove template parameter from merge_tests It is unnecessary, as we are only ever merging tests of type "test". --- conformity/opencv/tests.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/conformity/opencv/tests.cpp b/conformity/opencv/tests.cpp index 4f38648e0..0fe97db16 100644 --- a/conformity/opencv/tests.cpp +++ b/conformity/opencv/tests.cpp @@ -14,18 +14,17 @@ #include "test_gaussian_blur.h" #include "test_sobel.h" -template -static std::vector merge_tests( - std::initializer_list& (*)()> test_groups) { - std::vector all_tests; +static std::vector merge_tests( + std::initializer_list& (*)()> test_groups) { + std::vector all_tests; for (auto getter : test_groups) { - std::vector& group = getter(); + std::vector& group = getter(); all_tests.insert(all_tests.cend(), group.cbegin(), group.cend()); } return all_tests; } -std::vector all_tests = merge_tests({ +std::vector all_tests = merge_tests({ sobel_tests_get, gaussian_blur_tests_get, float_conversion_tests_get, -- GitLab From 52f811f86267645bde7b6f798b473932ae729ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Podgain=C3=B5i?= Date: Tue, 16 Apr 2024 16:54:52 +0200 Subject: [PATCH 12/12] Change custom testing values for float to int8 conversion The previously used values do not really make sense in the int8 context, since they had been copied from the float testing values. --- conformity/opencv/test_float_conv.cpp | 80 ++++++++++++--------------- test/api/test_float_conv.cpp | 17 ++---- 2 files changed, 40 insertions(+), 57 deletions(-) diff --git a/conformity/opencv/test_float_conv.cpp b/conformity/opencv/test_float_conv.cpp index bdbca493a..73baa0774 100644 --- a/conformity/opencv/test_float_conv.cpp +++ b/conformity/opencv/test_float_conv.cpp @@ -95,53 +95,45 @@ bool test_int8_to_float32_random(int index, return false; } -static constexpr int custom_data_height = 8; -static constexpr int custom_data_width = 4; - -static float custom_data_float[custom_data_height * custom_data_width] = { - // clang-format off - quietNaN, signalingNaN, posInfinity, negInfinity, - minusNaN, plusNaN, plusZero, minusZero, - oneNaN, zeroDivZero, floatMin, floatMax, - posSubnormalMin, posSubnormalMax, negSubnormalMin, negSubnormalMax, - 1111.11, -1112.22, 113.33, 114.44, - 111.51, 112.62, 113.73, 114.84, - 126.66, 127.11, 128.66, 129.11, - 11.5, 12.5, -11.5, -12.5, - // clang-format on +static constexpr int custom_data_float_height = 8; +static constexpr int custom_data_float_width = 4; + +static float + custom_data_float[custom_data_float_height * custom_data_float_width] = { + // clang-format off + quietNaN, signalingNaN, posInfinity, negInfinity, + minusNaN, plusNaN, plusZero, minusZero, + oneNaN, zeroDivZero, floatMin, floatMax, + posSubnormalMin, posSubnormalMax, negSubnormalMin, negSubnormalMax, + 1111.11, -1112.22, 113.33, 114.44, + 111.51, 112.62, 113.73, 114.84, + 126.66, 127.11, 128.66, 129.11, + 11.5, 12.5, -11.5, -12.5, + // clang-format on }; -static int8_t custom_data_int8[custom_data_height * custom_data_width] = { - // clang-format off - -128, -128, 126, 127, - -128, -128, -128, -128, - -128, -128, -128, 126, - -127, -127, -127, 125, - 126, 127, 113, 114, - 112, 113, 114, 115, - 12, 12, 12, 12, - 11, 11, 11, 11, - // clang-format on +static constexpr int custom_data_int8_height = 1; +static constexpr int custom_data_int8_width = 7; + +static int8_t + custom_data_int8[custom_data_int8_height * custom_data_int8_width] = { + // clang-format off + -128, -127, -1, 0, 1, 126, 127 + // clang-format on }; -static uint8_t custom_data_uint8[custom_data_height * custom_data_width] = { - // clang-format off - 0, 0, 254, 255, - 0, 0, 0, 0, - 0, 0, 0, 254, - 1, 1, 1, 253, - 254, 255, 113, 114, - 112, 113, 114, 115, - 12, 12, 12, 12, - 11, 11, 11, 11, - // clang-format on +static uint8_t + custom_data_uint8[custom_data_int8_height * custom_data_int8_width] = { + // clang-format off + 0, 1, 126, 127, 128, 254, 255 + // clang-format on }; template bool test_float32_to_int8_custom(int index, RecreatedMessageQueue& request_queue, RecreatedMessageQueue& reply_queue) { - cv::Mat input(custom_data_height, custom_data_width, CV_32FC1, + cv::Mat input(custom_data_float_height, custom_data_float_width, CV_32FC1, custom_data_float); cv::Mat actual = exec_float32_to_int8(input); @@ -149,8 +141,8 @@ bool test_float32_to_int8_custom(int index, get_expected_from_subordinate(index, request_queue, reply_queue, input); if (are_matrices_different(0, actual, expected)) { - fail_print_matrices(custom_data_height, custom_data_width, input, actual, - expected); + fail_print_matrices(custom_data_float_height, custom_data_float_width, + input, actual, expected); return true; } @@ -161,7 +153,7 @@ template bool test_int8_to_float32_custom(int index, RecreatedMessageQueue& request_queue, RecreatedMessageQueue& reply_queue) { - cv::Mat input(custom_data_height, custom_data_width, + cv::Mat input(custom_data_int8_height, custom_data_int8_width, Signed ? CV_8SC1 : CV_8UC1, Signed ? static_cast(custom_data_int8) : static_cast(custom_data_uint8)); @@ -171,8 +163,8 @@ bool test_int8_to_float32_custom(int index, get_expected_from_subordinate(index, request_queue, reply_queue, input); if (are_matrices_different(0, actual, expected)) { - fail_print_matrices(custom_data_height, custom_data_width, input, actual, - expected); + fail_print_matrices(custom_data_int8_height, custom_data_int8_width, input, + actual, expected); return true; } @@ -206,8 +198,8 @@ std::vector& float_conversion_tests_get() { TEST("Unsigned Int8 to Float32, fill, 3 channel", (test_int8_to_float32_random), exec_int8_to_float32), TEST("Unsigned Int8 to Float32, fill, 4 channel", (test_int8_to_float32_random), exec_int8_to_float32), - TEST("Signed Int8 Float32, custom (special)", test_int8_to_float32_custom, exec_int8_to_float32), - TEST("Unigned Int8 Float32, custom (special)", test_int8_to_float32_custom, exec_int8_to_float32), + TEST("Signed Int8 Float32, custom", test_int8_to_float32_custom, exec_int8_to_float32), + TEST("Unigned Int8 Float32, custom", test_int8_to_float32_custom, exec_int8_to_float32), }; // clang-format on return tests; diff --git a/test/api/test_float_conv.cpp b/test/api/test_float_conv.cpp index 7f509b990..49fdde174 100644 --- a/test/api/test_float_conv.cpp +++ b/test/api/test_float_conv.cpp @@ -152,22 +152,13 @@ class FloatConversionTest final { const Elements& get_custom_elements() { static const Elements kTestElements = { // clang-format off - 4, 6, + 5, 1, {{ - { min(), min(), max() - 1, max() }, - { min(), min(), min(), min() }, - { min(), min(), min(), max() - 1 }, - { max() - 1, max(), 113, 114 }, - { 112, 113, 114, 115 }, - { 12, 12, 12, 12 } + { min(), min() + 1, 0, max() - 1, max() } }}, {{ - { min(), min(), max() - 1.0, max() }, - { min(), min(), min(), min() }, - { min(), min(), min(), max() - 1.0 }, - { max() - 1.0, max(), 113.0, 114.0 }, - { 112.0, 113.0, 114.0, 115.0 }, - { 12.0, 12.0, 12.0, 12.0 } + { static_cast(min()), static_cast(min()) + 1.0, 0, + static_cast(max()) - 1.0, static_cast(max()) } }} // clang-format on }; -- GitLab