Commit 071ff1e
Create helper for comparing semantic equivalence of shapes (#2620)
This pull request introduces new utility functions for comparing shapes
and dimensions in the intermediate representation (IR) utilities, and
refactors existing rewrite rules to use these new utilities. The goal is
to improve semantic correctness and code clarity when checking shape and
dimension equality, especially in the presence of symbolic or unknown
values.
Key changes:
**New IR utility functions:**
* Added `same_shape` and `same_dim` functions to `_ir_utils.py` for more
robust and semantically correct comparison of shapes and dimensions,
accounting for unknown or symbolic values.
**Refactoring of rewrite rules to use new utilities:**
* Updated `_collapse_slices.py` and `_redundant_scatter_nd.py` to use
`_ir_utils.same_shape` and `_ir_utils.same_dim` instead of direct
equality checks or previous logic, ensuring that shape and dimension
comparisons are handled consistently and correctly.
[[1]](diffhunk://#diff-bd2dba53e1a4b4fb79975f7bceacf4b1c5b0b38a10d953af1e18a0b7af6c1050L85-R88)
[[2]](diffhunk://#diff-47bc4cbfc2fee996791be5a58bf9447dd44dd833e540139b5cd18b807757be4aL57-R57)
[[3]](diffhunk://#diff-47bc4cbfc2fee996791be5a58bf9447dd44dd833e540139b5cd18b807757be4aL90-R90)
**Code consistency improvements:**
* Standardized imports in affected files to use `_ir_utils`
consistently, replacing previous aliasing or direct imports.
[[1]](diffhunk://#diff-bd2dba53e1a4b4fb79975f7bceacf4b1c5b0b38a10d953af1e18a0b7af6c1050L8-R8)
[[2]](diffhunk://#diff-47bc4cbfc2fee996791be5a58bf9447dd44dd833e540139b5cd18b807757be4aL23-R23)
[[3]](diffhunk://#diff-47bc4cbfc2fee996791be5a58bf9447dd44dd833e540139b5cd18b807757be4aL44-R44)
---------
Signed-off-by: Justin Chu <[email protected]>
Co-authored-by: Copilot <[email protected]>1 parent 28a8f56 commit 071ff1e
File tree
3 files changed
+31
-11
lines changed- onnxscript/rewriter
- rules/common
3 files changed
+31
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 88 | + | |
93 | 89 | | |
94 | 90 | | |
95 | 91 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
0 commit comments