Improves Pseudolikelihood computation performance#18
Conversation
…ons and improve numerical stability
…tions, and optimize conditional probability functions for performance
There was a problem hiding this comment.
Pull request overview
This PR improves the performance of pseudo-likelihood computation in the mrf2d package by (1) refactoring the per-pixel conditional probability computation to use a log-space, log-sum-exp formulation that avoids per-pixel NumericVector allocation and gives better numerical stability, (2) reordering the inner loops to iterate over neighbors outermost and values innermost (better cache locality plus a single bounds check per direction), and (3) adding optional OpenMP parallelization over the pixel grid in log_pl_mrf / log_pl_mrf_sub.
Changes:
- Rewrite
conditional_probabilities_mrf{,_sub}to accumulate log-potentials and normalize with the log-sum-exp trick. - Add
log_cond_pixel{,_sub}helpers and OpenMPparallel for collapse(2)reductions inlog_pl_mrf{,_sub}, with thread-local scratch buffers. - Add
src/Makevarsandsrc/Makevars.winenablingSHLIB_OPENMP_CXXFLAGS; bumpVersionto 1.0.2,RoxygenNoteto 7.3.3, andactions/upload-artifactto v4.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/pseudo_likelihood.cpp | New log-space per-pixel helpers and OpenMP-parallel reductions over the grid. |
| src/conditional_probability.cpp | Reordered loops and added log-sum-exp normalization for numerical stability. |
| src/Makevars | New file enabling OpenMP flags on Unix builds. |
| src/Makevars.win | New file enabling OpenMP flags on Windows builds. |
| DESCRIPTION | Bumps package Version and RoxygenNote. |
| .github/workflows/test-coverage.yaml | Upgrades upload-artifact action from v3 to v4. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
No description provided.