Skip to content

feat: add lapack/base/dsptrs - #17001

Open
Udaygund wants to merge 1 commit into
stdlib-js:developfrom
Udaygund:feat/dsptrs
Open

Udaygund wants to merge 1 commit into
stdlib-js:developfrom
Udaygund:feat/dsptrs

Conversation

@Udaygund

@Udaygund Udaygund commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Resolves a part of #14631.

Description

What is the purpose of this pull request?

This pull request:

  • adds @stdlib/lapack/base/dsptrs, which solves a system of linear equations A * X = B with a real symmetric matrix A stored in packed format, using the factorization A = U * D * U^T or A = L * D * L^T computed by dsptrf (feat: add lapack/base/dsptrf #13288).

The implementation is a port of reference LAPACK DSPTRS: for U * D * U^T, it solves U * D * X = B (backward over the pivot blocks, using dswap, dger, and dscal) followed by U^T * X = B (forward, using dgemv); the L * D * L^T case is the mirror image. 1-by-1 and 2-by-2 diagonal blocks are handled as in the reference implementation.

Conventions follow lapack/base/dlaswp and #13288:

  • dsptrs( order, uplo, N, nrhs, AP, IPIV, B, LDB ) and dsptrs.ndarray( order, uplo, N, nrhs, AP, sap, oap, IPIV, si, oi, B, sb1, sb2, ob ). As in dsptrf.ndarray, order is kept in the ndarray API because the packed layout of AP can't be described by strides alone; the layout of B is given by sb1 and sb2.
  • LDB >= max(1,N) for column-major and LDB >= max(1,nrhs) for row-major.
  • For row-major input, uplo is resolved to the equivalent column-major factorization in the same way as feat: add lapack/base/dsptrf #13288 (row-major + upper is solved as L * D * L^T, and row-major + lower as U * D * U^T), so dsptrs consumes exactly the AP and IPIV that dsptrf returns for the same order and uplo.
  • uplo is validated in both APIs. The function returns B (overwritten by X); AP and IPIV are not modified. Reference DSPTRS only uses INFO to report invalid arguments, which are thrown as errors here.

Related Issues

Does this pull request have any related issues?

This pull request has the following related issues:

Reference Packages

Did the content of this pull request follow one or more existing packages? Answering is optional.

This pull request followed these packages:

What carried over from the reference(s)?

  • package layout (base.js + dsptrs.js + ndarray.js), argument validation, the row-major uplo resolution, docs, and test structure from feat: add lapack/base/dsptrf #13288
  • layout handling for B and the LDB checks from lapack/base/dlaswp

What differed, or what did you have to work out yourself?

  • the solve itself, ported from reference LAPACK DSPTRS; loop counters stay one-based as in the reference, with zero-based indices in the code comments
  • fixtures: each fixture picks an exact integer solution X, sets B = A * X, and factors A with reference LAPACK dsptrf (Apple Accelerate). Tests compare against X within 8 ULP. The fixtures cover upper/lower, both layouts, factorizations with only 2-by-2 blocks, 1-by-1 blocks with row interchanges, N = 1, multiple right-hand sides, LDB larger than required, offsets, and positive, negative, and mixed strides. Matrices are shown row by row in *_mat fields
  • additional checks outside the test suite: on 2,000 random matrices (1,321 requiring 2-by-2 pivots), the results agree with reference LAPACK dsptrs to within 5.3e-15 relative error in column-major, row-major, and strided/offset layouts. Running the feat: add lapack/base/dsptrf #13288 dsptrf implementation on the same matrices gives IPIV identical to reference LAPACK, so the two packages are compatible
  • as a check on the tests, disabling or perturbing each of the 14 branches in lib/base.js (each dger/dgemv/dscal/dswap step) makes the tests fail

Questions

Any questions for reviewers of this pull request?

Yes: the IPIV convention for 2-by-2 pivots (also asked in #14631). Other LAPACK packages here use zero-based IPIV (e.g., dgttrf, dlaswp), but #13288 currently stores the one-based reference LAPACK values, with negative values marking 2-by-2 blocks, and a zero-based row 0 can't be negated. This PR follows #13288 as it stands. All pivot decoding is in one helper (pivotRow in lib/base.js), so if dsptrf moves to a zero-based encoding (for example ~kp), only that helper and the fixtures need to change.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

Ran locally: package tests (110 assertions), benchmarks, the example, and the commit-hook linters (file names, EditorConfig, Markdown, package.json, repl.txt, JavaScript, TypeScript declarations and tests, license headers), all passing.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

  • Read, understood, and followed the [contributing guidelines][contributing].

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance. This helps reviewers determine how much scrutiny to apply when reviewing your contribution. Example disclosures: "This PR was written primarily by Claude Code." or "I consulted ChatGPT to understand the codebase, but the proposed changes were fully authored manually by myself.".


@stdlib-js/reviewers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown_pkg_readmes
    status: passed
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: passed
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: passed
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
@Udaygund
Udaygund requested a review from a team November 30, 2026 04:48
@stdlib-bot stdlib-bot added LAPACK Issue or pull request related to the Linear Algebra Package (LAPACK). Needs Review A pull request which needs code review. labels Nov 30, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
lapack/base/dsptrs $\\color{green}645/645$
$\\color{green}+100.00\\%$
$\\color{green}73/73$
$\\color{green}+100.00\\%$
$\\color{green}6/6$
$\\color{green}+100.00\\%$
$\\color{green}645/645$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LAPACK Issue or pull request related to the Linear Algebra Package (LAPACK). Needs Review A pull request which needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants