← Back to Pull requests

Add specialized svd(::SymTridiagonal{<:Real}) #1833

Open
unknown opened this pull request with 323 lines diff across 4 files
View on GitHub
unknown unknown commented on Oct 30, 2026 17:58 UTC
Author

Add specialized svd(::SymTridiagonal{<:Real})

Follow-up to #1827, which added svdvals(::SymTridiagonal{<:Real})). @stevengj flagged this in review as the natural next step.

Stacked on #1827, the diff below will show that PR's commits (06aebbf, 560a4f4, 58cb46a) until it merges.

Motivation

svd(A::SymTridiagonal) currently falls through to the generic svd(::AbstractMatrix), which goes through eigencopy_oftype -> dense gesdd!. Same root cause #1827 fixed for svdvals: the tridiagonal structure is thrown away.

Fix

Empty input is handled by returning an SVD with eigtype-typed fields before calling eigen! (eigen on n=0 throws inside stegr!). svd delegates to svd! via copymutable_oftype, so the guard lives in one place.

Signature

Matches the sibling svdvals(::SymTridiagonal{<:Real}). Complex falls through to the generic dense path; verified that SymTridiagonal{ComplexF64} constructs and svd returns the correct factorization via gesdd!. Float16 promotes to Float32 for the eigendecomposition, same as the dense path.

full, alg, atol, rtol are accepted for API compatibility with svd(::AbstractMatrix) but are no-ops for square input.

Tests

In test/tridiag.jl, new testset svd(::SymTridiag):

  • Reconstruction invariant F.U Diagonal(F.S) F.Vt ≈ A

  • Orthogonality F.U' F.U ≈ I, F.Vt F.Vt' ≈ I

  • Descending order issorted(F.S; rev=true)

  • Parity with svdvals(A)

  • Zero eigenvalue (catches the sign(0) trap)

  • Empty input (guard fires before eigen, which throws on n=0)

  • Float16 promotion, Int eigtype and @inferred

  • full kwarg no-op

  • Complex fallthrough correctness

  • rank(::SVD) on the result
  • Benchmarks

    svd(SymTridiagonal(randn(n), randn(n-1))) vs svd(Matrix(SymTridiagonal(...))), Julia 1.13.3, x86_64, @elapsed min-of-5-after-warmup:

    | n | dense (ms) | this PR (ms) | speedup |
    |-----:|-----------:|-------------:|--------:|
    | 256 | 12.0 | 7.7 | 1.6x |
    | 1024 | 322.0 | 124.4 | 2.6x |
    | 2048 | 4526.0 | 495.2 | 9.1x |

    Smaller ratios than #1827's svdvals table because stegr! with eigenvectors has a much larger constant than eigenvalues-only, and reconstruction adds another O(n^2). Asymptotics are still O(n^2) vs O(n^3), and the ratio grows with n.

    svd! avoids the copy(dv)/copy(ev) inside eigen, saving O(n) against the O(n^2) reconstruction. 26% faster at n=256, noise at n=1024, within noise at n=2048. Included for parity with svdvals!; happy to drop if smaller surface area is preferred.

    Diff: 323 lines (+242 / -81) across 4 files Reviewer: stevengj Review duration: 5571m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.42) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 323 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.346
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1833"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.0% (MEDIUM) · Higher = larger blast radius
    42.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.4% · Safe to merge
    22.4%