Skip to content

Commit fdcbb29

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 54e037d + 5e49f68 commit fdcbb29

File tree

2 files changed

+287
-9
lines changed

2 files changed

+287
-9
lines changed

lib/node_modules/@stdlib/math/base/special/abs/package.json

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,87 @@
6565
"double",
6666
"double-precision"
6767
],
68-
"__stdlib__": {}
68+
"__stdlib__": {
69+
"stability": "stable",
70+
"envs": {
71+
"node": true,
72+
"browser": true,
73+
"repl": true
74+
},
75+
"namespaces": {
76+
"repl": true,
77+
"parent": false
78+
},
79+
"namespace": false,
80+
"standalone": true,
81+
"c_api": true,
82+
"addon": false,
83+
"wasm": false,
84+
"cli": false,
85+
"benchmarks": {
86+
"c": true,
87+
"cephes": true,
88+
"cpp": false,
89+
"boost": false,
90+
"fortran": false,
91+
"python": true,
92+
"numpy": false,
93+
"scipy": false,
94+
"r": true,
95+
"julia": true,
96+
"js": true
97+
},
98+
"examples": {
99+
"c": true,
100+
"cpp": false,
101+
"fortran": false,
102+
"js": true
103+
},
104+
"dtype": "float64",
105+
"base_alias": "abs",
106+
"alias": "abs",
107+
"short_desc": "absolute value",
108+
"link_text": "absolute value",
109+
"domain": [
110+
{
111+
"min": "-infinity",
112+
"max": "infinity"
113+
}
114+
],
115+
"rand": {
116+
"min": -10,
117+
"max": 10
118+
},
119+
"keywords": [
120+
"absolute",
121+
"value",
122+
"abs",
123+
"magnitude"
124+
],
125+
"extra_keywords": [
126+
"math.abs"
127+
],
128+
"example_values": [
129+
-2,
130+
1,
131+
3,
132+
-5,
133+
4,
134+
0,
135+
-1,
136+
-3,
137+
-3.14,
138+
5.6,
139+
-9,
140+
-5.55,
141+
3.5,
142+
10,
143+
-9.99,
144+
3,
145+
-6,
146+
-7,
147+
8,
148+
-7.77
149+
]
150+
}
69151
}

lib/node_modules/@stdlib/ndarray/dispatch-by/README.md

Lines changed: 204 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2023 The Stdlib Authors.
5+
Copyright (c) 2022 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -18,9 +18,9 @@ limitations under the License.
1818
1919
-->
2020

21-
# Dispatch By
21+
# Dispatch
2222

23-
> Create an [ndarray][@stdlib/ndarray/ctor] function interface which accepts a callback function and performs multiple dispatch.
23+
> Create an [ndarray][@stdlib/ndarray/ctor] function interface which performs multiple dispatch.
2424
2525
<section class="intro">
2626

@@ -33,19 +33,180 @@ limitations under the License.
3333
## Usage
3434

3535
```javascript
36-
var dispatchBy = require( '@stdlib/ndarray/dispatch-by' );
36+
var dispatch = require( '@stdlib/ndarray/dispatch' );
3737
```
3838

39-
#### dispatchBy( fcns, types, data, nargs, nin, nout )
39+
#### dispatch( fcns, types, data, nargs, nin, nout )
4040

