-
Notifications
You must be signed in to change notification settings - Fork 128
Add symbolic expression #4782
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
pfultz2
wants to merge
159
commits into
develop
Choose a base branch
from
sym-expr2
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.
Open
Add symbolic expression #4782
Changes from 141 commits
Commits
Show all changes
159 commits
Select commit
Hold shift + click to select a range
45fa74f
Add sym::expr
pfultz2 3150f5a
Format
pfultz2 e1f4252
Move constructor inline
pfultz2 3e0d84b
Format
pfultz2 8752a2f
Move .cpp
pfultz2 31ca343
Format
pfultz2 a6552c1
Add comparison ops
pfultz2 e84dd47
Format
pfultz2 c2f3514
Add assign operators
pfultz2 0ba12f2
Add more functions
pfultz2 684d536
Format
pfultz2 90d30ac
Add to_string method
pfultz2 cecb90a
Format
pfultz2 c399c54
Add call associative
pfultz2 d2fc809
Foramt
pfultz2 92c716e
Add implicit const folding
pfultz2 7cb021a
Format
pfultz2 169c34a
Normalize subtract
pfultz2 2b01317
Format
pfultz2 cfdd0b0
Normalize subtraction
pfultz2 ed58ec1
Format
pfultz2 aeba6af
Some cleanup
pfultz2 f9364dd
Format
pfultz2 03f6064
Add normalize_expr
pfultz2 063645e
Add normalization
pfultz2 db9720d
Format
pfultz2 8b19cfc
Add rewrite rules
pfultz2 c55d529
Format
pfultz2 fd2c803
Add parser
pfultz2 cfa99b6
Format
pfultz2 0d8b391
Add first_of
pfultz2 910a68d
Format
pfultz2 fa5a44e
Add more operators
pfultz2 dd6670e
Format
pfultz2 14f4267
Add mod operator
pfultz2 f5cb5a2
Format
pfultz2 b50a9f0
Use call_function
pfultz2 1b18df4
Add lookup table
pfultz2 7526432
Format
pfultz2 07f5ba0
Add some missing methods
pfultz2 1120f04
Format
pfultz2 8476da0
Add print operators
pfultz2 6b3dfa0
Add to_value serialization
pfultz2 00a30e1
Format
pfultz2 3877b76
Add symlib
pfultz2 a9acf1d
Merge branch 'sym-expr' into sym-expr2
pfultz2 704d17a
Fix cmake
pfultz2 cc9ac2f
Fix ambiguous overloads
pfultz2 8f80176
Format
pfultz2 bd5bf3e
Fix some failures
pfultz2 8641ff8
Throw on missing variable
pfultz2 c6b44e5
Fix eval tests
pfultz2 b6bf47a
Use generic eval
pfultz2 b28a46a
Format
pfultz2 ffa3753
Make generic apply
pfultz2 53835f6
Format
pfultz2 314e4f0
Use generic_eval for string conversion
pfultz2 7b3e3f2
Reduce parens
pfultz2 9207d08
Normalize div
pfultz2 b1583f6
Format:
pfultz2 73c3e9e
Fix expression comparison
pfultz2 4bf7f5f
Format
pfultz2 2d4ea2b
Reorder
pfultz2 e2f0571
Format
pfultz2 89ca294
Switch order for mul
pfultz2 d98514b
Rename to scalar
pfultz2 3cb28d9
Format
pfultz2 a2e83a8
Simplify tuple creation
pfultz2 9664f59
Format
pfultz2 9f355aa
Use index method
pfultz2 f09949a
Simplify further
pfultz2 641a139
FOrmat
pfultz2 78a1e7b
Add fold_associative_args
pfultz2 ad867c7
Format
pfultz2 efe0002
Add unit tests
pfultz2 6917f91
Fix bug
pfultz2 2eed238
Update algorithm
pfultz2 2d64c2a
Use algorithms
pfultz2 8e2a187
Format
pfultz2 ffafd58
Use std::transform
pfultz2 0f47989
Cleanup the nasty loop
pfultz2 165e52a
Reuse subs
pfultz2 4a4af17
Format
pfultz2 089d3be
Unify associative
pfultz2 9697905
Format
pfultz2 6f39c04
Move to .cpp file
pfultz2 ff69c50
Remove simplify overload
pfultz2 b830f48
Adjust namespaces
pfultz2 89a4dab
Format
pfultz2 bdce060
Handle empty better
pfultz2 463a33f
Format
pfultz2 9f10d13
Fix associative ops
pfultz2 b481482
Add optimials
pfultz2 a88234b
Format
pfultz2 41e3d95
Use fix point combinator
pfultz2 53b36bc
Update eval
pfultz2 f7e37af
Format
pfultz2 cf81114
Use std::visit
pfultz2 becd81e
Format
pfultz2 ff856c9
Use static functions
pfultz2 ea0e0b9
Add clipping to make_scalar
pfultz2 2d3aeda
Format
pfultz2 dce28c0
Add tests for ceil div
pfultz2 a75d129
Throw div by zero
pfultz2 f2e162f
Fix eval tests
pfultz2 10a95e5
Update tests
pfultz2 d79be30
Improve printing
pfultz2 563165d
Format
pfultz2 34d75cb
use cached hash
pfultz2 314b257
Format
pfultz2 629b76a
Update type trait
pfultz2 2ed8ce9
Format
pfultz2 7b48135
Move ordered_as
pfultz2 c0eb314
Move ordered_as
pfultz2 50c3b30
Simplify overload
pfultz2 e017090
Remvoe the extra overload
pfultz2 d3ff9a8
Use float_equal
pfultz2 aadd5d6
Check div by zero
pfultz2 60136b2
Tidy fixits
pfultz2 c093a79
Format
pfultz2 7c5fa40
More tidy fixes
pfultz2 a6632b2
Format
pfultz2 e7b1d9d
Avoid copying the map
pfultz2 7ebfd5b
Format
pfultz2 640baf0
Remove unused template
pfultz2 3a1929e
Format
pfultz2 d631f84
Update license
pfultz2 4a8df17
Format
pfultz2 4a9a55b
Fix
pfultz2 5a12ce6
Update src/sym.cpp
pfultz2 8ed0d5e
Merge branch 'sym-expr2' of github.com:ROCm/AMDMIGraphX into sym-expr2
pfultz2 fa7874b
IMprove equality
pfultz2 1b8eeca
Format
pfultz2 e842038
Fix bug with serializing constraints
pfultz2 480b535
Format
pfultz2 2c97d17
Update year
pfultz2 d8de207
Format
pfultz2 d2e8522
Fix gcc warnings
pfultz2 87f463f
Add windows export
pfultz2 794c532
Call make_scalar
pfultz2 3e0c1ec
Format
pfultz2 93b46fb
Use hash method
pfultz2 177a0cb
Format
pfultz2 a2ad982
Use the provided hash functions
pfultz2 6f97ea3
Format
pfultz2 ebcf6ea
Add test for hash function
pfultz2 08220cd
Format
pfultz2 aacb571
Fix hashing
pfultz2 32abd4b
Format
pfultz2 6f8f0dc
Ignore constraints for equality
pfultz2 6caa980
Refactor eval_optimals
pfultz2 dbe8f16
Format
pfultz2 5835500
Merge branch 'develop' into sym-expr2
pfultz2 8a04ffb
Handle division by zero
pfultz2 fd08c6d
Format
pfultz2 a040784
Handl mod intervals with 0
pfultz2 98050ff
Merge branch 'develop' into sym-expr2
pfultz2 158cba8
Update src/sym.cpp
pfultz2 dc84048
Update test/sym.cpp
pfultz2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,229 @@ | ||
| /* | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2025-2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| * | ||
| */ | ||
| #ifndef MIGRAPHX_GUARD_MIGRAPHX_SIMPLE_PARSER_HPP | ||
| #define MIGRAPHX_GUARD_MIGRAPHX_SIMPLE_PARSER_HPP | ||
|
|
||
| #include <migraphx/config.hpp> | ||
| #include <migraphx/ranges.hpp> | ||
| #include <migraphx/errors.hpp> | ||
| #include <migraphx/stringutils.hpp> | ||
| #include <type_traits> | ||
| #include <vector> | ||
|
|
||
| namespace migraphx { | ||
| inline namespace MIGRAPHX_INLINE_NS { | ||
| namespace parser { | ||
|
|
||
| template <class Iterator, bool AutoSkipWhitespace = true, class View = iterator_range<Iterator>> | ||
| struct simple_parser | ||
| { | ||
| View buffer; | ||
| Iterator pos = buffer.begin(); | ||
|
|
||
| static View make_view(Iterator begin, Iterator end) | ||
| { | ||
| if constexpr(std::is_constructible<View, decltype(std::addressof(*begin)), std::size_t>{}) | ||
| { | ||
| auto n = std::distance(begin, end); | ||
| if(n == 0) | ||
| return {}; | ||
| return {std::addressof(*begin), static_cast<std::size_t>(n)}; | ||
| } | ||
| else | ||
| { | ||
| return {begin, end}; | ||
| } | ||
| } | ||
|
|
||
| View peek() const | ||
| { | ||
| if(pos >= buffer.end()) | ||
| return {}; | ||
| return make_view(pos, buffer.end()); | ||
| } | ||
|
|
||
| void advance(std::size_t n) | ||
| { | ||
| pos += n; | ||
| if(pos > buffer.end()) | ||
| MIGRAPHX_THROW("Parser advanced past end of buffer"); | ||
| if constexpr(AutoSkipWhitespace) | ||
| { | ||
| pos = std::find_if( | ||
| pos, buffer.end(), [](unsigned char c) { return not std::isspace(c); }); | ||
| } | ||
| } | ||
|
|
||
| template <class Pred> | ||
| View parse_while(Pred p) | ||
| { | ||
| auto start = pos; | ||
| auto it = std::find_if(pos, buffer.end(), [&](auto c) { return not p(c); }); | ||
| auto n = std::distance(pos, it); | ||
| advance(n); | ||
| return make_view(start, it); | ||
| } | ||
|
|
||
| bool starts_with(const View& prefix) const | ||
| { | ||
| auto tail = peek(); | ||
| if(prefix.size() > tail.size()) | ||
| return false; | ||
| else | ||
| return std::equal(prefix.begin(), prefix.end(), tail.begin()); | ||
| } | ||
|
|
||
| bool done() const { return pos >= buffer.end(); } | ||
|
|
||
| bool match(const View& prefix) | ||
| { | ||
| if(not starts_with(prefix)) | ||
| return false; | ||
| advance(prefix.size()); | ||
| return true; | ||
| } | ||
|
|
||
| void expect(const View& str) | ||
| { | ||
| if(not starts_with(str)) | ||
| MIGRAPHX_THROW(error_message("'" + std::string{str} + "'")); | ||
| advance(str.size()); | ||
| } | ||
|
|
||
| char peek_char() const | ||
| { | ||
| if(done()) | ||
| return '\0'; | ||
| return *pos; | ||
| } | ||
|
|
||
| std::string error_message(std::string_view expected) const | ||
| { | ||
| auto offset = std::distance(buffer.begin(), pos); | ||
| return "Expected " + std::string(expected) + " at position " + std::to_string(offset) + | ||
| " in '" + std::string(buffer) + "'"; | ||
| } | ||
|
|
||
| template <class F> | ||
| bool try_parse(F f) | ||
| { | ||
| auto copy = *this; | ||
| f(*this); | ||
| if(copy.pos != pos) | ||
| return true; | ||
| *this = copy; | ||
| return false; | ||
| } | ||
|
|
||
| View first_of(View view) | ||
| { | ||
| if(match(view)) | ||
| return view; | ||
| return {}; | ||
| } | ||
|
|
||
| template <class... Views> | ||
| View first_of(View view, Views... views) | ||
| { | ||
| if(match(view)) | ||
| return view; | ||
| return first_of(views...); | ||
| } | ||
|
|
||
| template <class F> | ||
| auto first_of(F f) -> decltype(f(*this)) | ||
| { | ||
| return f(*this); | ||
| } | ||
|
|
||
| template <class F, class G, class... Fs> | ||
| auto first_of(F f, G g, Fs... fs) -> decltype(f(*this)) | ||
| { | ||
| auto copy = *this; | ||
| auto result = f(*this); | ||
| if(copy.pos != pos) | ||
| return result; | ||
| *this = copy; | ||
| return first_of(g, fs...); | ||
| } | ||
|
|
||
| template <class F> | ||
| auto repeat(F f) | ||
| { | ||
| using result_type = decltype(f(*this)); | ||
| std::vector<result_type> results; | ||
| for(;;) | ||
| { | ||
| auto copy = *this; | ||
| results.push_back(f(*this)); | ||
| if(copy.pos == pos) | ||
| { | ||
| results.pop_back(); | ||
| break; | ||
| } | ||
| } | ||
| return results; | ||
| } | ||
| }; | ||
|
|
||
| template <class F> | ||
| struct parser_action | ||
| { | ||
| F fn; | ||
|
|
||
| template <class Parser> | ||
| auto operator()(Parser& p) const -> decltype(fn(p)) | ||
| { | ||
| return fn(p); | ||
| } | ||
| }; | ||
|
|
||
| template <class F> | ||
| parser_action<std::decay_t<F>> action(F&& f) | ||
| { | ||
| return {std::forward<F>(f)}; | ||
| } | ||
|
|
||
| template <class F1, class F2> | ||
| auto operator|(parser_action<F1> a, parser_action<F2> b) | ||
| { | ||
| return action([a = std::move(a), b = std::move(b)](auto& p) -> decltype(a(p)) { | ||
| return p.first_of(a, b); | ||
| }); | ||
| } | ||
|
|
||
| template <class F> | ||
| auto operator*(parser_action<F> a) | ||
| { | ||
| return action([a = std::move(a)](auto& p) { return p.repeat(a); }); | ||
| } | ||
|
|
||
| using simple_string_view_skip_parser = | ||
| simple_parser<std::string_view::const_iterator, true, std::string_view>; | ||
|
|
||
| } // namespace parser | ||
| } // namespace MIGRAPHX_INLINE_NS | ||
| } // namespace migraphx | ||
| #endif // MIGRAPHX_GUARD_MIGRAPHX_SIMPLE_PARSER_HPP |
Oops, something went wrong.
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.
iterator_range::size()usesstd::distance, butranges.hppdoesn’t include<iterator>. Please include it explicitly rather than relying on transitive includes.