@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.
@@ -0,0 +1,231 @@
1
+ /*
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2021 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
+ // TypeScript Version: 2.0
20
+
21
+ /// <reference types="@stdlib/types"/>
22
+
23
+ import { Collection } from '@stdlib/types/object';
24
+
25
+ /**
26
+ * Add-on function.
27
+ *
28
+ * @param N - number of indexed elements
29
+ * @param dtypeX - `x` data type (enumeration constant)
30
+ * @param x - input array
31
+ * @param strideX - `x` stride length
32
+ * @param dtypeY - `y` data type (enumeration constant)
33
+ * @param y - input array
34
+ * @param strideY - `y` stride length
35
+ * @param dtypeZ - `z` data type (enumeration constant)
36
+ * @param z - output array
37
+ * @param strideZ - `z` stride length
38
+ *
39
+ * @example
40
+ * function addon( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ ) {
41
+ * // Call into native add-on...
42
+ * }
43
+ */
44
+ type AddonFcn = ( N: number, dtypeX: number, x: Collection, strideX: number, dtypeY: number, y: Collection, strideY: number, dtypeZ: number, z: Collection, strideZ: number ) => any; // tslint:disable-line:max-line-length
45
+
46
+ /**
47
+ * Fallback function.
48
+ *
49
+ * @param N - number of indexed elements
50
+ * @param dtypeX - `x` data type
51
+ * @param x - input array
52
+ * @param strideX - `x` stride length
53
+ * @param dtypeY - `y` data type
54
+ * @param y - input array
55
+ * @param strideY - `y` stride length
56
+ * @param dtypeZ - `z` data type
57
+ * @param z - output array
58
+ * @param strideZ - `z` stride length
59
+ *
60
+ * @example
61
+ * function fallback( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ ) {
62
+ * // Fallback JavaScript implementation...
63
+ * }
64
+ */
65
+ type FallbackFcn = ( N: number, dtypeX: any, x: Collection, strideX: number, dtypeY: any, y: Collection, strideY: number, dtypeZ: any, z: Collection, strideZ: number ) => any; // tslint:disable-line:max-line-length
66
+
67
+ /**
68
+ * Fallback function supporting alternative indexing semantics.
69
+ *
70
+ * @param N - number of indexed elements
71
+ * @param dtypeX - `x` data type
72
+ * @param x - input array
73
+ * @param strideX - `x` stride length
74
+ * @param offsetX - starting `x` index
75
+ * @param dtypeY - `y` data type
76
+ * @param y - input array
77
+ * @param strideY - `y` stride length
78
+ * @param offsetY - starting `y` index
79
+ * @param dtypeZ - `z` data type
80
+ * @param z - output array
81
+ * @param strideZ - `z` stride length
82
+ * @param offsetZ - starting `z` index
83
+ *
84
+ * @example
85
+ * function fallback( N, dtypeX, x, strideX, offsetX, dtypeY, y, strideY, offsetY, dtypeZ, z, strideZ, offsetZ ) {
86
+ * // Fallback JavaScript implementation...
87
+ * }
88
+ */
89
+ type FallbackFcnWithOffsets = ( N: number, dtypeX: any, x: Collection, strideX: number, offsetX: number, dtypeY: any, y: Collection, strideY: number, offsetY: number, dtypeZ: any, z: Collection, strideZ: number, offsetZ: number ) => any; // tslint:disable-line:max-line-length
90
+
91
+ /**
92
+ * Dispatches to a native add-on.
93
+ *
94
+ * @param N - number of indexed elements
95
+ * @param dtypeX - `x` data type
96
+ * @param x - input array
97
+ * @param strideX - `x` stride length
98
+ * @param dtypeY - `y` data type
99
+ * @param y - input array
100
+ * @param strideY - `y` stride length
101
+ * @param dtypeZ - `z` data type
102
+ * @param z - destination array
103
+ * @param strideZ - `z` stride length
104
+ * @returns `z`
105
+ */
106
+ type Dispatcher = ( N: number, dtypeX: any, x: Collection, strideX: number, dtypeY: any, y: Collection, strideY: number, dtypeZ: any, z: Collection, strideZ: number ) => Collection; // tslint:disable-line:max-line-length
107
+
108
+ /**
109
+ * Dispatches to a native add-on.
110
+ *
111
+ * @param N - number of indexed elements
112
+ * @param dtypeX - `x` data type
113
+ * @param x - input array
114
+ * @param strideX - `x` stride length
115
+ * @param offsetX - starting `x` index
116
+ * @param dtypeY - `y` data type
117
+ * @param y - input array
118
+ * @param strideY - `y` stride length
119
+ * @param offsetY - starting `y` index
120
+ * @param dtypeZ - `z` data type
121
+ * @param z - destination array
122
+ * @param strideZ - `z` stride length
123
+ * @param offsetZ - starting `z` index
124
+ * @returns `z`
125
+ */
126
+ type DispatcherWithOffsets = ( N: number, dtypeX: any, x: Collection, strideX: number, offsetX: number, dtypeY: any, y: Collection, strideY: number, offsetY: number, dtypeZ: any, z: Collection, strideZ: number, offsetZ: number ) => Collection; // tslint:disable-line:max-line-length
127
+
128
+ /**
129
+ * Interface for creating a native add-on dispatcher.
130
+ */
131
+ interface Dispatch {
132
+ /**
133
+ * Returns a function which dispatches to a native add-on applying a binary function to two input strided arrays.
134
+ *
135
+ * @param addon - add-on function
136
+ * @param fallback - fallback function
137
+ * @returns dispatch function
138
+ *
139
+ * @example
140
+ * function addon( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypez, z, strideZ ) {
141
+ * // Call into native add-on...
142
+ * }
143
+ *
144
+ * function fallback( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypez, z, strideZ ) {
145
+ * // Fallback JavaScript implementation...
146
+ * }
147
+ *
148
+ * // Create a dispatch function:
149
+ * var f = dispatch( addon, fallback );
150
+ *
151
+ * // ...
152
+ *
153
+ * // Invoke the dispatch function with strided array arguments:
154
+ * f( 2, 'generic', [ 1, 2 ], 1, 'generic', [ 3, 4 ], 1, 'generic', [ 0, 0 ], 1 );
155
+ */
156
+ ( addon: AddonFcn, fallback: FallbackFcn ): Dispatcher;
157
+
158
+ /**
159
+ * Returns a function which dispatches to a native add-on applying a binary function to two input strided arrays using alternative indexing semantics.
160
+ *
161
+ * @param addon - add-on function
162
+ * @param fallback - fallback function
163
+ * @returns dispatch function
164
+ *
165
+ * @example
166
+ * function addon( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ ) {
167
+ * // Call into native add-on...
168
+ * }
169
+ *
170
+ * function fallback( N, dtypeX, x, strideX, offsetX, dtypeY, y, strideY, offsetY, dtypeZ, z, strideZ, offsetZ ) {
171
+ * // Fallback JavaScript implementation...
172
+ * }
173
+ *
174
+ * // Create a dispatch function:
175
+ * var f = dispatch.ndarray( addon, fallback );
176
+ *
177
+ * // ...
178
+ *
179
+ * // Invoke the dispatch function with strided array arguments:
180
+ * f( 2, 'generic', [ 1, 2 ], 1, 0, 'generic', [ 3, 4 ], 1, 0, 'generic', [ 0, 0 ], 1, 0 );
181
+ */
182
+ ndarray( addon: AddonFcn, fallback: FallbackFcnWithOffsets ): DispatcherWithOffsets; // tslint:disable-line:max-line-length
183
+ }
184
+
185
+ /**
186
+ * Returns a function which dispatches to a native add-on applying a unary function to two input strided arrays.
187
+ *
188
+ * @param addon - add-on function
189
+ * @param fallback - fallback function
190
+ * @returns dispatch function
191
+ *
192
+ * @example
193
+ * function addon( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ ) {
194
+ * // Call into native add-on...
195
+ * }
196
+ *
197
+ * function fallback( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ ) {
198
+ * // Fallback JavaScript implementation...
199
+ * }
200
+ *
201
+ * // Create a dispatch function:
202
+ * var f = dispatch( addon, fallback );
203
+ *
204
+ * // ...
205
+ *
206
+ * // Invoke the dispatch function with strided array arguments:
207
+ * f( 2, 'generic', [ 1, 2 ], 1, 'generic', [ 3, 4 ], 1, 'generic', [ 0, 0 ], 1 );
208
+ *
209
+ * @example
210
+ * function addon( N, dtypeX, x, strideX, dtypeY, y, strideY, dtypeZ, z, strideZ ) {
211
+ * // Call into native add-on...
212
+ * }
213
+ *
214
+ * function fallback( N, dtypeX, x, strideX, offsetX, dtypeY, y, strideY, offsetY, dtypeZ, z, strideZ, offsetZ ) {
215
+ * // Fallback JavaScript implementation...
216
+ * }
217
+ *
218
+ * // Create a dispatch function:
219
+ * var f = dispatch.ndarray( addon, fallback );
220
+ *
221
+ * // ...
222
+ *
223
+ * // Invoke the dispatch function with strided array arguments:
224
+ * f( 2, 'generic', [ 1, 2 ], 1, 0, 'generic', [ 3, 4 ], 1, 0, 'generic', [ 0, 0 ], 1, 0 );
225
+ */
226
+ declare var dispatch: Dispatch;
227
+
228
+
229
+ // EXPORTS //
230
+
231
+ export = dispatch;