Skip to content

feat: add C implementation for blas/ext/base/ndarray/dcusumkbn - #15818

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

benatsf wants to merge 1 commit into
stdlib-js:developfrom
benatsf:feat/ndarray-dcusumkbn-native

Conversation

@benatsf

@benatsf benatsf commented Oct 2, 2026

Copy link
Copy Markdown

Progresses #14819.

Description

Add the missing native implementation for blas/ext/base/ndarray/dcusumkbn: an ndarray-object C API, optional Node-API bridge, build metadata, header, C examples/benchmarks, native benchmark, fallback guards and meaningful cumulative-prefix regression coverage. The adopted one-argument JavaScript API and original JavaScript main are preserved; the existing compensated strided C kernel is reused unchanged.

The bridge extracts the input, output and initial scalar in the original order, then snapshots the original view-helper values once. Native execution supports byte-offset typed views, independent signed/nonunit/zero strides, output mutation and sequential input/output aliases. Initial scalar extraction precedes writes and still occurs for empty input. Generic/accessor-backed buffers, incompatible metadata and wider valid JavaScript indexing use the existing strided path. The result remains the exact original output ndarray object.

The C adapter checks the actual configured CBLAS_INT width before narrowing, including the reused kernel's final post-iteration increment. Exact integer division and unsigned-magnitude checks avoid dependence on extended floating-point precision. The addon uses conservative signed32 eligibility and intrinsic typed-array bounds; valid wider JavaScript cases fall back. Browser resolution selects the unchanged JavaScript implementation. Shared helpers and the numerical algorithm are unchanged.

Related Issues

Validation

  • Built and loaded the actual addon on Linux x86_64, Node 24.19.0 and GCC 14.2.0. Direct final public/native processes pass 2,352 assertions (25/2,327) with zero built-native skips. Thirty checked-in cancellation cases use independently rounded exact Fraction prefixes over binary scales from 2^-700 to 2^700; the native suite instruments 750 actual calls across 25 independent stride/layout combinations per case.
  • Whole-view tests verify prefix values, untouched inputs/guards, typed-array byte offsets, negative/nonunit/zero strides, sequential aliases, signed zeros, NaN/infinities, scalar extraction, empty behavior, output identity and wider-singleton fallback. NaN-aware SameValue comparisons preserve exact zero-sign checks.
  • A separate Codex agent independently exercises 60 exact Fraction fixtures across 4,500 JavaScript/public/native layout cases, measuring 3,026 numerical addon calls and 95,532 scalar checks. Its metadata suite passes 31 assertions with seven calls, raw-addon coverage checks 48 invocations including 46 intentional rejections, and an independent 4,097-prefix cancellation case uses eight actual calls.
  • LP64, LP64 with suffixed strided APIs, explicit 64-bit CBLAS_INT, and 64-bit with suffix each compile with warnings as errors and pass 2,117 ASan/UBSan checks. A harmless mock-kernel probe compiled with 53-bit long double rejects the 64-bit post-increment overflow boundary before dispatch. CBLAS_API64 controls suffixes separately from integer width.
  • Applicable real scoped JavaScript/C/Markdown/TypeScript/package/REPL/filename/header/license checks and both upstream EditorConfig checks pass. C lint explicitly includes this package's local header directory; metadata CLIs receive actual stdin filenames. TypeScript 4.9.5 verifies 11 expected-error lines and one return type without unexpected diagnostics. Existing line-length/single-property warnings remain warnings.
  • JavaScript and compiled C examples execute; twelve bounded JavaScript/native and four C benchmark runs complete. No performance improvement is claimed. With the binary physically absent, fresh public loading selects the exact original JS export, the original suite passes 25 assertions and the optional-native file safely loads; three unavailable-native groups skip only during that absence check. Other platforms were not executed.
  • The package-only patch applies independently to pristine current develop and exactly reproduces all 26 frozen source hashes. The original JS main, original tests/benchmark/example, REPL text and TypeScript files remain byte-for-byte unchanged.

Questions

No.

Other

This adds the requested native capability using the existing improved Kahan–Babuška/Neumaier implementation, without claiming a new numerical algorithm. The C caller supplies valid physical buffers and descriptors; unsupported metadata or configured-width arithmetic returns without output writes. JavaScript fallback preserves its existing accepted behavior.

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 under benatsf's explicit authorization to contribute. Codex generated the C ndarray adapter, normalized Node-API bridge, package-local dispatch guards, build metadata, exact-prefix fixtures, regression tests and native benchmark, and executed the recorded checks. A delegated Codex agent wrote the C documentation/example/benchmark; a separate agent independently reviewed the source, generated exact numerical fixtures and exercised the actual addon and configured-width C APIs. Codex reviewed and applied the contributing guidelines; the checked statement refers to that agent work and does not claim personal applicant review.


@stdlib-js/reviewers

Add the ndarray adapter and optional native bridge while preserving the adopted compensated prefix semantics and JavaScript fallback. Cover exact cancellation prefixes, aliases, scalar read order and configured integer widths.

Assisted-by: OpenAI Codex
@benatsf
benatsf requested a review from a team October 2, 2026 16:30
@stdlib-bot stdlib-bot added BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). First-time Contributor A pull request from a contributor who has never previously committed to the project repository. Needs Review A pull request which needs code review. labels Oct 2, 2026
@MeKaustubh07 MeKaustubh07 changed the title feat: add C implementation for blas/ext/base/ndarray/dcusumkbn feat: add C implementation for blas/ext/base/ndarray/dcusumkbn 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

BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). First-time Contributor A pull request from a contributor who has never previously committed to the project repository. Needs Review A pull request which needs code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants