Skip to content

Commit c1c92cd

Browse files
committed
Auto-generated commit
1 parent 14de993 commit c1c92cd

File tree

16 files changed

+2899
-0
lines changed

16 files changed

+2899
-0
lines changed

CHANGELOG.md

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

1111
### Features
1212

13+
- [`ce2a417`](https://github.com/stdlib-js/stdlib/commit/ce2a4171ac366e3023a240d01c154f8e9bfdfa5e) - add `ndarray/base/binary-reduce-strided1d-dispatch` [(#7908)](https://github.com/stdlib-js/stdlib/pull/7908)
1314
- [`17e89e8`](https://github.com/stdlib-js/stdlib/commit/17e89e85928ef1e38ad554975c62ea96c15c6c04) - generate loops for mostly safe casts
1415
- [`b18f473`](https://github.com/stdlib-js/stdlib/commit/b18f47378813b1a5dd0f4d669913c86cdd525ce4) - add `ndarray/base/unary-addon-dispatch`
1516
- [`cfe870b`](https://github.com/stdlib-js/stdlib/commit/cfe870b5ab3798377068aba5e239bf50f730f116) - add `ndarray/base/nullary-strided1d-dispatch` [(#7821)](https://github.com/stdlib-js/stdlib/pull/7821)
@@ -517,6 +518,7 @@ A total of 24 issues were closed in this release:
517518

518519
<details>
519520

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

0 commit comments

Comments
 (0)