@stdlib/blas-base-wasm-sasum 0.1.0

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,316 @@
1
+ /*
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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: 4.1
20
+
21
+ /// <reference types="@stdlib/types"/>
22
+
23
+ import { ModuleWrapper, Memory } from '@stdlib/types/wasm';
24
+
25
+ /**
26
+ * Interface defining a module constructor which is both "newable" and "callable".
27
+ */
28
+ interface ModuleConstructor {
29
+ /**
30
+ * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory.
31
+ *
32
+ * @param mem - WebAssembly memory instance
33
+ * @returns module wrapper instance
34
+ *
35
+ * @example
36
+ * var Memory = require( '@stdlib/wasm-memory' );
37
+ * var oneTo = require( '@stdlib/array-one-to' );
38
+ *
39
+ * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
40
+ * var mem = new Memory({
41
+ * 'initial': 10,
42
+ * 'maximum': 100
43
+ * });
44
+ *
45
+ * // Create a BLAS routine:
46
+ * var mod = new sasum.Module( mem );
47
+ * // returns <Module>
48
+ *
49
+ * // Initialize the routine:
50
+ * mod.initializeSync();
51
+ *
52
+ * // Define a vector data type:
53
+ * var dtype = 'float32';
54
+ *
55
+ * // Specify a vector length:
56
+ * var N = 5;
57
+ *
58
+ * // Define pointer (i.e., byte offsets) for storing two vectors:
59
+ * var xptr = 0;
60
+ *
61
+ * // Write vector values to module memory:
62
+ * mod.write( xptr, oneTo( N, dtype ) );
63
+ *
64
+ * // Perform computation:
65
+ * var out = mod.main( N, xptr, 1 );
66
+ * // returns 15.0
67
+ */
68
+ new( mem: Memory ): Module; // newable
69
+
70
+ /**
71
+ * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory.
72
+ *
73
+ * @param mem - WebAssembly memory instance
74
+ * @returns module wrapper instance
75
+ *
76
+ * @example
77
+ * var Memory = require( '@stdlib/wasm-memory' );
78
+ * var oneTo = require( '@stdlib/array-one-to' );
79
+ *
80
+ * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
81
+ * var mem = new Memory({
82
+ * 'initial': 10,
83
+ * 'maximum': 100
84
+ * });
85
+ *
86
+ * // Create a BLAS routine:
87
+ * var mod = sasum.Module( mem );
88
+ * // returns <Module>
89
+ *
90
+ * // Initialize the routine:
91
+ * mod.initializeSync();
92
+ *
93
+ * // Define a vector data type:
94
+ * var dtype = 'float32';
95
+ *
96
+ * // Specify a vector length:
97
+ * var N = 5;
98
+ *
99
+ * // Define pointer (i.e., byte offsets) for storing two vectors:
100
+ * var xptr = 0;
101
+ *
102
+ * // Write vector values to module memory:
103
+ * mod.write( xptr, oneTo( N, dtype ) );
104
+ *
105
+ * // Perform computation:
106
+ * var out = mod.main( N, xptr, 1 );
107
+ * // returns 15.0
108
+ */
109
+ ( mem: Memory ): Module; // callable
110
+ }
111
+
112
+ /**
113
+ * Interface describing a `sasum` WebAssembly module.
114
+ */
115
+ interface Module extends ModuleWrapper {
116
+ /**
117
+ * Computes the sum of absolute values.
118
+ *
119
+ * @param N - number of indexed elements
120
+ * @param xptr - input array pointer (i.e., byte offset)
121
+ * @param strideX - `x` stride length
122
+ * @returns sum of absolute values
123
+ *
124
+ * @example
125
+ * var Memory = require( '@stdlib/wasm-memory' );
126
+ * var oneTo = require( '@stdlib/array-one-to' );
127
+ *
128
+ * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
129
+ * var mem = new Memory({
130
+ * 'initial': 10,
131
+ * 'maximum': 100
132
+ * });
133
+ *
134
+ * // Create a BLAS routine:
135
+ * var mod = new sasum.Module( mem );
136
+ * // returns <Module>
137
+ *
138
+ * // Initialize the routine:
139
+ * mod.initializeSync();
140
+ *
141
+ * // Define a vector data type:
142
+ * var dtype = 'float32';
143
+ *
144
+ * // Specify a vector length:
145
+ * var N = 5;
146
+ *
147
+ * // Define pointer (i.e., byte offsets) for storing the input vector:
148
+ * var xptr = 0;
149
+ *
150
+ * // Write vector values to module memory:
151
+ * mod.write( xptr, oneTo( N, dtype ) );
152
+ *
153
+ * // Perform computation:
154
+ * var out = mod.main( N, xptr, 1 );
155
+ * // returns 15.0
156
+ */
157
+ main( N: number, xptr: number, strideX: number ): number;
158
+
159
+ /**
160
+ * Computes the sum of absolute values using alternative indexing semantics.
161
+ *
162
+ * @param N - number of indexed elements
163
+ * @param xptr - input array pointer (i.e., byte offset)
164
+ * @param strideX - `x` stride length
165
+ * @param offsetX - starting index for `x`
166
+ * @returns sum of absolute values
167
+ *
168
+ * @example
169
+ * var Memory = require( '@stdlib/wasm-memory' );
170
+ * var oneTo = require( '@stdlib/array-one-to' );
171
+ *
172
+ * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
173
+ * var mem = new Memory({
174
+ * 'initial': 10,
175
+ * 'maximum': 100
176
+ * });
177
+ *
178
+ * // Create a BLAS routine:
179
+ * var mod = new sasum.Module( mem );
180
+ * // returns <Module>
181
+ *
182
+ * // Initialize the routine:
183
+ * mod.initializeSync();
184
+ *
185
+ * // Define a vector data type:
186
+ * var dtype = 'float32';
187
+ *
188
+ * // Specify a vector length:
189
+ * var N = 5;
190
+ *
191
+ * // Define pointer (i.e., byte offsets) for storing the input vector:
192
+ * var xptr = 0;
193
+ *
194
+ * // Write vector values to module memory:
195
+ * mod.write( xptr, oneTo( N, dtype ) );
196
+ *
197
+ * // Perform computation:
198
+ * var out = mod.ndarray( N, xptr, 1, 0 );
199
+ * // returns 15.0
200
+ */
201
+ ndarray( N: number, xptr: number, strideX: number, offsetX: number ): number;
202
+ }
203
+
204
+ /**
205
+ * Interface describing `sasum`.
206
+ */
207
+ interface Routine extends ModuleWrapper {
208
+ /**
209
+ * Computes the sum of absolute values.
210
+ *
211
+ * @param N - number of indexed elements
212
+ * @param x - input array
213
+ * @param strideX - `x` stride length
214
+ * @returns sum of absolute values
215
+ *
216
+ * @example
217
+ * var Float32Array = require( '@stdlib/array-float32' );
218
+ *
219
+ * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
220
+ *
221
+ * var out = sasum.main( x.length, x, 1 );
222
+ * // returns 15.0
223
+ */
224
+ main( N: number, x: Float32Array, strideX: number ): number;
225
+
226
+ /**
227
+ * Computes the sum of absolute values using alternative indexing semantics.
228
+ *
229
+ * @param N - number of indexed elements
230
+ * @param x - input array
231
+ * @param strideX - `x` stride length
232
+ * @param offsetX - starting index for `x`
233
+ * @returns sum of absolute values
234
+ *
235
+ * @example
236
+ * var Float32Array = require( '@stdlib/array-float32' );
237
+ *
238
+ * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
239
+ *
240
+ * var out = sasum.ndarray( x.length, x, 1, 0 );
241
+ * // returns 15.0
242
+ */
243
+ ndarray( N: number, x: Float32Array, strideX: number, offsetX: number ): number;
244
+
245
+ /**
246
+ * Returns a new WebAssembly module wrapper instance which uses the provided WebAssembly memory instance as its underlying memory.
247
+ *
248
+ * @param mem - WebAssembly memory instance
249
+ * @returns module wrapper instance
250
+ *
251
+ * @example
252
+ * var Memory = require( '@stdlib/wasm-memory' );
253
+ * var oneTo = require( '@stdlib/array-one-to' );
254
+ *
255
+ * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
256
+ * var mem = new Memory({
257
+ * 'initial': 10,
258
+ * 'maximum': 100
259
+ * });
260
+ *
261
+ * // Create a BLAS routine:
262
+ * var mod = new sasum.Module( mem );
263
+ * // returns <Module>
264
+ *
265
+ * // Initialize the routine:
266
+ * mod.initializeSync();
267
+ *
268
+ * // Define a vector data type:
269
+ * var dtype = 'float32';
270
+ *
271
+ * // Specify a vector length:
272
+ * var N = 5;
273
+ *
274
+ * // Define pointer (i.e., byte offsets) for storing the input vector:
275
+ * var xptr = 0;
276
+ *
277
+ * // Write vector values to module memory:
278
+ * mod.write( xptr, oneTo( N, dtype ) );
279
+ *
280
+ * // Perform computation:
281
+ * var out = mod.main( N, xptr, 1 );
282
+ * // returns 15.0
283
+ */
284
+ Module: ModuleConstructor;
285
+ }
286
+
287
+ /**
288
+ * Computes the sum of absolute values.
289
+ *
290
+ * @param N - number of indexed elements
291
+ * @param x - input array
292
+ * @param strideX - `x` stride length
293
+ * @returns sum of absolute values
294
+ *
295
+ * @example
296
+ * var Float32Array = require( '@stdlib/array-float32' );
297
+ *
298
+ * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
299
+ *
300
+ * var out = sasum.main( x.length, x, 1 );
301
+ * // returns 15.0
302
+ *
303
+ * @example
304
+ * var Float32Array = require( '@stdlib/array-float32' );
305
+ *
306
+ * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
307
+ *
308
+ * var out = sasum.ndarray( x.length, x, 1, 0 );
309
+ * // returns 15.0
310
+ */
311
+ declare var sasum: Routine;
312
+
313
+
314
+ // EXPORTS //
315
+
316
+ export = sasum;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var base64ToUint8Array = require( '@stdlib/string-base-base64-to-uint8array' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ var wasm = base64ToUint8Array( 'AGFzbQEAAAAADwhkeWxpbmsuMAEEAAAAAAETA2AAAGADf39/AX1gBH9/f38BfQIPAQNlbnYGbWVtb3J5AgAAAwQDAAECB0wEEV9fd2FzbV9jYWxsX2N0b3JzAAAYX193YXNtX2FwcGx5X2RhdGFfcmVsb2NzAAAHY19zYXN1bQABD2Nfc2FzdW1fbmRhcnJheQACCvwBAwMAAQsaACAAIAEgAkEBIABrIAJsQQAgAkEATBsQAgvaAQIBfwF9AkAgAEEATARADAELIAJBAUcEQANAIAAgBEYNAiAEQQFqIQQgBSABIANBAnRqKgIAi5IhBSACIANqIQMMAAsACwJAIABBBnAiAkUNAANAIAIgBEYNASAEQQFqIQQgBSABIANBAnRqKgIAi5IhBSADQQFqIQMMAAsACyAAQQZIDQADQCAAIAJMDQEgBSABIANBAnRqIgQqAgCLIAQqAgSLkiAEKgIIi5IgBCoCDIuSIAQqAhCLkiAEKgIUi5KSIQUgAkEGaiECIANBBmohAwwACwALIAUL' );
29
+
30
+
31
+ // EXPORTS //
32
+
33
+ module.exports = wasm;
package/lib/binary.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var resolve = require( 'path' ).resolve;
24
+ var readWASM = require( '@stdlib/fs-read-wasm' ).sync;
25
+
26
+
27
+ // MAIN //
28
+
29
+ var wasm = readWASM( resolve( __dirname, '..', 'src', 'main.wasm' ) );
30
+
31
+
32
+ // EXPORTS //
33
+
34
+ module.exports = wasm;
package/lib/index.js ADDED
@@ -0,0 +1,93 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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
+ 'use strict';
20
+
21
+ /**
22
+ * WebAssembly routine to compute the sum of absolute values.
23
+ *
24
+ * @module @stdlib/blas-base-wasm-sasum
25
+ *
26
+ * @example
27
+ * var Float32Array = require( '@stdlib/array-float32' );
28
+ * var sasum = require( '@stdlib/blas-base-wasm-sasum' );
29
+ *
30
+ * // Define a strided array:
31
+ * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
32
+ *
33
+ * // Perform operation:
34
+ * var sum = sasum.main( x.length, x, 1 );
35
+ * // returns 15.0
36
+ *
37
+ * @example
38
+ * var Float32Array = require( '@stdlib/array-float32' );
39
+ * var sasum = require( '@stdlib/blas-base-wasm-sasum' );
40
+ *
41
+ * // Define a strided array:
42
+ * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
43
+ *
44
+ * // Perform operation:
45
+ * var sum = sasum.ndarray( x.length, x, 1, 0 );
46
+ * // returns 15.0
47
+ *
48
+ * @example
49
+ * var Memory = require( '@stdlib/wasm-memory' );
50
+ * var oneTo = require( '@stdlib/array-one-to' );
51
+ * var zeros = require( '@stdlib/array-zeros' );
52
+ * var sasum = require( '@stdlib/blas-base-wasm-sasum' );
53
+ *
54
+ * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
55
+ * var mem = new Memory({
56
+ * 'initial': 10,
57
+ * 'maximum': 100
58
+ * });
59
+ *
60
+ * // Create a BLAS routine:
61
+ * var mod = new sasum.Module( mem );
62
+ * // returns <Module>
63
+ *
64
+ * // Initialize the routine:
65
+ * mod.initializeSync();
66
+ *
67
+ * // Define a vector data type:
68
+ * var dtype = 'float32';
69
+ *
70
+ * // Specify a vector length:
71
+ * var N = 5;
72
+ *
73
+ * // Define a pointer (i.e., byte offset) for storing the input vector:
74
+ * var xptr = 0;
75
+ *
76
+ * // Write vector values to module memory:
77
+ * mod.write( xptr, oneTo( N, dtype ) );
78
+ *
79
+ * // Perform computation:
80
+ * var sum = mod.main( N, xptr, 1 );
81
+ * // returns 15.0
82
+ */
83
+
84
+ // MODULES //
85
+
86
+ var main = require( './main.js' );
87
+
88
+
89
+ // EXPORTS //
90
+
91
+ module.exports = main;
92
+
93
+ // exports: { "Module": "main.Module" }
package/lib/main.js ADDED
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
24
+ var Routine = require( './routine.js' );
25
+ var Module = require( './module.js' );
26
+
27
+
28
+ // MAIN //
29
+
30
+ /**
31
+ * WebAssembly module to compute the sum of absolute values.
32
+ *
33
+ * @name sasum
34
+ * @type {Routine}
35
+ *
36
+ * @example
37
+ * var Float32Array = require( '@stdlib/array-float32' );
38
+ *
39
+ * // Define a strided array:
40
+ * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
41
+ *
42
+ * // Perform operation:
43
+ * var sum = sasum.main( x.length, x, 1 );
44
+ * // returns 15.0
45
+ *
46
+ * @example
47
+ * var Float32Array = require( '@stdlib/array-float32' );
48
+ *
49
+ * // Define a strided array:
50
+ * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
51
+ *
52
+ * // Perform operation:
53
+ * var sum = sasum.ndarray( x.length, x, 1, 0 );
54
+ * // returns 15.0
55
+ */
56
+ var sasum = new Routine();
57
+ sasum.initializeSync(); // eslint-disable-line node/no-sync
58
+ setReadOnly( sasum, 'Module', Module.bind( null ) );
59
+
60
+
61
+ // EXPORTS //
62
+
63
+ module.exports = sasum;