Skip to content

Commit 7559ce0

Browse files
committed
refactor: add explicit rank tests for initial value 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 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 ---
1 parent 9929838 commit 7559ce0

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

lib/node_modules/@stdlib/blas/ext/cusum/lib/assign.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' );
3030
var getDType = require( '@stdlib/ndarray/dtype' );
3131
var getShape = require( '@stdlib/ndarray/shape' );
3232
var getOrder = require( '@stdlib/ndarray/order' );
33+
var ndims = require( '@stdlib/ndarray/base/ndims' );
3334
var format = require( '@stdlib/string/format' );
3435
var base = require( './base.js' ).assign;
3536

@@ -112,6 +113,9 @@ function assign( x ) {
112113
// Case: assign( x, initial_ndarray, out )
113114
if ( isndarrayLike( v ) ) {
114115
// As the operation is performed across all dimensions, `v` is assumed to be a zero-dimensional ndarray...
116+
if ( ndims( v ) !== 0 ) {
117+
throw new TypeError( format( 'invalid argument. Second argument must be a zero-dimensional ndarray.' ) );
118+
}
115119
return base( x, v, out );
116120
}
117121
// When computing the sum, initial values must be numeric...
@@ -134,9 +138,11 @@ function assign( x ) {
134138
}
135139
// Case: assign( x, initial_ndarray, out, opts )
136140
if ( isndarrayLike( v ) ) {
137-
// When not provided `dims`, the operation is performed across all dimensions and `v` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions...
141+
// When not provided `dims`, the operation is performed across all dimensions and `v` must be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions...
138142
if ( hasOwnProp( opts, 'dims' ) ) {
139143
v = maybeBroadcastArray( v, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len
144+
} else if ( ndims( v ) !== 0 ) {
145+
throw new TypeError( format( 'invalid argument. Second argument must be a zero-dimensional ndarray.' ) );
140146
}
141147
}
142148
// Case: assign( x, initial_scalar, out, opts )

lib/node_modules/@stdlib/blas/ext/cusum/lib/main.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var nonCoreShape = require( '@stdlib/ndarray/base/complement-shape' );
3030
var getDType = require( '@stdlib/ndarray/dtype' );
3131
var getShape = require( '@stdlib/ndarray/shape' );
3232
var getOrder = require( '@stdlib/ndarray/order' );
33+
var ndims = require( '@stdlib/ndarray/base/ndims' );
3334
var format = require( '@stdlib/string/format' );
3435
var base = require( './base.js' );
3536

@@ -99,7 +100,10 @@ function cusum( x ) {
99100
if ( nargs === 2 ) {
100101
// Case: cusum( x, initial_ndarray )
101102
if ( isndarrayLike( v ) ) {
102-
// As the operation is performed across all dimensions, `v` is assumed to be a zero-dimensional ndarray...
103+
// As the operation is performed across all dimensions, `v` must be a zero-dimensional ndarray...
104+
if ( ndims( v ) !== 0 ) {
105+
throw new TypeError( format( 'invalid argument. Second argument must be a zero-dimensional ndarray.' ) );
106+
}
103107
return base( x, v );
104108
}
105109
// Case: cusum( x, initial_scalar )
@@ -118,9 +122,11 @@ function cusum( x ) {
118122
}
119123
// Case: cusum( x, initial_ndarray, opts )
120124
if ( isndarrayLike( v ) ) {
121-
// When not provided `dims`, the operation is performed across all dimensions and `v` is assumed to be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions...
125+
// When not provided `dims`, the operation is performed across all dimensions and `v` must be a zero-dimensional ndarray; when `dims` is provided, we need to broadcast `v` to match the shape of the non-core dimensions...
122126
if ( hasOwnProp( opts, 'dims' ) ) {
123127
v = maybeBroadcastArray( v, nonCoreShape( getShape( x ), opts.dims ) ); // eslint-disable-line max-len
128+
} else if ( ndims( v ) !== 0 ) {
129+
throw new TypeError( format( 'invalid argument. Second argument must be a zero-dimensional ndarray.' ) );
124130
}
125131
}
126132
// Case: cusum( x, initial_scalar, opts )

0 commit comments

Comments
 (0)