Skip to content

Commit 7378f4d

Browse files
committed
fix: ensure support when providing no dimensions to reduce
--- 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent abbc923 commit 7378f4d

File tree

1 file changed

+49
-1
lines changed
  • lib/node_modules/@stdlib/ndarray/base/unary-reduce-subarray/lib

1 file changed

+49
-1
lines changed

lib/node_modules/@stdlib/ndarray/base/unary-reduce-subarray/lib/main.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,54 @@ var MAX_DIMS = UNARY.length - 1;
205205
*
206206
* var v = y.data;
207207
* // returns [ true ]
208+
*
209+
* @example
210+
* var Float64Array = require( '@stdlib/array/float64' );
211+
* var filled = require( '@stdlib/array/base/filled' );
212+
* var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
213+
* var every = require( '@stdlib/ndarray/base/every' );
214+
*
215+
* // Create data buffers:
216+
* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
217+
* var ybuf = filled( false, 12 );
218+
*
219+
* // Define the array shapes:
220+
* var xsh = [ 3, 2, 2 ];
221+
* var ysh = [ 3, 2, 2 ];
222+
*
223+
* // Define the array strides:
224+
* var sx = [ 4, 2, 1 ];
225+
* var sy = [ 4, 2, 1 ];
226+
*
227+
* // Define the index offsets:
228+
* var ox = 0;
229+
* var oy = 0;
230+
*
231+
* // Create an input ndarray-like object:
232+
* var x = {
233+
* 'dtype': 'float64',
234+
* 'data': xbuf,
235+
* 'shape': xsh,
236+
* 'strides': sx,
237+
* 'offset': ox,
238+
* 'order': 'row-major'
239+
* };
240+
*
241+
* // Create an output ndarray-like object:
242+
* var y = {
243+
* 'dtype': 'generic',
244+
* 'data': ybuf,
245+
* 'shape': ysh,
246+
* 'strides': sy,
247+
* 'offset': oy,
248+
* 'order': 'row-major'
249+
* };
250+
*
251+
* // Perform a reduction:
252+
* unaryReduceSubarray( every, [ x, y ], [] );
253+
*
254+
* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order );
255+
* // returns [ [ [ true, true ], [ true, true ] ], [ [ true, false ], [ true, true ] ], [ [ true, true ], [ true, true ] ] ]
208256
*/
209257
function unaryReduceSubarray( fcn, arrays, dims, options ) { // eslint-disable-line max-statements
210258
var views;
@@ -310,7 +358,7 @@ function unaryReduceSubarray( fcn, arrays, dims, options ) { // eslint-disable-l
310358
}
311359
}
312360
// Check whether we were provided empty ndarrays...
313-
if ( len === 0 || numel( shc ) === 0 ) {
361+
if ( len === 0 || ( shc.length && numel( shc ) === 0 ) ) {
314362
return;
315363
}
316364
// Initialize ndarray-like objects for representing sub-array views...

0 commit comments

Comments
 (0)