From ebdb0e834a5c36eb439d7568f18c1f9ba647f8ab Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 16 Aug 2026 14:22:41 +0000 Subject: [PATCH] fix(@stdlib/blas/ext/circshift): validate `k` shape when `dims` is omitted The job `Node.js v16` on workflow `macos_test` failed on develop with 6 tape assertion failures under "throws an error if provided a `k` argument which is not broadcast-compatible": `circshift( x, k )` and `circshift( x, k, {} )` did not throw for `k` shapes `[4]`, `[2,2,2]`, and `[0]` against a `[2,2]` input, contrary to the documented contract. Root cause: in `lib/main.js`, the no-`dims` branches for an ndarray-valued `k` (`k_ndarray` in both the 2-argument and options- argument call forms) passed `k` straight through to `base()` without validating that its shape is broadcast-compatible with the implied zero-dimensional target shape, unlike the `dims`-provided branch, which already validates via `maybeBroadcastArray`. This commit applies the same `maybeBroadcastArray( k, [] )` validation to both no-`dims` branches, matching the idiom already used elsewhere in the codebase (e.g. `@stdlib/blas/ext/copy-within/lib/broadcast_index.js`) and restoring the documented `@throws` contract without changing behavior for already-valid inputs (a 0-dimensional `k` continues to pass through `maybeBroadcastArray` unchanged). Ref: https://github.com/stdlib-js/stdlib/actions/runs/31938255523 --- lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js index c83f975c12c5..d9e7de2d64ac 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js @@ -53,6 +53,7 @@ var DEFAULT_DTYPE = defaults.get( 'dtypes.integer' ); * @throws {RangeError} dimension indices must not exceed input ndarray bounds * @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions * @throws {Error} must provide valid options +* @throws {Error} second argument must be broadcast-compatible with the non-core dimensions of the first argument * @returns {ndarray} input ndarray * * @example @@ -86,7 +87,7 @@ function circshift( x, k ) { // Case: circshift( x, k_ndarray ) if ( isndarrayLike( k ) ) { // As the operation is performed across all dimensions, `k` is assumed to be a zero-dimensional ndarray... - return base( x, k ); + return base( x, maybeBroadcastArray( k, [] ) ); } throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', k ) ); } @@ -108,7 +109,7 @@ function circshift( x, k ) { if ( hasOwnProp( opts, 'dims' ) ) { ka = maybeBroadcastArray( k, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len } else { - ka = k; + ka = maybeBroadcastArray( k, [] ); } } else { throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray or an integer. Value: `%s`.', k ) );