41-
Creates an [ndarray][@stdlib/ndarray/ctor] function interface which accepts a callback function and performs multiple dispatch.
41+
Returns an [ndarray][@stdlib/ndarray/ctor] function interface which performs multiple dispatch.
42+
43+
<!-- eslint-disable array-element-newline -->
44+
45+
```javascript
46+
var unary = require( '@stdlib/ndarray/base/unary' );
47+
var Float64Array = require( '@stdlib/array/float64' );
48+
var Float32Array = require( '@stdlib/array/float32' );
49+
var ndarray = require( '@stdlib/ndarray/ctor' );
50+
51+
function foo( x ) {
52+
return x * 10.0;
53+
}
54+
55+
function bar( x ) {
56+
return x * 5.0;
57+
}
58+
59+
// Define a list of ndarray functions for applying a unary callback:
60+
var fcns = [
61+
unary,
62+
unary
63+
];
64+
65+
// Define a one-dimensional list of input and output array types:
66+
var types = [
67+
'float64', 'float64', // input, output
68+
'float32', 'float32' // input, output
69+
];
70+
71+
// Define a list of callbacks which should be applied based on the provided array types:
72+
var data = [
73+
foo,
74+
bar
75+
];
76+
77+
// Define the total number of input arguments:
78+
var nargs = 2; // input_array + output_array
79+
80+
// Define the number of input ndarrays:
81+
var nin = 1;
82+
83+
// Define the number of output ndarrays:
84+
var nout = 1;
85+
86+
// Create an ndarray function interface:
87+
var fcn = dispatch( fcns, types, data, nargs, nin, nout );
88+
89+
// ...
90+
91+
var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] );
92+
var ybuf = new Float64Array( xbuf.length );
93+
94+
var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' );
95+
var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' );
96+
97+
fcn( x, y );
98+
// ybuf => <Float64Array>[ 10.0, 20.0, 30.0 ]
99+
100+
xbuf = new Float32Array( [ 1.0, 2.0, 3.0 ] );
101+
ybuf = new Float32Array( xbuf.length );
102+
103+
x = ndarray( 'float32', xbuf, [ 3 ], [ 1 ], 0, 'row-major' );
104+
y = ndarray( 'float32', ybuf, [ 3 ], [ 1 ], 0, 'row-major' );
105+
106+
fcn( x, y );
107+
// ybuf => <Float32Array>[ 5.0, 10.0, 15.0 ]
108+
```
109+
110+
The function accepts the following arguments:
111+
112+
- **fcns**: list of [ndarray][@stdlib/ndarray/ctor] functions.
113+
- **types**: one-dimensional list of [ndarray][@stdlib/ndarray/ctor] argument [data types][@stdlib/ndarray/dtypes]. The length of `types` must be the number of [ndarray][@stdlib/ndarray/ctor] functions multiplied by `nin+nout`. If `fcns` is a function, rather than a list, the number of [ndarray][@stdlib/ndarray/ctor] functions is computed as `types.length / (nin+nout)`.
114+
- **data**: [ndarray][@stdlib/ndarray/ctor] function data (e.g., callbacks). If a list, the length of `data` must equal the number of [ndarray][@stdlib/ndarray/ctor] functions. If `null`, a returned [ndarray][@stdlib/ndarray/ctor] function interface does **not** provide a `data` argument to an invoked [ndarray][@stdlib/ndarray/ctor] function.
115+
- **nargs**: total number of [ndarray][@stdlib/ndarray/ctor] function interface arguments.
116+
- **nin**: number of input [ndarrays][@stdlib/ndarray/ctor].
117+
- **nout**: number of output [ndarrays][@stdlib/ndarray/ctor].
42118

43119
</section>
44120

45121
<!-- /.usage -->
46122

47123
<section class="notes">
48124

