-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add function to convert mdspan to a const view #1188
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this!
Thanks for writing this! This facility serves an analogous purpose as https://en.cppreference.com/w/cpp/ranges/as_const_view The use case example here https://en.cppreference.com/w/cpp/ranges/constant_range looks very much like the use cases you would like to support. The idea is that you would like to use |
Codecov ReportBase: 87.99% // Head: 87.99% // No change to project coverage 👍
Additional details and impacted files@@ Coverage Diff @@
## branch-23.02 #1188 +/- ##
=============================================
Coverage 87.99% 87.99%
=============================================
Files 21 21
Lines 483 483
=============================================
Hits 425 425
Misses 58 58 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for considering this design change! I find that this makes the code clean and easy to extend.
Optionally, if you want users to be able to add support for their custom accessors, you might want to consider a customization point object or tag_invoke
design for accessor_of_const
.
host_device_accessor<std::experimental::default_accessor<std::add_const_t<ElementType>>, MemType> | ||
accessor_of_const(host_device_accessor<std::experimental::default_accessor<ElementType>, MemType> a) | ||
{ | ||
return {a}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the correct way to do it, as long as host_device_accessor
has an element type converting constructor like default_accessor
does (see the first constructor here). A straightforward unit test would fail to compile without that constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great point, @mhoemmen. It's nice to see the new function being used in the k-means tests but we should probably have a dedicated testcase for this (ideally in the mdspan cpp test file).
Co-authored-by: Mark Hoemmen <[email protected]>
/merge |
`make_const_mdspan` is a helper function to convert `mdspan<T>` into `mdspan<const T>`. I added examples of it's usage @mhoemmen @Nyrio Authors: - Micka (https://github.com/lowener) - Corey J. Nolet (https://github.com/cjnolet) Approvers: - Louis Sugy (https://github.com/Nyrio) - Corey J. Nolet (https://github.com/cjnolet) - Mark Hoemmen (https://github.com/mhoemmen) URL: rapidsai#1188
make_const_mdspan
is a helper function to convertmdspan<T>
intomdspan<const T>
.I added examples of it's usage
@mhoemmen @Nyrio