You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: base/binary-reduce-strided1d/README.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -128,7 +128,11 @@ Each provided ndarray should be an object with the following properties:
128
128
129
129
## Notes
130
130
131
-
- The output ndarray and any additional ndarray arguments are expected to have the same dimensions as the non-reduced dimensions of the input ndarrays. When calling the reduction function, any additional ndarray arguments are provided as zero-dimensional ndarray-like objects.
131
+
- The output ndarray is expected to have the same dimensions as the non-reduced dimensions of the input ndarrays.
132
+
133
+
- Any additional ndarray arguments are expected to have the same leading dimensions as the non-reduced dimensions of the input ndarrays.
134
+
135
+
- When calling the reduction function, any additional ndarray arguments are provided as k-dimensional subarrays, where `k = M - N` with `M` being the number of dimensions in an ndarray argument and `N` being the number of non-reduced dimensions in the input ndarrays. For example, if an input ndarrays have three dimensions, the number of reduced dimensions is two, and an additional ndarray argument has one dimension, thus matching the number of non-reduced dimensions in the input ndarrays, the reduction function is provided a zero-dimensional subarray as an additional ndarray argument. In the same scenario but where an additional ndarray argument has two dimensions, thus exceeding the number of non-reduced dimensions in the input ndarrays, the reduction function is provided a one-dimensional subarray as an additional ndarray argument.
132
136
133
137
- The reduction function is expected to have the following signature:
134
138
@@ -138,7 +142,7 @@ Each provided ndarray should be an object with the following properties:
138
142
139
143
where
140
144
141
-
- **arrays**: array containing a one-dimensional subarray for each input ndarray and any additional ndarray arguments as zero-dimensional ndarrays.
145
+
- **arrays**: array containing a one-dimensional subarray for each input ndarray and any additional ndarray arguments as subarrays.
142
146
- **options**: function options (_optional_).
143
147
144
148
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before performing a reduction in order to achieve better performance.
thrownewError(format('invalid argument. Input arrays must have the same shape. First array shape: [%s]. Second array shape: [%s].',join(shx,','),join(shy,',')));
419
419
}
420
420
}
421
-
422
421
// Verify that we've been provided a list of unique dimension indices...
thrownewRangeError(format('invalid argument. Number of specified dimensions cannot exceed the number of dimensions in the input array. Number of dimensions: %d. Value: [%s].',ndims,join(dims,',')));
435
434
}
436
-
// Verify that provided ndarrays have the expected number of dimensions...
435
+
// Compute the number of non-reduced dimensions:
437
436
K=ndims-M;
437
+
438
+
// Verify that the output ndarray has the expected number of dimensions...
438
439
if(z.shape.length!==K){
439
-
thrownewError(format('invalid argument. Output array must have the same number of non-reduced dimensions as input arrays. Input array shape: [%s]. Number of non-reduced dimensions: %d. Output array shape: [%s].',join(shx,','),K,join(z.shape,',')));
440
+
thrownewError(format('invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).',join(shx,','),K,join(z.shape,','),2));
441
+
}
442
+
// Verify that any ancillary ndarrays have at least the number of non-reduced dimensions...
443
+
for(i=3;i<N;i++){
444
+
if(arr[i].shape.length<K){
445
+
thrownewError(format('invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).',join(shx,','),K,join(arr[i].shape,','),i));
446
+
}
440
447
}
441
-
442
448
// Resolve the non-reduced ("loop") dimensions and associated strides:
// Determine whether the loop dimensions have only **one** non-singleton dimension (e.g., shape=[10,1,1,1]) so that we can treat loop iteration as being equivalent to one-dimensional iteration...
521
525
if(ns===K-1){
522
526
// Get the index of the non-singleton dimension...
// Verify that the output ndarray has the expected number of dimensions...
423
-
if(arr[1].shape.length!==K){
424
-
thrownewError(format('invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).',join(shx,','),K,join(arr[1].shape,','),1));
423
+
if(y.shape.length!==K){
424
+
thrownewError(format('invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).',join(shx,','),K,join(y.shape,','),1));
425
425
}
426
426
// Verify that any ancillary ndarrays have at least the number of non-reduced dimensions...
// Verify that the output ndarray has the expected number of dimensions...
398
-
if(arr[1].shape.length!==K){
399
-
thrownewError(format('invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).',join(shx,','),K,join(arr[1].shape,','),1));
398
+
if(y.shape.length!==K){
399
+
thrownewError(format('invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).',join(shx,','),K,join(y.shape,','),1));
400
400
}
401
401
// Verify that any ancillary ndarrays have at least the number of non-reduced dimensions...
// Verify that the output ndarray has the expected number of dimensions...
381
-
if(arr[1].shape.length!==K){
382
-
thrownewError(format('invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).',join(shx,','),K,join(arr[1].shape,','),1));
381
+
if(y.shape.length!==K){
382
+
thrownewError(format('invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).',join(shx,','),K,join(y.shape,','),1));
383
383
}
384
384
// Verify that any ancillary ndarrays have at least the number of non-reduced dimensions...
// Verify that the output ndarray has the expected number of dimensions...
399
-
if(arr[1].shape.length!==K){
400
-
thrownewError(format('invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).',join(shx,','),K,join(arr[1].shape,','),1));
399
+
if(y.shape.length!==K){
400
+
thrownewError(format('invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).',join(shx,','),K,join(y.shape,','),1));
401
401
}
402
402
// Verify that any ancillary ndarrays have at least the number of non-reduced dimensions...
// Verify that the output ndarray has the expected number of dimensions...
355
-
if(arr[1].shape.length!==K){
356
-
thrownewError(format('invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).',join(shx,','),K,join(arr[1].shape,','),1));
355
+
if(y.shape.length!==K){
356
+
thrownewError(format('invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).',join(shx,','),K,join(y.shape,','),1));
357
357
}
358
358
// Verify that any ancillary ndarrays have at least the number of non-reduced dimensions...
0 commit comments