diff --git a/test/parallel_api/ranges/std_ranges.pass.cpp b/test/parallel_api/ranges/std_ranges.pass.cpp index 7484ce38a10..f64911d6e51 100644 --- a/test/parallel_api/ranges/std_ranges.pass.cpp +++ b/test/parallel_api/ranges/std_ranges.pass.cpp @@ -41,9 +41,8 @@ main() test_range_algo{}(oneapi::dpl::ranges::adjacent_find, std::ranges::adjacent_find, pred_2, proj); - test_range_algo{}(oneapi::dpl::ranges::search, std::ranges::search, pred_2, proj); - test_range_algo{}(oneapi::dpl::ranges::search_n, std::ranges::search_n, pred_2, proj); - + test_range_algo{}(oneapi::dpl::ranges::search, std::ranges::search, pred_2, proj, proj); + test_range_algo{}(oneapi::dpl::ranges::search_n, std::ranges::search_n, 3, 5, pred_2, proj); #endif //_ENABLE_STD_RANGES_TESTING return TestUtils::done(_ENABLE_STD_RANGES_TESTING); diff --git a/test/parallel_api/ranges/std_ranges_2.pass.cpp b/test/parallel_api/ranges/std_ranges_2.pass.cpp index 7621698828b..fa217286956 100644 --- a/test/parallel_api/ranges/std_ranges_2.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_2.pass.cpp @@ -21,11 +21,11 @@ main() #if _ENABLE_STD_RANGES_TESTING using namespace test_std_ranges; - +#if 1 test_range_algo{}(oneapi::dpl::ranges::count_if, std::ranges::count_if, pred, proj); test_range_algo{}(oneapi::dpl::ranges::count, std::ranges::count, 4, proj); - test_range_algo{}(oneapi::dpl::ranges::equal, std::ranges::equal, pred_2, proj); + test_range_algo{}(oneapi::dpl::ranges::equal, std::ranges::equal, pred_2, proj, proj); test_range_algo{}(oneapi::dpl::ranges::is_sorted, std::ranges::is_sorted, std::ranges::less{}, proj); test_range_algo{}(oneapi::dpl::ranges::is_sorted, std::ranges::is_sorted, std::ranges::greater{}, proj); @@ -43,6 +43,13 @@ main() test_range_algo{}(oneapi::dpl::ranges::max_element, std::ranges::max_element, std::ranges::less{}, proj); test_range_algo{}(oneapi::dpl::ranges::max_element, std::ranges::max_element, std::ranges::greater{}, proj); + test_range_algo{}(oneapi::dpl::ranges::copy, std::ranges::copy); + test_range_algo{}(oneapi::dpl::ranges::copy_if, std::ranges::copy_if, + pred, proj); +#endif + test_range_algo{}(oneapi::dpl::ranges::merge, std::ranges::merge, std::ranges::less{}, proj, proj); + test_range_algo{}(oneapi::dpl::ranges::merge, std::ranges::merge, std::ranges::greater{}, proj, proj); + #endif //_ENABLE_STD_RANGES_TESTING return TestUtils::done(_ENABLE_STD_RANGES_TESTING); diff --git a/test/parallel_api/ranges/std_ranges_test.h b/test/parallel_api/ranges/std_ranges_test.h index fa479e76944..0ace2076a75 100644 --- a/test/parallel_api/ranges/std_ranges_test.h +++ b/test/parallel_api/ranges/std_ranges_test.h @@ -48,8 +48,7 @@ enum TestDataMode data_in, data_in_out, data_in_in, - data_in_in_out, - data_in_val_n, + data_in_in_out }; template @@ -65,26 +64,25 @@ struct test operator()(oneapi::dpl::execution::par_unseq, algo, args...); } - template + template std::enable_if_t && Ranges == data_in> - operator()(Policy&& exec, Algo algo, Checker checker, FunctorOrVal f, Proj proj = {}, Transform tr = {}) + operator()(Policy&& exec, Algo algo, Checker checker, Transform tr, auto... args) { constexpr int max_n = 10; int data[max_n] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int expected[max_n] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; auto expected_view = tr(std::ranges::subrange(expected, expected + max_n)); - auto expected_res = checker(expected_view, f, proj); + auto expected_res = checker(expected_view, args...); { Container cont(exec, data, max_n); typename Container::type& A = cont(); - auto res = algo(exec, tr(A), f, proj); + auto res = algo(exec, tr(A), args...); //check result if constexpr(RetTypeCheck) - static_assert(std::is_same_v, "Wrong return type"); + static_assert(std::is_same_v, "Wrong return type"); auto bres = ret_in_val(expected_res, expected_view.begin()) == ret_in_val(res, tr(A).begin()); EXPECT_TRUE(bres, (std::string("wrong return value from algo with ranges: ") + typeid(Algo).name() + @@ -95,11 +93,9 @@ struct test EXPECT_EQ_N(expected, data, max_n, (std::string("wrong effect algo with ranges: ") + typeid(Algo).name() + typeid(decltype(tr(std::declval()()))).name()).c_str()); } - - template + template std::enable_if_t && Ranges == data_in_out> - operator()(Policy&& exec, Algo algo, Checker checker, Functor f, Proj proj = {}, Transform tr = {}) + operator()(Policy&& exec, Algo algo, Checker checker, Transform tr, auto... args) { constexpr int max_n = 10; int data_in[max_n] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; @@ -107,7 +103,7 @@ struct test int expected[max_n] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; auto src_view = tr(std::ranges::subrange(data_in, data_in + max_n)); - auto expected_res = checker(src_view, expected, f, proj); + auto expected_res = checker(src_view, expected, args...); { Container cont_in(exec, data_in, max_n); Container cont_out(exec, data_out, max_n); @@ -115,11 +111,11 @@ struct test typename Container::type& A = cont_in(); typename Container::type& B = cont_out(); - auto res = algo(exec, tr(A), B, f, proj); + auto res = algo(exec, tr(A), B, args...); //check result if constexpr(RetTypeCheck) - static_assert(std::is_same_v, "Wrong return type"); + static_assert(std::is_same_v, "Wrong return type"); auto bres_in = ret_in_val(expected_res, src_view.begin()) == ret_in_val(res, tr(A).begin()); EXPECT_TRUE(bres_in, (std::string("wrong return value from algo with input range: ") + typeid(Algo).name()).c_str()); @@ -132,10 +128,9 @@ struct test EXPECT_EQ_N(expected, data_out, max_n, (std::string("wrong effect algo with ranges: ") + typeid(Algo).name()).c_str()); } - template + template std::enable_if_t && Ranges == data_in_in> - operator()(Policy&& exec, Algo algo, Checker checker, Functor f, Proj proj = {}, Transform tr = {}) + operator()(Policy&& exec, Algo algo, Checker checker, Transform tr, auto... args) { constexpr int max_n = 10; int data_in1[max_n] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; @@ -143,7 +138,7 @@ struct test auto src_view1 = tr(std::ranges::subrange(data_in1, data_in1 + max_n)); auto src_view2 = tr(std::ranges::subrange(data_in2, data_in2 + max_n)); - auto expected_res = checker(src_view1, src_view2, f, proj, proj); + auto expected_res = checker(src_view1, src_view2, args...); { Container cont_in1(exec, data_in1, max_n); Container cont_in2(exec, data_in2, max_n); @@ -151,48 +146,51 @@ struct test typename Container::type& A = cont_in1(); typename Container::type& B = cont_in2(); - auto res = algo(exec, tr(A), tr(B), f, proj, proj); + auto res = algo(exec, tr(A), tr(B), args...); if constexpr(RetTypeCheck) - static_assert(std::is_same_v, "Wrong return type"); + static_assert(std::is_same_v, "Wrong return type"); auto bres_in = ret_in_val(expected_res, src_view1.begin()) == ret_in_val(res, tr(A).begin()); EXPECT_TRUE(bres_in, (std::string("wrong return value from algo: ") + typeid(Algo).name() + typeid(decltype(tr(std::declval()()))).name()).c_str()); } } - - template - std::enable_if_t && Ranges == data_in_val_n> - operator()(Policy&& exec, Algo algo, Checker checker, FunctorOrVal f, Proj proj = {}, Transform tr = {}) + template + std::enable_if_t && Ranges == data_in_in_out> + operator()(Policy&& exec, Algo algo, Checker checker, Transform tr, auto... args) { constexpr int max_n = 10; - int data[max_n] = {0, 1, 2, 5, 5, 5, 6, 7, 8, 9}; - int expected[max_n] = {0, 1, 2, 5, 5, 5, 6, 7, 8, 9}; - int val = 5, n = 3; + int data_in1[max_n] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int data_in2[max_n] = {0, 0, 2, 3, 4, 5, 6, 6, 6, 6}; + constexpr int max_n_out = max_n*2; + int data_out[max_n_out] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //TODO: size + int expected[max_n_out] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - auto expected_view = tr(std::ranges::subrange(expected, expected + max_n)); - auto expected_res = checker(expected_view, n, val, f, proj); + auto src_view1 = tr(std::ranges::subrange(data_in1, data_in1 + max_n)); + auto src_view2 = tr(std::ranges::subrange(data_in2, data_in2 + max_n)); + auto expected_res = checker(src_view1, src_view2, expected, args...); { - Container cont(exec, data, max_n); - typename Container::type& A = cont(); + Container cont_in1(exec, data_in1, max_n); + Container cont_in2(exec, data_in2, max_n); + Container cont_out(exec, data_out, max_n_out); - auto res = algo(exec, tr(A), n, val, f, proj); + typename Container::type& A = cont_in1(); + typename Container::type& B = cont_in2(); + typename Container::type& С = cont_out(); + + auto res = algo(exec, tr(A), tr(B), С, args...); - //check result if constexpr(RetTypeCheck) - static_assert(std::is_same_v, "Wrong return type"); + static_assert(std::is_same_v, "Wrong return type"); - auto bres = ret_in_val(expected_res, expected_view.begin()) == ret_in_val(res, tr(A).begin()); - EXPECT_TRUE(bres, (std::string("wrong return value from algo with ranges: ") + typeid(Algo).name()).c_str()); + auto bres_in = ret_in_val(expected_res, src_view1.begin()) == ret_in_val(res, tr(A).begin()); + EXPECT_TRUE(bres_in, (std::string("wrong return value from algo: ") + typeid(Algo).name() + + typeid(decltype(tr(std::declval()()))).name()).c_str()); } - //check result - EXPECT_EQ_N(expected, data, max_n, (std::string("wrong effect algo with ranges: ") - + typeid(Algo).name() + typeid(decltype(tr(std::declval()()))).name()).c_str()); + EXPECT_EQ_N(expected, data_out, max_n_out, (std::string("wrong effect algo with ranges: ") + typeid(Algo).name()).c_str()); } - private: template @@ -209,6 +207,20 @@ struct test static constexpr bool check_in().in)>> = true; + template + static constexpr bool check_in1{}; + + template + static constexpr + bool check_in1().in1)>> = true; + + template + static constexpr bool check_in2{}; + + template + static constexpr + bool check_in2().in2)>> = true; + template static constexpr bool check_out{}; @@ -216,7 +228,6 @@ struct test static constexpr bool check_out().out)>> = true; - template static constexpr bool is_range{}; @@ -229,6 +240,10 @@ struct test { if constexpr (check_in) return std::distance(begin, ret.in); + else if constexpr (check_in1) + return std::distance(begin, ret.in1); + else if constexpr (check_in2) + return std::distance(begin, ret.in2); else if constexpr (is_iterator) return std::distance(begin, ret); else if constexpr(is_range) @@ -363,7 +378,7 @@ using usm_span = usm_subrange_impl>; template struct test_range_algo { - void operator()(auto algo, auto checker, auto f, auto proj) + void operator()(auto algo, auto checker, auto... args) { auto subrange_view = [](auto&& v) { return std::ranges::subrange(v); }; @@ -375,24 +390,24 @@ struct test_range_algo }; if constexpr(ForwardRangeCheck) - test{}(host_policies(), algo, checker, f, std::identity{}, forward_view); + test{}(host_policies(), algo, checker, forward_view, args...); - test{}(host_policies(), algo, checker, f, std::identity{}, subrange_view); - test{}(host_policies(), algo, checker, f, std::identity{}, span_view); - test{}(host_policies(), algo, checker, f, proj, std::views::all); - test{}(host_policies(), algo, checker, f, proj, std::views::all); - test{}(host_policies(), algo, checker, f, proj, std::views::all); + test{}(host_policies(), algo, checker, subrange_view, args...); + test{}(host_policies(), algo, checker, span_view, args...); + test{}(host_policies(), algo, checker, std::views::all, args...); + test{}(host_policies(), algo, checker, std::views::all, args...); + test{}(host_policies(), algo, checker, std::views::all, args...); #if 1//_ONEDPL_HETERO_BACKEND - test{}(dpcpp_policy(), algo, checker, f, proj); - test{}(dpcpp_policy(), algo, checker, f, proj, oneapi::dpl::views::all); - test{}(dpcpp_policy(), algo, checker, f, proj, subrange_view); - test{}(dpcpp_policy(), algo, checker, f, std::identity{}, span_view); - test{}(dpcpp_policy(), algo, checker, f, proj); - test{}(dpcpp_policy(), algo, checker, f, proj); + test{}(dpcpp_policy(), algo, checker, std::identity{}, args...); + test{}(dpcpp_policy(), algo, checker, oneapi::dpl::views::all, args...); + test{}(dpcpp_policy(), algo, checker, subrange_view, args...); + test{}(dpcpp_policy(), algo, checker, span_view, args...); + test{}(dpcpp_policy(), algo, checker, std::identity{}, args...); + test{}(dpcpp_policy(), algo, checker, std::identity{}, args...); #if 0 //sycl buffer - test{}(dpcpp_policy(), algo, checker, f, std::identity{}, oneapi::dpl::views::all); + test{}(dpcpp_policy(), algo, checker, oneapi::dpl::views::all, f, args...); #endif #endif //_ONEDPL_HETERO_BACKEND