Fix clip function issue 21936 #28931
Open
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.
Issue Analysis
Identified that the clip_ function was missing from the main paddle math module (ivy/ivy/functional/frontends/paddle/math.py)
Found that it existed in the tensor math module but not in the main module where it should be accessible as paddle.clip_
Implementation
Added clip function to ivy/ivy/functional/frontends/paddle/math.py:
Proper error handling with ivy.utils.assertions.check_all_or_any_fn
Handles cases where min or max are None
Uses appropriate decorators: @with_supported_dtypes and @to_ivy_arrays_and_back
Supports dtypes: float32, float64, int32, int64
Added clip_ inplace function to ivy/ivy/functional/frontends/paddle/math.py:
Uses ivy.inplace_update(x, clip(x, min, max)) pattern consistent with other inplace operations
Same decorators and dtype support as clip
Testing
Added comprehensive tests to ivy_tests/test_ivy/test_frontends/test_paddle/test_math.py:
Added get_clip_inputs() helper function for generating test data
Added test_paddle_clip() test function
Added test_paddle_clip_() test function
Tests use proper hypothesis strategies and follow established patterns
Files Modified
ivy/ivy/functional/frontends/paddle/math.py - Added clip and clip_ functions
ivy_tests/test_ivy/test_frontends/test_paddle/test_math.py - Added helper and test functions