⚡ Bolt: vectorize trial loop in jointprob#272
Conversation
Vectorize the inner trial loop in the \`jointprob\` function by reshaping the probabilities array and using NumPy axis-based aggregation. This reduces the overhead of Python loops and slice-based indexing. Benchmark results (64 channels, 500 points, 200 trials): - Original: 0.3083s - Vectorized: 0.1814s - Improvement: ~41% Co-authored-by: suraj-ranganath <14310165+suraj-ranganath@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Claude finished @suraj-ranganath's task in 1m 25s —— View job Code review
I verified the vectorization is numerically identical to the original loop, not just approximately equal: In Existing coverage in BlockingNone. ImportantNone. Nits
Test gapsNone. Changed behavior is byte-for-byte equivalent and already covered. EEGLAB parity notesNone. Scores are unchanged, so Checked for correctness bugs, EEGLAB parity, data-structure compatibility, changed-behavior tests, and CLAUDE.md/AGENTS.md compliance. (Note: I could not run the test suite in this environment due to sandbox command restrictions, but the equivalence is provable by inspection of the array layout.) |
💡 What: The optimization implemented
Vectorized the inner loop over trials in the
jointprobfunction withinsrc/eegprep/functions/popfunc/_rejection.py. Instead of iterating through each trial and slicing the probability array, we now reshape the entire probability vector into a 2D array of(trials, points)and perform the log-summation across the points axis in a single NumPy operation.🎯 Why: The performance problem it solves
The previous implementation used a nested Python loop to iterate over trials for every channel. For EEG datasets with a large number of trials (epochs), this Python loop overhead and repeated slicing became a significant bottleneck in rejection scoring.
📊 Impact: Expected performance improvement
Expected performance improvement of ~40% for standard EEG datasets (e.g., 64 channels, 500 points, 200 trials).
🔬 Measurement: How to verify the improvement
The optimization was verified using a benchmark script comparing the original logic with the vectorized approach. Correctness was confirmed by a parity test ensuring identical results for the joint probability scores.
PR created automatically by Jules for task 3768410077254852708 started by @suraj-ranganath