[oneDPL][ranges] + zip_view implementation for C++20#1877
Conversation
9342293 to
91cf6b0
Compare
603daed to
80ef9c5
Compare
dmitriy-sobolev
left a comment
There was a problem hiding this comment.
Let me leave just a couple of minor comments. I am going to look at the whole PR during this week.
There was a problem hiding this comment.
What do you think about testing the following properties of zip_view/zip?
- begin/end (they should also probably be checked if they are iterators)
- cbegin/cend
- front/back
- size
- empty
- operator bool
- construction:
- ranges::zip(...)/ranges::zip_view(...)
- empty view (views::zip())
- another view (*move construction is not checked)
- another zip_view
- ranges::zip(...) is a customization point object
I assume that the functionality must match what is required from c++ standard looking at the description. That's why I suggest testing all these properties. Let me know if the implementation is expected to be more relaxed (and how if it is).
Update. I see that the PR integrates the whole LLVM test suite now. The table is not relevant now
|
The description says:
According to SYCL 2020, |
The advantage here of using oneDPL's tuple is that it is trivially copyable (for trivially copyable types) which means that any class or structure which uses oneDPL's tuple can be implicitly device copyable rather than requiring a specialization of sycl::is_device_copyable (because of the tuple). The advantage is not just to avoid extra code here but also to not impose requirements on users to provide these specializations for types which are composed of a zip_view as well. There can be downsides to using oneDPLs tuple in that it may not be as fully featured as |
Actually, before C++23 standard library there is a problem with |
f1c08a6 to
74d52be
Compare
|
regarding > * cbegin + cend |
78abd7f to
fdf3e9b
Compare
| if (x.current_ < y.current_) | ||
| return -1; | ||
| else if (x.current_ == y.current_) | ||
| return 0; | ||
| return 1; //x.current > y.current_ |
There was a problem hiding this comment.
Why cannot we use x.current <=> y.current? Spaceship operator is undefined for some of our internal iterator types or it is undefined for internal tuple?
There was a problem hiding this comment.
yes, spaceship operator is undefined for x.current_...
There was a problem hiding this comment.
When adding comparison between internal tuples, we looked at adding spaceship and it was deemed not worth the effort at the time. We could use this as motivation for adding it, but it would require a bit of work. We would need to trigger it off of __cpp_lib_three_way_comparison >= 201907L, and in that case replace the existing comparison operators with the spaceship, to time it properly with std::tuple <=> operator
There was a problem hiding this comment.
The thought was that it wasn't worth the maintenance because we would need to implement both to support our full support matrix, and it would be only helpful for those explicitly calling <=> on the internal tuple (which is what we might want to do here as I understand it).
There was a problem hiding this comment.
In any case it doesnt block zip_view productization, I believe. And we keep a spaceship operator for zip_view as is proposed.
|
|
||
| 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); |
There was a problem hiding this comment.
Our testing framework is not adapted for assert: it defines NDEBUG during release test builds. We should either avoid that definition, or do not rely on assert in the tests.
There was a problem hiding this comment.
- In spite of that we are using
assertin our tests more then 10 files... It seems an issue should be created. - I know that a better way to use our own macro like
EXPECT_TRUEf.e.
There was a problem hiding this comment.
- I will create it.
- That sounds good. Could you do it? I see that there is still one
assertin the test.
There was a problem hiding this comment.
- done.
And I suggest offline discussion aboutassert/EXPECT_TRUE/NDEBUG
zip_view is based on view_iterface, and the later does not have cbegin/cend in c++20. That means our c++20 zip_view will not have cbegin/cend, and we are not going to provide them. Is that correct understanding? |
0e35be1 to
5f43b52
Compare
| else if constexpr ((std::ranges::random_access_range<_Views> && ...)) | ||
| { | ||
| auto __it = begin(); | ||
| __it += size(); |
There was a problem hiding this comment.
Do we need to convert size() to iter_difference_t<iterator<false>> before +?
There was a problem hiding this comment.
It is made implicitly..
Explicit conversion? But it doesn't solve integer (difference type) overflow.
We may add a RT assert here for an integer overflow case.
There was a problem hiding this comment.
Actually, there is an assumnption in the standard: size() <= difference_type::max()
BTW, for C++20 there is std::ssize (https://en.cppreference.com/w/cpp/iterator/size.html)
There was a problem hiding this comment.
Yes, the conversion can be done implicitly, but for example with -Wsign-conversion, the clang compiler with generate warning if size() returns std::size_t and then cast it implicitly to difference_type that is std::ptrdiff_t.
I think it makes sense to avoid it by doing an explicit cast.
Uglification the uniglified names in zip_view_impl.h
[onedpl][zip_view] "<class' -> "<typename"
Co-authored-by: Konstantin Boyarinov <konstantin.boyarinov@intel.com>
|
@MikeDvorskiy @kboyarinov I ran a full CI which looks OK so far, still waiting for it to finish and aggregate. |
Thank you, @danhoeflinger. I'll take a look at #2608. |
[oneDPL][zip_view] minor changes: explicit cast to difference_type, the overloads for __apply_to_tuple
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
|
There are some per-commit errors showing, also the full CI showed a couple other issues:
|
[oneDPL][zip_view] +fixes in "zip_view::end" methods
Co-authored-by: Konstantin Boyarinov <konstantin.boyarinov@intel.com>
Probably, a reason is #1877 (comment) |
change in __apply_to_tuple_impl
undo explicit (see N4910)
|
Consider a prototype that simplifies usage of __apply_to_tuple: #2613. |
@danhoeflinger, Thank you for reporting this. |
…PRESENT definition: + (__GLIBCXX__ >= 20220728)
* fix static asserts for std::ranges::view Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * improve naming of input output iterator guard Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * default constructor for BufferView Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> * guarding checks for NoDefaultCtr views Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> --------- Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
…PRESENT definition
…PRESENT definition
…DPL_CPP20_IN_OUT_ITERATOR_BROKEN
* add minimal test for cpp20 zip_view --------- Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
--------- Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com> Co-authored-by: Mikhail Dvorskiy <mikhail.dvorskiy@intel.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Dan Hoeflinger <dan.hoeflinger@intel.com>
[oneDPL][ranges] + zip_view implementation for C++20. The implementation and test.
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2321r2.html
An update:
test_dangling_pointers_args_<x>and the other tests.oneapi::dpl::experimental::ranges::zip_viewoneapi::dpl::experimental::ranges::views::ziponeapi::dpl::experimental::views::zipAdded
zip_view::base()method.