Registry Mirror
Skip to content

Conversation

@mtantaoui

Copy link
Copy Markdown
Contributor

Speed up elastic net fitting

Fits are 3–31× faster, with the same number of passes and the same results.

Changes

  • Contiguous features. Coordinate descent updates one feature at a time and read
    it as a column of a row-major x, with a stride of a full row, three times per
    update. It now runs on a feature-major copy of x (none if x is already
    column-major), so dot and scaled_add run on contiguous data.
  • One residual update per coordinate instead of two, using
    x_jᵀ(r + w_old x_j) = x_jᵀ r + w_old ‖x_j‖²; skipped when the coefficient doesn't
    change.
  • Multi-task residuals stored task by task, so each coordinate is a contiguous
    dot and scaled_add per task instead of two small matrix products.
  • The duality gap uses the feature-major copy for xᵀ r.

Every bench fit takes exactly as many passes as before, and the final duality gaps
match (f64: to 11–12 digits).

Results

cargo bench -p linfa-elasticnet --bench fit (new): default settings, penalty 0.1,
n = 5 000, correlated features (ρ = 0.8), 4 tasks for multi-task. Core Ultra 7 155H,
one core.

fit d passes master this PR speedup
single-task f32 8 66 3.0 ms 0.4 ms 8.1×
32 611 147.3 ms 14.5 ms 10.1×
128 1000 2763.7 ms 88.8 ms 31.1×
single-task f64 8 66 3.2 ms 0.9 ms 3.6×
32 611 223.2 ms 34.5 ms 6.5×
128 1000 3536.3 ms 213.4 ms 16.6×
multi-task f32 8 68 19.3 ms 1.8 ms 10.9×
32 787 992.7 ms 91.7 ms 10.8×
128 1000 9986.2 ms 407.7 ms 24.5×
multi-task f64 8 68 12.0 ms 3.7 ms 3.2×
32 787 823.1 ms 179.0 ms 4.6×
128 1000 9816.1 ms 876.3 ms 11.2×

@mtantaoui

Copy link
Copy Markdown
Contributor Author

The criterion bench (benches/fit.rs) and its dev-dependencies are only there to
measure this change. If you'd rather not keep them in the repository, let me know
and I'll drop them from the PR.

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.90909% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.67%. Comparing base (935c437) to head (391d267).

Files with missing lines Patch % Lines
algorithms/linfa-elasticnet/benches/fit.rs 0.00% 27 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #469      +/-   ##
==========================================
- Coverage   76.95%   76.67%   -0.29%     
==========================================
  Files         105      106       +1     
  Lines        7612     7635      +23     
==========================================
- Hits         5858     5854       -4     
- Misses       1754     1781      +27     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mtantaoui
mtantaoui force-pushed the perf/elasticnet-contiguous branch from 98d2224 to 72c867f Compare November 23, 2026 16:22
@mtantaoui
mtantaoui force-pushed the perf/elasticnet-contiguous branch from 72c867f to 6cedd14 Compare November 23, 2026 16:41

This branch has not been deployed

No deployments
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.

1 participant