Skip to content

Commit 9d65cdd

Browse files
committed
Auto-generated commit
1 parent c909f8f commit 9d65cdd

File tree

20 files changed

+2098
-12
lines changed

20 files changed

+2098
-12
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
### Features
1212

13+
- [`9a30157`](https://github.com/stdlib-js/stdlib/commit/9a3015754f96452f5f205d91338bbc92def20249) - add `unaryReduceStrided1dDispatchByFactory` to namespace
14+
- [`50ebfa6`](https://github.com/stdlib-js/stdlib/commit/50ebfa6340bddbb7627195e27bdf7ece3a6f1198) - add `unaryReduceStrided1dDispatchBy` to namespace
15+
- [`64103e2`](https://github.com/stdlib-js/stdlib/commit/64103e22a2cf0fcad5914d53885d09e311fef6ee) - add `ndarray/base/unary-reduce-strided1d-dispatch-by-factory`
1316
- [`34ed9af`](https://github.com/stdlib-js/stdlib/commit/34ed9af63e302a5f4a759c7ef9b4f048b3ef89d4) - add `ndarray/base/unary-reduce-strided1d-dispatch-by`
1417
- [`2460ce8`](https://github.com/stdlib-js/stdlib/commit/2460ce82935de6512ee0979cc3b3918924af5ae1) - add `unaryReduceStrided1dBy` to namespace
1518
- [`b228b5e`](https://github.com/stdlib-js/stdlib/commit/b228b5e89da183b38160c6cd6f9908a07918dd09) - add `ndarray/base/unary-reduce-strided1d-by` [(#7214)](https://github.com/stdlib-js/stdlib/pull/7214)
@@ -437,6 +440,13 @@ A total of 17 issues were closed in this release:
437440

438441
<details>
439442

443+
- [`71f1df4`](https://github.com/stdlib-js/stdlib/commit/71f1df4e7a7c70aa99e3ea52aaabaafa6d033878) - **docs:** update examples _(by Athan Reines)_
444+
- [`9b376ef`](https://github.com/stdlib-js/stdlib/commit/9b376effa2bcc564e59814df6bb609b40370c303) - **docs:** update examples _(by Athan Reines)_
445+
- [`da7f3a3`](https://github.com/stdlib-js/stdlib/commit/da7f3a3223a6f8cef6847d05ddc059825d93dbbd) - **docs:** fix require path _(by Athan Reines)_
446+
- [`9a30157`](https://github.com/stdlib-js/stdlib/commit/9a3015754f96452f5f205d91338bbc92def20249) - **feat:** add `unaryReduceStrided1dDispatchByFactory` to namespace _(by Athan Reines)_
447+
- [`50ebfa6`](https://github.com/stdlib-js/stdlib/commit/50ebfa6340bddbb7627195e27bdf7ece3a6f1198) - **feat:** add `unaryReduceStrided1dDispatchBy` to namespace _(by Athan Reines)_
448+
- [`64103e2`](https://github.com/stdlib-js/stdlib/commit/64103e22a2cf0fcad5914d53885d09e311fef6ee) - **feat:** add `ndarray/base/unary-reduce-strided1d-dispatch-by-factory` _(by Athan Reines)_
449+
- [`5b938ee`](https://github.com/stdlib-js/stdlib/commit/5b938eee513bfe9b1859cb2875aaed8d787daf74) - **docs:** update description _(by Athan Reines)_
440450
- [`34ed9af`](https://github.com/stdlib-js/stdlib/commit/34ed9af63e302a5f4a759c7ef9b4f048b3ef89d4) - **feat:** add `ndarray/base/unary-reduce-strided1d-dispatch-by` _(by Athan Reines)_
441451
- [`970b3be`](https://github.com/stdlib-js/stdlib/commit/970b3be65917ec995e5d8c0e06fbebd5870a4687) - **docs:** fix description _(by Athan Reines)_
442452
- [`c86cb96`](https://github.com/stdlib-js/stdlib/commit/c86cb96872dce4d7b508daf43886e10c0fedad8f) - **fix:** update require path _(by Athan Reines)_

base/lib/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,24 @@ setReadOnly( ns, 'unaryReduceStrided1dBy', require( './../../base/unary-reduce-s
10841084
*/
10851085
setReadOnly( ns, 'unaryReduceStrided1dDispatch', require( './../../base/unary-reduce-strided1d-dispatch' ) );
10861086

1087+
/**
1088+
* @name unaryReduceStrided1dDispatchBy
1089+
* @memberof ns
1090+
* @readonly
1091+
* @type {Function}
1092+
* @see {@link module:@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-by}
1093+
*/
1094+
setReadOnly( ns, 'unaryReduceStrided1dDispatchBy', require( './../../base/unary-reduce-strided1d-dispatch-by' ) );
1095+
1096+
/**
1097+
* @name unaryReduceStrided1dDispatchByFactory
1098+
* @memberof ns
1099+
* @readonly
1100+
* @type {Function}
1101+
* @see {@link module:@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-by-factory}
1102+
*/
1103+
setReadOnly( ns, 'unaryReduceStrided1dDispatchByFactory', require( './../../base/unary-reduce-strided1d-dispatch-by-factory' ) );
1104+
10871105
/**
10881106
* @name unaryReduceStrided1dDispatchFactory
10891107
* @memberof ns
Lines changed: 337 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,337 @@
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+
# unaryStrided1dDispatchByFactory
22+
23+
> Create a function for performing a reduction on an input ndarray according to a callback function.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
<!-- eslint-disable id-length -->
30+
31+
```javascript
32+
var unaryStrided1dDispatchByFactory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-by-factory' );
33+
```
34+
35+
#### unaryStrided1dDispatchByFactory( table, idtypes, odtypes, policies )
36+
37+
Returns a function for performing a reduction on an input ndarray according to a callback function.
38+
39+
<!-- eslint-disable id-length -->
40+
41+
```javascript
42+
var base = require( '@stdlib/stats/base/ndarray/max-by' );
43+
44+
var table = {
45+
'default': base
46+
};
47+
48+
var dtypes = [ 'float64', 'float32', 'generic' ];
49+
var policies = {
50+
'output': 'same',
51+
'casting': 'none'
52+
};
53+
54+
var unary = unaryStrided1dDispatchByFactory( table, [ dtypes ], dtypes, policies );
55+
```
56+
57+
The function has the following parameters:
58+
59+
- **table**: strided reduction function dispatch table. Must have the following properties:
60+
61+
- **default**: default strided reduction function which should be invoked when provided ndarrays have data types which do not have a corresponding specialized implementation.
62+
63+
A dispatch table may have the following additional properties:
64+
65+
- **types**: one-dimensional list of ndarray data types describing specialized input ndarray argument signatures. Only the input ndarray argument data types should be specified. Output ndarray and additional input ndarray argument data types should be omitted and are not considered during dispatch. The length of `types` must equal the number of strided functions specified by `fcns` (i.e., for every input ndarray data type, there must be a corresponding strided reduction function in `fcns`).
66+
- **fcns**: list of strided reduction functions which are specific to specialized input ndarray argument signatures.
67+
68+
- **idtypes**: list containing lists of supported input data types for each input ndarray argument.
69+
70+
- **odtypes**: list of supported output data types.
71+
72+
- **policies**: dispatch policies. Must have the following properties:
73+
74+
- **output**: output data type [policy][@stdlib/ndarray/output-dtype-policies].
75+
- **casting**: input ndarray casting [policy][@stdlib/ndarray/input-casting-policies].
76+
77+
#### unary( x\[, ...args]\[, options], clbk\[, thisArg] )
78+
79+
Performs a reduction on a provided input ndarray according to a callback function.
80+
81+
<!-- eslint-disable id-length -->
82+
83+
```javascript
84+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
85+
var base = require( '@stdlib/stats/base/ndarray/max-by' );
86+
87+
var table = {
88+
'default': base
89+
};
90+
91+
var dtypes = [ 'float64', 'float32', 'generic' ];
92+
var policies = {
93+
'output': 'same',
94+
'casting': 'none'
95+
};
96+
97+
var unary = unaryStrided1dDispatchByFactory( table, [ dtypes ], dtypes, policies );
98+
99+
var xbuf = [ -1.0, 2.0, -3.0 ];
100+
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
101+
102+
function clbk( v ) {
103+
return v * 2.0;
104+
}
105+
106+
var y = unary( x, clbk );
107+
// returns <ndarray>
108+
109+
var v = y.get();
110+
// returns 4.0
111+
```
112+
113+
The function has the following parameters:
114+
115+
- **x**: input ndarray.
116+
- **...args**: additional input ndarray arguments (_optional_).
117+
- **options**: function options (_optional_).
118+
- **clbk**: callback function.
119+
- **thisArg**: callback function execution context (_optional_).
120+
121+
The function accepts the following options:
122+
123+
- **dims**: list of dimensions over which to perform a reduction.
124+
- **dtype**: output ndarray data type. Setting this option, overrides the output data type policy.
125+
- **keepdims**: boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions. Default: `false`.
126+
127+
By default, the function returns an ndarray having a data type determined by the output data type policy. To override the default behavior, set the `dtype` option.
128+
129+
<!-- eslint-disable id-length -->
130+
131+
```javascript
132+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
133+
var base = require( '@stdlib/stats/base/ndarray/max-by' );
134+
var getDType = require( '@stdlib/ndarray/dtype' );
135+
136+
var table = {
137+
'default': base
138+
};
139+
140+
var dtypes = [ 'float64', 'float32', 'generic' ];
141+
var policies = {
142+
'output': 'same',
143+
'casting': 'none'
144+
};
145+
146+
var unary = unaryStrided1dDispatchByFactory( table, [ dtypes ], dtypes, policies );
147+
148+
var xbuf = [ -1.0, 2.0, -3.0 ];
149+
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
150+
151+
function clbk( v ) {
152+
return v * 2.0;
153+
}
154+
155+
var opts = {
156+
'dtype': 'float64'
157+
};
158+
var y = unary( x, opts, clbk );
159+
// returns <ndarray>
160+
161+
var dt = getDType( y );
162+
// returns 'float64'
163+
```
164+
165+
#### unary.assign( x\[, ...args], out\[, options], clbk\[, thisArg] )
166+
167+
Performs a reduction on a provided input ndarray according to a callback function and assigns results to a provided output ndarray.
168+
169+
<!-- eslint-disable id-length -->
170+
171+
```javascript
172+
var base = require( '@stdlib/stats/base/ndarray/max-by' );
173+
var dtypes = require( '@stdlib/ndarray/dtypes' );
174+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
175+
176+
var idt = dtypes( 'real_and_generic' );
177+
var odt = idt;
178+
var policies = {
179+
'output': 'same',
180+
'casting': 'none'
181+
};
182+
183+
var table = {
184+
'default': base
185+
};
186+
var unary = unaryStrided1dDispatchByFactory( table, [ idt ], odt, policies );
187+
188+
var xbuf = [ -1.0, 2.0, -3.0 ];
189+
var x = new ndarray( 'generic', xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
190+
191+
var ybuf = [ 0.0 ];
192+
var y = new ndarray( 'generic', ybuf, [], [ 0 ], 0, 'row-major' );
193+
194+
function clbk( v ) {
195+
return v * 2.0;
196+
}
197+
198+
var out = unary.assign( x, y, clbk );
199+
// returns <ndarray>
200+
201+
var v = out.get();
202+
// returns 4.0
203+
204+
var bool = ( out === y );
205+
// returns true
206+
```
207+
208+
The method has the following parameters:
209+
210+
- **x**: input ndarray.
211+
- **args**: additional input ndarray arguments (_optional_).
212+
- **out**: output ndarray.
213+
- **options**: function options (_optional_).
214+
- **clbk**: callback function.
215+
- **thisArg**: callback function execution context (_optional_).
216+
217+
The method accepts the following options:
218+
219+
- **dims**: list of dimensions over which to perform a reduction.
220+
221+
</section>
222+
223+
<!-- /.usage -->
224+
225+
<section class="notes">
226+
227+
## Notes
228+
229+
- A strided reduction function should have the following signature:
230+
231+
```text
232+
f( arrays, clbk, thisArg )
233+
```
234+
235+
where
236+
237+
- **arrays**: array containing an input ndarray, followed by any additional ndarray arguments.
238+
- **clbk**: callback function.
239+
- **thisArg**: callback function execution context.
240+
241+
- The output data type policy only applies to the function returned by the main function. For the `assign` method, the output ndarray is allowed to have any supported output data type.
242+
243+
</section>
244+
245+
<!-- /.notes -->
246+
247+
<section class="examples">
248+
249+
## Examples
250+
251+
<!-- eslint-disable id-length, max-len -->
252+
253+
<!-- eslint no-undef: "error" -->
254+
255+
```javascript
256+
var base = require( '@stdlib/stats/base/ndarray/max-by' );
257+
var filledarrayBy = require( '@stdlib/array/filled-by' );
258+
var uniform = require( '@stdlib/random/base/uniform' );
259+
var dtypes = require( '@stdlib/ndarray/dtypes' );
260+
var dtype = require( '@stdlib/ndarray/dtype' );
261+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
262+
var ndarray = require( '@stdlib/ndarray/ctor' );
263+
var unaryStrided1dDispatchByFactory = require( '@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-by-factory' );
264+
265+
// Define the supported input and output data types:
266+
var idt = dtypes( 'real_and_generic' );
267+
var odt = idt;
268+
269+
// Define dispatch policies:
270+
var policies = {
271+
'output': 'same',
272+
'casting': 'none'
273+
};
274+
275+
// Define a dispatch table:
276+
var table = {
277+
'default': base
278+
};
279+
280+
// Create an interface for performing a reduction:
281+
var maxBy = unaryStrided1dDispatchByFactory( table, [ idt ], odt, policies );
282+
283+
// Define a function for creating an object with a random value:
284+
function random() {
285+
return {
286+
'value': uniform( -1.0, 1.0 )
287+
};
288+
}
289+
290+
// Generate an array of random numbers:
291+
var xbuf = filledarrayBy( 100, 'generic', random );
292+
293+
// Wrap in an ndarray:
294+
var x = new ndarray( 'generic', xbuf, [ 10, 10 ], [ 10, 1 ], 0, 'row-major' );
295+
296+
// Define an accessor function:
297+
function accessor( v ) {
298+
return v.value * 100.0;
299+
}
300+
301+
// Perform a reduction:
302+
var opts = {
303+
'dims': [ 0 ]
304+
};
305+
var y = maxBy( x, opts, accessor );
306+
307+
// Resolve the output array data type:
308+
var dt = dtype( y );
309+
console.log( dt );
310+
311+
// Print the results:
312+
console.log( ndarray2array( y ) );
313+
```
314+
315+
</section>
316+
317+
<!-- /.examples -->
318+
319+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
320+
321+
<section class="related">
322+
323+
</section>
324+
325+
<!-- /.related -->
326+
327+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
328+
329+
<section class="links">
330+
331+
[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/ndarray/tree/main/output-dtype-policies
332+
333+
[@stdlib/ndarray/input-casting-policies]: https://github.com/stdlib-js/ndarray/tree/main/input-casting-policies
334+
335+
</section>
336+
337+
<!-- /.links -->

0 commit comments

Comments
 (0)