125+
## Notes
126+
127+
- A returned [ndarray][@stdlib/ndarray/ctor] function interface has the following signature:
128+
129+
```text
130+
f( x, y, ... )
131+
```
132+
133+
where
134+
135+
- **x**: [ndarray][@stdlib/ndarray/ctor].
136+
- **y**: [ndarray][@stdlib/ndarray/ctor].
137+
- **...**: additional [ndarrays][@stdlib/ndarray/ctor].
138+
139+
- The number of [ndarray][@stdlib/ndarray/ctor] function interface parameters is derived from `nargs`, the number of input [ndarrays][@stdlib/ndarray/ctor] is derived from `nin`, and the number of output [ndarrays][@stdlib/ndarray/ctor] is derived from `nout`.
140+
141+
- An [ndarray][@stdlib/ndarray/ctor] function (i.e., a value provided for the `fcns` argument) should have the following signature:
142+
143+
```text
144+
f( arrays[, data] )
145+
```
146+
147+
where
148+
149+
- **arrays**: array containing input and output [ndarrays][@stdlib/ndarray/ctor].
150+
- **data**: [ndarray][@stdlib/ndarray/ctor] function data (e.g., a callback).
151+
152+
- For convenience, a single [ndarray][@stdlib/ndarray/ctor] function may be provided which will be invoked whenever the [ndarray][@stdlib/ndarray/ctor] argument data types match a sequence of types in `types`. Providing a single [ndarray][@stdlib/ndarray/ctor] function is particularly convenient for the case where, regardless of array data types, traversing arrays remains the same, but the [ndarray][@stdlib/ndarray/ctor] function `data` differs (e.g., callbacks which differ based on the array data types). For example, the following
153+
154+
<!-- eslint-disable array-element-newline -->
155+
156+
```javascript
157+
var unary = require( '@stdlib/ndarray/base/unary' );
158+
159+
function foo( x ) {
160+
return x * 10.0;
161+
}
162+
163+
function bar( x ) {
164+
return x * 5.0;
165+
}
166+
167+
var fcns = [
168+
unary,
169+
unary
170+
];
171+
var types = [
172+
'float64', 'float64',
173+
'float32', 'float32'
174+
];
175+
var data = [
176+
foo,
177+
bar
178+
];
179+
180+
var fcn = dispatch( fcns, types, data, 2, 1, 1 );
181+
```
182+
183+
is equivalent to
184+
185+
<!-- eslint-disable array-element-newline -->
186+
187+
```javascript
188+
var unary = require( '@stdlib/ndarray/base/unary' );
189+
190+
function foo( x ) {
191+
return x * 10.0;
192+
}
193+
194+
function bar( x ) {
195+
return x * 5.0;
196+
}
197+
198+
var types = [
199+
'float64', 'float64',
200+
'float32', 'float32'
201+
];
202+
var data = [
203+
foo,
204+
bar
205+
];
206+
207+
var fcn = dispatch( unary, types, data, 2, 1, 1 );
208+
```
209+
49210
</section>
50211
51212
<!-- /.notes -->
@@ -57,7 +218,29 @@ Creates an [ndarray][@stdlib/ndarray/ctor] function interface which accepts a ca
57218
<!-- eslint no-undef: "error" -->
58219
59220
```javascript
60-
var dispatchBy = require( '@stdlib/ndarray/dispatch-by' );
221+
var unary = require( '@stdlib/ndarray/base/unary' );
222+
var ndarray = require( '@stdlib/ndarray/ctor' );
223+
var abs = require( '@stdlib/math/base/special/abs' );
224+
var Float64Array = require( '@stdlib/array/float64' );
225+
var dispatch = require( '@stdlib/ndarray/dispatch' );
226+
227+
var types = [ 'float64', 'float64' ];
228+
229+
var data = [
230+
abs
231+
];
232+
233+
var absolute = dispatch( unary, types, data, 2, 1, 1 );
234+
235+
var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );
236+
var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
237+
238+
var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );
239+
var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );
240+
241+
absolute( x, y );
242+
console.log( ybuf );
243+
// => <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0 ]
61244
```
62245

63246
</section>
@@ -68,15 +251,28 @@ var dispatchBy = require( '@stdlib/ndarray/dispatch-by' );
68251

69252
<section class="related">
70253

254+
* * *
255+
256+
## See Also
257+
258+
- <span class="package-name">[`@stdlib/ndarray/array`][@stdlib/ndarray/array]</span><span class="delimiter">: </span><span class="description">multidimensional arrays.</span>
259+
- <span class="package-name">[`@stdlib/ndarray/ctor`][@stdlib/ndarray/ctor]</span><span class="delimiter">: </span><span class="description">multidimensional array constructor.</span>
260+
261+
</section>
262+
71263
<!-- /.related -->
72264

73265
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
74266

75267
<section class="links">
76268

269+
<!-- <related-links> -->
270+
271+
[@stdlib/ndarray/array]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array
272+
77273
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor
78274

79-
<!-- <related-links> -->
275+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes
80276

81277
<!-- </related-links> -->
82278

0 commit comments

Comments
 (0)