Skip to content

Add C2 math_utils.smooth_abs helper and unit tests. - #2959

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

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

Conversation

@copybara-service

Copy link
Copy Markdown

Add C2 math_utils.smooth_abs helper and unit tests.

Hard jnp.abs introduces a derivative kink at zero into the transport residual
Jacobian.

  • Add math_utils.smooth_abs using an even C2 sextic on (-margin, margin)
    that equals 0 at 0 and exact |x| for |x| >= margin.
  • Require keyword-only margin so callers explicitly choose the smoothing
    scale.
  • Match jnp.abs edge cases (margin <= 0, NaN propagation, dtype
    preservation) with finite forward and reverse AD at x = +/-inf and 0.
  • Add unit tests in math_utils_test.py.

Child CLs will wire this into models.

Hard `jnp.abs` introduces a derivative kink at zero into the transport residual
Jacobian.

- Add `math_utils.smooth_abs` using an even C2 sextic on `(-margin, margin)`
  that equals `0` at `0` and exact `|x|` for `|x| >= margin`.
- Require keyword-only `margin` so callers explicitly choose the smoothing
  scale.
- Match `jnp.abs` edge cases (`margin <= 0`, `NaN` propagation, dtype
  preservation) with finite forward and reverse AD at `x = +/-inf` and `0`.
- Add unit tests in `math_utils_test.py`.

Child CLs will wire this into models.

PiperOrigin-RevId: 1031193984
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