@stdlib/strided-base-binary-addon-dispatch 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,385 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2021 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
+ # dispatch
22
+
23
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
24
+
25
+ > Dispatch to a native add-on applying a binary function to two input strided arrays.
26
+
27
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
28
+
29
+ <section class="intro">
30
+
31
+ </section>
32
+
33
+ <!-- /.intro -->
34
+
35
+ <!-- Package usage documentation. -->
36
+
37
+ <section class="installation">
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ npm install @stdlib/strided-base-binary-addon-dispatch
43
+ ```
44
+
45
+ </section>
46
+
47
+ <section class="usage">
48
+
49
+ ## Usage
50
+
51
+ ```javascript
52
+ var dispatch = require( '@stdlib/strided-base-binary-addon-dispatch' );
53
+ ```
54
+
55
+ #### dispatch( addon, fallback )
56
+
57
+ Returns a function which dispatches to a native add-on applying a binary function to two input strided arrays.
58
+
59
+ <!-- eslint-disable max-len -->
60
+
61
+ ```javascript
62
+ function addon( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ ) {
63
+ // Call into native add-on...
64
+ }
65
+
66
+ function fallback( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ ) {
67
+ // Fallback JavaScript implementation...
68
+ }
69
+
70
+ // Create a dispatch function:
71
+ var f = dispatch( addon, fallback );
72
+
73
+ // ...
74
+
75
+ // Invoke the dispatch function with strided array arguments:
76
+ f( 2, 'generic', [ 1, 2 ], 1, 'generic', [ 3, 4 ], 1, 'generic', [ 0, 0 ], 1 );
77
+ ```
78
+
79
+ The returned function has the following signature:
80
+
81
+ ```text
82
+ f( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ )
83
+ ```
84
+
85
+ where
86
+
87
+ - **N**: number of indexed elements.
88
+ - **dtypeX**: `x` data type.
89
+ - **x**: input array.
90
+ - **strideX**: `x` stride length.
91
+ - **dtypeY**: `y` data type.
92
+ - **y**: input array.
93
+ - **strideY**: `y` stride length.
94
+ - **dtypeZ**: `z` data type.
95
+ - **z**: output array.
96
+ - **strideZ**: `z` stride length.
97
+
98
+ The `addon` function should have the following signature:
99
+
100
+ ```text
101
+ f( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ )
102
+ ```
103
+
104
+ where
105
+
106
+ - **N**: number of indexed elements.
107
+ - **dtypeX**: `x` data type (enumeration constant).
108
+ - **x**: input array.
109
+ - **strideX**: `x` stride length.
110
+ - **dtypeY**: `y` data type (enumeration constant).
111
+ - **y**: input array.
112
+ - **strideY**: `y` stride length.
113
+ - **dtypeZ**: `z` data type (enumeration constant).
114
+ - **z**: output array.
115
+ - **strideZ**: `z` stride length.
116
+
117
+ The `fallback` function should have the following signature:
118
+
119
+ ```text
120
+ f( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ )
121
+ ```
122
+
123
+ where
124
+
125
+ - **N**: number of indexed elements.
126
+ - **dtypeX**: `x` data type.
127
+ - **x**: input array.
128
+ - **strideX**: `x` stride length.
129
+ - **dtypeY**: `y` data type.
130
+ - **y**: input array.
131
+ - **strideY**: `y` stride length.
132
+ - **dtypeZ**: `z` data type.
133
+ - **z**: output array.
134
+ - **strideZ**: `z` stride length.
135
+
136
+ #### dispatch.ndarray( addon, fallback )
137
+
138
+ Returns a function which dispatches to a native add-on applying a binary function to two input arrays using alternative indexing semantics.
139
+
140
+ <!-- eslint-disable max-len, max-params -->
141
+
142
+ ```javascript
143
+ function addon( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ ) {
144
+ // Call into native add-on...
145
+ }
146
+
147
+ function fallback( N, dtypeX, x, strideX, offsetX, dtypeY, y, strideY, offsetY, dtypeZ, z, strideZ, offsetZ ) {
148
+ // Fallback JavaScript implementation...
149
+ }
150
+
151
+ // Create a dispatch function:
152
+ var f = dispatch.ndarray( addon, fallback );
153
+
154
+ // ...
155
+
156
+ // Invoke the dispatch function with strided array arguments:
157
+ f( 2, 'generic', [ 1, 2 ], 1, 0, 'generic', [ 3, 4 ], 1, 0, 'generic', [ 0, 0 ], 1, 0 );
158
+ ```
159
+
160
+ The returned function has the following signature:
161
+
162
+ ```text
163
+ f( N, dtypeX, x, strideX, offsetX, dtypeY, y, strideY, offsetY, dtypeZ, z, strideZ, offsetZ )
164
+ ```
165
+
166
+ where
167
+
168
+ - **N**: number of indexed elements.
169
+ - **dtypeX**: `x` data type.
170
+ - **x**: input array.
171
+ - **strideX**: `x` stride length.
172
+ - **offsetX**: starting `x` index.
173
+ - **dtypeY**: `y` data type.
174
+ - **y**: input array.
175
+ - **strideY**: `y` stride length.
176
+ - **offsetY**: starting `y` index.
177
+ - **dtypeZ**: `z` data type.
178
+ - **z**: output array.
179
+ - **strideZ**: `z` stride length.
180
+ - **offsetZ**: starting `z` index.
181
+
182
+ The `addon` function should have the following signature:
183
+
184
+ ```text
185
+ f( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ )
186
+ ```
187
+
188
+ where
189
+
190
+ - **N**: number of indexed elements.
191
+ - **dtypeX**: `x` data type (enumeration constant).
192
+ - **x**: input array.
193
+ - **strideX**: `x` stride length.
194
+ - **dtypeY**: `y` data type (enumeration constant).
195
+ - **y**: input array.
196
+ - **strideY**: `y` stride length.
197
+ - **dtypeZ**: `z` data type (enumeration constant).
198
+ - **z**: output array.
199
+ - **strideZ**: `z` stride length.
200
+
201
+ The `fallback` function should have the following signature:
202
+
203
+ ```text
204
+ f( N, dtypeX, x, strideX, offsetX, dtypeY, y, strideY, offsetY, dtypeZ, z, strideZ, offsetZ )
205
+ ```
206
+
207
+ where
208
+
209
+ - **N**: number of indexed elements.
210
+ - **dtypeX**: `x` data type.
211
+ - **x**: input array.
212
+ - **strideX**: `x` stride length.
213
+ - **offsetX**: starting `x` index.
214
+ - **dtypeY**: `y` data type.
215
+ - **y**: input array.
216
+ - **strideY**: `y` stride length.
217
+ - **offsetY**: starting `y` index.
218
+ - **dtypeZ**: `z` data type.
219
+ - **z**: output array.
220
+ - **strideZ**: `z` stride length.
221
+ - **offsetZ**: starting `z` index.
222
+
223
+ </section>
224
+
225
+ <!-- /.usage -->
226
+
227
+ <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
228
+
229
+ <section class="notes">
230
+
231
+ ## Notes
232
+
233
+ - To determine whether to dispatch to the `addon` function, the returned dispatch function checks whether the provided arrays are typed arrays. If the provided arrays are typed arrays, the dispatch function invokes the `addon` function; otherwise, the dispatch function invokes the `fallback` function.
234
+
235
+ </section>
236
+
237
+ <!-- /.notes -->
238
+
239
+ <!-- Package usage examples. -->
240
+
241
+ <section class="examples">
242
+
243
+ ## Examples
244
+
245
+ <!-- eslint-disable max-len, max-params -->
246
+
247
+ <!-- eslint no-undef: "error" -->
248
+
249
+ ```javascript
250
+ var Float64Array = require( '@stdlib/array-float64' );
251
+ var dispatch = require( '@stdlib/strided-base-binary-addon-dispatch' );
252
+
253
+ function addon( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ ) {
254
+ console.log( x );
255
+ // => <Float64Array>[ 3, 4 ]
256
+
257
+ console.log( y );
258
+ // => <Float64Array>[ 7, 8 ]
259
+
260
+ console.log( z );
261
+ // => <Float64Array>[ 0, 0 ]
262
+ }
263
+
264
+ function fallback( N, dtypeX, x, strideX, offsetX, dtypeY, y, strideY, offsetY, dtypeZ, z, strideZ, offsetZ ) {
265
+ console.log( x );
266
+ // => [ 1, 2, 3, 4 ]
267
+
268
+ console.log( y );
269
+ // => [ 5, 6, 7, 8 ]
270
+
271
+ console.log( z );
272
+ // => [ 0, 0, 0, 0 ]
273
+ }
274
+
275
+ // Create a dispatch function:
276
+ var f = dispatch.ndarray( addon, fallback );
277
+
278
+ // Create strided arrays:
279
+ var x = new Float64Array( [ 1, 2, 3, 4 ] );
280
+ var y = new Float64Array( [ 5, 6, 7, 8 ] );
281
+ var z = new Float64Array( [ 0, 0, 0, 0 ] );
282
+
283
+ // Dispatch to the add-on function:
284
+ f( 2, 'float64', x, 1, 2, 'float64', y, 1, 2, 'float64', z, 1, 2 );
285
+
286
+ // Define new strided arrays:
287
+ x = [ 1, 2, 3, 4 ];
288
+ y = [ 5, 6, 7, 8 ];
289
+ z = [ 0, 0, 0, 0 ];
290
+
291
+ // Dispatch to the fallback function:
292
+ f( 2, 'generic', x, 1, 2, 'generic', y, 1, 2, 'generic', z, 1, 2 );
293
+ ```
294
+
295
+ </section>
296
+
297
+ <!-- /.examples -->
298
+
299
+ <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
300
+
301
+ <section class="references">
302
+
303
+ </section>
304
+
305
+ <!-- /.references -->
306
+
307
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
308
+
309
+ <section class="related">
310
+
311
+ </section>
312
+
313
+ <!-- /.related -->
314
+
315
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
316
+
317
+
318
+ <section class="main-repo" >
319
+
320
+ * * *
321
+
322
+ ## Notice
323
+
324
+ This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
325
+
326
+ For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
327
+
328
+ #### Community
329
+
330
+ [![Chat][chat-image]][chat-url]
331
+
332
+ ---
333
+
334
+ ## License
335
+
336
+ See [LICENSE][stdlib-license].
337
+
338
+
339
+ ## Copyright
340
+
341
+ Copyright &copy; 2016-2022. The Stdlib [Authors][stdlib-authors].
342
+
343
+ </section>
344
+
345
+ <!-- /.stdlib -->
346
+
347
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
348
+
349
+ <section class="links">
350
+
351
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/strided-base-binary-addon-dispatch.svg
352
+ [npm-url]: https://npmjs.org/package/@stdlib/strided-base-binary-addon-dispatch
353
+
354
+ [test-image]: https://github.com/stdlib-js/strided-base-binary-addon-dispatch/actions/workflows/test.yml/badge.svg
355
+ [test-url]: https://github.com/stdlib-js/strided-base-binary-addon-dispatch/actions/workflows/test.yml
356
+
357
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/strided-base-binary-addon-dispatch/main.svg
358
+ [coverage-url]: https://codecov.io/github/stdlib-js/strided-base-binary-addon-dispatch?branch=main
359
+
360
+ <!--
361
+
362
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/strided-base-binary-addon-dispatch.svg
363
+ [dependencies-url]: https://david-dm.org/stdlib-js/strided-base-binary-addon-dispatch/main
364
+
365
+ -->
366
+
367
+ [umd]: https://github.com/umdjs/umd
368
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
369
+
370
+ [deno-url]: https://github.com/stdlib-js/strided-base-binary-addon-dispatch/tree/deno
371
+ [umd-url]: https://github.com/stdlib-js/strided-base-binary-addon-dispatch/tree/umd
372
+ [esm-url]: https://github.com/stdlib-js/strided-base-binary-addon-dispatch/tree/esm
373
+
374
+ [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
375
+ [chat-url]: https://gitter.im/stdlib-js/stdlib/
376
+
377
+ [stdlib]: https://github.com/stdlib-js/stdlib
378
+
379
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
380
+
381
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/strided-base-binary-addon-dispatch/main/LICENSE
382
+
383
+ </section>
384
+
385
+ <!-- /.links -->
package/docs/repl.txt ADDED
@@ -0,0 +1,179 @@
1
+
2
+ {{alias}}( addon, fallback )
3
+ Returns a function which dispatches to a native add-on applying binary
4
+ function to two input strided arrays.
5
+
6
+ The returned function has the following signature:
7
+
8
+ f( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ )
9
+
10
+ where
11
+
12
+ - N: number of indexed elements.
13
+ - dtypeX: `x` data type.
14
+ - x: input array.
15
+ - strideX: `x` stride length.
16
+ - dtypeY: `y` data type.
17
+ - y: input array.
18
+ - strideY: `y` stride length.
19
+ - dtypeZ: `z` data type.
20
+ - z: output array.
21
+ - strideZ: `z` stride length.
22
+
23
+ To determine whether to dispatch to the `addon` function, the returned
24
+ dispatch function checks whether the provided arrays are typed arrays.
25
+
26
+ If the provided arrays are typed arrays, the dispatch function invokes the
27
+ `addon` function; otherwise, the dispatch function invokes the `fallback`
28
+ function.
29
+
30
+ Parameters
31
+ ----------
32
+ addon: Function
33
+ Add-on interface. The function should have the following signature:
34
+
35
+ f( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ )
36
+
37
+ where
38
+
39
+ - N: number of indexed elements.
40
+ - dtypeX: `x` data type (enumeration constant).
41
+ - x: input array.
42
+ - strideX: `x` stride length.
43
+ - dtypeY: `y` data type (enumeration constant).
44
+ - y: input array.
45
+ - strideY: `y` stride length.
46
+ - dtypeZ: `z` data type.
47
+ - z: output array.
48
+ - strideZ: `z` stride length.
49
+
50
+ fallback: Function
51
+ Fallback function. The function should have the following signature:
52
+
53
+ f( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ )
54
+
55
+ where
56
+
57
+ - N: number of indexed elements.
58
+ - dtypeX: `x` data type.
59
+ - x: input array.
60
+ - strideX: `x` stride length.
61
+ - dtypeY: `y` data type.
62
+ - y: input array.
63
+ - strideY: `y` stride length.
64
+ - dtypeZ: `z` data type.
65
+ - z: output array.
66
+ - strideZ: `z` stride length.
67
+
68
+ Returns
69
+ -------
70
+ fcn: Function
71
+ Dispatch function.
72
+
73
+ Examples
74
+ --------
75
+ > function addon( N, dx, x, sx, dy, y, sy, dz, z, sz ) {
76
+ ... // Call into native add-on...
77
+ ... };
78
+ > function fallback( N, dx, x, sx, dy, y, sy, dz, z, sz ) {
79
+ ... // Fallback JavaScript implementation...
80
+ ... };
81
+ > var f = {{alias}}( addon, fallback );
82
+ > var dt = 'generic';
83
+ > f( 2, dt, [ 1, 2 ], 1, dt, [ 3, 4 ], 1, dt, [ 0, 0 ], 1 );
84
+
85
+
86
+ {{alias}}.ndarray( addon, fallback )
87
+ Returns a function which dispatches to a native add-on applying a binary
88
+ function to two input strided arrays using alternative indexing semantics.
89
+
90
+ The returned function has the following signature:
91
+
92
+ f( N, dtypeX, x, strideX, offsetX, dtypeY, y, strideY, offsetY, dtypeZ, z,
93
+ strideZ, offsetZ )
94
+
95
+ where
96
+
97
+ - N: number of indexed elements.
98
+ - dtypeX: `x` data type.
99
+ - x: input array.
100
+ - strideX: `x` stride length.
101
+ - offsetX: starting `x` index.
102
+ - dtypeY: `y` data type.
103
+ - y: input array.
104
+ - strideY: `y` stride length.
105
+ - offsetY: starting `y` index.
106
+ - dtypeZ: `z` data type.
107
+ - z: output array.
108
+ - strideZ: `z` stride length.
109
+ - offsetZ: starting `z` index.
110
+
111
+ To determine whether to dispatch to the `addon` function, the returned
112
+ dispatch function checks whether the provided arrays are typed arrays.
113
+
114
+ If the provided arrays are typed arrays, the dispatch function invokes the
115
+ `addon` function; otherwise, the dispatch function invokes the `fallback`
116
+ function.
117
+
118
+ Parameters
119
+ ----------
120
+ addon: Function
121
+ Add-on interface. The function should have the following signature:
122
+
123
+ f( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ )
124
+
125
+ where
126
+
127
+ - N: number of indexed elements.
128
+ - dtypeX: `x` data type (enumeration constant).
129
+ - x: input array.
130
+ - strideX: `x` stride length.
131
+ - dtypeY: `y` data type (enumeration constant).
132
+ - y: input array.
133
+ - strideY: `y` stride length.
134
+ - dtypeZ: `z` data type (enumeration constant).
135
+ - z: output array.
136
+ - strideZ: `z` stride length.
137
+
138
+ fallback: Function
139
+ Fallback function. The function should have the following signature:
140
+
141
+ f( N, dtypeX, x, strideX, offsetX, dtypeY, y, strideY, offsetY,
142
+ dtypeZ, z, strideZ, offsetZ )
143
+
144
+ where
145
+
146
+ - N: number of indexed elements.
147
+ - dtypeX: `x` data type.
148
+ - x: input array.
149
+ - strideX: `x` stride length.
150
+ - offsetX: starting `x` index.
151
+ - dtypeY: `y` data type.
152
+ - y: input array.
153
+ - strideY: `y` stride length.
154
+ - offsetY: starting `y` index.
155
+ - dtypeZ: `z` data type.
156
+ - z: output array.
157
+ - strideZ: `z` stride length.
158
+ - offsetZ: starting `z` index.
159
+
160
+ Returns
161
+ -------
162
+ fcn: Function
163
+ Dispatch function.
164
+
165
+ Examples
166
+ --------
167
+ > function addon( N, dx, x, sx, dy, y, sy, dz, z, sz ) {
168
+ ... // Call into native add-on...
169
+ ... };
170
+ > function fallback( N, dx, x, sx, ox, dy, y, sy, dz, z, sz, oz ) {
171
+ ... // Fallback JavaScript implementation...
172
+ ... };
173
+ > var f = {{alias}}.ndarray( addon, fallback );
174
+ > var dt = 'generic';
175
+ > f( 2, dt, [ 1, 2 ], 1, 0, dt, [ 3, 4 ], 1, 0, dt, [ 0, 0 ], 1, 0 );
176
+
177
+ See Also
178
+ --------
179
+