Skip to content

Ensure matmul in periodic bspline fit dispatches to specialized sparse method when ys is a Vector eltype#114

Merged
jipolanco merged 1 commit into
jipolanco:masterfrom
halleysfifthinc:sparse-matmul-dispatch
Sep 17, 2025
Merged

Ensure matmul in periodic bspline fit dispatches to specialized sparse method when ys is a Vector eltype#114
jipolanco merged 1 commit into
jipolanco:masterfrom
halleysfifthinc:sparse-matmul-dispatch

Conversation

@halleysfifthinc

@halleysfifthinc halleysfifthinc commented Sep 16, 2025

Copy link
Copy Markdown
Contributor

While profiling some of my code that fits a periodic b-spline on multi-dimensional points, I
noticed a generic matmul taking a substantial amount of the fit runtime (~30%).

Some @descending later, I determined that the specialized sparse matmul method signature
requires the destination matrix to be a <:StridedMatrix, and a transposed
reshape/reinterpreted matrix isn't.

I tweaked the reinterpret/reshapeing to keep the destination array <:StridedMatrix when
ys are multi-dimensional points (e.g. SVector).

master:

julia> @benchmark fit(BSplineOrder(4), $ts, vvs, λ, Periodic(2π)) setup=(vvs=copy(vs))
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
 Range (min  max):  170.360 μs    6.467 ms  ┊ GC (min  max): 0.00%  83.29%
 Time  (median):     200.202 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   215.333 μs ± 134.002 μs  ┊ GC (mean ± σ):  4.43% ±  7.07%

  ▄▇█▅▂▂▁▂▂                                                     ▂
  █████████▇▅▆▃▁▁▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▃▃▅▆ █
  170 μs        Histogram: log(frequency) by time          1 ms <

 Memory estimate: 253.10 KiB, allocs estimate: 204.
image

PR:

julia> @benchmark fit(BSplineOrder(4), $ts, vvs, λ, Periodic(2π)) setup=(vvs=copy(vs))
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
 Range (min  max):  121.648 μs    6.925 ms  ┊ GC (min  max): 0.00%  76.07%
 Time  (median):     126.277 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   143.236 μs ± 180.047 μs  ┊ GC (mean ± σ):  8.12% ±  6.54%

  ▁▆██▆▄▅▅▄▃▃▂▁                                                 ▂
  █████████████████▇▆▆▅▅▆▅▄▄▄▃▃▅▅▄▄▄▄▃▃▃▁▁▁▃▁▃▁▁▁▁▄▃▄▅▆▇██▇▆▆▇▇ █
  122 μs        Histogram: log(frequency) by time        208 μs <

 Memory estimate: 253.10 KiB, allocs estimate: 204.
image

@codecov

codecov Bot commented Sep 17, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.17%. Comparing base (d38bb55) to head (3815c07).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #114   +/-   ##
=======================================
  Coverage   95.17%   95.17%           
=======================================
  Files          36       36           
  Lines        2342     2344    +2     
=======================================
+ Hits         2229     2231    +2     
  Misses        113      113           

☔ View full report in Codecov by Sentry.
📢 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.

@jipolanco

Copy link
Copy Markdown
Owner

This is great, thank you!

@jipolanco jipolanco merged commit 80fc868 into jipolanco:master Sep 17, 2025
6 checks passed
@halleysfifthinc halleysfifthinc deleted the sparse-matmul-dispatch branch September 17, 2025 15:49
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