Add value check for chunk#73857
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds validation for the chunks parameter in paddle.chunk and corresponding error-case tests.
- Enforces that
chunksmust be >0 and ≤ the size of the specified (non-negative) axis. - Raises
ValueErrorwhenchunksis out of range. - Adds unit tests for negative and too-large
chunksvalues.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/legacy_test/test_chunk_op.py | Added tests for chunks=-1 and chunks>dim to ensure errors. |
| python/paddle/tensor/manipulation.py | Inserted a guard to validate chunks bounds and raise ValueError. |
Comments suppressed due to low confidence (2)
test/legacy_test/test_chunk_op.py:63
- Add a test case for a negative axis (e.g.,
axis=-1) withchunkslarger than that dimension to verify the validation logic for negative axes.
def test_negative_chunks_tensor():
python/paddle/tensor/manipulation.py:4487
- The current check only covers non-negative axes. Negative axis values (e.g., -1) bypass this validation and may lead to inconsistent behavior; consider normalizing negative axes before comparing against
x.shape.
isinstance(axis, int) and axis >= 0 and chunks > x.shape[axis]
| >>> # out2.shape [3, 3, 5] | ||
| """ | ||
| check_type(chunks, 'chunks', (int), 'chunk') | ||
| # check the chunks value to avoid the meanless split operation, such as <=0 or > x.shape[axis] |
There was a problem hiding this comment.
Minor spelling issue: change 'meanless' to 'meaningless' in the comment.
| # check the chunks value to avoid the meanless split operation, such as <=0 or > x.shape[axis] | |
| # check the chunks value to avoid the meaningless split operation, such as <=0 or > x.shape[axis] |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #73857 +/- ##
===========================================
Coverage ? 100.00%
===========================================
Files ? 1
Lines ? 2
Branches ? 0
===========================================
Hits ? 2
Misses ? 0
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
你的PR提交成功,感谢你对开源项目的贡献! |
PR Category
User Experience
PR Types
Others
Description
#65043