Fix nonzero for non-standard input layouts - #5046
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5046 +/- ##
===========================================
+ Coverage 92.78% 92.90% +0.12%
===========================================
Files 596 603 +7
Lines 32011 32524 +513
===========================================
+ Hits 29700 30214 +514
+ Misses 2311 2310 -1
🚀 New features to boost your workflow:
|
Regressions detected 🔴 |
|
There was a problem hiding this comment.
Pull request overview
Fixes the reference implementation of the nonzero operator to correctly handle non-standard input layouts (e.g., transposed and broadcasted tensors), aligning compute-time element access with logical indexing.
Changes:
- Removed the standard-layout constraint from
nonzeroshape validation and updated compute-time access to use logical indices fromshape_for_each. - Added new reference + verify tests covering transposed inputs and reference coverage for broadcasted inputs.
- Added a changelog entry under “Resolved issues”.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/include/migraphx/op/nonzero.hpp |
Removes standard-layout requirement and updates indexing logic to support non-standard layouts. |
test/ref/nonzero.cpp |
Adds reference tests for transposed and broadcasted inputs. |
test/verify/test_nonzero.cpp |
Adds verify coverage for transposed inputs. |
CHANGELOG.md |
Documents the fix under resolved issues. |
| @@ -56,8 +58,8 @@ struct nonzero | |||
| std::vector<std::vector<std::size_t>> vec_idx; | |||
| auto s = args.front().get_shape(); | |||
| args.front().visit([&](auto v) { | |||
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
TedThemistokleous
left a comment
There was a problem hiding this comment.
Just need clarification on your test data. I think you have extra values that aren't checked / dont make sense.
Possible to also clean up the output assignment with a transform using migraphx ranges for front().size instead of keeping the raw loop.
CharlieL7
left a comment
There was a problem hiding this comment.
LGTM, tests work out correctly vs. what I did by hand.
|
Need to fix Tidy CI check |
TedThemistokleous
left a comment
There was a problem hiding this comment.
Thanks for the clarification and contribution. Looks good to me too.
Motivation
Fix the reference
nonzerooperator so it accepts and correctly reads non-standard input layouts such as transposed and broadcasted tensors.Technical Details
Removed the standard-layout requirement from
nonzeroshape checking and changed compute-time element access to use the logical index fromshape_for_each. Added reference and verify tests for transposed inputs, plus reference coverage for broadcasted inputs.Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot Applicable