SciML / SciML/SparseWithDenseRowColMatrices.jl
Adjoint/transpose matvec allocates per call (forward path is alloc-free) — hurts the `:iterative` lstsq loop
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 0
- Forks
- 1
- Avg merge
- 14m
- Merged PRs (30d)
- 6
Description
WHAT: _adjoint_matvec! allocates a fresh length-r scratch w = Vector{...}(undef, r) on every call (src/matvec.jl:152). Confirmed by reading the source. Measured 96-128 B/call vs 0 B for the forward mul!. Likewise the cached LS solve _structured_apply! (src/lstsq.jl:247-263) allocates the temporaries F.W'*b, F.QL'*b, F.Msp*Wtc (256 B/solve) despite the struct carrying a length-n cbuf — every other ldiv! (Woodbury/augmented/QR) measures exactly 0. WHY IT MATTERS: The adjoint matvec is what the :iterative (LSQR/LSMR) engine drives every iteration, so an iterative solve allocates O(iterations); the cached LS solve is sold for hot Newton loops. Both break the API's allocation-free contract. FIX: (a) Hoist the length-r adjoint scratch into a reusable/size-guarded buffer (for SelectorMatrix U the common case, w is just u[1:r] and needs no allocation at all). (b) Add s-length and r-length scratch fields to the LS struct and mul! into them, mirroring the Woodbury buffer approach. EFFORT: S (selector matvec) / M (general + LS struct).
Priority: medium. Filed from an automated next-steps audit of the QR/lstsq work (see PR #6).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read src/matvec.jl:152 and src/lstsq.jl:247-263, then trace the iterative matvec and cached solve callers to understand the existing buffer patterns. Confirm allocation counts for both paths; done means adjoint matvec and cached LS solves meet the zero-allocation contract without changing results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100