Skip to content

Commit efc15ae

Browse files
committed
Auto-generated commit
1 parent ec4bc34 commit efc15ae

25 files changed

+2968
-2
lines changed

CHANGELOG.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2025-03-25)
7+
## Unreleased (2025-03-27)
88

99
<section class="packages">
1010

@@ -829,6 +829,28 @@ This release closes the following issue:
829829

830830
<!-- /.package -->
831831

832+
<section class="package" id="ndarray-base-unary-reduce-subarray-unreleased">
833+
834+
#### [@stdlib/ndarray/base/unary-reduce-subarray](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/unary-reduce-subarray)
835+
836+
<details>
837+
838+
<section class="features">
839+
840+
##### Features
841+
842+
- [`935f698`](https://github.com/stdlib-js/stdlib/commit/935f698bd565928d3fc862dfdff14ab0e56aa478) - add initial implementation for `ndarray/base/unary-reduce-subarray`
843+
844+
</section>
845+
846+
<!-- /.features -->
847+
848+
</details>
849+
850+
</section>
851+
852+
<!-- /.package -->
853+
832854
<section class="package" id="ndarray-ctor-unreleased">
833855

834856
#### [@stdlib/ndarray/ctor](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor)
@@ -1217,6 +1239,12 @@ A total of 7 people contributed to this release. Thank you to the following cont
12171239

12181240
<details>
12191241

1242+
- [`9cb2473`](https://github.com/stdlib-js/stdlib/commit/9cb247321b8b2285713404fc4e43d43630163097) - **chore:** update directory list _(by Athan Reines)_
1243+
- [`0fc4015`](https://github.com/stdlib-js/stdlib/commit/0fc401573e94e99adbd3c31d7067c28ee2d270a1) - **docs:** add README and repl help _(by Athan Reines)_
1244+
- [`a331234`](https://github.com/stdlib-js/stdlib/commit/a33123481db5e24d5f0550b837b81bd0574d748e) - **test:** add initial test file _(by Athan Reines)_
1245+
- [`6d21670`](https://github.com/stdlib-js/stdlib/commit/6d21670d117320f7bc77b2b3ad4ce2fc51dbdd75) - **chore:** update directory list _(by Athan Reines)_
1246+
- [`935f698`](https://github.com/stdlib-js/stdlib/commit/935f698bd565928d3fc862dfdff14ab0e56aa478) - **feat:** add initial implementation for `ndarray/base/unary-reduce-subarray` _(by Athan Reines)_
1247+
- [`ad7c705`](https://github.com/stdlib-js/stdlib/commit/ad7c7056b95d52aac386e81209fbcd7fe8eac81f) - **refactor:** format error message _(by Athan Reines)_
12201248
- [`70bee88`](https://github.com/stdlib-js/stdlib/commit/70bee887bd024ca10b1676742e0f3b3051fa7b00) - **docs:** update namespace TypeScript declarations [(#6357)](https://github.com/stdlib-js/stdlib/pull/6357) _(by stdlib-bot)_
12211249
- [`442efb4`](https://github.com/stdlib-js/stdlib/commit/442efb4980c95c38eb1333c1d7a38b5e2ab4d2ec) - **chore:** resolve lint errors _(by Athan Reines)_
12221250
- [`3419f20`](https://github.com/stdlib-js/stdlib/commit/3419f20af1c819b14ab5ccf7b17379fa8f977399) - **chore:** resolve lint errors _(by Athan Reines)_
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# unaryReduceSubarray
22+
23+
> Perform a reduction over a list of specified dimensions in an input ndarray and assign results to a provided output ndarray.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var unaryReduceSubarray = require( '@stdlib/ndarray/base/unary-reduce-subarray' );
37+
```
38+
39+
#### unaryReduceSubarray( fcn, arrays, dims\[, options] )
40+
41+
Performs a reduction over a list of specified dimensions in an input ndarray and assigns results to a provided output ndarray.
42+
43+
<!-- eslint-disable max-len -->
44+
45+
```javascript
46+
var Float64Array = require( '@stdlib/array/float64' );
47+
var filled = require( '@stdlib/array/base/filled' );
48+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
49+
var every = require( '@stdlib/ndarray/base/every' );
50+
51+
// Create data buffers:
52+
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 ] );
53+
var ybuf = filled( false, 3 );
54+
55+
// Define the array shapes:
56+
var xsh = [ 1, 3, 2, 2 ];
57+
var ysh = [ 1, 3 ];
58+
59+
// Define the array strides:
60+
var sx = [ 12, 4, 2, 1 ];
61+
var sy = [ 3, 1 ];
62+
63+
// Define the index offsets:
64+
var ox = 0;
65+
var oy = 0;
66+
67+
// Create an input ndarray-like object:
68+
var x = {
69+
'dtype': 'float64',
70+
'data': xbuf,
71+
'shape': xsh,
72+
'strides': sx,
73+
'offset': ox,
74+
'order': 'row-major'
75+
};
76+
77+
// Create an output ndarray-like object:
78+
var y = {
79+
'dtype': 'generic',
80+
'data': ybuf,
81+
'shape': ysh,
82+
'strides': sy,
83+
'offset': oy,
84+
'order': 'row-major'
85+
};
86+
87+
// Perform a reduction:
88+
unaryReduceSubarray( every, [ x, y ], [ 2, 3 ] );
89+
90+
var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order );
91+
// returns [ [ true, false, true ] ]
92+
```
93+
94+
The function accepts the following arguments:
95+
96+
- **fcn**: function which will be applied to a subarray and should reduce the subarray to a single scalar value.
97+
- **arrays**: array-like object containing one input ndarray and one output ndarray, followed by any additional ndarray arguments.
98+
- **dims**: list of dimensions over which to perform a reduction.
99+
- **options**: function options which are passed through to `fcn` (_optional_).
100+
101+
Each provided ndarray should be an object with the following properties:
102+
103+
- **dtype**: data type.
104+
- **data**: data buffer.
105+
- **shape**: dimensions.
106+
- **strides**: stride lengths.
107+
- **offset**: index offset.
108+
- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
109+
110+
</section>
111+
112+
<!-- /.usage -->
113+
114+
<section class="notes">
115+
116+
## Notes
117+
118+
- The output ndarray and any additional ndarray arguments are expected to have the same dimensions as the non-reduced dimensions of the input ndarray. When calling the reduction function, any additional ndarray arguments are provided as zero-dimensional ndarray-like objects.
119+
120+
- The reduction function is expected to have the following signature:
121+
122+
```text
123+
fcn( arrays[, options] )
124+
```
125+
126+
where
127+
128+
- **arrays**: array containing a subarray from the input ndarray and any additional ndarray arguments as zero-dimensional ndarrays.
129+
- **options**: function options (_optional_).
130+
131+
- 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.
132+
133+
</section>
134+
135+
<!-- /.notes -->
136+
137+
<section class="examples">
138+
139+
## Examples
140+
141+
<!-- eslint no-undef: "error" -->
142+
143+
```javascript
144+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
145+
var filled = require( '@stdlib/array/base/filled' );
146+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
147+
var every = require( '@stdlib/ndarray/base/every' );
148+
var unaryReduceSubarray = require( '@stdlib/ndarray/base/unary-reduce-subarray' );
149+
150+
var N = 10;
151+
var x = {
152+
'dtype': 'generic',
153+
'data': discreteUniform( N, -5, 5, {
154+
'dtype': 'generic'
155+
}),
156+
'shape': [ 1, 5, 2 ],
157+
'strides': [ 10, 2, 1 ],
158+
'offset': 0,
159+
'order': 'row-major'
160+
};
161+
var y = {
162+
'dtype': 'generic',
163+
'data': filled( false, 2 ),
164+
'shape': [ 1, 2 ],
165+
'strides': [ 2, 1 ],
166+
'offset': 0,
167+
'order': 'row-major'
168+
};
169+
170+
unaryReduceSubarray( every, [ x, y ], [ 1 ] );
171+
172+
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
173+
console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) );
174+
```
175+
176+
</section>
177+
178+
<!-- /.examples -->
179+
180+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
181+
182+
<section class="related">
183+
184+
</section>
185+
186+
<!-- /.related -->
187+
188+
<section class="links">
189+
190+
</section>
191+
192+
<!-- /.links -->
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
{{alias}}( fcn, arrays, dims[, options] )
3+
Performs a reduction over a list of specified dimensions in an input ndarray
4+
and assigns results to a provided output ndarray.
5+
6+
Each provided "ndarray" should be an object with the following properties:
7+
8+
- dtype: data type.
9+
- data: data buffer.
10+
- shape: dimensions.
11+
- strides: stride lengths.
12+
- offset: index offset.
13+
- order: specifies whether an ndarray is row-major (C-style) or column-major
14+
(Fortran-style).
15+
16+
The output ndarray and any additional ndarray arguments are expected to have
17+
the same dimensions as the non-reduced dimensions of the input ndarray. When
18+
calling the reduction function, any additional ndarray arguments are
19+
provided as zero-dimensional ndarray-like objects.
20+
21+
Parameters
22+
----------
23+
fcn: Function
24+
Function which will be applied to a subarray and should reduce the
25+
subarray to a single scalar value. The function should have the
26+
following signature:
27+
28+
fcn( arrays[, options] )
29+
30+
where
31+
32+
- arrays: array containing subarray from the input ndarray and any
33+
additional ndarray arguments as zero-dimensional ndarrays.
34+
- options: function options.
35+
36+
arrays: ArrayLikeObject<ndarray>
37+
Array-like object containing one input ndarray and one output ndarray,
38+
followed by any additional ndarray arguments.
39+
40+
dims: Array<integer>
41+
List of dimensions over which to perform a reduction.
42+
43+
options: Object (optional)
44+
Function options.
45+
46+
Examples
47+
--------
48+
// Define ndarray data and meta data...
49+
> var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] );
50+
> var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0 ] );
51+
> var dtype = 'float64';
52+
> var shx = [ 2, 2 ];
53+
> var shy = [];
54+
> var sx = [ 2, 1 ];
55+
> var sy = [ 0 ];
56+
> var ox = 0;
57+
> var oy = 0;
58+
> var order = 'row-major';
59+
60+
// Define a trivial reduction function...
61+
> function fcn( arrays ) { return arrays[0].data[ arrays[0].offset ]; };
62+
63+
// Using minimal ndarray-like objects...
64+
> x = {
65+
... 'dtype': dtype,
66+
... 'data': xbuf,
67+
... 'shape': shx,
68+
... 'strides': sx,
69+
... 'offset': ox,
70+
... 'order': order
71+
... };
72+
> y = {
73+
... 'dtype': dtype,
74+
... 'data': ybuf,
75+
... 'shape': shy,
76+
... 'strides': sy,
77+
... 'offset': oy,
78+
... 'order': order
79+
... };
80+
> {{alias}}( fcn, [ x, y ], [ 0, 1 ] );
81+
> y.data
82+
<Float64Array>[ 1.0 ]
83+
84+
See Also
85+
--------
86+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
22+
var filled = require( '@stdlib/array/base/filled' );
23+
var ndarray2array = require( './../../../base/to-array' );
24+
var every = require( './../../../base/every' );
25+
var unaryReduceSubarray = require( './../lib' );
26+
27+
var N = 10;
28+
var x = {
29+
'dtype': 'generic',
30+
'data': discreteUniform( N, -5, 5, {
31+
'dtype': 'generic'
32+
}),
33+
'shape': [ 1, 5, 2 ],
34+
'strides': [ 10, 2, 1 ],
35+
'offset': 0,
36+
'order': 'row-major'
37+
};
38+
var y = {
39+
'dtype': 'generic',
40+
'data': filled( false, 2 ),
41+
'shape': [ 1, 2 ],
42+
'strides': [ 2, 1 ],
43+
'offset': 0,
44+
'order': 'row-major'
45+
};
46+
47+
unaryReduceSubarray( every, [ x, y ], [ 1 ] );
48+
49+
console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
50+
console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) );

0 commit comments

Comments
 (0)