fix(@stdlib/blas/ext): validate broadcast compatibility of ndarray second args - #14228
Open
Planeshifter wants to merge 1 commit into
Open
fix(@stdlib/blas/ext): validate broadcast compatibility of ndarray second args#14228Planeshifter wants to merge 1 commit into
Planeshifter wants to merge 1 commit into
Conversation
…cond args The nightly full-matrix `macos_test` job on develop failed with `not ok` assertions in `blas/ext/circshift`, `blas/ext/sort`, and `blas/ext/sorthp` test suites, in blocks named "the function throws an error if provided a `k`/`sortOrder` argument which is not broadcast-compatible" (and their `(options)` variants). Each package expected a thrown error for a non-scalar-shaped ndarray second argument, but none was thrown. Root cause: in all three packages' `lib/main.js`, when the second argument is supplied as an ndarray and either no options object or an options object without a `dims` property is given, the code passed the ndarray straight through to the base implementation without checking that it is broadcast-compatible with the (empty) core shape implied by "operating across all dimensions". The sibling `dims`- provided branch in each file already performed this check correctly via `maybeBroadcastArray()`. This commit routes the no-`dims` code paths in `circshift`, `sort`, and `sorthp` through `maybeBroadcastArray( arg, [] )`, matching each file's already-correct `dims` branch, so a non-broadcast-compatible second argument throws as documented. Ref: https://github.com/stdlib-js/stdlib/actions/runs/31686732576
Contributor
Coverage Report
The above coverage report was generated for the changes in this PR. |
kgryte
self-requested a review
August 14, 2026 00:10
kgryte
marked this pull request as ready for review
August 14, 2026 00:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #{{TODO: add issue number}}.
Description
This pull request:
blas/ext/circshift,blas/ext/sort, andblas/ext/sorthpto throw when thek/sortOrderndarray argument is not broadcast-compatible with the target shape, restoring the missing check on the no-dimscode path.Related Issues
This pull request has the following related issues:
Questions
No.
Other
Failing run: https://github.com/stdlib-js/stdlib/actions/runs/31686732576 (nightly
macos_test, Node.js 16,develop).Symptom: 6 assertion failures across
blas/ext/circshift,blas/ext/sort,blas/ext/sorthp— the "throws an error if provided ak/sortOrderargument which is not broadcast-compatible" tests (plus(options)variants). Non-scalar-shaped ndarrays ([4],[2,2,2],[0]) passed as the second argument did not trigger a throw.Root cause: in each
lib/main.js, when the second argument is an ndarray and either no options object or an options object withoutdimsis supplied, the value was passed straight tobase()with no broadcast check. Theopts.dimsbranch already calledmaybeBroadcastArray()correctly. With nodims, the operation spans all dimensions, so the implicit target shape is[]— this case had no check.Fix: route the no-
dimspaths throughmaybeBroadcastArray( arg, [] ), matching each file's existingdimsbranch.circshift/lib/main.js: 2 insertions / 2 deletions (both call sites already existed; swapped pass-through for the broadcast check).sort/lib/main.js: 3 insertions / 1 deletion (2-argument form swapped; the 3-argument opts-without-dimsform had noelsebranch, one was added).sorthp/lib/main.js: 3 insertions / 1 deletion (same assort).No new imports —
maybeBroadcastArraywas already imported and used in each file'sdimsbranch.Scope note:
sort/sorthpwere not in the original failure report. An independent reviewer found during review that they share the same code pattern and were failing in the same nightly job on the same commit, so the fix was expanded here rather than filed as a second PR for the same defect.Downstream effect (found during review): the fix also silently repairs 12 previously-failing assertions in
@stdlib/blas/ext/to-sortedand@stdlib/blas/ext/to-sortedhp, which delegate tosort/sorthpand had matching broadcast-compatibility test blocks failing for the same reason. Not part of the original CI report — incidental repair, not new scope.Validation:
examples/index.jsfor all three changed packages runs cleanly (exit 0).to-sorted/to-sortedhp, both net-improved), and style/conventions (spacing, idiom, commit message format, copyright headers checked against each file's owndimsbranch). All three approved in round 2, no blocking findings.Reviewer notes (non-blocking):
ErrorfrommaybeBroadcastArray("Cannot broadcast an array to a shape having fewer dimensions..."). The structurally similarblas/ext/cusumandblas/ext/jointhrow a more specificTypeError("...must be a zero-dimensional ndarray") for the equivalent condition. Both satisfy the existing tests (t.throws(fn, Error)) and the chosen approach matches each file's owndimsbranch, but the error message is not uniform acrossblas/extfor this condition.@throwsblocks document a broadcast-incompatibility error. Predates this commit (thedimsbranch has the same gap); left out of scope for a CI-failure fix.Checklist
AI Assistance
If you answered "yes" above, how did you use AI assistance?
Disclosure
This PR was authored by Claude Code (Anthropic) as part of an automated CI-failure investigation and fix routine; all changes were validated against the failing test suite and independently reviewed by three automated reviewer passes before submission.
@stdlib-js/reviewers
Generated by Claude Code