Repository navigation
svd: dqds takes its work arrays from the caller's MemStack (#156) - #157
Merged
Merged
Conversation
The values-only SVD allocated on the heap in 0.26.0 although the caller passes a MemStack sized by svd_scratch: dqds::singular_values built its four work arrays with vec! (two allocations at 1 x 1, four above), and its stable sort moves its merge buffer to the heap for large slices (700 x 700 f64). The arrays now come from the stack through dqds::singular_values_scratch, which the values-only bidiagonal scratch (and so svd_scratch) includes, and the sort is sort_unstable_by. faer/tests/svd_values_no_alloc.rs counts zero allocations for f64/f32/c64/c32 from 1 x 1 to 700 x 700; before, [2, 2, 2, 2] at 1 x 1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shinaoka
force-pushed
the
fix/156-dqds-scratch
branch
from
October 29, 2026 15:29
eedf9c5 to
02fcefd
Compare
shinaoka
added a commit
that referenced
this pull request
Oct 30, 2026
…allocation (#159) The minor version moves because Par::Team and ParShape::Team carry threadteam's types and the requirement moved from threadteam 0.1 to 0.2 (#158): a crate that lends a threadteam 0.1 team to faer does not compile against it (reproduced: E0308 on Par::Team). Carries #157 (#156). t4a-faer-traits stays 0.24.2. CHANGELOG and PATCHSET record the release. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #156.
Problem
In 0.26.0 the values-only SVD allocates on the heap, although the caller passes a
MemStacksized bysvd_scratch. 0.25.0 did not allocate. tlinalg'salloc_countstest fails on it, which blocks the tlinalg 0.8.0 release.There are two sources, both in
dqds::singular_values:a,band the ping-pong buffersa2,b2) were built withvec!. That is two allocations at 1 × 1 and four above.sort_by. Its merge buffer moves from the stack to the heap for large slices: one allocation for f64 and c64 at 700 × 700 (f32 and c32 still fit on the stack).Fix
dqds::singular_values_scratch::<T>(n)describes the four arrays, andsingular_valuestakes them from theMemStackwithmake_with.bidiag_real_svd_scratchwith no U and no V) includes it, throughany_ofwith the fallback paths, since dqds runs first and a failed dqds then runs the rotation path. Sosvd_scratchand the complex route include it too.sort_unstable_by. All equal keys are equal values, so the result does not change.Tests
faer/tests/svd_values_no_alloc.rs: its own test binary with a process-wide counting allocator.svdonPar::Seqfor f64/f32/c64/c32 at 1×1, 2×2, 17×17, 40×33, 33×40, 128×128, 300×60 (the QR route) and 700×700.[2, 2, 2, 2]at 1 × 1 (the issue's numbers).[1, 0, 1, 0]at 700 × 700.cargo test -p t4a-faer --lib linalg::svd: 74 passed.linalg::svd::tests --include-ignored): 88/88 passed (131 s).run-lapack-validation.pyrun, every other family passed.parallel_paths, while primerose's load average was 60. Run directly without that limit, it passes, as above.cargo check --no-default-featuresand--features std: no warning or error from this change.Review
The independent post-review (gpt-6.1-sol) found no BLOCKER or IMPORTANT issues. It checked:
any_ofis right because dqds releases its arrays before the fallback runs;Copyscalars;Its one MINOR (a redundant f64 copy in the test) is applied. The test checks steady-state calls after a warm-up;
Par::Teamand cold calls are outside its scope.Records
🤖 Generated with Claude Code