Skip to content

Fix truncate/untruncate for Reactant - #37

Merged
penelopeysm merged 7 commits into
mainfrom
py/better-reactant-testing
Nov 22, 2026
Merged

penelopeysm merged 7 commits into
mainfrom
py/better-reactant-testing

Conversation

@penelopeysm

@penelopeysm penelopeysm commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

We tested the correctness quite thoroughly for bijector(x) where x is a traced array / number, but we didn't cover the case where bijector is itself traced.

For Truncate/Untruncate, this hit a problem because if isfinite(lower) would error if lower was a traced number (and then isfinite(lower) would be a traced bool).

The fix for this is to just add @trace before the if. That means that we pick up ReactantCore as a dep, which is fine.

The newly added tests fail (for Truncate/Untruncate) before the code change, and pass now. For Exp and Log they always passed, but I figured we should test it for good measure.

Closes #36

@github-actions

Copy link
Copy Markdown

Docs preview for PR #37

@penelopeysm

penelopeysm commented Nov 21, 2026 •

Copy link
Copy Markdown
Member Author

Ah, ffs, this is in #34.

Edit: OK, this PR is slightly cleaner (and hanldes both Truncate and Untruncate) and has more tests.

@penelopeysm penelopeysm reopened this Nov 21, 2026
Comment thread src/univariate/truncated.jl Outdated
@@ -91,7 +94,7 @@ function with_logabsdet_jacobian(u::Untruncate, x::Number)
#
# That's a failure with Enzyme.jacobian rather than Enzyme.gradient, so it's unlikely
# that it will really be hit in practice. But it's still worth being careful here

@penelopeysm penelopeysm Nov 21, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks irrelevant as the upstream fix has already landed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude says it works fine now on 1.10. I'll let CI be the arbiter

@penelopeysm
penelopeysm merged commit e06cc5a into main Nov 22, 2026
8 checks passed
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.

Truncate and Untruncate don't work with Reactant

1 participant