-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add FuncVec convenience type #9387
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
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #include "Halide.h" | ||
| #include "expect_user_error.h" | ||
|
|
||
| #include <cstdio> | ||
| #include <string> | ||
| #include <type_traits> | ||
| #include <vector> | ||
|
|
||
| using namespace Halide; | ||
|
|
||
| namespace { | ||
|
|
||
| bool check(bool condition, const char *message) { | ||
| if (!condition) { | ||
| std::printf("FAIL: %s\n", message); | ||
| } | ||
| return condition; | ||
| } | ||
|
|
||
| size_t vector_size(const std::vector<Func> &funcs) { | ||
| return funcs.size(); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| int main(int argc, char **argv) { | ||
| static_assert(std::is_base_of_v<std::vector<Func>, FuncVec>); | ||
| static_assert(std::is_convertible_v<FuncVec, Func>); | ||
|
|
||
| bool success = true; | ||
|
|
||
| FuncVec named("func_vec_stage_", 3); | ||
| success &= check(named.size() == 3, "named constructor created the wrong number of Funcs"); | ||
| for (size_t i = 0; i < named.size(); ++i) { | ||
| const std::string expected = "func_vec_stage_" + std::to_string(i); | ||
| success &= check(named[i].name() == expected, "named constructor created an incorrect Func name"); | ||
| } | ||
|
|
||
| FuncVec singleton_named("func_vec_singleton", 1); | ||
| success &= check(singleton_named[0].name() == "func_vec_singleton", | ||
| "singleton named constructor should preserve its base name"); | ||
|
|
||
| Func a("func_vec_a"); | ||
| Func b("func_vec_b"); | ||
| FuncVec funcs{a}; | ||
| funcs.push_back(b); | ||
| success &= check(vector_size(funcs) == 2, "FuncVec is not usable as a std::vector<Func>"); | ||
|
|
||
| std::vector<Func> base{a}; | ||
| FuncVec copied(base); | ||
| FuncVec assigned; | ||
| assigned = base; | ||
| std::vector<Func> round_trip = copied; | ||
| success &= check(assigned.size() == 1 && round_trip.size() == 1, | ||
| "FuncVec conversion to or from std::vector<Func> failed"); | ||
|
|
||
| Func singleton = copied; | ||
| success &= check(singleton.name() == a.name(), "singleton FuncVec converted to the wrong Func"); | ||
|
|
||
| Pipeline pipeline(copied); | ||
| Func pipeline_output = pipeline.outputs(); | ||
| success &= check(pipeline_output.name() == a.name(), "Pipeline::outputs() did not decay to its singleton Func"); | ||
|
|
||
| #if HALIDE_WITH_EXCEPTIONS | ||
| FuncVec empty; | ||
| success &= expect_user_error("empty_func_vec", "size 0", [&]() { | ||
| Func f = empty; | ||
| (void)f; | ||
| }); | ||
| success &= expect_user_error("multi_func_vec", "size 2", [&]() { | ||
| Func f = funcs; | ||
| (void)f; | ||
| }); | ||
| #endif | ||
|
|
||
| if (!success) { | ||
| return 1; | ||
| } | ||
| std::printf("Success!\n"); | ||
| return 0; | ||
| } |
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.
What do you think about:
name + "[" + std::to_string(i) + "]"Uh oh!
There was an error while loading. Please reload this page.
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.
I'm not sure what
[would do in a Func name.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.
I think I prefer to keep
f0,f1, ...,fNrather than burn two characters (on[]) ofstd::string's short-string optimizations.Uh oh!
There was an error while loading. Please reload this page.
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.
I think
[eventually gets legalized into___(three underscoeres)except if the Func is used as an input/output generator, in which case it gets rejected. Seems safer to avoid
[.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.
I really like e.g. gPyramid[3] because it reads way better in the profiler output and corresponds more closely to source code. That's what I've been using locally.
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.
If we hard-reject it for output funcs though, that seems decisive
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.
How about this: Have the constructor also take an optional suffix string. Right now it's a prefix string and a count. If it had a suffix too I could just say:
FuncVec v("foo[", 17, "]");