Skip to content

Use posterior::is_constant() instead of a copy in loo - #433

Merged
florence-bockting merged 2 commits into
stan-dev:masterfrom
soujasK:refactor/408-use-posterior-is-constant
Nov 30, 2026
Merged

florence-bockting merged 2 commits into
stan-dev:masterfrom
soujasK:refactor/408-use-posterior-is-constant

Conversation

@soujasK

@soujasK soujasK commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Part of #408

loo kept its own is_constant() in R/helpers.R. Since #407 it uses a tolerance relative to the magnitude of x, and posterior 1.8.0 has the same function (stan-dev/posterior#469). This PR removes the copy and uses posterior::is_constant() in .E_loo_khat_i().

Changes:

  • R/E_loo.R: call posterior::is_constant()
  • R/helpers.R: remove loo's is_constant()
  • DESCRIPTION: require posterior (>= 1.8.0). posterior 1.7.x still has the absolute tolerance, so without the bump the problem fixed in Use a relative tolerance in is_constant #407 would come back for users with an older posterior.
  • tests/testthat/test_0_helpers.R: remove the test of loo's copy
  • tests/testthat/test_E_loo.R: remove the skip_if() for an older posterior, so the scale test always runs
  • NEWS.md: add a bullet

Requiring posterior 1.8.0 so soon after its release is your call. If you prefer to wait, I can keep this PR open until then.

I left out the n_pareto / ps_tail_length ceiling vs floor question, since that is still open in #408.

Tests: devtools::test() passes locally (1366 passed, 0 failed, 0 skipped) with R 4.4.3 and posterior 1.8.0.

AI disclosure: I used Claude to help prepare this change. I reviewed and understood all of it and can explain and defend it in review.

loo kept its own is_constant() with a tolerance relative to the magnitude
of x (stan-dev#407). posterior 1.8.0 has the same function (stan-dev/posterior#469),
so loo now uses posterior::is_constant() and requires posterior >= 1.8.0.
With an older posterior the absolute tolerance would come back.

The skip in the E_loo scale test is no longer needed, so the test always runs.

Part of stan-dev#408

Signed-off-by: Soujas K <kudchadkarsoujas@gmail.com>
@soujasK
soujasK marked this pull request as ready for review November 30, 2026 13:41
@codecov-commenter

codecov-commenter commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.81%. Comparing base (2d229e5) to head (4964f94).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #433      +/-   ##
==========================================
- Coverage   92.82%   92.81%   -0.01%     
==========================================
  Files          31       31              
  Lines        3078     3075       -3     
==========================================
- Hits         2857     2854       -3     
  Misses        221      221              

☔ 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.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 4964f94 is merged into master:

Status Name Current Incoming Interval
✔️ loo_matrix 1.3s 1.3s [-0.29%, +1.1%]
✔️ loo_function 1.16s 1.16s [-1.83%, +1.69%]

Further explanation regarding interpretation and methodology can be found in the documentation.

Comment thread NEWS.md Outdated
@@ -1,5 +1,6 @@
# loo (development version)

* Use `posterior::is_constant()` instead of a copy in loo and require posterior >= 1.8.0 (#408)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you adapt this point and make it consistent with the style of the other points in NEWS.md and add also your GitHub name for acknowledgement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @florence-bockting!I updated the bullet to match the other entries and added my GitHub name (4964f94).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great. Thank you. I will go ahead and merge the PR now. Congrats for your first merged PR in loo =)

@florence-bockting florence-bockting left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for your work and contribution to the loo package. Very well done.
I had only one minor comment with respect to the NEWS.md bullet point otherwise I think its good and can be merged once the slight change has been done.

Signed-off-by: Soujas K <kudchadkarsoujas@gmail.com>
@florence-bockting
florence-bockting merged commit 1d64b82 into stan-dev:master Nov 30, 2026
10 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.

3 participants