Skip to content

feat: add C implementation for lapack/base/dgttrf - #15810

Open
benatsf wants to merge 1 commit into
stdlib-js:developfrom
benatsf:feat/lapack-dgttrf-native
Open

benatsf wants to merge 1 commit into
stdlib-js:developfrom
benatsf:feat/lapack-dgttrf-native

Conversation

@benatsf

@benatsf benatsf commented Oct 2, 2026

Copy link
Copy Markdown

Progresses #2464.

Description

lapack/base/dgttrf currently factors real tridiagonal matrices in JavaScript. This adds contiguous and independently strided C implementations, an optional Node-API addon, public headers, build manifests, C examples/benchmarks and native regression coverage.

The port preserves the existing in-place mutation order, zero-based pivot indices and zero-based singular status, including the existing ambiguity when the first pivot is zero. All five existing JavaScript implementation/dispatch files remain byte-for-byte unchanged. Ordinary buffers, incompatible metadata, short views and numeric/pivot byte overlap use the existing JavaScript implementation. The addon uses a width-correct LAPACK_INT workspace instead of treating JavaScript Int32Array pivots as ILP64 integers; disjoint typed views retain native execution. Browser resolution uses the JavaScript entrypoint.

The kernel is adapted from Reference LAPACK DGTTRF with its complete copyright and BSD redistribution notice retained. It is self-contained and does not introduce an external LAPACK runtime dependency or modify shared helpers.

Related Issues

Validation

  • Built and loaded the actual addon on Linux x86_64 with Node 24.19.0 and GCC 14.2.0. Four directly executed package suites pass 3,287 assertions with zero skipped native tests; the native suite includes 243 instrumented addon calls over independently varied strides and guarded byte-offset views.
  • Checked-in fixtures come from 58 executions of compiled Reference LAPACK through SciPy 1.17.0, covering small/empty matrices, pivot ties/swaps, singular pivots and scaled inputs. Dense reconstruction independently verifies the finite factors. Nonfinite values, signed zeros, zero strides, byte overlap and fallback behavior are checked against the unchanged JavaScript implementation.
  • A separate Codex agent independently exercised 70 actual LAPACK cases across six view layouts, 420 dense reconstructions, floating and pivot aliases, metadata overrides and nonfinite/fallback behavior, measuring 533 real addon calls and 41,795 exact whole-view comparisons.
  • LP64, ILP64 and ILP64 with suffixed C APIs compile with warnings as errors and pass AddressSanitizer/UndefinedBehaviorSanitizer probes for pivoting, singular status, negative/zero strides, guards and small/empty arguments.
  • A fresh process with the binary physically absent selects the exact original JavaScript export; fallback tests pass and the five optional native groups skip only in that absent-addon check. Applicable JavaScript/C/Markdown/TypeScript/package/REPL/license/filename lint and both upstream EditorConfig checks pass. TypeScript 4.9.5 verifies 210 expected-error lines and two return types with no unexpected diagnostics. Existing spelling/line-length lint warnings remain warnings.
  • JavaScript and compiled C examples execute, and all nine bounded C benchmark runs complete. No performance improvement is claimed. Other platforms were not tested.

Questions

No.

Other

This is one complete native routine under the accepted RFC. Existing JavaScript semantics, including its zero-based status convention, are deliberately preserved.

Checklist

AI Assistance

  • Yes

  • No

  • Code generation

  • Test/benchmark generation

  • Documentation (including examples)

  • Research and understanding

Disclosure

This contribution was authored primarily with OpenAI Codex. Codex generated the C implementation, width-safe Node-API bridge, package-local dispatch guards, build metadata, numerical fixtures, tests, benchmarks and documentation, and ran the recorded validation. A delegated Codex agent independently reviewed the source and exercised the compiled numerical implementation against LAPACK. Codex reviewed and applied the contributing guidelines under benatsf's explicit authorization to contribute; the checklist does not claim that benatsf personally read the guidelines or manually reviewed the generated code. No manual applicant review is claimed.


@stdlib-js/reviewers

Add contiguous and strided native tridiagonal LU factorization with width-safe Node-API pivots, guarded JavaScript fallback and independent LAPACK regression coverage. Preserve all existing JavaScript implementations and zero-based pivot/status semantics.

AI assistance: OpenAI Codex generated the implementation, tests, fixtures, benchmarks and documentation, ran validation and delegated an independent automated numerical review. No manual applicant review is claimed.
@benatsf
benatsf requested a review from a team October 2, 2026 13:07
@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. First-time Contributor A pull request from a contributor who has never previously committed to the project repository. labels Oct 2, 2026

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

First-time Contributor A pull request from a contributor who has never previously committed to the project repository. 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