Skip to content

Add C2 math_utils.smooth_clip helper and unit tests. - #2958

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1029926568
Open

copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1029926568

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Add C2 math_utils.smooth_clip helper and unit tests.

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.

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 copybara-service Bot changed the title Add C1 math_utils.smooth_clip helper and unit tests. Add C2 math_utils.smooth_clip helper and unit tests. Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant