-
Notifications
You must be signed in to change notification settings - Fork 114
Python like Range #2006
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
artv3
wants to merge
26
commits into
develop
Choose a base branch
from
artv3/zeroTo
base: develop
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.
+946
−34
Open
Python like Range #2006
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
4b5e5a3
add ZeroTo RangeSegment
artv3 124338d
add python like behavior for RAJA::Range
artv3 801bd00
pr comments
artv3 6dbb367
Update include/RAJA/index/RangeSegment.hpp
artv3 17b5e57
include stride in common type find
artv3 ce732f4
Merge branch 'artv3/zeroTo' of https://github.com/LLNL/RAJA into artv…
artv3 3d0195a
PR comments
artv3 ddae21a
use _v instead of ::value
artv3 e243737
build fix
artv3 23a04d6
clean up pass
artv3 6a8995a
just use decay_t
artv3 66be94f
simplify
artv3 0c4666e
remove redundant decay
artv3 d2886c0
add strongly typed begin and end test
artv3 ab3c185
add mixed index support
artv3 ad5f132
add sphinx docs
artv3 1fc8ac3
Merge branch 'develop' into artv3/zeroTo
artv3 c7589b4
fix merge conflict
artv3 744cbc5
clean up pass, throw error for mixed types
artv3 c30299d
clean up pass
artv3 557dc27
Merge branch 'develop' into artv3/zeroTo
artv3 b7b14db
PR comments, add testing and checks
artv3 2f9edca
Merge branch 'artv3/zeroTo' of github.com:llnl/RAJA into artv3/zeroTo
artv3 0b1e0d2
Merge branch 'develop' into artv3/zeroTo
artv3 03b4af1
Merge branch 'develop' into artv3/zeroTo
artv3 5fd1ee6
Merge branch 'develop' into artv3/zeroTo
artv3 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// | ||
| // Copyright (c) Lawrence Livermore National Security, LLC and other | ||
| // RAJA Project Developers. See top-level LICENSE and COPYRIGHT | ||
| // files for dates and other details. No copyright assignment is required | ||
| // to contribute to RAJA. | ||
| // | ||
| // SPDX-License-Identifier: (BSD-3-Clause) | ||
| //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// | ||
|
|
||
| #include <iostream> | ||
|
|
||
| #include "RAJA/RAJA.hpp" | ||
|
|
||
| /* | ||
| * RAJA ranges example | ||
| * | ||
| * Demonstrates Python-like range helpers backed by RAJA segments: | ||
| * 1. RAJA::Range(N) for [0, N) | ||
| * 2. RAJA::Range<T>(N) for a TypedRangeSegment<T> over [0, N) | ||
| * 3. RAJA::Range(begin, end) for [begin, end) | ||
| * 4. RAJA::Range(begin, end, step) for a strided half-open interval | ||
| */ | ||
|
|
||
| RAJA_INDEX_VALUE(CellIndex, "CellIndex"); | ||
|
|
||
| int main(int RAJA_UNUSED_ARG(argc), char** RAJA_UNUSED_ARG(argv)) | ||
| { | ||
| constexpr RAJA::Index_type N = 8; | ||
|
|
||
| int values[N] = {}; | ||
| int typed_values[N] = {}; | ||
| int subrange_values[N] = {}; | ||
| int odd_values[N] = {}; | ||
|
|
||
| // Equivalent to Python range(N): [0, N) | ||
| RAJA::forall<RAJA::seq_exec>(RAJA::Range(N), [&](RAJA::Index_type i) { | ||
| values[i] = static_cast<int>(i * i); | ||
| }); | ||
|
|
||
| // Equivalent to Python range(N), but preserving a strong index type. | ||
| RAJA::forall<RAJA::seq_exec>(RAJA::Range<CellIndex>(N), [&](CellIndex i) { | ||
| typed_values[*i] = static_cast<int>(*i + 10); | ||
| }); | ||
|
|
||
| // Equivalent to Python range(2, 6): [2, 6) | ||
| RAJA::forall<RAJA::seq_exec>(RAJA::Range(2, 6), [&](int i) { | ||
| subrange_values[i] = i; | ||
| }); | ||
|
|
||
| // Equivalent to Python range(1, N, 2): odd indices in [1, N) | ||
| RAJA::forall<RAJA::seq_exec>(RAJA::Range(1, N, 2), [&](int i) { | ||
| odd_values[i] = i; | ||
| }); | ||
|
|
||
| std::cout << "Range(N):"; | ||
| for (auto i : RAJA::Range(N)) { | ||
| std::cout << ' ' << values[i]; | ||
| } | ||
| std::cout << '\n'; | ||
|
|
||
| std::cout << "Range<CellIndex>(N):"; | ||
| for (auto i : RAJA::Range<CellIndex>(N)) { | ||
| std::cout << ' ' << typed_values[*i]; | ||
| } | ||
| std::cout << '\n'; | ||
|
|
||
| std::cout << "Range(2, 6):"; | ||
| for (auto i : RAJA::Range(2, 6)) { | ||
| std::cout << ' ' << subrange_values[i]; | ||
| } | ||
| std::cout << '\n'; | ||
|
|
||
| std::cout << "Range(1, N, 2):"; | ||
| for (auto i : RAJA::Range(1, N, 2)) { | ||
| std::cout << ' ' << odd_values[i]; | ||
| } | ||
| std::cout << '\n'; | ||
|
|
||
| std::cout << "Range(N - 1, -1, -2):"; | ||
| for (auto i : RAJA::Range(N - 1, -1, -2)) { | ||
| std::cout << ' ' << i; | ||
| } | ||
| std::cout << '\n'; | ||
|
|
||
| return 0; | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.