Skip to content

feat: add C implementation for blas/ext/base/ndarray/dwhere - #15807

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

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

Conversation

@benatsf

@benatsf benatsf commented Oct 2, 2026

Copy link
Copy Markdown

Refs #14819.

Description

blas/ext/base/ndarray/dwhere currently provides a JavaScript ndarray interface but no native C interface. This PR adds the complete native conditional-selection kernel, Node-API addon, optional native dispatch, and C examples/benchmark/documentation under the accepted native implementation initiative.

The native kernel reads condition storage as bytes so every nonzero BooleanArray byte selects the first input, preserving ArrayBuffer-backed BooleanArray behavior. Each of the four views retains its own stride and offset, including overlapping input/output storage. Package-local guards keep previously accepted non-native buffers and scalar/error cases on the unchanged JavaScript path; fresh view metadata avoids invoking custom hooks or reusing stale serialized metadata. Common ndarray/N-API helpers are unchanged, and browser consumers continue using JavaScript.

Package scaffolding follows the existing blas/ext/base/ndarray/dxpy conventions. The bytewise conditional loop preserves BooleanArray truthiness rather than assuming arbitrary ArrayBuffer bytes are canonical C boolean representations.

Related Issues

Validation

  • Validated on Linux x86_64 with GCC 14.2.0; other platforms were not tested. Built and loaded the actual addon with Node 24.19.0/node-gyp 9.4.1; public export selects native. A separate Node process with the binary absent selected the JavaScript fallback.
  • Direct Node test processes: 1,353 assertions passed, zero skipped, all actual exit codes 0. The parity suite includes 625 independently strided typed fixtures with recorded compiled-addon calls, BooleanArray/float64 byte views, special values, alias behavior, accepted non-native fallback and scalar/empty errors.
  • JavaScript and compiled C examples passed; C benchmark 18/18 completed. No performance improvement is claimed.
  • Applicable upstream JavaScript/C/Markdown/package/license and both EditorConfig checks passed. Original-test spelling/line-length warnings remain; no lint errors.

Questions

No.

Other

Original lib/main.js is byte-for-byte unchanged. The standalone package patch and retained source hashes/output are available in the contribution campaign evidence. This PR adds one package's native interface and does not close the general tracking RFC.

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 implementation, tests, benchmarks and documentation, investigated compatibility behavior, and ran the recorded validation. A second Codex agent independently reviewed and exercised the native implementation. The contributing-guidelines acknowledgment records Codex's review and application of the guidelines under benatsf's explicit authorization to contribute. It does not claim that benatsf personally read the guide or manually reviewed the code. No manual applicant review is claimed.


@stdlib-js/reviewers

Add bytewise conditional selection, the Node-API bridge and native dispatch while preserving BooleanArray semantics, independent ndarray views, sequential aliases and legacy JavaScript fallback behavior. Add meaningful native parity, regression coverage and complete C package assets.

Assisted-by: OpenAI Codex
@benatsf
benatsf requested a review from a team October 2, 2026 11:40
@stdlib-bot stdlib-bot added BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). 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

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