Skip to content

Clarify what sparse(F.LD) returns in the ldlt docstring - #774

Open
ViralBShah wants to merge 1 commit into
mainfrom
ldlt-docs
Open

Clarify what sparse(F.LD) returns in the ldlt docstring#774
ViralBShah wants to merge 1 commit into
mainfrom
ldlt-docs

Conversation

@ViralBShah

Copy link
Copy Markdown
Member

Fixes #725.

F.LD means two different matrices depending on how you use it:

Use What it is
F.LD \ b solves with the product L*D (cholmod_solve with CHOLMOD_LD)
sparse(F.LD) CHOLMOD's packed LDL' factor — L with its unit diagonal overwritten by diag(D)

so F.LD \ b and sparse(F.LD) \ b are different operations:

sparse(F.LD)           recovered L            recovered D
 7.0    0    0    0     1.0    0    0    0     7.0
 0.29  3.43  0    0     0.29  1.0   0    0          3.43
 0     0.29 4.71  0     0     0.29 1.0   0               4.71
 0.14 -0.08 0.23 5.58   0.14 -0.08 0.23 1.0                   5.58

L*D*L' == A[p,p]              : true
sparse(F.LD) == L*D           : false
F.LD \ b == (L*D) \ b         : true
F.LD \ b == sparse(F.LD) \ b  : false

The docstring said only that "the LD component can be materialized as a
sparse matrix using sparse(F.LD)", mentioning neither the packed layout nor
the divergence from F.LD \ b. Sitting next to F.PtL = P'*L and F.UP =
L'*P, which really are products, LD reads as L*D.

The internals already rely on the packed convention: sparse(::Factor) calls
getLd! on sparse(F.LD), which reads d off the diagonal and writes 1
back into it to recover L.

This documents both meanings and replaces the vague "can be reconstructed from
sparse(F.LD) and F.p if needed" with the actual recipe. The snippet is
verified on a 200×200 problem: diag(LD) == diag(F), L comes back as a
SparseMatrixCSC, and L*D*L' == A[F.p, F.p].

Docstring change only — no behavior change. Two alternatives I did not take:

  • Renaming or aliasing the component. F.LD as an operator is consistent
    with PtL/UP; only sparse exposes the packed form, and changing either
    would break code.
  • Making sparse(F.LD) return L*D. As the reporter notes, L is
    unrecoverable from L*D when D has a zero diagonal entry, and
    sparse(::Factor) depends on the packed layout. The packed form is strictly
    more informative — it just needed documenting.

🤖 Generated with Claude Code

https://claude.ai/code/session_01L8HenXTVrASo1sBZVGhpDQ

`F.LD` behaves as two different matrices depending on how it is used: as an
operator `F.LD \ b` solves with the product `L*D`, matching the `PtL`/`UP`
naming, but `sparse(F.LD)` returns CHOLMOD's packed LDL' factor -- `L` with
its unit diagonal overwritten by `diag(D)`. So `F.LD \ b` and
`sparse(F.LD) \ b` are different operations, and next to `F.PtL == P'*L` the
name reads as the product.

Document both meanings, and replace the vague "can be reconstructed from
`sparse(F.LD)` and `F.p`" with the actual recipe for unpacking `L` and `D`.

Fixes #725.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L8HenXTVrASo1sBZVGhpDQ
@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.19%. Comparing base (53690b3) to head (930159b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #774   +/-   ##
=======================================
  Coverage   84.19%   84.19%           
=======================================
  Files          13       13           
  Lines        9403     9403           
=======================================
  Hits         7917     7917           
  Misses       1486     1486           

☔ 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.

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.

Confusing documentation for ldlt

1 participant