@stdlib/blas-base-wasm-sdsdot 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/lib/module.js ADDED
@@ -0,0 +1,220 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 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
+ /* eslint-disable no-restricted-syntax, no-invalid-this */
20
+
21
+ 'use strict';
22
+
23
+ // MODULES //
24
+
25
+ var isWebAssemblyMemory = require( '@stdlib/assert-is-wasm-memory' );
26
+ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
27
+ var inherits = require( '@stdlib/utils-inherit' );
28
+ var WasmModule = require( '@stdlib/wasm-module-wrapper' );
29
+ var format = require( '@stdlib/string-format' );
30
+ var wasmBinary = require( './binary.js' );
31
+
32
+
33
+ // MAIN //
34
+
35
+ /**
36
+ * BLAS routine WebAssembly module wrapper constructor.
37
+ *
38
+ * @constructor
39
+ * @param {Object} memory - WebAssembly memory instance
40
+ * @throws {TypeError} must provide a WebAssembly memory instance
41
+ * @returns {Module} module instance
42
+ *
43
+ * @example
44
+ * var Memory = require( '@stdlib/wasm-memory' );
45
+ * var oneTo = require( '@stdlib/array-one-to' );
46
+ * var ones = require( '@stdlib/array-ones' );
47
+ * var zeros = require( '@stdlib/array-zeros' );
48
+ * var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );
49
+ *
50
+ * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
51
+ * var mem = new Memory({
52
+ * 'initial': 10,
53
+ * 'maximum': 100
54
+ * });
55
+ *
56
+ * // Create a BLAS routine:
57
+ * var sdsdot = new Module( mem );
58
+ * // returns <Module>
59
+ *
60
+ * // Initialize the routine:
61
+ * sdsdot.initializeSync();
62
+ *
63
+ * // Define a vector data type:
64
+ * var dtype = 'float32';
65
+ *
66
+ * // Specify a vector length:
67
+ * var N = 5;
68
+ *
69
+ * // Define pointers (i.e., byte offsets) for storing two vectors:
70
+ * var xptr = 0;
71
+ * var yptr = N * bytesPerElement( dtype );
72
+ *
73
+ * // Write vector values to module memory:
74
+ * sdsdot.write( xptr, oneTo( N, dtype ) );
75
+ * sdsdot.write( yptr, ones( N, dtype ) );
76
+ *
77
+ * // Perform computation:
78
+ * var dot = sdsdot.main( N, 0.0, xptr, 1, yptr, 1 );
79
+ * // returns 15.0
80
+ */
81
+ function Module( memory ) {
82
+ if ( !( this instanceof Module ) ) {
83
+ return new Module( memory );
84
+ }
85
+ if ( !isWebAssemblyMemory( memory ) ) {
86
+ throw new TypeError( format( 'invalid argument. Must provide a WebAssembly memory instance. Value: `%s`.', memory ) );
87
+ }
88
+ // Call the parent constructor:
89
+ WasmModule.call( this, wasmBinary, memory, {
90
+ 'env': {
91
+ 'memory': memory
92
+ }
93
+ });
94
+
95
+ return this;
96
+ }
97
+
98
+ // Inherit from the parent constructor:
99
+ inherits( Module, WasmModule );
100
+
101
+ /**
102
+ * Computes the dot product of two single-precision floating-point vectors with extended accumulation.
103
+ *
104
+ * @name main
105
+ * @memberof Module.prototype
106
+ * @readonly
107
+ * @type {Function}
108
+ * @param {PositiveInteger} N - number of indexed elements
109
+ * @param {number} scalar - scalar constant to add to dot product
110
+ * @param {NonNegativeInteger} xptr - first input array pointer (i.e., byte offset)
111
+ * @param {integer} strideX - `x` stride length
112
+ * @param {NonNegativeInteger} yptr - second input array pointer (i.e., byte offset)
113
+ * @param {integer} strideY - `y` stride length
114
+ * @returns {number} dot product
115
+ *
116
+ * @example
117
+ * var Memory = require( '@stdlib/wasm-memory' );
118
+ * var oneTo = require( '@stdlib/array-one-to' );
119
+ * var ones = require( '@stdlib/array-ones' );
120
+ * var zeros = require( '@stdlib/array-zeros' );
121
+ * var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );
122
+ *
123
+ * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
124
+ * var mem = new Memory({
125
+ * 'initial': 10,
126
+ * 'maximum': 100
127
+ * });
128
+ *
129
+ * // Create a BLAS routine:
130
+ * var sdsdot = new Module( mem );
131
+ * // returns <Module>
132
+ *
133
+ * // Initialize the routine:
134
+ * sdsdot.initializeSync();
135
+ *
136
+ * // Define a vector data type:
137
+ * var dtype = 'float32';
138
+ *
139
+ * // Specify a vector length:
140
+ * var N = 5;
141
+ *
142
+ * // Define pointers (i.e., byte offsets) for storing two vectors:
143
+ * var xptr = 0;
144
+ * var yptr = N * bytesPerElement( dtype );
145
+ *
146
+ * // Write vector values to module memory:
147
+ * sdsdot.write( xptr, oneTo( N, dtype ) );
148
+ * sdsdot.write( yptr, ones( N, dtype ) );
149
+ *
150
+ * // Perform computation:
151
+ * var dot = sdsdot.main( N, 0.0, xptr, 1, yptr, 1 );
152
+ * // returns 15.0
153
+ */
154
+ setReadOnly( Module.prototype, 'main', function sdsdot( N, scalar, xptr, strideX, yptr, strideY ) {
155
+ return this._instance.exports.c_sdsdot( N, scalar, xptr, strideX, yptr, strideY );
156
+ });
157
+
158
+ /**
159
+ * Computes the dot product of two single-precision floating-point vectors with extended accumulation using alternative indexing semantics.
160
+ *
161
+ * @name ndarray
162
+ * @memberof Module.prototype
163
+ * @readonly
164
+ * @type {Function}
165
+ * @param {PositiveInteger} N - number of indexed elements
166
+ * @param {number} scalar - scalar constant to add to dot product
167
+ * @param {NonNegativeInteger} xptr - first input array pointer (i.e., byte offset)
168
+ * @param {integer} strideX - `x` stride length
169
+ * @param {NonNegativeInteger} offsetX - starting `x` index
170
+ * @param {NonNegativeInteger} yptr - second input array pointer (i.e., byte offset)
171
+ * @param {integer} strideY - `y` stride length
172
+ * @param {NonNegativeInteger} offsetY - starting `y` index
173
+ * @returns {number} dot product
174
+ *
175
+ * @example
176
+ * var Memory = require( '@stdlib/wasm-memory' );
177
+ * var oneTo = require( '@stdlib/array-one-to' );
178
+ * var ones = require( '@stdlib/array-ones' );
179
+ * var zeros = require( '@stdlib/array-zeros' );
180
+ * var bytesPerElement = require( '@stdlib/ndarray-base-bytes-per-element' );
181
+ *
182
+ * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
183
+ * var mem = new Memory({
184
+ * 'initial': 10,
185
+ * 'maximum': 100
186
+ * });
187
+ *
188
+ * // Create a BLAS routine:
189
+ * var sdsdot = new Module( mem );
190
+ * // returns <Module>
191
+ *
192
+ * // Initialize the routine:
193
+ * sdsdot.initializeSync();
194
+ *
195
+ * // Define a vector data type:
196
+ * var dtype = 'float32';
197
+ *
198
+ * // Specify a vector length:
199
+ * var N = 5;
200
+ *
201
+ * // Define pointers (i.e., byte offsets) for storing two vectors:
202
+ * var xptr = 0;
203
+ * var yptr = N * bytesPerElement( dtype );
204
+ *
205
+ * // Write vector values to module memory:
206
+ * sdsdot.write( xptr, oneTo( N, dtype ) );
207
+ * sdsdot.write( yptr, ones( N, dtype ) );
208
+ *
209
+ * // Perform computation:
210
+ * var sdsdot = sdsdot.ndarray( N, 0.0, xptr, 1, 0, yptr, 1, 0 );
211
+ * // returns 15.0
212
+ */
213
+ setReadOnly( Module.prototype, 'ndarray', function sdsdot( N, scalar, xptr, strideX, offsetX, yptr, strideY, offsetY ) {
214
+ return this._instance.exports.c_sdsdot_ndarray( N, scalar, xptr, strideX, offsetX, yptr, strideY, offsetY ); // eslint-disable-line max-len
215
+ });
216
+
217
+
218
+ // EXPORTS //
219
+
220
+ module.exports = Module;
package/lib/routine.js ADDED
@@ -0,0 +1,180 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 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
+ /* eslint-disable no-restricted-syntax, no-invalid-this */
20
+
21
+ 'use strict';
22
+
23
+ // MODULES //
24
+
25
+ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
26
+ var inherits = require( '@stdlib/utils-inherit' );
27
+ var stride2offset = require( '@stdlib/strided-base-stride2offset' );
28
+ var Memory = require( '@stdlib/wasm-memory' );
29
+ var arrays2ptrs = require( '@stdlib/wasm-base-arrays2ptrs' );
30
+ var strided2object = require( '@stdlib/wasm-base-strided2object' );
31
+ var Module = require( './module.js' );
32
+
33
+
34
+ // MAIN //
35
+
36
+ /**
37
+ * Routine constructor.
38
+ *
39
+ * @private
40
+ * @constructor
41
+ * @returns {Routine} routine instance
42
+ *
43
+ * @example
44
+ * var Float32Array = require( '@stdlib/array-float32' );
45
+ *
46
+ * // Create a new routine:
47
+ * var sdsdot = new Routine();
48
+ *
49
+ * // Initialize the module:
50
+ * sdsdot.initializeSync();
51
+ *
52
+ * // Define strided arrays:
53
+ * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
54
+ * var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] );
55
+ *
56
+ * // Perform operation:
57
+ * var dot = sdsdot.main( x.length, 0.0, x, 1, y, 1 );
58
+ * // returns 15.0
59
+ *
60
+ * @example
61
+ * var Float32Array = require( '@stdlib/array-float32' );
62
+ *
63
+ * // Create a new routine:
64
+ * var sdsdot = new Routine();
65
+ *
66
+ * // Initialize the module:
67
+ * sdsdot.initializeSync();
68
+ *
69
+ * // Define strided arrays:
70
+ * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
71
+ * var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] );
72
+ *
73
+ * // Perform operation:
74
+ * var dot = sdsdot.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0 );
75
+ * // returns 15.0
76
+ */
77
+ function Routine() {
78
+ if ( !( this instanceof Routine ) ) {
79
+ return new Routine();
80
+ }
81
+ Module.call( this, new Memory({
82
+ 'initial': 0
83
+ }));
84
+ return this;
85
+ }
86
+
87
+ // Inherit from the parent constructor:
88
+ inherits( Routine, Module );
89
+
90
+ /**
91
+ * Computes the dot product of two single-precision floating-point vectors with extended accumulation.
92
+ *
93
+ * @name main
94
+ * @memberof Routine.prototype
95
+ * @readonly
96
+ * @type {Function}
97
+ * @param {PositiveInteger} N - number of indexed elements
98
+ * @param {number} scalar - scalar constant to add to dot product
99
+ * @param {Float32Array} x - first input array
100
+ * @param {integer} strideX - `x` stride length
101
+ * @param {Float32Array} y - second input array
102
+ * @param {integer} strideY - `y` stride length
103
+ * @returns {number} dot product
104
+ *
105
+ * @example
106
+ * var Float32Array = require( '@stdlib/array-float32' );
107
+ *
108
+ * // Create a new routine:
109
+ * var sdsdot = new Routine();
110
+ *
111
+ * // Initialize the module:
112
+ * sdsdot.initializeSync();
113
+ *
114
+ * // Define strided arrays:
115
+ * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
116
+ * var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] );
117
+ *
118
+ * // Perform operation:
119
+ * var dot = sdsdot.main( x.length, 0.0, x, 1, y, 1 );
120
+ * // returns 15.0
121
+ */
122
+ setReadOnly( Routine.prototype, 'main', function sdsdot( N, scalar, x, strideX, y, strideY ) {
123
+ return this.ndarray( N, scalar, x, strideX, stride2offset( N, strideX ), y, strideY, stride2offset( N, strideY ) ); // eslint-disable-line max-len
124
+ });
125
+
126
+ /**
127
+ * Computes the dot product of two single-precision floating-point vectors with extended accumulation using alternative indexing semantics.
128
+ *
129
+ * @name ndarray
130
+ * @memberof Routine.prototype
131
+ * @readonly
132
+ * @type {Function}
133
+ * @param {PositiveInteger} N - number of indexed elements
134
+ * @param {number} scalar - scalar constant to add to dot product
135
+ * @param {Float32Array} x - first input array
136
+ * @param {integer} strideX - `x` stride length
137
+ * @param {NonNegativeInteger} offsetX - starting `x` index
138
+ * @param {Float32Array} y - second input array
139
+ * @param {integer} strideY - `y` stride length
140
+ * @param {NonNegativeInteger} offsetY - starting `y` index
141
+ * @returns {number} dot product
142
+ *
143
+ * @example
144
+ * var Float32Array = require( '@stdlib/array-float32' );
145
+ *
146
+ * // Create a new routine:
147
+ * var sdsdot = new Routine();
148
+ *
149
+ * // Initialize the module:
150
+ * sdsdot.initializeSync();
151
+ *
152
+ * // Define strided arrays:
153
+ * var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
154
+ * var y = new Float32Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] );
155
+ *
156
+ * // Perform operation:
157
+ * var dot = sdsdot.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0 );
158
+ * // returns 15.0
159
+ */
160
+ setReadOnly( Routine.prototype, 'ndarray', function sdsdot( N, scalar, x, strideX, offsetX, y, strideY, offsetY ) {
161
+ var ptrs;
162
+ var p0;
163
+ var p1;
164
+
165
+ // Convert the input arrays to "pointers" in the module's memory:
166
+ ptrs = arrays2ptrs( this, [
167
+ strided2object( N, x, strideX, offsetX ),
168
+ strided2object( N, y, strideY, offsetY )
169
+ ]);
170
+ p0 = ptrs[ 0 ];
171
+ p1 = ptrs[ 1 ];
172
+
173
+ // Perform computation by calling the corresponding parent method:
174
+ return Module.prototype.ndarray.call( this, N, scalar, p0.ptr, p0.stride, p0.offset, p1.ptr, p1.stride, p1.offset ); // eslint-disable-line max-len
175
+ });
176
+
177
+
178
+ // EXPORTS //
179
+
180
+ module.exports = Routine;
package/manifest.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "options": {},
3
+ "fields": [
4
+ {
5
+ "field": "src",
6
+ "resolve": true,
7
+ "relative": true
8
+ },
9
+ {
10
+ "field": "include",
11
+ "resolve": true,
12
+ "relative": true
13
+ },
14
+ {
15
+ "field": "libraries",
16
+ "resolve": false,
17
+ "relative": false
18
+ },
19
+ {
20
+ "field": "libpath",
21
+ "resolve": true,
22
+ "relative": false
23
+ }
24
+ ],
25
+ "confs": [
26
+ {
27
+ "src": [],
28
+ "include": [],
29
+ "libraries": [],
30
+ "libpath": [],
31
+ "dependencies": [
32
+ "@stdlib/blas-base-sdsdot"
33
+ ]
34
+ }
35
+ ]
36
+ }
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "@stdlib/blas-base-wasm-sdsdot",
3
+ "version": "0.1.0",
4
+ "description": "Calculate the dot product of two single-precision floating-point vectors with extended accumulation.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "browser": {
18
+ "./lib/binary.js": "./lib/binary.browser.js"
19
+ },
20
+ "directories": {
21
+ "doc": "./docs",
22
+ "lib": "./lib",
23
+ "scripts": "./scripts",
24
+ "src": "./src",
25
+ "dist": "./dist"
26
+ },
27
+ "types": "./docs/types",
28
+ "scripts": {},
29
+ "homepage": "https://stdlib.io",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git://github.com/stdlib-js/blas-base-wasm-sdsdot.git"
33
+ },
34
+ "bugs": {
35
+ "url": "https://github.com/stdlib-js/stdlib/issues"
36
+ },
37
+ "dependencies": {
38
+ "@stdlib/assert-is-wasm-memory": "^0.1.0",
39
+ "@stdlib/blas-base-sdsdot": "^0.3.0",
40
+ "@stdlib/fs-read-wasm": "^0.2.2",
41
+ "@stdlib/strided-base-stride2offset": "^0.1.0",
42
+ "@stdlib/string-format": "^0.2.2",
43
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
44
+ "@stdlib/utils-inherit": "^0.2.2",
45
+ "@stdlib/wasm-base-arrays2ptrs": "github:stdlib-js/wasm-base-arrays2ptrs#main",
46
+ "@stdlib/wasm-base-strided2object": "github:stdlib-js/wasm-base-strided2object#main",
47
+ "@stdlib/wasm-memory": "^0.1.0",
48
+ "@stdlib/wasm-module-wrapper": "github:stdlib-js/wasm-module-wrapper#main",
49
+ "@stdlib/error-tools-fmtprodmsg": "^0.2.2"
50
+ },
51
+ "devDependencies": {},
52
+ "engines": {
53
+ "node": ">=0.10.0",
54
+ "npm": ">2.7.0"
55
+ },
56
+ "os": [
57
+ "aix",
58
+ "darwin",
59
+ "freebsd",
60
+ "linux",
61
+ "macos",
62
+ "openbsd",
63
+ "sunos",
64
+ "win32",
65
+ "windows"
66
+ ],
67
+ "keywords": [
68
+ "stdlib",
69
+ "stdmath",
70
+ "mathematics",
71
+ "math",
72
+ "blas",
73
+ "level 1",
74
+ "sdsdot",
75
+ "linear",
76
+ "algebra",
77
+ "subroutines",
78
+ "dot",
79
+ "vector",
80
+ "array",
81
+ "ndarray",
82
+ "float32",
83
+ "float",
84
+ "float32array",
85
+ "webassembly",
86
+ "wasm"
87
+ ],
88
+ "funding": {
89
+ "type": "opencollective",
90
+ "url": "https://opencollective.com/stdlib"
91
+ }
92
+ }
@@ -0,0 +1,4 @@
1
+ [
2
+ "_c_sdsdot",
3
+ "_c_sdsdot_ndarray"
4
+ ]
package/src/main.wasm ADDED
Binary file