⚡ Bolt: Vectorize inner trial loop in jointprob#275
Conversation
Optimized the \`jointprob\` function in \`src/eegprep/functions/popfunc/_rejection.py\` by vectorizing the reduction across trials. - Replaced the per-trial Python loop with a NumPy \`reshape\` and \`sum(axis=1)\` operation. - Achieved ~30% performance improvement on datasets with 500 trials. - Maintained exact parity with the original implementation. 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 56s —— View job Code Review: Vectorize inner trial loop in
|
⚡ Bolt: Vectorize inner trial loop in jointprob
💡 What:
Refactored the `jointprob` function in `src/eegprep/functions/popfunc/_rejection.py` to eliminate a nested Python loop that iterated over every trial for every channel. The new implementation reshapes the calculated probabilities into a (trials, points) matrix and performs a vectorized sum.
🎯 Why:
The original implementation used a Python `for` loop over trials, which incurred significant overhead as the number of epochs increased. In EEG processing, datasets often contain hundreds or thousands of trials, making this a clear bottleneck during artifact rejection.
📊 Impact:
🔬 Measurement:
Verified using a benchmark script (`tools/benchmark_jointprob.py`, since deleted) that compared the old loop-based logic against the vectorized logic, ensuring identical numeric results and measuring execution time. Passed all relevant tests in `tests/test_rejection_workflows.py`.
PR created automatically by Jules for task 11480320677431492768 started by @suraj-ranganath