Commit a0722c3
Fix Shape operator specification: correct range bounds and document start > end behavior (onnx#7132)
The Shape operator specification incorrectly stated that axes are
clamped to the range `[0, r-1]`, but since the `end` parameter is
exclusive in slicing operations, the correct range should be `[0, r]`.
Additionally, the spec was missing documentation for the `start > end`
case.
## Changes Made
### Documentation Fixes
- **Corrected range specification**: Changed from `[0, r-1]` to `[0, r]`
in all Shape operator documentation
- **Added start > end behavior**: Added "If start > end, the result will
be an empty shape." to clarify edge case behavior
### Affected Versions
Updated documentation for all Shape operator versions that support
`start` and `end` attributes:
- `Shape_ver24_doc` (current version)
- `Shape_ver23_doc`
- `Shape_ver19_doc`
- `Shape_ver15_doc`
Note: Older versions (ver13, ver1) don't have `start`/`end` attributes
so no changes were needed.
### Test Coverage
- Added test case `test_shape("_start_greater_than_end", x, start=2,
end=1)` to validate the documented behavior
- Verified that the reference implementation correctly returns an empty
array when `start > end`
## Implementation Verification
The underlying C++ implementation was already correct - it properly
clamps both `start` and `end` to `[0, rank]` and handles the `start >
end` case by returning an empty shape:
```cpp
start = (start < 0) ? 0 : (start > rank) ? rank : start;
end = (end < 0) ? 0 : (end > rank) ? rank : end;
output_length->set_dim_value((end - start) < 0 ? 0 : (end - start));
```
This fix ensures the documentation accurately reflects the actual
behavior, making it consistent with how ONNX Runtime handles these edge
cases.
Fixes onnx#6862.
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 Share your feedback on Copilot coding agent for the chance to win a
$200 gift card! Click
[here](https://survey.alchemer.com/s3/8343779/Copilot-Coding-agent) to
start the survey.
---------
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>1 parent a0e90be commit a0722c3
File tree
9 files changed
+27
-20
lines changed- docs
- onnx
- backend/test
- case/node
- data/node/test_shape_start_greater_than_end
- test_data_set_0
- defs/tensor
9 files changed
+27
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19866 | 19866 | | |
19867 | 19867 | | |
19868 | 19868 | | |
19869 | | - | |
| 19869 | + | |
19870 | 19870 | | |
19871 | 19871 | | |
19872 | 19872 | | |
19873 | | - | |
| 19873 | + | |
19874 | 19874 | | |
19875 | 19875 | | |
19876 | 19876 | | |
| |||
23815 | 23815 | | |
23816 | 23816 | | |
23817 | 23817 | | |
23818 | | - | |
| 23818 | + | |
23819 | 23819 | | |
23820 | 23820 | | |
23821 | 23821 | | |
23822 | | - | |
| 23822 | + | |
23823 | 23823 | | |
23824 | 23824 | | |
23825 | 23825 | | |
| |||
25660 | 25660 | | |
25661 | 25661 | | |
25662 | 25662 | | |
25663 | | - | |
| 25663 | + | |
25664 | 25664 | | |
25665 | 25665 | | |
25666 | 25666 | | |
25667 | | - | |
| 25667 | + | |
25668 | 25668 | | |
25669 | 25669 | | |
25670 | 25670 | | |
| |||
29557 | 29557 | | |
29558 | 29558 | | |
29559 | 29559 | | |
29560 | | - | |
| 29560 | + | |
29561 | 29561 | | |
29562 | 29562 | | |
29563 | 29563 | | |
29564 | | - | |
| 29564 | + | |
29565 | 29565 | | |
29566 | 29566 | | |
29567 | 29567 | | |
| |||
30811 | 30811 | | |
30812 | 30812 | | |
30813 | 30813 | | |
30814 | | - | |
| 30814 | + | |
30815 | 30815 | | |
30816 | 30816 | | |
30817 | 30817 | | |
30818 | | - | |
| 30818 | + | |
30819 | 30819 | | |
30820 | 30820 | | |
30821 | 30821 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32527 | 32527 | | |
32528 | 32528 | | |
32529 | 32529 | | |
32530 | | - | |
| 32530 | + | |
32531 | 32531 | | |
32532 | 32532 | | |
32533 | 32533 | | |
32534 | | - | |
| 32534 | + | |
32535 | 32535 | | |
32536 | 32536 | | |
32537 | 32537 | | |
| |||
32632 | 32632 | | |
32633 | 32633 | | |
32634 | 32634 | | |
| 32635 | + | |
| 32636 | + | |
32635 | 32637 | | |
32636 | 32638 | | |
32637 | 32639 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23046 | 23046 | | |
23047 | 23047 | | |
23048 | 23048 | | |
| 23049 | + | |
| 23050 | + | |
23049 | 23051 | | |
23050 | 23052 | | |
23051 | 23053 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
Binary file not shown.
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Binary file not shown.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
402 | 402 | | |
403 | 403 | | |
404 | 404 | | |
405 | | - | |
| 405 | + | |
406 | 406 | | |
407 | 407 | | |
408 | 408 | | |
409 | | - | |
| 409 | + | |
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1752 | 1752 | | |
1753 | 1753 | | |
1754 | 1754 | | |
1755 | | - | |
| 1755 | + | |
1756 | 1756 | | |
1757 | 1757 | | |
1758 | 1758 | | |
1759 | | - | |
| 1759 | + | |
1760 | 1760 | | |
1761 | 1761 | | |
1762 | 1762 | | |
| |||
7553 | 7553 | | |
7554 | 7554 | | |
7555 | 7555 | | |
7556 | | - | |
| 7556 | + | |
7557 | 7557 | | |
7558 | 7558 | | |
7559 | 7559 | | |
7560 | | - | |
| 7560 | + | |
7561 | 7561 | | |
7562 | 7562 | | |
7563 | 7563 | | |
| |||
7656 | 7656 | | |
7657 | 7657 | | |
7658 | 7658 | | |
7659 | | - | |
| 7659 | + | |
7660 | 7660 | | |
7661 | 7661 | | |
7662 | 7662 | | |
7663 | | - | |
| 7663 | + | |
7664 | 7664 | | |
7665 | 7665 | | |
7666 | 7666 | | |
| |||
0 commit comments