@stdlib/blas-base-wasm-dnrm2 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.
- package/LICENSE +177 -0
- package/NOTICE +1 -0
- package/README.md +388 -0
- package/SECURITY.md +5 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +316 -0
- package/lib/binary.browser.js +33 -0
- package/lib/binary.js +34 -0
- package/lib/index.js +92 -0
- package/lib/main.js +63 -0
- package/lib/module.js +198 -0
- package/lib/routine.js +166 -0
- package/manifest.json +36 -0
- package/package.json +97 -0
- package/src/exports.json +4 -0
- package/src/main.wasm +0 -0
- package/src/main.wat +213 -0
|
@@ -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 dnrm2.Module( mem );
|
|
47
|
+
* // returns <Module>
|
|
48
|
+
*
|
|
49
|
+
* // Initialize the routine:
|
|
50
|
+
* mod.initializeSync();
|
|
51
|
+
*
|
|
52
|
+
* // Define a vector data type:
|
|
53
|
+
* var dtype = 'float64';
|
|
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 ~7.42
|
|
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 = dnrm2.Module( mem );
|
|
88
|
+
* // returns <Module>
|
|
89
|
+
*
|
|
90
|
+
* // Initialize the routine:
|
|
91
|
+
* mod.initializeSync();
|
|
92
|
+
*
|
|
93
|
+
* // Define a vector data type:
|
|
94
|
+
* var dtype = 'float64';
|
|
95
|
+
*
|
|
96
|
+
* // Specify a vector length:
|
|
97
|
+
* var N = 5;
|
|
98
|
+
*
|
|
99
|
+
* // Define pointer (i.e., byte offsets) for storing vector:
|
|
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 ~7.42
|
|
108
|
+
*/
|
|
109
|
+
( mem: Memory ): Module; // callable
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Interface describing a `dnrm2` WebAssembly module.
|
|
114
|
+
*/
|
|
115
|
+
interface Module extends ModuleWrapper {
|
|
116
|
+
/**
|
|
117
|
+
* Computes the L2-norm of a double-precision floating-point vector.
|
|
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 L2-norm
|
|
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 dnrm2.Module( mem );
|
|
136
|
+
* // returns <Module>
|
|
137
|
+
*
|
|
138
|
+
* // Initialize the routine:
|
|
139
|
+
* mod.initializeSync();
|
|
140
|
+
*
|
|
141
|
+
* // Define a vector data type:
|
|
142
|
+
* var dtype = 'float64';
|
|
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 ~7.42
|
|
156
|
+
*/
|
|
157
|
+
main( N: number, xptr: number, strideX: number ): number;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Computes the L2-norm of a double-precision floating-point vector 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 L2-norm
|
|
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 dnrm2.Module( mem );
|
|
180
|
+
* // returns <Module>
|
|
181
|
+
*
|
|
182
|
+
* // Initialize the routine:
|
|
183
|
+
* mod.initializeSync();
|
|
184
|
+
*
|
|
185
|
+
* // Define a vector data type:
|
|
186
|
+
* var dtype = 'float64';
|
|
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 ~7.42
|
|
200
|
+
*/
|
|
201
|
+
ndarray( N: number, xptr: number, strideX: number, offsetX: number ): number;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Interface describing `dnrm2`.
|
|
206
|
+
*/
|
|
207
|
+
interface Routine extends ModuleWrapper {
|
|
208
|
+
/**
|
|
209
|
+
* Computes the L2-norm of a double-precision floating-point vector.
|
|
210
|
+
*
|
|
211
|
+
* @param N - number of indexed elements
|
|
212
|
+
* @param x - input array
|
|
213
|
+
* @param strideX - `x` stride length
|
|
214
|
+
* @returns L2-norm
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
218
|
+
*
|
|
219
|
+
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
|
|
220
|
+
*
|
|
221
|
+
* var out = dnrm2.main( x.length, x, 1 );
|
|
222
|
+
* // returns ~7.42
|
|
223
|
+
*/
|
|
224
|
+
main( N: number, x: Float64Array, strideX: number ): number;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Computes the L2-norm of a double-precision floating-point vector 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 L2-norm
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
237
|
+
*
|
|
238
|
+
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
|
|
239
|
+
*
|
|
240
|
+
* var out = dnrm2.ndarray( x.length, x, 1, 0 );
|
|
241
|
+
* // returns ~7.42
|
|
242
|
+
*/
|
|
243
|
+
ndarray( N: number, x: Float64Array, 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 dnrm2.Module( mem );
|
|
263
|
+
* // returns <Module>
|
|
264
|
+
*
|
|
265
|
+
* // Initialize the routine:
|
|
266
|
+
* mod.initializeSync();
|
|
267
|
+
*
|
|
268
|
+
* // Define a vector data type:
|
|
269
|
+
* var dtype = 'float64';
|
|
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 ~7.42
|
|
283
|
+
*/
|
|
284
|
+
Module: ModuleConstructor;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Computes the L2-norm of a double-precision floating-point vector.
|
|
289
|
+
*
|
|
290
|
+
* @param N - number of indexed elements
|
|
291
|
+
* @param x - input array
|
|
292
|
+
* @param strideX - `x` stride length
|
|
293
|
+
* @returns L2-norm
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
297
|
+
*
|
|
298
|
+
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
|
|
299
|
+
*
|
|
300
|
+
* var out = dnrm2.main( x.length, x, 1 );
|
|
301
|
+
* // returns ~7.42
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
305
|
+
*
|
|
306
|
+
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
|
|
307
|
+
*
|
|
308
|
+
* var out = dnrm2.ndarray( x.length, x, 1, 0 );
|
|
309
|
+
* // returns ~7.42
|
|
310
|
+
*/
|
|
311
|
+
declare var dnrm2: Routine;
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
// EXPORTS //
|
|
315
|
+
|
|
316
|
+
export = dnrm2;
|
|
@@ -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/AXxgBH9/f38BfAIPAQNlbnYGbWVtb3J5AgAAAwQDAAECB0wEEV9fd2FzbV9jYWxsX2N0b3JzAAAYX193YXNtX2FwcGx5X2RhdGFfcmVsb2NzAAAHY19kbnJtMgABD2NfZG5ybTJfbmRhcnJheQACCsUDAwMAAQsaACAAIAEgAkEBIABrIAJsQQAgAkEATBsQAgujAwIFfAN/QQEhCSAAQQBKBHwDQCAAIApGRQRAAkAgASADQQN0aisDACIImSIHRAAAAAAAAFBeZARAIAYgB0QAAAAAAABQHqIiBiAGoqAhBkEAIQkMAQsgB0QAAAAAAAAAIGMEQCAJIQtBACEJIAtFDQEgBSAHRAAAAAAAAIBhoiIFIAWioCEFQQEhCQwBCyAEIAggCKKgIQQLIApBAWohCiACIANqIQMMAQsLAnwgBkQAAAAAAAAAAGQEQCAERAAAAAAAAFAeokQAAAAAAABQHqIgBqAiBSAGIARE////////739kGyAFIAREAAAAAAAAAABlGyEERAAAAAAAAJBhDAELRAAAAAAAAPA/IAVEAAAAAAAAAABkRQ0AGiAEIARiIAREAAAAAAAAAABkciAERP///////+9/ZHJFBEAgBSEERAAAAAAAAGAeDAELIAWfRAAAAAAAAGAeoiIFIASfIgQgBCAFYyIAGyIHIAeiIAQgBSAAGyAHoyIEIASiRAAAAAAAAPA/oKIhBEQAAAAAAADwPwsgBJ+iBUQAAAAAAAAAAAsL' );
|
|
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,92 @@
|
|
|
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 calculate the L2-norm of a double-precision floating-point vector.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/blas-base-wasm-dnrm2
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
28
|
+
* var dnrm2 = require( '@stdlib/blas-base-wasm-dnrm2' );
|
|
29
|
+
*
|
|
30
|
+
* // Define a strided array:
|
|
31
|
+
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
|
|
32
|
+
*
|
|
33
|
+
* // Perform operation:
|
|
34
|
+
* var out = dnrm2.main( x.length, x, 1 );
|
|
35
|
+
* // returns ~7.42
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
39
|
+
* var dnrm2 = require( '@stdlib/blas-base-wasm-dnrm2' );
|
|
40
|
+
*
|
|
41
|
+
* // Define a strided array:
|
|
42
|
+
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
|
|
43
|
+
*
|
|
44
|
+
* // Perform operation:
|
|
45
|
+
* var out = dnrm2.ndarray( x.length, x, 1, 0 );
|
|
46
|
+
* // returns ~7.42
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* var Memory = require( '@stdlib/wasm-memory' );
|
|
50
|
+
* var oneTo = require( '@stdlib/array-one-to' );
|
|
51
|
+
* var dnrm2 = require( '@stdlib/blas-base-wasm-dnrm2' );
|
|
52
|
+
*
|
|
53
|
+
* // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
|
|
54
|
+
* var mem = new Memory({
|
|
55
|
+
* 'initial': 10,
|
|
56
|
+
* 'maximum': 100
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* // Create a BLAS routine:
|
|
60
|
+
* var mod = new dnrm2.Module( mem );
|
|
61
|
+
* // returns <Module>
|
|
62
|
+
*
|
|
63
|
+
* // Initialize the routine:
|
|
64
|
+
* mod.initializeSync();
|
|
65
|
+
*
|
|
66
|
+
* // Define a vector data type:
|
|
67
|
+
* var dtype = 'float64';
|
|
68
|
+
*
|
|
69
|
+
* // Specify a vector length:
|
|
70
|
+
* var N = 5;
|
|
71
|
+
*
|
|
72
|
+
* // Define a pointer (i.e., byte offset) for storing the input vector:
|
|
73
|
+
* var xptr = 0;
|
|
74
|
+
*
|
|
75
|
+
* // Write vector values to module memory:
|
|
76
|
+
* mod.write( xptr, oneTo( N, dtype ) );
|
|
77
|
+
*
|
|
78
|
+
* // Perform computation:
|
|
79
|
+
* var out = mod.main( N, xptr, 1 );
|
|
80
|
+
* // returns ~7.42
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
// MODULES //
|
|
84
|
+
|
|
85
|
+
var main = require( './main.js' );
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
// EXPORTS //
|
|
89
|
+
|
|
90
|
+
module.exports = main;
|
|
91
|
+
|
|
92
|
+
// 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 calculate the L2-norm of a double-precision floating-point vector.
|
|
32
|
+
*
|
|
33
|
+
* @name dnrm2
|
|
34
|
+
* @type {Routine}
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
38
|
+
*
|
|
39
|
+
* // Define a strided array:
|
|
40
|
+
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
|
|
41
|
+
*
|
|
42
|
+
* // Perform operation:
|
|
43
|
+
* var out = dnrm2.main( x.length, x, 1 );
|
|
44
|
+
* // returns ~7.42
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* var Float64Array = require( '@stdlib/array-float64' );
|
|
48
|
+
*
|
|
49
|
+
* // Define a strided array:
|
|
50
|
+
* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
|
|
51
|
+
*
|
|
52
|
+
* // Perform operation:
|
|
53
|
+
* var out = dnrm2.ndarray( x.length, x, 1, 0 );
|
|
54
|
+
* // returns ~7.42
|
|
55
|
+
*/
|
|
56
|
+
var dnrm2 = new Routine();
|
|
57
|
+
dnrm2.initializeSync(); // eslint-disable-line node/no-sync
|
|
58
|
+
setReadOnly( dnrm2, 'Module', Module.bind( null ) );
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// EXPORTS //
|
|
62
|
+
|
|
63
|
+
module.exports = dnrm2;
|