Skip to content

Fix with_logabsdet_jacobian for mapped/broadcasted functions - #40

Open
oschulz wants to merge 5 commits into
masterfrom
fix-mapped-noladj
Open

Fix with_logabsdet_jacobian for mapped/broadcasted functions#40
oschulz wants to merge 5 commits into
masterfrom
fix-mapped-noladj

Conversation

@oschulz

@oschulz oschulz commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Occurances of NoLogAbsDetJacobian in intermediate result were not handled properly.

@oschulz
oschulz requested a review from devmotion July 8, 2026 20:12
@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.77%. Comparing base (e826632) to head (cb671fb).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #40      +/-   ##
==========================================
+ Coverage   97.64%   97.77%   +0.13%     
==========================================
  Files           5        5              
  Lines          85       90       +5     
==========================================
+ Hits           83       88       +5     
  Misses          2        2              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@oschulz
oschulz force-pushed the fix-mapped-noladj branch 2 times, most recently from 21489fe to 15abf0a Compare July 12, 2026 15:30
@oschulz

oschulz commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator Author

Any objections @devmotion ?

Comment thread src/with_ladj.jl Outdated
Comment thread src/with_ladj.jl Outdated
@oschulz
oschulz force-pushed the fix-mapped-noladj branch from 15abf0a to 7732448 Compare July 27, 2026 11:21
@oschulz

oschulz commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator Author

Good like this now @devmotion ?

Comment thread .github/workflows/ci.yml Outdated
Comment thread src/setladj.jl Outdated
Comment thread src/with_ladj.jl Outdated
Comment on lines +134 to +141
function _with_ladj_on_mapped(y_with_ladj::Tuple{NoLogAbsDetJacobian, Vararg{Union{NoLogAbsDetJacobian, Tuple{Any,Real}}}})
return first(y_with_ladj)
end

function _with_ladj_on_mapped(y_with_ladj::Tuple{Tuple{Any,Real}, Vararg{Union{NoLogAbsDetJacobian, Tuple{Any,Real}}}})
a, bs = first(y_with_ladj), Base.tail(y_with_ladj)
return foldl(_combine_y_ladj, bs, init = ((a[1],), a[2]))
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder - can we limit the summation already on the dispatch level to the case without NoLogAbsDetJacobian, by restricting the acutal summation path to Tuple{Tuple{Any,Real}, Vararg{Tuple{Any,Real}}}? All other cases should result in NoLogAbsDetJacobian anyway? And presumably, in contrast to the current foldl result, not in any NoLogAbsDetJacobian but the one of the mapped_f and X, to be consistent with other NoLogAbsDetJacobian results?

@oschulz oschulz Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Tuple{Any,Real} will cause problems with Reactant, which I definitely want to use with ChangesOfVariables soon. And while it's not sanctioned I've been using with_logabsdet_jacobian in machine-learning cases that necessarily use a flat array for batching instead of nested arrays, and so the ladj value then has to be a vector, not a number. I've been thinking about making it "official", but at least for now, we only required ladj to be additive.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@devmotion I changed the dispatch now on the lines you suggested, based on "positive" instead of "negative" patterns.

@oschulz
oschulz force-pushed the fix-mapped-noladj branch from 3a95955 to cb671fb Compare July 28, 2026 19:52
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.

2 participants