From c363074e276df59edb2c57cb3dca4bcd63eae5db Mon Sep 17 00:00:00 2001 From: manit2004 Date: Tue, 29 Sep 2026 21:53:22 +0530 Subject: [PATCH] fix: validate broadcast-compatibility of ndarray sort/shift argument --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js | 6 +++--- lib/node_modules/@stdlib/blas/ext/sort/lib/main.js | 6 ++++-- lib/node_modules/@stdlib/blas/ext/sorthp/lib/main.js | 6 ++++-- 3 files changed, 11 insertions(+), 7 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..dffddc966b72 100644 --- a/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/circshift/lib/main.js @@ -85,8 +85,8 @@ 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 ); + // As the operation is performed across all dimensions, `k` is assumed to be a zero-dimensional ndarray, so ensure that `k` is broadcast-compatible with a zero-dimensional shape... + 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 +108,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 ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/sort/lib/main.js b/lib/node_modules/@stdlib/blas/ext/sort/lib/main.js index e63d1b1a31d7..c273441391cf 100644 --- a/lib/node_modules/@stdlib/blas/ext/sort/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/sort/lib/main.js @@ -176,8 +176,8 @@ function sort( x ) { } // Case: sort( x, sortOrder_ndarray ) if ( isndarrayLike( o ) ) { - // As the operation is performed across all dimensions, `o` is assumed to be a zero-dimensional ndarray... - return base( x, o ); + // As the operation is performed across all dimensions, `o` is assumed to be a zero-dimensional ndarray, so ensure that `o` is broadcast-compatible with a zero-dimensional shape... + return base( x, maybeBroadcastArray( o, [] ) ); } // Case: sort( x, opts ) opts = o; @@ -204,6 +204,8 @@ function sort( x ) { // When not provided `dims`, the operation is performed across all dimensions and `o` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `o` to match the shape of the non-core dimensions... if ( hasOwnProp( opts, 'dims' ) ) { o = maybeBroadcastArray( o, nonCoreShape( getShape( x ), opts.dims ) ); + } else { + o = maybeBroadcastArray( o, [] ); } } else { throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray, a numeric scalar value, or a supported string. Value: `%s`.', o ) ); diff --git a/lib/node_modules/@stdlib/blas/ext/sorthp/lib/main.js b/lib/node_modules/@stdlib/blas/ext/sorthp/lib/main.js index fb9353958dc3..128b27abcb54 100644 --- a/lib/node_modules/@stdlib/blas/ext/sorthp/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/sorthp/lib/main.js @@ -176,8 +176,8 @@ function sorthp( x ) { } // Case: sorthp( x, sortOrder_ndarray ) if ( isndarrayLike( o ) ) { - // As the operation is performed across all dimensions, `o` is assumed to be a zero-dimensional ndarray... - return base( x, o ); + // As the operation is performed across all dimensions, `o` is assumed to be a zero-dimensional ndarray, so ensure that `o` is broadcast-compatible with a zero-dimensional shape... + return base( x, maybeBroadcastArray( o, [] ) ); } // Case: sorthp( x, opts ) opts = o; @@ -204,6 +204,8 @@ function sorthp( x ) { // When not provided `dims`, the operation is performed across all dimensions and `o` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `o` to match the shape of the non-core dimensions... if ( hasOwnProp( opts, 'dims' ) ) { o = maybeBroadcastArray( o, nonCoreShape( getShape( x ), opts.dims ) ); + } else { + o = maybeBroadcastArray( o, [] ); } } else { throw new TypeError( format( 'invalid argument. Second argument must be either an ndarray, a numeric scalar value, or a supported string. Value: `%s`.', o ) );