From c47cd4d70d2ddd0bf7428da089e6c5a52944f119 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Tue, 17 Sep 2024 15:31:33 +0200 Subject: [PATCH 01/43] [oneDPL][ranges][zip_view] + initial implementation of standard compliance zip_view --- include/oneapi/dpl/pstl/zip_view_impl.h | 336 ++++++++++++++++++++++++ 1 file changed, 336 insertions(+) create mode 100644 include/oneapi/dpl/pstl/zip_view_impl.h diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h new file mode 100644 index 0000000000..ce8a5e97f7 --- /dev/null +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -0,0 +1,336 @@ +#include +#include +#include +#include +#include +#include + + +namespace my { + +template +concept all_forward = ( std::ranges::forward_range> && ... ); + +template +concept all_bidirectional = ( std::ranges::bidirectional_range> && ... ); + +template +concept all_random_access = ( std::ranges::random_access_range> && ... ); + +template +concept zip_is_common = + (sizeof...(Rs) == 1 && ( std::ranges::common_range && ... )) + || + (!(std::ranges::bidirectional_range && ...) && (std::ranges::common_range && ...)) + || + ((std::ranges::random_access_range && ...) && (std::ranges::sized_range && ...)); + +template +struct declare_iterator_category {}; + +template + requires all_forward +struct declare_iterator_category { + using iterator_category = std::input_iterator_tag; +}; + +template + requires ((std::ranges::view && ... ) && (sizeof...(Views) > 0)) +class zip_view : public std::ranges::view_interface> { +public: + zip_view() = default; + constexpr zip_view(Views... views) : views_(views...) {} + + template + class iterator : declare_iterator_category { + public: + using iterator_concept = std::conditional_t, + std::random_access_iterator_tag, + std::conditional_t, + std::bidirectional_iterator_tag, + std::conditional_t, + std::forward_iterator_tag, + std::input_iterator_tag>>>; + + using value_type = std::conditional_t...>, + std::tuple...>>; + + using difference_type = std::conditional_t...>, + std::common_type_t...>>; + + iterator() = default; + + constexpr iterator(iterator i) + requires Const && (std::convertible_to, std::ranges::iterator_t> && ...) + : current_(std::move(i.current_)) {} + + private: + template + constexpr iterator(const Iterators&... iterators) + : current_(iterators...) {} + public: + + constexpr auto operator*() const { + using return_tuple_type = std::conditional_t>::reference...>, + std::tuple>::reference...>>; + + + return std::apply([](auto&... iterators) { + return std::make_tuple((*iterators)...); + }, + current_); + } + + constexpr auto operator[]( difference_type n ) const + requires all_random_access + { + return *(*this + n); + } + + constexpr iterator& operator++() { + std::apply([](auto&... iterators) { + ( (++iterators) , ... ); + }, + current_); + return *this; + } + + constexpr void operator++(int) { + ++*this; + } + + constexpr iterator operator++(int) requires all_forward { + auto tmp = *this; + ++*this; + return tmp; + } + + constexpr iterator& operator--() requires all_bidirectional { + step_backward(std::make_index_sequence()); + + std::apply([](auto&... iterators) { + ((--iterators) , ... ); + }, + current_); + return *this; + } + + constexpr iterator operator--(int) requires all_bidirectional { + auto tmp = *this; + --*this; + return tmp; + } + + constexpr iterator& operator+=(difference_type n) + requires all_random_access + { + std::apply([n](auto&... iterators) { + ((iterators += n) , ...); + }, + current_); + return *this; + } + + constexpr iterator& operator-=(difference_type n) + requires all_random_access + { + std::apply([n](auto&... iterators) { + ((iterators -= n) , ...); + }, + current_); + return *this; + } + + friend constexpr bool operator==(const iterator& x, const iterator& y) + requires ( std::equality_comparable, + std::ranges::iterator_t>> && ... ) + { + if constexpr (all_bidirectional) { + return x.current_ == y.current_; + } else { + return x.compare_equal(y, std::make_index_sequence()); + } + } + + friend constexpr auto operator<=>(const iterator& x, const iterator& y) + requires all_random_access + { + return x.current_ <=> y.current_; + } + + private: + template + constexpr bool compare_equal(iterator y, std::index_sequence) { + return ((std::get(current_) == std::get(y.current_)) && ...); + } + + template + constexpr bool compare_with_sentinels(const SentinelsTuple& sentinels, std::index_sequence) { + return ( (std::get(current_) == std::get(sentinels)) || ... ); + } + + template + constexpr std::common_type_t, + std::ranges::range_difference_t>...> + distance_to_sentinels(const SentinelsTuple& sentinels, std::index_sequence<0, In...>) { + auto min = std::get<0>(current_) - std::get<0>(sentinels); + + ( (min = std::min(min, (std::get(current_) - std::get(sentinels)))) , ... ); + return min; + } + + friend class zip_view; + + using current_type = std::conditional_t...>, + std::tuple...>>; + + current_type current_; + }; // class iterator + + template + class sentinel { + public: + sentinel() = default; + constexpr sentinel(sentinel i) + requires Const && + ( std::convertible_to, std::ranges::sentinel_t> && ... ) + : end_(std::move(i.end_)) {} + + private: + template + constexpr sentinel(const Sentinels&... sentinels) + : end_(sentinels...) {} + public: + template + requires (std::sentinel_for, + std::ranges::sentinel_t>, + std::conditional_t, + std::ranges::iterator_t>> && ...) + friend constexpr bool operator==(const iterator& x, const sentinel& y) + { + return x.compare_with_sentinels(y.end_, std::make_index_sequence()); + } + + template + requires (std::sized_sentinel_for, + std::ranges::sentinel_t>, + std::conditional_t, + std::ranges::iterator_t>> && ...) + friend constexpr std::common_type_t, + std::ranges::range_difference_t>...> + operator-(const iterator& x, const sentinel& y) { + return x.distance_to_sentinels(y.end_, std::make_index_sequence()); + } + + template + requires (std::sized_sentinel_for, + std::ranges::sentinel_t>, + std::conditional_t, + std::ranges::iterator_t>> && ...) + friend constexpr std::common_type_t, + std::ranges::range_difference_t>...> + operator-(const sentinel& y, const iterator& x) { + return -(x - y); + } + + private: + friend class zip_view; + + using end_type = std::conditional_t...>, + std::tuple...>>; + + end_type end_; + }; // class sentinel + + constexpr auto begin() requires (std:: ranges::range && ...) // !simple_view? + { + return std::apply([](auto... views) { + return iterator(std::ranges::begin(views)...); + }, + views_); + } + + constexpr auto begin() const requires ( std::ranges::range && ... ) + { + return std::apply([](auto... views) { + return iterator(std::ranges::begin(views)...); + }, + views_); + } + + constexpr auto end() requires (std::ranges::range && ...) // requires !simple_view { + { + if constexpr (!zip_is_common) { + return std::apply([](auto... views) { + return sentinel(std::ranges::end(views)...); + }, + views_); + } else if constexpr ((std::ranges::random_access_range && ...)) { + auto it = begin(); + it += size(); + return it; + } else { + return std::apply([](auto... views) { + return iterator(std::ranges::end(views)...); + }, + views_); + } + } + + constexpr auto end() const requires (std::ranges::range && ...) + { + if constexpr (!zip_is_common) { + return std::apply([](auto... views) { + return sentinel(std::ranges::end(views)...); + }, + views_); + } else if constexpr ((std::ranges::random_access_range && ...)) { + auto it = begin(); + it += size(); + return it; + } else { + return std::apply([](auto... views) { + return iterator(std::ranges::end(views)...); + }, + views_); + } + } + + constexpr auto size() requires (std::ranges::sized_range && ...) + { + return std::apply([](auto... sizes) { + using CT = std::make_unsigned_t>; + return std::ranges::min({CT(sizes)...}); + }, + std::apply([](auto... views) { + return std::make_tuple(std::ranges::size(views)...); + }, + views_)); + } + + constexpr auto size() const requires (std::ranges::sized_range && ...) + { + return const_cast(this)->size(); + } +private: + std::tuple views_; +}; // class zip_view + +template +zip_view(Rs&&...) -> zip_view...>; + +struct zip_fn { + template + constexpr auto operator()( Rs&&... rs ) const { + return zip_view...>(std::forward(rs)...); + } +}; + +inline constexpr zip_fn zip{}; + +} // namespace my + +int main() +{ + +} \ No newline at end of file From 185de57269ac76469ec91b62ba7f97a3b68bee46 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Wed, 18 Sep 2024 18:38:34 +0200 Subject: [PATCH 02/43] [oneDPL][ranges][zip_view] + missing arithmetic operations for zip_view::iterator type --- include/oneapi/dpl/pstl/zip_view_impl.h | 28 +++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index ce8a5e97f7..b7164223c9 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -158,6 +158,27 @@ class zip_view : public std::ranges::view_interface> { return x.current_ <=> y.current_; } + friend constexpr auto operator-(const iterator& x, const iterator& y) + requires all_random_access + { + return std::get<0>(x.current_) - std::get<0>(y.current_); + } + + friend constexpr iterator operator+(iterator it, difference_type n) + { + return it+=n; + } + + friend constexpr iterator operator+(difference_type n, iterator it) + { + return it+=n; + } + + friend constexpr iterator operator-(iterator it, difference_type n) + { + return it-=n; + } + private: template constexpr bool compare_equal(iterator y, std::index_sequence) { @@ -328,9 +349,4 @@ struct zip_fn { inline constexpr zip_fn zip{}; -} // namespace my - -int main() -{ - -} \ No newline at end of file +} // namespace my \ No newline at end of file From fa16bdffe258d3ff842c3e09ba52da3cc204ac29 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Fri, 20 Sep 2024 14:17:50 +0200 Subject: [PATCH 03/43] [oneDPL][ranges][zip_view] + return type fix for operator*() --- include/oneapi/dpl/pstl/zip_view_impl.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index b7164223c9..54b128bf84 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -5,7 +5,6 @@ #include #include - namespace my { template @@ -57,6 +56,8 @@ class zip_view : public std::ranges::view_interface> { using difference_type = std::conditional_t...>, std::common_type_t...>>; + using return_tuple_type = std::conditional_t>::reference...>, + std::tuple>::reference...>>; iterator() = default; @@ -70,18 +71,16 @@ class zip_view : public std::ranges::view_interface> { : current_(iterators...) {} public: - constexpr auto operator*() const { - using return_tuple_type = std::conditional_t>::reference...>, - std::tuple>::reference...>>; + constexpr return_tuple_type operator*() const { - return std::apply([](auto&... iterators) { - return std::make_tuple((*iterators)...); + return std::apply([](auto... iterators) { + return return_tuple_type((*iterators)...); }, current_); } - constexpr auto operator[]( difference_type n ) const + constexpr return_tuple_type operator[]( difference_type n ) const requires all_random_access { return *(*this + n); From cefbbf5831340a75f3e96c65964808f7974774b4 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Tue, 24 Sep 2024 18:05:43 +0200 Subject: [PATCH 04/43] [oneDPL][ranges][tuple] + const assignment operator overload --- include/oneapi/dpl/pstl/tuple_impl.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/oneapi/dpl/pstl/tuple_impl.h b/include/oneapi/dpl/pstl/tuple_impl.h index 239734d486..01b5237bdf 100644 --- a/include/oneapi/dpl/pstl/tuple_impl.h +++ b/include/oneapi/dpl/pstl/tuple_impl.h @@ -500,6 +500,15 @@ struct tuple next = other.next; return *this; } + + template + tuple& + operator=(const tuple& other) const + { + holder.value = other.holder.value; + next = other.next; + return *this; + } // if T1 is deduced with reference, compiler generates deleted operator= and, // since "template operator=" is not considered as operator= overload From 0b4d86bebf90ff33917f702ceea40380e72118c1 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Tue, 24 Sep 2024 18:05:58 +0200 Subject: [PATCH 05/43] [oneDPL][ranges][zip_view] + test --- test/parallel_api/ranges/std_ranges_test.h | 14 +++++ .../ranges/std_ranges_zip_view.pass.cpp | 56 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 test/parallel_api/ranges/std_ranges_zip_view.pass.cpp diff --git a/test/parallel_api/ranges/std_ranges_test.h b/test/parallel_api/ranges/std_ranges_test.h index b022dea294..745bfefc6f 100644 --- a/test/parallel_api/ranges/std_ranges_test.h +++ b/test/parallel_api/ranges/std_ranges_test.h @@ -15,6 +15,7 @@ #include #include +#include #include "support/test_config.h" #include "support/test_macros.h" @@ -144,6 +145,14 @@ template static constexpr bool is_range().begin())>> = true; +void call_with_host_policies(auto algo, auto... args) +{ + algo(oneapi::dpl::execution::seq, args...); + algo(oneapi::dpl::execution::unseq, args...); + algo(oneapi::dpl::execution::par, args...); + algo(oneapi::dpl::execution::par_unseq, args...); +} + template struct test { @@ -541,6 +550,11 @@ struct test_range_algo test, mode>{max_n}(host_policies(), algo, checker, std::views::all, std::identity{}, args...); #endif +#if 0//zip_view + auto zip_view = [](auto&& v) { return my::zip(v); }; + test, mode>{}(host_policies(), algo, checker, zip_view, std::identity{}, args...); +#endif + #if TEST_DPCPP_BACKEND_PRESENT //Skip the cases with pointer-to-function and hetero policy because pointer-to-function is not supported within kernel code. if constexpr(!std::disjunction_v...>) diff --git a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp new file mode 100644 index 0000000000..a777db2bad --- /dev/null +++ b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Copyright (C) Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// This file incorporates work covered by the following copyright and permission +// notice: +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// +//===----------------------------------------------------------------------===// + +#include "std_ranges_test.h" + +template +struct print_type; + +std::int32_t +main() +{ +#if _ENABLE_STD_RANGES_TESTING + + namespace dpl_ranges = oneapi::dpl::ranges; + const char* err_msg = "Wrong effect algo transform with zip_view."; + + constexpr int max_n = 10; + int data[max_n] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + + auto zip_view = my::zip(data, std::views::iota(0, max_n)) | std::views::take(5); + std::ranges::for_each(zip_view, test_std_ranges::f_mutuable, [](const auto& val) { return std::get<1>(val); }); + + test_std_ranges::call_with_host_policies(dpl_ranges::for_each, zip_view, test_std_ranges::f_mutuable, [](const auto& val) { return std::get<1>(val); }); + //EXPECT_EQ_N(expected.begin(), res.begin(), n, err_msg); + + dpl_ranges::for_each(test_std_ranges::dpcpp_policy(), zip_view, test_std_ranges::f_mutuable, [](const auto& val) { return std::get<1>(val); }); + + auto zip_view_sort = my::zip(data, data); + + auto it = zip_view_sort.begin(); + std::sort(zip_view_sort.begin(), zip_view_sort.begin() + 5, [](const auto& val1, const auto& val2) { return std::get<0>(val1) < std::get<0>(val2); }); + std::ranges::sort(zip_view_sort, std::greater{}, [](auto&& val) { return std::get<0>(val); }); + + static_assert(std::ranges::random_access_range); + static_assert(std::random_access_iterator); + //dpl_ranges::sort(oneapi::dpl::execution::seq, zip_view_sort, std::greater{}, [](auto&& val) { return std::get<0>(val); }); + + //test_std_ranges::call_with_host_policies(dpl_ranges::sort, zip_view_sort, test_std_ranges::binary_pred, [](const auto& val) { return std::get<0>(val); }); + + +#endif //_ENABLE_STD_RANGES_TESTING + + return TestUtils::done(_ENABLE_STD_RANGES_TESTING); +} From d7785f5a7b4a4cac3966b2ce4343bc936550a4a5 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Tue, 24 Sep 2024 18:07:19 +0200 Subject: [PATCH 06/43] [oneDPL][ranges][zip_view] + apply_to_tuple instead of std::apply; std::apply doesnt work with oneDPL tuple --- include/oneapi/dpl/pstl/zip_view_impl.h | 111 +++++++++++++----------- 1 file changed, 59 insertions(+), 52 deletions(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 54b128bf84..6b3df2bc15 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -33,9 +33,38 @@ struct declare_iterator_category { using iterator_category = std::input_iterator_tag; }; +template +using tuple_type = oneapi::dpl::__internal::tuple; + template requires ((std::ranges::view && ... ) && (sizeof...(Views) > 0)) class zip_view : public std::ranges::view_interface> { +public: + template + using tuple_type = oneapi::dpl::__internal::tuple; + +private: + template + static decltype(auto) + apply_to_tuple_impl(_ReturnAdapter __tr, _F __f, _Tuple& __t, std::index_sequence<_Ip...>) + { + return __tr(__f(oneapi::dpl::__internal::get_impl<_Ip>()(__t))...); + } + + template + static decltype(auto) + apply_to_tuple(_ReturnAdapter __tr, _F __f, _Tuple& __t) + { + return apply_to_tuple_impl(__tr, __f, __t, std::make_index_sequence{}); + } + + template + static auto + apply_to_tuple(_F __f, _Tuple& __t) + { + apply_to_tuple_impl([](auto...){}, __f, __t, std::make_index_sequence{}); + } + public: zip_view() = default; constexpr zip_view(Views... views) : views_(views...) {} @@ -51,13 +80,13 @@ class zip_view : public std::ranges::view_interface> { std::forward_iterator_tag, std::input_iterator_tag>>>; - using value_type = std::conditional_t...>, - std::tuple...>>; + using value_type = std::conditional_t...>, + tuple_type...>>; using difference_type = std::conditional_t...>, std::common_type_t...>>; - using return_tuple_type = std::conditional_t>::reference...>, - std::tuple>::reference...>>; + using return_tuple_type = std::conditional_t>::reference...>, + tuple_type>::reference...>>; iterator() = default; @@ -71,26 +100,20 @@ class zip_view : public std::ranges::view_interface> { : current_(iterators...) {} public: - constexpr return_tuple_type operator*() const { + return_tuple_type operator*() const { - - return std::apply([](auto... iterators) { - return return_tuple_type((*iterators)...); - }, - current_); + auto __tr = [](auto&&... __args) -> decltype(auto) { return return_tuple_type(__args...);}; + return apply_to_tuple(__tr, [](auto it) -> decltype(auto) { return *it;}, current_); } constexpr return_tuple_type operator[]( difference_type n ) const requires all_random_access { return *(*this + n); - } + } constexpr iterator& operator++() { - std::apply([](auto&... iterators) { - ( (++iterators) , ... ); - }, - current_); + zip_view::apply_to_tuple([](auto& it) { return ++it; }, current_); return *this; } @@ -105,12 +128,8 @@ class zip_view : public std::ranges::view_interface> { } constexpr iterator& operator--() requires all_bidirectional { - step_backward(std::make_index_sequence()); - std::apply([](auto&... iterators) { - ((--iterators) , ... ); - }, - current_); + zip_view::apply_to_tuple([](auto& it) { return --it; }, current_); return *this; } @@ -123,20 +142,14 @@ class zip_view : public std::ranges::view_interface> { constexpr iterator& operator+=(difference_type n) requires all_random_access { - std::apply([n](auto&... iterators) { - ((iterators += n) , ...); - }, - current_); + zip_view::apply_to_tuple([n](auto& it) { return it += n; }, current_); return *this; } constexpr iterator& operator-=(difference_type n) requires all_random_access { - std::apply([n](auto&... iterators) { - ((iterators -= n) , ...); - }, - current_); + zip_view::apply_to_tuple([n](auto& it) { return it -= n; }, current_); return *this; } @@ -154,7 +167,7 @@ class zip_view : public std::ranges::view_interface> { friend constexpr auto operator<=>(const iterator& x, const iterator& y) requires all_random_access { - return x.current_ <=> y.current_; + return x.current_ == y.current_; } friend constexpr auto operator-(const iterator& x, const iterator& y) @@ -201,8 +214,8 @@ class zip_view : public std::ranges::view_interface> { friend class zip_view; - using current_type = std::conditional_t...>, - std::tuple...>>; + using current_type = std::conditional_t...>, + tuple_type...>>; current_type current_; }; // class iterator @@ -256,26 +269,22 @@ class zip_view : public std::ranges::view_interface> { private: friend class zip_view; - using end_type = std::conditional_t...>, - std::tuple...>>; + using end_type = std::conditional_t...>, + tuple_type...>>; end_type end_; - }; // class sentinel + }; // class sentinel - constexpr auto begin() requires (std:: ranges::range && ...) // !simple_view? + constexpr auto begin() requires (std::ranges::range && ...) // !simple_view? { - return std::apply([](auto... views) { - return iterator(std::ranges::begin(views)...); - }, - views_); + auto __tr = [](auto... __args) { return iterator(__args...);}; + return apply_to_tuple(__tr, std::ranges::begin, views_); } constexpr auto begin() const requires ( std::ranges::range && ... ) { - return std::apply([](auto... views) { - return iterator(std::ranges::begin(views)...); - }, - views_); + auto __tr = [](auto... __args) { return iterator(__args...);}; + return apply_to_tuple(__tr, std::ranges::begin, views_); } constexpr auto end() requires (std::ranges::range && ...) // requires !simple_view { @@ -318,14 +327,12 @@ class zip_view : public std::ranges::view_interface> { constexpr auto size() requires (std::ranges::sized_range && ...) { - return std::apply([](auto... sizes) { - using CT = std::make_unsigned_t>; - return std::ranges::min({CT(sizes)...}); - }, - std::apply([](auto... views) { - return std::make_tuple(std::ranges::size(views)...); - }, - views_)); + auto __tr = [](auto... __args) { + using CT = std::make_unsigned_t>; + return std::ranges::min({CT(__args)...}); + }; + + return apply_to_tuple(__tr, std::ranges::size, views_); } constexpr auto size() const requires (std::ranges::sized_range && ...) @@ -333,7 +340,7 @@ class zip_view : public std::ranges::view_interface> { return const_cast(this)->size(); } private: - std::tuple views_; + tuple_type views_; }; // class zip_view template From def05cf6a5d9c7d7279b3248116f2a987ff79e0e Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Wed, 25 Sep 2024 15:47:23 +0200 Subject: [PATCH 07/43] [oneDPL][ranges][zip_view] + changes in the test --- .../ranges/std_ranges_zip_view.pass.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp index a777db2bad..99f2157e50 100644 --- a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp @@ -24,7 +24,6 @@ main() #if _ENABLE_STD_RANGES_TESTING namespace dpl_ranges = oneapi::dpl::ranges; - const char* err_msg = "Wrong effect algo transform with zip_view."; constexpr int max_n = 10; int data[max_n] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; @@ -33,22 +32,25 @@ main() std::ranges::for_each(zip_view, test_std_ranges::f_mutuable, [](const auto& val) { return std::get<1>(val); }); test_std_ranges::call_with_host_policies(dpl_ranges::for_each, zip_view, test_std_ranges::f_mutuable, [](const auto& val) { return std::get<1>(val); }); - //EXPECT_EQ_N(expected.begin(), res.begin(), n, err_msg); dpl_ranges::for_each(test_std_ranges::dpcpp_policy(), zip_view, test_std_ranges::f_mutuable, [](const auto& val) { return std::get<1>(val); }); auto zip_view_sort = my::zip(data, data); - auto it = zip_view_sort.begin(); - std::sort(zip_view_sort.begin(), zip_view_sort.begin() + 5, [](const auto& val1, const auto& val2) { return std::get<0>(val1) < std::get<0>(val2); }); - std::ranges::sort(zip_view_sort, std::greater{}, [](auto&& val) { return std::get<0>(val); }); + std::sort(zip_view_sort.begin(), zip_view_sort.begin() + max_n, [](const auto& val1, const auto& val2) { return std::get<0>(val1) > std::get<0>(val2); }); + for(int i = 0; i < max_n; ++i) + assert(std::get<0>(zip_view_sort[i]) == max_n - 1 - i); + + std::ranges::sort(zip_view_sort, std::less{}, [](auto&& val) { return std::get<0>(val); }); + for(int i = 0; i < max_n; ++i) + assert(std::get<0>(zip_view_sort[i]) == i); static_assert(std::ranges::random_access_range); static_assert(std::random_access_iterator); - //dpl_ranges::sort(oneapi::dpl::execution::seq, zip_view_sort, std::greater{}, [](auto&& val) { return std::get<0>(val); }); - - //test_std_ranges::call_with_host_policies(dpl_ranges::sort, zip_view_sort, test_std_ranges::binary_pred, [](const auto& val) { return std::get<0>(val); }); + test_std_ranges::call_with_host_policies(dpl_ranges::sort, zip_view_sort, std::greater{}, [](const auto& val) { return std::get<0>(val); }); + for(int i = 0; i < max_n; ++i) + assert(std::get<0>(zip_view_sort[i]) == max_n - 1 - i); #endif //_ENABLE_STD_RANGES_TESTING From b78b59a09fb1f29f90d5a446f39630e13fb7cbe3 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Wed, 25 Sep 2024 16:09:00 +0200 Subject: [PATCH 08/43] [oneDPL][ranges][zip_view] -> oneapi::dpl::ranges --- include/oneapi/dpl/pstl/zip_view_impl.h | 40 ++++++++++++++----------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 6b3df2bc15..ae1345b434 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -5,7 +5,13 @@ #include #include -namespace my { +namespace oneapi +{ +namespace dpl +{ + +namespace ranges +{ template concept all_forward = ( std::ranges::forward_range> && ... ); @@ -33,9 +39,6 @@ struct declare_iterator_category { using iterator_category = std::input_iterator_tag; }; -template -using tuple_type = oneapi::dpl::__internal::tuple; - template requires ((std::ranges::view && ... ) && (sizeof...(Views) > 0)) class zip_view : public std::ranges::view_interface> { @@ -283,7 +286,7 @@ class zip_view : public std::ranges::view_interface> { constexpr auto begin() const requires ( std::ranges::range && ... ) { - auto __tr = [](auto... __args) { return iterator(__args...);}; + auto __tr = [](auto... __args) { return iterator(__args...);}; return apply_to_tuple(__tr, std::ranges::begin, views_); } @@ -308,20 +311,21 @@ class zip_view : public std::ranges::view_interface> { constexpr auto end() const requires (std::ranges::range && ...) { - if constexpr (!zip_is_common) { - return std::apply([](auto... views) { - return sentinel(std::ranges::end(views)...); - }, - views_); - } else if constexpr ((std::ranges::random_access_range && ...)) { + if constexpr (!zip_is_common) + { + auto __tr = [](auto... __args) { return sentinel(__args...);}; + return apply_to_tuple(__tr, std::ranges::end, views_); + } + else if constexpr ((std::ranges::random_access_range && ...)) + { auto it = begin(); it += size(); return it; - } else { - return std::apply([](auto... views) { - return iterator(std::ranges::end(views)...); - }, - views_); + } + else + { + auto __tr = [](auto... __args) { return iterator(__args...);}; + return apply_to_tuple(__tr, std::ranges::end, views_); } } @@ -355,4 +359,6 @@ struct zip_fn { inline constexpr zip_fn zip{}; -} // namespace my \ No newline at end of file +} // namespace ranges +} // namespace dpl +} // namespace oneapi \ No newline at end of file From 495393cee6016359ce0215f2c7497782b6314d6f Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Wed, 25 Sep 2024 16:09:27 +0200 Subject: [PATCH 09/43] [oneDPL][ranges][zip_view][test] -> oneapi::dpl::ranges --- test/parallel_api/ranges/std_ranges_zip_view.pass.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp index 99f2157e50..b4b972e0c7 100644 --- a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp @@ -28,14 +28,14 @@ main() constexpr int max_n = 10; int data[max_n] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; - auto zip_view = my::zip(data, std::views::iota(0, max_n)) | std::views::take(5); + auto zip_view = dpl_ranges::zip(data, std::views::iota(0, max_n)) | std::views::take(5); std::ranges::for_each(zip_view, test_std_ranges::f_mutuable, [](const auto& val) { return std::get<1>(val); }); test_std_ranges::call_with_host_policies(dpl_ranges::for_each, zip_view, test_std_ranges::f_mutuable, [](const auto& val) { return std::get<1>(val); }); dpl_ranges::for_each(test_std_ranges::dpcpp_policy(), zip_view, test_std_ranges::f_mutuable, [](const auto& val) { return std::get<1>(val); }); - auto zip_view_sort = my::zip(data, data); + auto zip_view_sort = dpl_ranges::zip(data, data); std::sort(zip_view_sort.begin(), zip_view_sort.begin() + max_n, [](const auto& val1, const auto& val2) { return std::get<0>(val1) > std::get<0>(val2); }); for(int i = 0; i < max_n; ++i) From 9e7ed54da9f4ffe107728a2a7fc9f1134c982940 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Wed, 25 Sep 2024 16:14:31 +0200 Subject: [PATCH 10/43] [oneDPL][ranges][zip_view] + file header and guards --- include/oneapi/dpl/pstl/zip_view_impl.h | 29 +++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index ae1345b434..f975e9a255 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -1,8 +1,25 @@ -#include +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Copyright (C) Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// This file incorporates work covered by the following copyright and permission +// notice: +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// +//===----------------------------------------------------------------------===// + +#ifndef _ONEDPL_ZIP_VIEW_IMPL_H +#define _ONEDPL_ZIP_VIEW_IMPL_H + +#if _ONEDPL_CPP20_RANGES_PRESENT + #include -#include #include -#include #include namespace oneapi @@ -361,4 +378,8 @@ inline constexpr zip_fn zip{}; } // namespace ranges } // namespace dpl -} // namespace oneapi \ No newline at end of file +} // namespace oneapi + +#endif //_ONEDPL_CPP20_RANGES_PRESENT + +#endif //_ONEDPL_ZIP_VIEW_IMPL_H \ No newline at end of file From 4f86d0e8a07967a44fb8135972c9e3b97a389362 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Wed, 25 Sep 2024 17:08:46 +0200 Subject: [PATCH 11/43] [oneDPL][ranges][zip_view] + apply_to_tuple instead of std::apply; std::apply doesnt work with oneDPL tuple --- include/oneapi/dpl/pstl/zip_view_impl.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index f975e9a255..6b3afad9e0 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -309,20 +309,21 @@ class zip_view : public std::ranges::view_interface> { constexpr auto end() requires (std::ranges::range && ...) // requires !simple_view { { - if constexpr (!zip_is_common) { - return std::apply([](auto... views) { - return sentinel(std::ranges::end(views)...); - }, - views_); - } else if constexpr ((std::ranges::random_access_range && ...)) { + if constexpr (!zip_is_common) + { + auto __tr = [](auto... __args) { return sentinel(__args...);}; + return apply_to_tuple(__tr, std::ranges::end, views_); + } + else if constexpr ((std::ranges::random_access_range && ...)) + { auto it = begin(); it += size(); return it; - } else { - return std::apply([](auto... views) { - return iterator(std::ranges::end(views)...); - }, - views_); + } + else + { + auto __tr = [](auto... __args) { return iterator(__args...);}; + return apply_to_tuple(__tr, std::ranges::end, views_); } } From 803c787567f289276d6d017a1bc4fb7f29f465b8 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Thu, 26 Sep 2024 11:31:10 +0200 Subject: [PATCH 12/43] [oneDPL][ranges][zip_view] + begin_imp, end_impl to reduce code duplication --- include/oneapi/dpl/pstl/zip_view_impl.h | 54 ++++++++++++------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 6b3afad9e0..913724ee0c 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -293,25 +293,22 @@ class zip_view : public std::ranges::view_interface> { tuple_type...>>; end_type end_; - }; // class sentinel + }; // class sentinel - constexpr auto begin() requires (std::ranges::range && ...) // !simple_view? - { - auto __tr = [](auto... __args) { return iterator(__args...);}; - return apply_to_tuple(__tr, std::ranges::begin, views_); - } - - constexpr auto begin() const requires ( std::ranges::range && ... ) +private: + template + constexpr auto begin_impl() { - auto __tr = [](auto... __args) { return iterator(__args...);}; + auto __tr = [](auto... __args) { return iterator(__args...);}; return apply_to_tuple(__tr, std::ranges::begin, views_); } - constexpr auto end() requires (std::ranges::range && ...) // requires !simple_view { + template + constexpr auto end_impl() { if constexpr (!zip_is_common) { - auto __tr = [](auto... __args) { return sentinel(__args...);}; + auto __tr = [](auto... __args) { return sentinel(__args...);}; return apply_to_tuple(__tr, std::ranges::end, views_); } else if constexpr ((std::ranges::random_access_range && ...)) @@ -322,29 +319,30 @@ class zip_view : public std::ranges::view_interface> { } else { - auto __tr = [](auto... __args) { return iterator(__args...);}; + auto __tr = [](auto... __args) { return iterator(__args...);}; return apply_to_tuple(__tr, std::ranges::end, views_); } } +public: + constexpr auto begin() requires (std::ranges::range && ...) // !simple_view? + { + return begin_impl(); + } + + constexpr auto begin() const requires ( std::ranges::range && ... ) + { + return const_cast(this)->begin_impl(); + } + + constexpr auto end() requires (std::ranges::range && ...) // requires !simple_view { + { + return end_impl(); + } + constexpr auto end() const requires (std::ranges::range && ...) { - if constexpr (!zip_is_common) - { - auto __tr = [](auto... __args) { return sentinel(__args...);}; - return apply_to_tuple(__tr, std::ranges::end, views_); - } - else if constexpr ((std::ranges::random_access_range && ...)) - { - auto it = begin(); - it += size(); - return it; - } - else - { - auto __tr = [](auto... __args) { return iterator(__args...);}; - return apply_to_tuple(__tr, std::ranges::end, views_); - } + return const_cast(this)->end_impl(); } constexpr auto size() requires (std::ranges::sized_range && ...) From b99e73522bdafa43fcc135a79de1505b733e41e5 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Thu, 26 Sep 2024 14:18:20 +0200 Subject: [PATCH 13/43] Revert "[oneDPL][ranges][zip_view] + begin_imp, end_impl to reduce code duplication" This reverts commit fc04cafc39bc694473a2b8a34ea578dc6fcf4562. --- include/oneapi/dpl/pstl/zip_view_impl.h | 54 +++++++++++++------------ 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 913724ee0c..6b3afad9e0 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -293,22 +293,25 @@ class zip_view : public std::ranges::view_interface> { tuple_type...>>; end_type end_; - }; // class sentinel + }; // class sentinel -private: - template - constexpr auto begin_impl() + constexpr auto begin() requires (std::ranges::range && ...) // !simple_view? { - auto __tr = [](auto... __args) { return iterator(__args...);}; + auto __tr = [](auto... __args) { return iterator(__args...);}; return apply_to_tuple(__tr, std::ranges::begin, views_); } - template - constexpr auto end_impl() + constexpr auto begin() const requires ( std::ranges::range && ... ) + { + auto __tr = [](auto... __args) { return iterator(__args...);}; + return apply_to_tuple(__tr, std::ranges::begin, views_); + } + + constexpr auto end() requires (std::ranges::range && ...) // requires !simple_view { { if constexpr (!zip_is_common) { - auto __tr = [](auto... __args) { return sentinel(__args...);}; + auto __tr = [](auto... __args) { return sentinel(__args...);}; return apply_to_tuple(__tr, std::ranges::end, views_); } else if constexpr ((std::ranges::random_access_range && ...)) @@ -319,30 +322,29 @@ class zip_view : public std::ranges::view_interface> { } else { - auto __tr = [](auto... __args) { return iterator(__args...);}; + auto __tr = [](auto... __args) { return iterator(__args...);}; return apply_to_tuple(__tr, std::ranges::end, views_); } } -public: - constexpr auto begin() requires (std::ranges::range && ...) // !simple_view? - { - return begin_impl(); - } - - constexpr auto begin() const requires ( std::ranges::range && ... ) - { - return const_cast(this)->begin_impl(); - } - - constexpr auto end() requires (std::ranges::range && ...) // requires !simple_view { - { - return end_impl(); - } - constexpr auto end() const requires (std::ranges::range && ...) { - return const_cast(this)->end_impl(); + if constexpr (!zip_is_common) + { + auto __tr = [](auto... __args) { return sentinel(__args...);}; + return apply_to_tuple(__tr, std::ranges::end, views_); + } + else if constexpr ((std::ranges::random_access_range && ...)) + { + auto it = begin(); + it += size(); + return it; + } + else + { + auto __tr = [](auto... __args) { return iterator(__args...);}; + return apply_to_tuple(__tr, std::ranges::end, views_); + } } constexpr auto size() requires (std::ranges::sized_range && ...) From ea711d9449941357d62bebc1aca5addd0b814db7 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Fri, 27 Sep 2024 18:41:35 +0200 Subject: [PATCH 14/43] [oneDPL][ranges][zip_view][test] + minor changes --- test/parallel_api/ranges/std_ranges_test.h | 6 ------ test/parallel_api/ranges/std_ranges_zip_view.pass.cpp | 3 +++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/test/parallel_api/ranges/std_ranges_test.h b/test/parallel_api/ranges/std_ranges_test.h index 745bfefc6f..0efc433648 100644 --- a/test/parallel_api/ranges/std_ranges_test.h +++ b/test/parallel_api/ranges/std_ranges_test.h @@ -15,7 +15,6 @@ #include #include -#include #include "support/test_config.h" #include "support/test_macros.h" @@ -550,11 +549,6 @@ struct test_range_algo test, mode>{max_n}(host_policies(), algo, checker, std::views::all, std::identity{}, args...); #endif -#if 0//zip_view - auto zip_view = [](auto&& v) { return my::zip(v); }; - test, mode>{}(host_policies(), algo, checker, zip_view, std::identity{}, args...); -#endif - #if TEST_DPCPP_BACKEND_PRESENT //Skip the cases with pointer-to-function and hetero policy because pointer-to-function is not supported within kernel code. if constexpr(!std::disjunction_v...>) diff --git a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp index b4b972e0c7..d560b94b45 100644 --- a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp @@ -14,6 +14,7 @@ //===----------------------------------------------------------------------===// #include "std_ranges_test.h" +#include template struct print_type; @@ -33,7 +34,9 @@ main() test_std_ranges::call_with_host_policies(dpl_ranges::for_each, zip_view, test_std_ranges::f_mutuable, [](const auto& val) { return std::get<1>(val); }); +#if TEST_DPCPP_BACKEND_PRESENT dpl_ranges::for_each(test_std_ranges::dpcpp_policy(), zip_view, test_std_ranges::f_mutuable, [](const auto& val) { return std::get<1>(val); }); +#endif auto zip_view_sort = dpl_ranges::zip(data, data); From f73db46a0a2f4b12aa2b3d9503112d25e12b199d Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 7 Oct 2024 18:33:23 +0200 Subject: [PATCH 15/43] [oneDPL][ranges][zip_view] + minor changes --- include/oneapi/dpl/pstl/ranges_defs.h | 3 +++ include/oneapi/dpl/pstl/zip_view_impl.h | 2 +- test/parallel_api/ranges/std_ranges_zip_view.pass.cpp | 5 +---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/oneapi/dpl/pstl/ranges_defs.h b/include/oneapi/dpl/pstl/ranges_defs.h index 39f67ed858..aab2aad2db 100644 --- a/include/oneapi/dpl/pstl/ranges_defs.h +++ b/include/oneapi/dpl/pstl/ranges_defs.h @@ -23,6 +23,9 @@ #include #endif +//oneapi::dpl::ranges::zip_view support for C++20 +#include "zip_view_impl.h" + #include "utils_ranges.h" #if _ONEDPL_BACKEND_SYCL # include "hetero/dpcpp/utils_ranges_sycl.h" diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 6b3afad9e0..e40626cbd5 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -383,4 +383,4 @@ inline constexpr zip_fn zip{}; #endif //_ONEDPL_CPP20_RANGES_PRESENT -#endif //_ONEDPL_ZIP_VIEW_IMPL_H \ No newline at end of file +#endif //_ONEDPL_ZIP_VIEW_IMPL_H diff --git a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp index d560b94b45..cacbedfcd3 100644 --- a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp @@ -14,10 +14,7 @@ //===----------------------------------------------------------------------===// #include "std_ranges_test.h" -#include - -template -struct print_type; +#include std::int32_t main() From 73f5a3530888e8636a67815d2ad62be36609c1ce Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Wed, 9 Oct 2024 14:56:52 +0200 Subject: [PATCH 16/43] [oneDPL][ranges][zip_view] + #include "tuple_impl.h" --- include/oneapi/dpl/pstl/zip_view_impl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index e40626cbd5..08ee581198 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -22,6 +22,8 @@ #include #include +#include "tuple_impl.h" + namespace oneapi { namespace dpl From 304e42ac14d376068bc580d82adf6799cbf4ea21 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Tue, 22 Oct 2024 14:38:45 +0200 Subject: [PATCH 17/43] [oneDPL][ranges][zip_view][test] + test_zip_view_base_op() --- .../ranges/std_ranges_zip_view.pass.cpp | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp index cacbedfcd3..eb65ab140c 100644 --- a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp @@ -16,11 +16,43 @@ #include "std_ranges_test.h" #include +#if _ENABLE_STD_RANGES_TESTING +#include + +void test_zip_view_base_op() +{ + namespace dpl_ranges = oneapi::dpl::ranges; + + constexpr int max_n = 100; + std::vector vec1(max_n); + std::vector vec2(max_n/2); + + auto zip_view = dpl_ranges::zip(vec1, vec2); + + static_assert(std::random_access_iterator); + static_assert(std::sentinel_for); + + static_assert(std::random_access_iterator); + static_assert(std::sentinel_for); + + EXPECT_TRUE(zip_view.end() - zip_view.begin() == max_n/2, + "Difference operation between an iterator and a sentinel (zip_view) returns a wrong result."); + + EXPECT_TRUE(zip_view[2] == *(zip_view.begin() + 2), + "Subscription or dereferencing operation for zip_view returns a wrong result."); + + EXPECT_TRUE(std::ranges::size(zip_view) == max_n/2, "zip_view::size method returns a wrong result."); + EXPECT_TRUE((bool)zip_view, "zip_view::operator bool() method returns a wrong result."); +} +#endif //_ENABLE_STD_RANGES_TESTING + std::int32_t main() { #if _ENABLE_STD_RANGES_TESTING + test_zip_view_base_op(); + namespace dpl_ranges = oneapi::dpl::ranges; constexpr int max_n = 10; From 1b58400946ce7e13df597071ed1d73c188eb414a Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Fri, 18 Oct 2024 18:11:38 +0200 Subject: [PATCH 18/43] [oneDPL][ranges][zip_view] + implementation fix for 'operator-' between zip_view::iterators --- include/oneapi/dpl/pstl/zip_view_impl.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 08ee581198..793fc3d661 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -189,13 +189,13 @@ class zip_view : public std::ranges::view_interface> { friend constexpr auto operator<=>(const iterator& x, const iterator& y) requires all_random_access { - return x.current_ == y.current_; + return x.current_ <=> y.current_; } friend constexpr auto operator-(const iterator& x, const iterator& y) requires all_random_access { - return std::get<0>(x.current_) - std::get<0>(y.current_); + return x.distance_to_it(y.current_, std::make_index_sequence()); } friend constexpr iterator operator+(iterator it, difference_type n) @@ -233,6 +233,15 @@ class zip_view : public std::ranges::view_interface> { ( (min = std::min(min, (std::get(current_) - std::get(sentinels)))) , ... ); return min; } + template + constexpr std::common_type_t, + std::ranges::range_difference_t>...> + distance_to_it(const iterator it, std::index_sequence<0, In...>) const { + auto min = std::get<0>(it.current_) - std::get<0>(current_); + + ( (min = std::min(min, (std::get(it.current_) - std::get(current_)))) , ... ); + return min; + } friend class zip_view; From 7a7facb050d24e133c17330c48776294dce652f7 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 21 Oct 2024 13:58:29 +0200 Subject: [PATCH 19/43] Update include/oneapi/dpl/pstl/zip_view_impl.h Co-authored-by: Konstantin Boyarinov --- include/oneapi/dpl/pstl/zip_view_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 793fc3d661..5f29dd544a 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -84,7 +84,7 @@ class zip_view : public std::ranges::view_interface> { static auto apply_to_tuple(_F __f, _Tuple& __t) { - apply_to_tuple_impl([](auto...){}, __f, __t, std::make_index_sequence{}); + apply_to_tuple([](auto...){}, __f, __t); } public: From 44fa2ae4ed5121c0d0982504840a2582e482da50 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 21 Oct 2024 13:58:35 +0200 Subject: [PATCH 20/43] Update include/oneapi/dpl/pstl/zip_view_impl.h Co-authored-by: Konstantin Boyarinov --- include/oneapi/dpl/pstl/zip_view_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 5f29dd544a..32f72447b4 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -81,7 +81,7 @@ class zip_view : public std::ranges::view_interface> { } template - static auto + static decltype(auto) apply_to_tuple(_F __f, _Tuple& __t) { apply_to_tuple([](auto...){}, __f, __t); From 3bf4b6ddf412d68be74744d97e75653ad7d9b474 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 21 Oct 2024 13:58:46 +0200 Subject: [PATCH 21/43] Update include/oneapi/dpl/pstl/zip_view_impl.h Co-authored-by: Konstantin Boyarinov --- include/oneapi/dpl/pstl/zip_view_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 32f72447b4..9f9aeeb5bb 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -89,7 +89,7 @@ class zip_view : public std::ranges::view_interface> { public: zip_view() = default; - constexpr zip_view(Views... views) : views_(views...) {} + constexpr zip_view(Views... views) : views_(std::move(views)...) {} template class iterator : declare_iterator_category { From d2aa94258f4ff19b39161220e9526c251d807b5d Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 21 Oct 2024 13:58:54 +0200 Subject: [PATCH 22/43] Update include/oneapi/dpl/pstl/zip_view_impl.h Co-authored-by: Konstantin Boyarinov --- include/oneapi/dpl/pstl/zip_view_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 9f9aeeb5bb..1c66652f22 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -205,7 +205,7 @@ class zip_view : public std::ranges::view_interface> { friend constexpr iterator operator+(difference_type n, iterator it) { - return it+=n; + return it += n; } friend constexpr iterator operator-(iterator it, difference_type n) From 6d61fe9cc2ddf7581f401077546fe7fcda38951b Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 21 Oct 2024 13:59:11 +0200 Subject: [PATCH 23/43] Update include/oneapi/dpl/pstl/zip_view_impl.h Co-authored-by: Konstantin Boyarinov --- include/oneapi/dpl/pstl/zip_view_impl.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 1c66652f22..5835d2fedf 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -123,7 +123,6 @@ class zip_view : public std::ranges::view_interface> { public: return_tuple_type operator*() const { - auto __tr = [](auto&&... __args) -> decltype(auto) { return return_tuple_type(__args...);}; return apply_to_tuple(__tr, [](auto it) -> decltype(auto) { return *it;}, current_); } From 9e8b0b68dd3af01aae1c40fc7f53f90808b9ad28 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 21 Oct 2024 13:59:17 +0200 Subject: [PATCH 24/43] Update include/oneapi/dpl/pstl/zip_view_impl.h Co-authored-by: Konstantin Boyarinov --- include/oneapi/dpl/pstl/zip_view_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 5835d2fedf..3e2629e8ff 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -209,7 +209,7 @@ class zip_view : public std::ranges::view_interface> { friend constexpr iterator operator-(iterator it, difference_type n) { - return it-=n; + return it -= n; } private: From 93f7a393b60d9308e3be0216de14f2820afa1da7 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 21 Oct 2024 13:59:28 +0200 Subject: [PATCH 25/43] Update include/oneapi/dpl/pstl/zip_view_impl.h Co-authored-by: Konstantin Boyarinov --- include/oneapi/dpl/pstl/zip_view_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 3e2629e8ff..3ae6ac7f50 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -199,7 +199,7 @@ class zip_view : public std::ranges::view_interface> { friend constexpr iterator operator+(iterator it, difference_type n) { - return it+=n; + return it += n; } friend constexpr iterator operator+(difference_type n, iterator it) From b8ae836ebe11b431b3f1d70c3913d26ae913073c Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 21 Oct 2024 14:11:54 +0200 Subject: [PATCH 26/43] Update include/oneapi/dpl/pstl/zip_view_impl.h Co-authored-by: Konstantin Boyarinov --- include/oneapi/dpl/pstl/zip_view_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 3ae6ac7f50..16286c15be 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -122,7 +122,7 @@ class zip_view : public std::ranges::view_interface> { : current_(iterators...) {} public: - return_tuple_type operator*() const { + constexpr return_tuple_type operator*() const { auto __tr = [](auto&&... __args) -> decltype(auto) { return return_tuple_type(__args...);}; return apply_to_tuple(__tr, [](auto it) -> decltype(auto) { return *it;}, current_); } From 60dca5c5c5c6f18dc8b8b2d7499a3d5f8af93a0f Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 21 Oct 2024 14:12:08 +0200 Subject: [PATCH 27/43] Update include/oneapi/dpl/pstl/zip_view_impl.h Co-authored-by: Konstantin Boyarinov --- include/oneapi/dpl/pstl/zip_view_impl.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 16286c15be..6e9856fe50 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -149,7 +149,6 @@ class zip_view : public std::ranges::view_interface> { } constexpr iterator& operator--() requires all_bidirectional { - zip_view::apply_to_tuple([](auto& it) { return --it; }, current_); return *this; } From 59e4587184990474cb7cc284aa5b7011b1aab9b5 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 21 Oct 2024 14:16:51 +0200 Subject: [PATCH 28/43] [oneDPL][ranges][zip_view] + std::get usage --- include/oneapi/dpl/pstl/zip_view_impl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 6e9856fe50..d32662c16f 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -70,7 +70,7 @@ class zip_view : public std::ranges::view_interface> { static decltype(auto) apply_to_tuple_impl(_ReturnAdapter __tr, _F __f, _Tuple& __t, std::index_sequence<_Ip...>) { - return __tr(__f(oneapi::dpl::__internal::get_impl<_Ip>()(__t))...); + return __tr(__f(std::get<_Ip>(__t))...); } template @@ -81,7 +81,7 @@ class zip_view : public std::ranges::view_interface> { } template - static decltype(auto) + static void apply_to_tuple(_F __f, _Tuple& __t) { apply_to_tuple([](auto...){}, __f, __t); From 0f761d071e48caee59f6d7fef8e028c565b32261 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 21 Oct 2024 14:22:56 +0200 Subject: [PATCH 29/43] [oneDPL][ranges][zip_view] + 'std::forward(__args)' usage --- include/oneapi/dpl/pstl/zip_view_impl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index d32662c16f..41140b6a1a 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -123,7 +123,8 @@ class zip_view : public std::ranges::view_interface> { public: constexpr return_tuple_type operator*() const { - auto __tr = [](auto&&... __args) -> decltype(auto) { return return_tuple_type(__args...);}; + auto __tr = [](auto&&... __args) -> decltype(auto) + { return return_tuple_type(std::forward(__args)...);}; return apply_to_tuple(__tr, [](auto it) -> decltype(auto) { return *it;}, current_); } From 929c2376e14633d2a823e82d29278ff4c8ac1524 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 21 Oct 2024 14:31:09 +0200 Subject: [PATCH 30/43] [oneDPL][ranges][zip_view] + 'minor change' for const/non const type definition --- include/oneapi/dpl/pstl/zip_view_impl.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 41140b6a1a..d45fd5fb1c 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -102,13 +102,15 @@ class zip_view : public std::ranges::view_interface> { std::forward_iterator_tag, std::input_iterator_tag>>>; - using value_type = std::conditional_t...>, - tuple_type...>>; + using value_type = std::conditional_t...>, + tuple_type...>>; - using difference_type = std::conditional_t...>, - std::common_type_t...>>; - using return_tuple_type = std::conditional_t>::reference...>, - tuple_type>::reference...>>; + using difference_type = std::conditional_t...>, + std::common_type_t...>>; + + using return_tuple_type = std::conditional_t>::reference...>, + tuple_type>::reference...>>; iterator() = default; @@ -303,9 +305,9 @@ class zip_view : public std::ranges::view_interface> { tuple_type...>>; end_type end_; - }; // class sentinel + }; // class sentinel - constexpr auto begin() requires (std::ranges::range && ...) // !simple_view? + constexpr auto begin() requires (std::ranges::range && ...) { auto __tr = [](auto... __args) { return iterator(__args...);}; return apply_to_tuple(__tr, std::ranges::begin, views_); @@ -317,7 +319,7 @@ class zip_view : public std::ranges::view_interface> { return apply_to_tuple(__tr, std::ranges::begin, views_); } - constexpr auto end() requires (std::ranges::range && ...) // requires !simple_view { + constexpr auto end() requires (std::ranges::range && ...) { if constexpr (!zip_is_common) { From 555e1ee2ef0c06f321cd83d6366180333be4b615 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Tue, 22 Oct 2024 16:25:32 +0200 Subject: [PATCH 31/43] [oneDPL][ranges][zip_view] + fix operator<=> implementation --- include/oneapi/dpl/pstl/zip_view_impl.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index d45fd5fb1c..8df66df08f 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -190,7 +190,11 @@ class zip_view : public std::ranges::view_interface> { friend constexpr auto operator<=>(const iterator& x, const iterator& y) requires all_random_access { - return x.current_ <=> y.current_; + if (x.current_ < y.current_) + return -1; + else if (x.current_ == y.current_) + return 0; + return 1; //x.current > y.current_ } friend constexpr auto operator-(const iterator& x, const iterator& y) From 06888b7832464c063a8d8cc7d70bdbcf252156f2 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Fri, 25 Oct 2024 17:20:08 +0200 Subject: [PATCH 32/43] [oneDPL][ranges][zip_view][test] removed cbegin(), cend() test cases because they are supported only with C++23 --- test/parallel_api/ranges/std_ranges_zip_view.pass.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp index eb65ab140c..46d82849b8 100644 --- a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp @@ -32,9 +32,6 @@ void test_zip_view_base_op() static_assert(std::random_access_iterator); static_assert(std::sentinel_for); - static_assert(std::random_access_iterator); - static_assert(std::sentinel_for); - EXPECT_TRUE(zip_view.end() - zip_view.begin() == max_n/2, "Difference operation between an iterator and a sentinel (zip_view) returns a wrong result."); From 2ce2dfb6b684fe56afa18002e906b267404435f9 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Fri, 25 Oct 2024 18:12:45 +0200 Subject: [PATCH 33/43] [oneDPL][ranges][zip_view][test] + front(), back() methods check --- test/parallel_api/ranges/std_ranges_zip_view.pass.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp index 46d82849b8..43b28e01b7 100644 --- a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp @@ -40,6 +40,9 @@ void test_zip_view_base_op() EXPECT_TRUE(std::ranges::size(zip_view) == max_n/2, "zip_view::size method returns a wrong result."); EXPECT_TRUE((bool)zip_view, "zip_view::operator bool() method returns a wrong result."); + + EXPECT_TRUE(zip_view[0] == zip_view.front(), "zip_view::front method returns a wrong result."); + EXPECT_TRUE(zip_view[z_v.size() - 1] == zip_view.back(), "zip_view::back method returns a wrong result.") } #endif //_ENABLE_STD_RANGES_TESTING From ce181ff3eb947ef8b4a9160ba040dfc6dbd0bbfd Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Tue, 29 Oct 2024 11:20:43 +0100 Subject: [PATCH 34/43] [oneDPL][ranges][zip_view][test] + empty constructor call check --- test/parallel_api/ranges/std_ranges_zip_view.pass.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp index 43b28e01b7..4450c4dd9f 100644 --- a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp @@ -42,7 +42,11 @@ void test_zip_view_base_op() EXPECT_TRUE((bool)zip_view, "zip_view::operator bool() method returns a wrong result."); EXPECT_TRUE(zip_view[0] == zip_view.front(), "zip_view::front method returns a wrong result."); - EXPECT_TRUE(zip_view[z_v.size() - 1] == zip_view.back(), "zip_view::back method returns a wrong result.") + EXPECT_TRUE(zip_view[zip_view.size() - 1] == zip_view.back(), "zip_view::back method returns a wrong result.") + + using zip_view_t = dpl_ranges::zip_view>; + auto zip_view_0 = zip_view_t(); + EXPECT_TRUE(zip_view_0.empty(), "zip_view::empty() method returns a wrong result."); } #endif //_ENABLE_STD_RANGES_TESTING From 5248f891a57833b7a284acb27830d3780a96559b Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Wed, 30 Oct 2024 17:55:56 +0100 Subject: [PATCH 35/43] [oneDPL][ranges][zip_view][test] + ; --- test/parallel_api/ranges/std_ranges_zip_view.pass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp index 4450c4dd9f..e1da7b1146 100644 --- a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp @@ -42,7 +42,7 @@ void test_zip_view_base_op() EXPECT_TRUE((bool)zip_view, "zip_view::operator bool() method returns a wrong result."); EXPECT_TRUE(zip_view[0] == zip_view.front(), "zip_view::front method returns a wrong result."); - EXPECT_TRUE(zip_view[zip_view.size() - 1] == zip_view.back(), "zip_view::back method returns a wrong result.") + EXPECT_TRUE(zip_view[zip_view.size() - 1] == zip_view.back(), "zip_view::back method returns a wrong result."); using zip_view_t = dpl_ranges::zip_view>; auto zip_view_0 = zip_view_t(); From 78d8c8ffae279b7ebf308a9cd33dc0a765abaed3 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 4 Nov 2024 16:22:51 +0100 Subject: [PATCH 36/43] [oneDPL][ranges][zip_view][test] const for compare_with_sentinels --- include/oneapi/dpl/pstl/zip_view_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 8df66df08f..dcdce7421b 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -225,7 +225,7 @@ class zip_view : public std::ranges::view_interface> { } template - constexpr bool compare_with_sentinels(const SentinelsTuple& sentinels, std::index_sequence) { + constexpr bool compare_with_sentinels(const SentinelsTuple& sentinels, std::index_sequence) const { return ( (std::get(current_) == std::get(sentinels)) || ... ); } From aa2011765e30e057fc0d199aaca3f8d8a88b7d9a Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Wed, 6 Nov 2024 18:47:41 +0100 Subject: [PATCH 37/43] [oneDPL][ranges][zip_view][test] a fix for zip_view::iterator::operator- --- include/oneapi/dpl/pstl/zip_view_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index dcdce7421b..8a65e37264 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -200,7 +200,7 @@ class zip_view : public std::ranges::view_interface> { friend constexpr auto operator-(const iterator& x, const iterator& y) requires all_random_access { - return x.distance_to_it(y.current_, std::make_index_sequence()); + return y.distance_to_it(x.current_, std::make_index_sequence()); } friend constexpr iterator operator+(iterator it, difference_type n) From e18c255b5ef5441504b48ef55b802685be8e1812 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Fri, 8 Nov 2024 14:55:02 +0100 Subject: [PATCH 38/43] [oneDPL][rfc][zip_view] + std::ranges::range_reference_t usage; it fixes some issues --- include/oneapi/dpl/pstl/zip_view_impl.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 8a65e37264..710da9e860 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -108,9 +108,8 @@ class zip_view : public std::ranges::view_interface> { using difference_type = std::conditional_t...>, std::common_type_t...>>; - using return_tuple_type = std::conditional_t>::reference...>, - tuple_type>::reference...>>; + using return_tuple_type = std::conditional_t...>, + tuple_type...>>; iterator() = default; From 36c198905f778aa1b6cf4d7beefa098a4e215988 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Fri, 8 Nov 2024 18:13:39 +0100 Subject: [PATCH 39/43] [oneDPL][ranges][zip_view][test] + minor changes --- test/parallel_api/ranges/std_ranges_zip_view.pass.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp index e1da7b1146..f3fac936e9 100644 --- a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp @@ -43,10 +43,11 @@ void test_zip_view_base_op() EXPECT_TRUE(zip_view[0] == zip_view.front(), "zip_view::front method returns a wrong result."); EXPECT_TRUE(zip_view[zip_view.size() - 1] == zip_view.back(), "zip_view::back method returns a wrong result."); + EXPECT_TRUE(!zip_view.empty(), "zip_view::empty() method returns a wrong result."); using zip_view_t = dpl_ranges::zip_view>; auto zip_view_0 = zip_view_t(); - EXPECT_TRUE(zip_view_0.empty(), "zip_view::empty() method returns a wrong result."); + EXPECT_TRUE(!zip_view_0.empty(), "zip_view::empty() method returns a wrong result."); } #endif //_ENABLE_STD_RANGES_TESTING From ea1c686ab9e5ca0164f3aa7b58f1565c04579681 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Fri, 15 Nov 2024 16:46:10 +0100 Subject: [PATCH 40/43] [oneDPL][zip_view] + minor improvements --- include/oneapi/dpl/pstl/zip_view_impl.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index 710da9e860..c0531c716d 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -61,11 +61,9 @@ struct declare_iterator_category { template requires ((std::ranges::view && ... ) && (sizeof...(Views) > 0)) class zip_view : public std::ranges::view_interface> { -public: template using tuple_type = oneapi::dpl::__internal::tuple; -private: template static decltype(auto) apply_to_tuple_impl(_ReturnAdapter __tr, _F __f, _Tuple& __t, std::index_sequence<_Ip...>) @@ -92,7 +90,7 @@ class zip_view : public std::ranges::view_interface> { constexpr zip_view(Views... views) : views_(std::move(views)...) {} template - class iterator : declare_iterator_category { + class iterator : declare_iterator_category { public: using iterator_concept = std::conditional_t, std::random_access_iterator_tag, @@ -108,9 +106,6 @@ class zip_view : public std::ranges::view_interface> { using difference_type = std::conditional_t...>, std::common_type_t...>>; - using return_tuple_type = std::conditional_t...>, - tuple_type...>>; - iterator() = default; constexpr iterator(iterator i) @@ -123,13 +118,17 @@ class zip_view : public std::ranges::view_interface> { : current_(iterators...) {} public: - constexpr return_tuple_type operator*() const { - auto __tr = [](auto&&... __args) -> decltype(auto) - { return return_tuple_type(std::forward(__args)...);}; + constexpr decltype(auto) operator*() const { + auto __tr = [](auto&&... __args) -> decltype(auto) { + using return_tuple_type = std::conditional_t< + !Const, tuple_type...>, + tuple_type...>>; + return return_tuple_type(std::forward(__args)...); + }; return apply_to_tuple(__tr, [](auto it) -> decltype(auto) { return *it;}, current_); } - constexpr return_tuple_type operator[]( difference_type n ) const + constexpr decltype(auto) operator[]( difference_type n ) const requires all_random_access { return *(*this + n); @@ -372,7 +371,7 @@ class zip_view : public std::ranges::view_interface> { return apply_to_tuple(__tr, std::ranges::size, views_); } - constexpr auto size() const requires (std::ranges::sized_range && ...) + constexpr auto size() const requires (std::ranges::sized_range && ...) { return const_cast(this)->size(); } From 5f43b524f8315e9505bfd9f6e82a69c5971cf846 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Tue, 19 Nov 2024 17:17:22 +0100 Subject: [PATCH 41/43] [oneDPL][ranges][zip_view][test] + EXPECT_TRUE usage --- test/parallel_api/ranges/std_ranges_zip_view.pass.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp index f3fac936e9..469512db27 100644 --- a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp @@ -76,11 +76,11 @@ main() std::sort(zip_view_sort.begin(), zip_view_sort.begin() + max_n, [](const auto& val1, const auto& val2) { return std::get<0>(val1) > std::get<0>(val2); }); for(int i = 0; i < max_n; ++i) - assert(std::get<0>(zip_view_sort[i]) == max_n - 1 - i); + EXPECT_TRUE(std::get<0>(zip_view_sort[i]) == max_n - 1 - i, "Wrong effect for std::sort with zip_view."); std::ranges::sort(zip_view_sort, std::less{}, [](auto&& val) { return std::get<0>(val); }); for(int i = 0; i < max_n; ++i) - assert(std::get<0>(zip_view_sort[i]) == i); + EXPECT_TRUE(std::get<0>(zip_view_sort[i]) == i, "Wrong effect for std::ranges::sort with zip_view."); static_assert(std::ranges::random_access_range); static_assert(std::random_access_iterator); From 5c4d5e179cc5710a700da0063e534e25168d7702 Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 2 Dec 2024 13:04:13 +0100 Subject: [PATCH 42/43] [oneDPL][ranges][zip_view] + operator oneapi::dpl::zip_iterator() --- include/oneapi/dpl/pstl/zip_view_impl.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/oneapi/dpl/pstl/zip_view_impl.h b/include/oneapi/dpl/pstl/zip_view_impl.h index c0531c716d..2a7d88f8e6 100644 --- a/include/oneapi/dpl/pstl/zip_view_impl.h +++ b/include/oneapi/dpl/pstl/zip_view_impl.h @@ -23,6 +23,7 @@ #include #include "tuple_impl.h" +#include "iterator_impl.h" namespace oneapi { @@ -118,6 +119,13 @@ class zip_view : public std::ranges::view_interface> { : current_(iterators...) {} public: + template + operator oneapi::dpl::zip_iterator() const + { + auto __tr = [](auto&&... __args) -> decltype(auto) { return oneapi::dpl::make_zip_iterator(__args...);}; + return apply_to_tuple(__tr, [](auto it) -> decltype(auto) { return it;}, current_); + } + constexpr decltype(auto) operator*() const { auto __tr = [](auto&&... __args) -> decltype(auto) { using return_tuple_type = std::conditional_t< From 1accd2a51323702fc3b8e7fc347d99a761c280bd Mon Sep 17 00:00:00 2001 From: MikeDvorskiy Date: Mon, 2 Dec 2024 14:22:08 +0100 Subject: [PATCH 43/43] [oneDPL][ranges][zip_view][test] + check conversion to oneapi::dpl::zip_iterator --- test/parallel_api/ranges/std_ranges_zip_view.pass.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp index 469512db27..3e4bc3366a 100644 --- a/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp +++ b/test/parallel_api/ranges/std_ranges_zip_view.pass.cpp @@ -74,6 +74,8 @@ main() auto zip_view_sort = dpl_ranges::zip(data, data); + oneapi::dpl::zip_iterator zip_it = zip_view_sort.begin(); //check conversion to oneapi::dpl::zip_iterator + std::sort(zip_view_sort.begin(), zip_view_sort.begin() + max_n, [](const auto& val1, const auto& val2) { return std::get<0>(val1) > std::get<0>(val2); }); for(int i = 0; i < max_n; ++i) EXPECT_TRUE(std::get<0>(zip_view_sort[i]) == max_n - 1 - i, "Wrong effect for std::sort with zip_view.");