Repository navigation
Refactor: Vectorize dotprodScoring in StatsHelpers using Eigen (Closes #8126) - #8848
Conversation
|
@jpfeuffer can you check ? |
|
This is awesome and exactly what I was looking for! |
📝 WalkthroughWalkthroughVectorized mathematical operations in a statistics helper file by replacing element-wise square root loops with Eigen-based vectorized calculations. Added Eigen/Dense header support and optimized accumulation operations using Eigen maps for improved computational efficiency. Changes
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/openswathalgo/source/OPENSWATHALGO/ALGO/StatsHelpers.cpp (2)
41-53: Variable naming: prefersnake_casefor local variables.The coding guidelines specify that variable names must use
snake_case. Consider renamingmapExp→map_expandmapTheor→map_theor.The vectorization approach using
Eigen::MapwithcwiseSqrt()is correct and efficient—it modifies the vector storage in-place without copying.🔧 Suggested naming fix
- Eigen::Map<Eigen::VectorXd> mapExp(intExp.data(), intExp.size()); - Eigen::Map<Eigen::VectorXd> mapTheor(theorint.data(), theorint.size()); + Eigen::Map<Eigen::VectorXd> map_exp(intExp.data(), intExp.size()); + Eigen::Map<Eigen::VectorXd> map_theor(theorint.data(), theorint.size()); - mapExp = mapExp.cwiseSqrt(); - mapTheor = mapTheor.cwiseSqrt(); + map_exp = map_exp.cwiseSqrt(); + map_theor = map_theor.cwiseSqrt();As per coding guidelines: "Variable names must use snake_case".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openswathalgo/source/OPENSWATHALGO/ALGO/StatsHelpers.cpp` around lines 41 - 53, Rename the local Eigen::Map variables to follow snake_case: change mapExp to map_exp and mapTheor to map_theor in the StatsHelpers.cpp snippet (update the declarations Eigen::Map<Eigen::VectorXd> map_exp(...) and map_theor(...), and their subsequent cwiseSqrt() assignments) so all references (assignments and any future uses) use the new snake_case names consistently.
15-16: Remove#include <Eigen/Dense>and rely on#include <Eigen/Core>(line 15) only.
Eigen/Corealready provides all the functionality used in this file:Eigen::Map,VectorXd,cwiseSqrt(),sum(),norm(),cwiseAbs(), anddot(). TheEigen/Denseheader additionally pulls in decomposition modules (LU, Cholesky, QR, SVD, Geometry, Eigenvalues) which are not used here, increasing compile time unnecessarily.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openswathalgo/source/OPENSWATHALGO/ALGO/StatsHelpers.cpp` around lines 15 - 16, Remove the unnecessary `#include` <Eigen/Dense> and rely solely on `#include` <Eigen/Core> (already present) because this translation unit only uses Eigen::Map, Eigen::VectorXd and element-wise/aggregate ops such as cwiseSqrt(), sum(), norm(), cwiseAbs(), and dot(); delete the Eigen/Dense include to avoid pulling in unused decomposition modules and reduce compile time.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/openswathalgo/source/OPENSWATHALGO/ALGO/StatsHelpers.cpp`:
- Around line 41-53: Rename the local Eigen::Map variables to follow snake_case:
change mapExp to map_exp and mapTheor to map_theor in the StatsHelpers.cpp
snippet (update the declarations Eigen::Map<Eigen::VectorXd> map_exp(...) and
map_theor(...), and their subsequent cwiseSqrt() assignments) so all references
(assignments and any future uses) use the new snake_case names consistently.
- Around line 15-16: Remove the unnecessary `#include` <Eigen/Dense> and rely
solely on `#include` <Eigen/Core> (already present) because this translation unit
only uses Eigen::Map, Eigen::VectorXd and element-wise/aggregate ops such as
cwiseSqrt(), sum(), norm(), cwiseAbs(), and dot(); delete the Eigen/Dense
include to avoid pulling in unused decomposition modules and reduce compile
time.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 703432b0-994d-4fe1-904c-1a12f645d079
📒 Files selected for processing (1)
src/openswathalgo/source/OPENSWATHALGO/ALGO/StatsHelpers.cpp
|
What hardware did you run the benchmarks on? |
|
Hi @cbielow, I ran the standalone benchmarks locally on my Mac Mini (m4) with [16GB] of RAM. |
Description
This PR addresses issue #8126 by vectorizing and centralizing math operations, starting with the heavily utilized
dotprodScoringandmanhattanScoringfunctions inStatsHelpers.cpp.Replaced the manual
forloop iterations andstd::accumulatewithEigen::Map,cwiseSqrt(), andEigen::VectorXd::dot(). This avoids memory copying while leveraging Eigen's underlying SIMD vectorization for the square roots, summations, and dot products.Benchmarking
I ran a standalone benchmark to test the speedup of the Eigen implementation against the existing manual loop. Testing was done on arrays of size 1,000 across 1,000,000 iterations (simulating heavy OpenSwath usage).
Result: ~5.2x speedup.
If this architectural approach looks good to the maintainers, I can follow up with further PRs to address the redundant sums and norms scattered across
Scoring.cppandLinearRegression.cpp.Summary by CodeRabbit