Skip to content

⚡ Bolt: Cache matrix inversions in vuongtest to reduce redundant calculations#15

Open
seonghobae wants to merge 1 commit into
masterfrom
bolt/cache-matrix-inversions-15346295909571307141
Open

⚡ Bolt: Cache matrix inversions in vuongtest to reduce redundant calculations#15
seonghobae wants to merge 1 commit into
masterfrom
bolt/cache-matrix-inversions-15346295909571307141

Conversation

@seonghobae

Copy link
Copy Markdown
Collaborator

💡 What

Cached the result of matrix inversions (chol2inv(chol())) inside the calcLambda function in R/vuongtest.R.

🎯 Why

Matrix inversions scale with $O(N^3)$ complexity. The previous implementation called chol2inv(chol(AB1$A)) and chol2inv(chol(AB2$A)) twice each while assembling the W matrix block. Hoisting these into invA1 and invA2 variables prevents these redundant computations, reducing overall runtime for complex vuongtest calls.

📊 Impact

Halves the number of matrix inversions inside calcLambda. This reduces the computational overhead significantly for model comparisons involving large asymptotic covariance matrices, accelerating the test without any changes to statistical outcomes.

🔬 Measurement

Run a profiling trace (Rprof) over vuongtest(model1, model2) on models with large coefficient matrices, and observe that the cumulative time spent in chol() and chol2inv() drops by up to 50%. Statistical results remain mathematically identical.


PR created automatically by Jules for task 15346295909571307141 started by @seonghobae

…3) calculations

Added `invA1` and `invA2` to cache the results of `chol2inv(chol())` in `calcLambda` inside `vuongtest.R`, halving the matrix inversion overhead.
Copilot AI review requested due to automatic review settings June 28, 2026 03:44
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes vuongtest’s calcLambda() by caching expensive matrix inversions so they are computed once and reused when constructing the W matrix, reducing redundant chol2inv(chol()) calls.

Changes:

  • Hoists chol2inv(chol(AB1$A)) and chol2inv(chol(AB2$A)) into cached variables (invA1, invA2) to avoid repeated O(N³) work.
  • Adds a .jules/bolt.md note documenting the optimization rationale.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
R/vuongtest.R Caches matrix inversions inside calcLambda() to avoid recomputation during W assembly.
.jules/bolt.md Adds an internal/automation note describing the optimization and guiding future inspections.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .jules/bolt.md
Comment on lines +1 to +3
## 2024-05-18 - Caching Matrix Inversions in Vuong Test
**Learning:** Found redundant `chol2inv(chol())` calls within the `calcLambda` matrix construction block in `vuongtest.R`. Matrix inversions are $O(N^3)$, so caching them and reusing is an effective and non-intrusive optimization for matrix-heavy statistic R packages.
**Action:** When inspecting matrix operations inside block initializations or recursive calls, always check if invariant intermediate expressions like inversion or decomposition are evaluated multiple times and hoist them.
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