Repository navigation
Add C2 math_utils.smooth_clip helper and unit tests. - #2958
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
Hard `jnp.clip` introduces derivative kinks at active bounds into the transport residual Jacobian. - Add `math_utils.smooth_clip` using a one-sided C2 quintic transition inside each active bound, preserving exact `min_val` / `max_val` outside the bounds and exact `x` in the interior. - Require keyword-only `margin` (scalar/array, or `(lower, upper)` tuple for bounds on different scales) so callers explicitly choose the transition scale. - Match `jnp.clip` edge cases (`margin <= 0`, `NaN` propagation, dtype preservation) with finite AD for infinite `x` or unbounded sides. - Add unit tests in `math_utils_test.py`. Child CLs will wire this into models. PiperOrigin-RevId: 1029926568
copybara-service
Bot
force-pushed
the
test_1029926568
branch
from
November 27, 2026 15:40
4a384d2 to
ab6c3cb
Compare
math_utils.smooth_clip helper and unit tests.math_utils.smooth_clip helper and unit tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add C2
math_utils.smooth_cliphelper and unit tests.Hard
jnp.clipintroduces derivative kinks at active bounds into the transportresidual Jacobian.
math_utils.smooth_clipusing a one-sided C2 quintic transition insideeach active bound, preserving exact
min_val/max_valoutside the boundsand exact
xin the interior.margin(scalar/array, or(lower, upper)tuple forbounds on different scales) so callers explicitly choose the transition scale.
jnp.clipedge cases (margin <= 0,NaNpropagation, dtypepreservation) with finite AD for infinite
xor unbounded sides.math_utils_test.py.Child CLs will wire this into models.