-
Notifications
You must be signed in to change notification settings - Fork 116
Implement P2248R8: Enable list-initialization for algorithms #2398
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
Open
rarutyun
wants to merge
4
commits into
main
Choose a base branch
from
rarutyun/implement_p2248r8
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
745544f
Implement P2248R8: Enable list-initialization for algorithms
rarutyun 7f0ec2b
Add default template argument tests. Improve replace_copy tests
rarutyun a1561db
Implement empty list initialization for uninitialized_fill[_n]
rarutyun f1b47c6
Add tests for uninitialized_fill[_n] for hetero backend
rarutyun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,85 @@ test_fill_by_type(::std::size_t n) | |
| #endif | ||
| } | ||
|
|
||
| void test_empty_list_initialization_for_fill() | ||
danhoeflinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| { | ||
| std::vector<int> v{3,6,5,4,3,7,8,0,2,4}; | ||
| oneapi::dpl::fill(oneapi::dpl::execution::seq, v.begin(), v.end(), {}); | ||
| EXPECT_TRUE(std::count(v.begin(), v.end(), 0) == v.size(), "a sequence is not filled properly by oneapi::dpl::fill with `seq` policy"); | ||
| } | ||
| { | ||
| std::vector<int> v{3,6,5,4,3,7,8,0,2,4}; | ||
| oneapi::dpl::fill(oneapi::dpl::execution::unseq, v.begin(), v.end(), {}); | ||
| EXPECT_TRUE(std::count(v.begin(), v.end(), 0) == v.size(), "a sequence is not filled properly by oneapi::dpl::fill with `unseq` policy"); | ||
| } | ||
|
|
||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Remove extra unnecessary braces (this goes away if we use |
||
| { | ||
| std::vector<TestUtils::DefaultInitializedToOne> v_custom{{3},{6},{5},{4},{3},{7},{8},{2},{1},{4}}; | ||
| oneapi::dpl::fill(oneapi::dpl::execution::par, v_custom.begin(), v_custom.end(), {}); | ||
| EXPECT_TRUE(std::count(v_custom.begin(), v_custom.end(), TestUtils::DefaultInitializedToOne{}) == v_custom.size(), | ||
| "a sequence is not filled properly by oneapi::dpl::fill with `par` policy"); | ||
| } | ||
| { | ||
| std::vector<TestUtils::DefaultInitializedToOne> v_custom{{3},{6},{5},{4},{3},{7},{8},{2},{1},{4}}; | ||
| oneapi::dpl::fill(oneapi::dpl::execution::par_unseq, v_custom.begin(), v_custom.end(), {}); | ||
| EXPECT_TRUE(std::count(v_custom.begin(), v_custom.end(), TestUtils::DefaultInitializedToOne{}) == v_custom.size(), | ||
| "a sequence is not filled properly by oneapi::dpl::fill with `par_unseq` policy"); | ||
| } | ||
| } | ||
| #if TEST_DPCPP_BACKEND_PRESENT | ||
| std::vector<int> v{3,6,5,4,3,7,8,0,2,4}; | ||
| sycl::buffer<int> buf(v); | ||
| auto it = oneapi::dpl::fill(oneapi::dpl::execution::dpcpp_default, oneapi::dpl::begin(buf), oneapi::dpl::end(buf), {}); | ||
| EXPECT_TRUE(std::count(v.begin(), v.end(), 0) == v.size(), "a sequence is not filled properly by oneapi::dpl::fill with `device_policy` policy"); | ||
| #endif | ||
| } | ||
|
|
||
| void test_empty_list_initialization_for_fill_n() | ||
| { | ||
| constexpr std::size_t fill_number = 6; | ||
| { | ||
| std::vector<int> v{3,6,5,4,3,7,8,0,2,4}; | ||
| auto it = oneapi::dpl::fill_n(oneapi::dpl::execution::seq, v.begin(), fill_number, {}); | ||
| auto count = std::count(v.begin(), v.begin() + fill_number, 0); | ||
| EXPECT_TRUE(it == (v.begin() + fill_number), "an incorrect iterator returned from oneapi::dpl::fill_n with `seq` policy"); | ||
| EXPECT_TRUE(count == fill_number, "a sequence is not filled properly by oneapi::dpl::fill_n with `seq` policy"); | ||
| } | ||
| { | ||
| std::vector<int> v{3,6,5,4,3,7,8,0,2,4}; | ||
| auto it = oneapi::dpl::fill_n(oneapi::dpl::execution::unseq, v.begin(), fill_number, {}); | ||
| auto count = std::count(v.begin(), v.begin() + fill_number, 0); | ||
| EXPECT_TRUE(it == (v.begin() + fill_number), "an incorrect iterator returned from oneapi::dpl::fill_n with `unseq` policy"); | ||
| EXPECT_TRUE(count == fill_number, "a sequence is not filled properly by oneapi::dpl::fill_n with `unseq` policy"); | ||
| } | ||
|
|
||
| { | ||
| { | ||
| std::vector<TestUtils::DefaultInitializedToOne> v_custom{{3},{6},{5},{4},{3},{7},{8},{2},{1},{4}}; | ||
| auto it = oneapi::dpl::fill_n(oneapi::dpl::execution::par, v_custom.begin(), fill_number, {}); | ||
| auto count = std::count(v_custom.begin(), v_custom.begin() + fill_number, TestUtils::DefaultInitializedToOne{1}); | ||
| EXPECT_TRUE(it == (v_custom.begin() + fill_number), "an incorrect iterator returned from oneapi::dpl::fill_n with `par` policy"); | ||
| EXPECT_TRUE(count == fill_number, "a sequence is not filled properly by oneapi::dpl::fill_n with `par` policy"); | ||
| } | ||
| { | ||
| std::vector<TestUtils::DefaultInitializedToOne> v_custom{{3},{6},{5},{4},{3},{7},{8},{2},{1},{4}}; | ||
| auto it = oneapi::dpl::fill_n(oneapi::dpl::execution::par_unseq, v_custom.begin(), fill_number, {}); | ||
| auto count = std::count(v_custom.begin(), v_custom.begin() + fill_number, TestUtils::DefaultInitializedToOne{1}); | ||
| EXPECT_TRUE(it == (v_custom.begin() + fill_number), "an incorrect iterator returned from oneapi::dpl::fill_n with `par_unseq` policy"); | ||
| EXPECT_TRUE(count == fill_number, "a sequence is not filled properly by oneapi::dpl::fill_n with `par_unseq` policy"); | ||
| } | ||
| } | ||
| #if TEST_DPCPP_BACKEND_PRESENT | ||
| std::vector<int> v{3,6,5,4,3,7,8,0,2,4}; | ||
| sycl::buffer<int> buf(v); | ||
| auto it = oneapi::dpl::fill_n(oneapi::dpl::execution::dpcpp_default, oneapi::dpl::begin(buf), fill_number, {}); | ||
| auto count = std::count(v.begin(), v.begin() + fill_number, 0); | ||
| EXPECT_TRUE(it.get_idx() == fill_number, "an incorrect iterator returned from oneapi::dpl::fill_n with `device_policy` policy"); | ||
| EXPECT_TRUE(count == fill_number, "a sequence is not filled properly by oneapi::dpl::fill_n with `device_policy` policy"); | ||
| #endif | ||
| } | ||
|
|
||
| int | ||
| main() | ||
| { | ||
|
|
@@ -108,5 +187,8 @@ main() | |
| test_fill_by_type<float64_t>(n); | ||
| } | ||
|
|
||
| test_empty_list_initialization_for_fill(); | ||
| test_empty_list_initialization_for_fill_n(); | ||
|
|
||
| return done(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Doesn't the paper conclude not to make any changes to replace_copy for non ranges api?