@stdlib/blas-base-wasm-scasum 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,198 @@
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
+ *
47
+ * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
48
+ * var mem = new Memory({
49
+ * 'initial': 10,
50
+ * 'maximum': 100
51
+ * });
52
+ *
53
+ * // Create a BLAS routine:
54
+ * var scasum = new Module( mem );
55
+ * // returns <Module>
56
+ *
57
+ * // Initialize the routine:
58
+ * scasum.initializeSync();
59
+ *
60
+ * // Define a vector data type:
61
+ * var dtype = 'complex64';
62
+ *
63
+ * // Specify a vector length:
64
+ * var N = 4;
65
+ *
66
+ * // Define a pointer (i.e., byte offset) for storing the input vector:
67
+ * var xptr = 0;
68
+ *
69
+ * // Write vector values to module memory:
70
+ * scasum.write( xptr, oneTo( N, dtype ) );
71
+ *
72
+ * // Perform computation:
73
+ * var sum = scasum.main( N, xptr, 1 );
74
+ * // returns 10.0
75
+ */
76
+ function Module( memory ) {
77
+ if ( !( this instanceof Module ) ) {
78
+ return new Module( memory );
79
+ }
80
+ if ( !isWebAssemblyMemory( memory ) ) {
81
+ throw new TypeError( format( 'invalid argument. Must provide a WebAssembly memory instance. Value: `%s`.', memory ) );
82
+ }
83
+ // Call the parent constructor:
84
+ WasmModule.call( this, wasmBinary, memory, {
85
+ 'env': {
86
+ 'memory': memory
87
+ }
88
+ });
89
+
90
+ return this;
91
+ }
92
+
93
+ // Inherit from the parent constructor:
94
+ inherits( Module, WasmModule );
95
+
96
+ /**
97
+ * Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector.
98
+ *
99
+ * @name main
100
+ * @memberof Module.prototype
101
+ * @readonly
102
+ * @type {Function}
103
+ * @param {PositiveInteger} N - number of indexed elements
104
+ * @param {NonNegativeInteger} xptr - input array pointer (i.e., byte offset)
105
+ * @param {integer} strideX - `x` stride length
106
+ * @returns {number} sum of absolute values
107
+ *
108
+ * @example
109
+ * var Memory = require( '@stdlib/wasm-memory' );
110
+ * var oneTo = require( '@stdlib/array-one-to' );
111
+ *
112
+ * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
113
+ * var mem = new Memory({
114
+ * 'initial': 10,
115
+ * 'maximum': 100
116
+ * });
117
+ *
118
+ * // Create a BLAS routine:
119
+ * var scasum = new Module( mem );
120
+ * // returns <Module>
121
+ *
122
+ * // Initialize the routine:
123
+ * scasum.initializeSync();
124
+ *
125
+ * // Define a vector data type:
126
+ * var dtype = 'complex64';
127
+ *
128
+ * // Specify a vector length:
129
+ * var N = 4;
130
+ *
131
+ * // Define a pointer (i.e., byte offset) for storing the input vector:
132
+ * var xptr = 0;
133
+ *
134
+ * // Write vector values to module memory:
135
+ * scasum.write( xptr, oneTo( N, dtype ) );
136
+ *
137
+ * // Perform computation:
138
+ * var sum = scasum.main( N, xptr, 1 );
139
+ * // returns 10.0
140
+ */
141
+ setReadOnly( Module.prototype, 'main', function scasum( N, xptr, strideX ) {
142
+ return this._instance.exports.c_scasum( N, xptr, strideX );
143
+ });
144
+
145
+ /**
146
+ * Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector using alternative indexing semantics.
147
+ *
148
+ * @name ndarray
149
+ * @memberof Module.prototype
150
+ * @readonly
151
+ * @type {Function}
152
+ * @param {PositiveInteger} N - number of indexed elements
153
+ * @param {NonNegativeInteger} xptr - input array pointer (i.e., byte offset)
154
+ * @param {integer} strideX - `x` stride length
155
+ * @param {NonNegativeInteger} offsetX - starting index for `x`
156
+ * @returns {number} sum of absolute values
157
+ *
158
+ * @example
159
+ * var Memory = require( '@stdlib/wasm-memory' );
160
+ * var oneTo = require( '@stdlib/array-one-to' );
161
+ *
162
+ * // Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
163
+ * var mem = new Memory({
164
+ * 'initial': 10,
165
+ * 'maximum': 100
166
+ * });
167
+ *
168
+ * // Create a BLAS routine:
169
+ * var scasum = new Module( mem );
170
+ * // returns <Module>
171
+ *
172
+ * // Initialize the routine:
173
+ * scasum.initializeSync();
174
+ *
175
+ * // Define a vector data type:
176
+ * var dtype = 'complex64';
177
+ *
178
+ * // Specify a vector length:
179
+ * var N = 4;
180
+ *
181
+ * // Define a pointer (i.e., byte offset) for storing the input vector:
182
+ * var xptr = 0;
183
+ *
184
+ * // Write vector values to module memory:
185
+ * scasum.write( xptr, oneTo( N, dtype ) );
186
+ *
187
+ * // Perform computation:
188
+ * var sum = scasum.ndarray( N, xptr, 1, 0 );
189
+ * // returns 10.0
190
+ */
191
+ setReadOnly( Module.prototype, 'ndarray', function scasum( N, xptr, strideX, offsetX ) {
192
+ return this._instance.exports.c_scasum_ndarray( N, xptr, strideX, offsetX );
193
+ });
194
+
195
+
196
+ // EXPORTS //
197
+
198
+ module.exports = Module;
package/lib/routine.js ADDED
@@ -0,0 +1,166 @@
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 max-len, 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 Complex64Array = require( '@stdlib/array-complex64' );
45
+ *
46
+ * // Create a new routine:
47
+ * var scasum = new Routine();
48
+ *
49
+ * // Initialize the module:
50
+ * scasum.initializeSync();
51
+ *
52
+ * // Define a strided array:
53
+ * var x = new Complex64Array( [ 2.0, 1.0, 3.0, 5.0, 4.0, 0.0, 1.0, 3.0 ]);
54
+ *
55
+ * // Perform operation:
56
+ * var sum = scasum.main( x.length, x, 1 );
57
+ * // returns 19.0
58
+ *
59
+ * @example
60
+ * var Complex64Array = require( '@stdlib/array-complex64' );
61
+ *
62
+ * // Create a new routine:
63
+ * var scasum = new Routine();
64
+ *
65
+ * // Initialize the module:
66
+ * scasum.initializeSync();
67
+ *
68
+ * // Define a strided array:
69
+ * var x = new Complex64Array( [ 2.0, 1.0, 3.0, 5.0, 4.0, 0.0, 1.0, 3.0 ]);
70
+ *
71
+ * // Perform operation:
72
+ * var sum = scasum.ndarray( x.length, x, 1, 0 );
73
+ * // returns 19.0
74
+ */
75
+ function Routine() {
76
+ if ( !( this instanceof Routine ) ) {
77
+ return new Routine();
78
+ }
79
+ Module.call( this, new Memory({
80
+ 'initial': 0
81
+ }));
82
+ return this;
83
+ }
84
+
85
+ // Inherit from the parent constructor:
86
+ inherits( Routine, Module );
87
+
88
+ /**
89
+ * Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector.
90
+ *
91
+ * @name main
92
+ * @memberof Routine.prototype
93
+ * @readonly
94
+ * @type {Function}
95
+ * @param {PositiveInteger} N - number of indexed elements
96
+ * @param {Float32Array} x - input array
97
+ * @param {integer} strideX - `x` stride length
98
+ * @returns {number} sum of absolute values
99
+ *
100
+ * @example
101
+ * var Complex64Array = require( '@stdlib/array-complex64' );
102
+ *
103
+ * // Create a new routine:
104
+ * var scasum = new Routine();
105
+ *
106
+ * // Initialize the module:
107
+ * scasum.initializeSync();
108
+ *
109
+ * // Define a strided array:
110
+ * var x = new Complex64Array( [ 2.0, 1.0, 3.0, 5.0, 4.0, 0.0, 1.0, 3.0 ]);
111
+ *
112
+ * // Perform operation:
113
+ * var sum = scasum.main( x.length, x, 1 );
114
+ * // returns 19.0
115
+ */
116
+ setReadOnly( Routine.prototype, 'main', function scasum( N, x, strideX ) {
117
+ return this.ndarray( N, x, strideX, stride2offset( N, strideX ) );
118
+ });
119
+
120
+ /**
121
+ * Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector using alternative indexing semantics.
122
+ *
123
+ * @name ndarray
124
+ * @memberof Routine.prototype
125
+ * @readonly
126
+ * @type {Function}
127
+ * @param {PositiveInteger} N - number of indexed elements
128
+ * @param {Float32Array} x - input array
129
+ * @param {integer} strideX - `x` stride length
130
+ * @param {NonNegativeInteger} offsetX - starting `x` index
131
+ * @returns {number} sum of absolute values
132
+ *
133
+ * @example
134
+ * var Complex64Array = require( '@stdlib/array-complex64' );
135
+ *
136
+ * // Create a new routine:
137
+ * var scasum = new Routine();
138
+ *
139
+ * // Initialize the module:
140
+ * scasum.initializeSync();
141
+ *
142
+ * // Define a strided array:
143
+ * var x = new Complex64Array( [ 2.0, 1.0, 3.0, 5.0, 4.0, 0.0, 1.0, 3.0 ]);
144
+ *
145
+ * // Perform operation:
146
+ * var sum = scasum.ndarray( x.length, x, 1, 0 );
147
+ * // returns 19.0
148
+ */
149
+ setReadOnly( Routine.prototype, 'ndarray', function scasum( N, x, strideX, offsetX ) {
150
+ var ptrs;
151
+ var p0;
152
+
153
+ // Convert the input arrays to "pointers" in the module's memory:
154
+ ptrs = arrays2ptrs( this, [
155
+ strided2object( N, x, strideX, offsetX )
156
+ ]);
157
+ p0 = ptrs[ 0 ];
158
+
159
+ // Perform computation by calling the corresponding parent method:
160
+ return Module.prototype.ndarray.call( this, N, p0.ptr, p0.stride, p0.offset );
161
+ });
162
+
163
+
164
+ // EXPORTS //
165
+
166
+ 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-scasum"
33
+ ]
34
+ }
35
+ ]
36
+ }
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "@stdlib/blas-base-wasm-scasum",
3
+ "version": "0.1.0",
4
+ "description": "Compute the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector.",
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-scasum.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-scasum": "^0.2.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
+ "scasum",
75
+ "linear",
76
+ "algebra",
77
+ "subroutines",
78
+ "sum",
79
+ "vector",
80
+ "array",
81
+ "ndarray",
82
+ "complex64",
83
+ "complex",
84
+ "complex64array",
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_scasum",
3
+ "_c_scasum_ndarray"
4
+ ]
package/src/main.wasm ADDED
Binary file
package/src/main.wat ADDED
@@ -0,0 +1,93 @@
1
+ ;; @license Apache-2.0
2
+ ;;
3
+ ;; Copyright (c) 2025 The Stdlib Authors.
4
+ ;;
5
+ ;; Licensed under the Apache License, Version 2.0 (the "License");
6
+ ;; you may not use this file except in compliance with the License.
7
+ ;; You may obtain a copy of the License at
8
+ ;;
9
+ ;; http://www.apache.org/licenses/LICENSE-2.0
10
+ ;;
11
+ ;; Unless required by applicable law or agreed to in writing, software
12
+ ;; distributed under the License is distributed on an "AS IS" BASIS,
13
+ ;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ ;; See the License for the specific language governing permissions and
15
+ ;; limitations under the License.
16
+
17
+ (module
18
+ (type (;0;) (func))
19
+ (type (;1;) (func (param i32 i32 i32) (result f32)))
20
+ (type (;2;) (func (param i32 i32 i32 i32) (result f32)))
21
+ (import "env" "memory" (memory (;0;) 0))
22
+ (func (;0;) (type 0)
23
+ nop)
24
+ (func (;1;) (type 1) (param i32 i32 i32) (result f32)
25
+ local.get 0
26
+ local.get 1
27
+ local.get 2
28
+ i32.const 1
29
+ local.get 0
30
+ i32.sub
31
+ local.get 2
32
+ i32.mul
33
+ i32.const 0
34
+ local.get 2
35
+ i32.const 0
36
+ i32.le_s
37
+ select
38
+ call 2)
39
+ (func (;2;) (type 2) (param i32 i32 i32 i32) (result f32)
40
+ (local f32 i32 i32)
41
+ block ;; label = @1
42
+ local.get 0
43
+ i32.const 0
44
+ i32.le_s
45
+ if ;; label = @2
46
+ br 1 (;@1;)
47
+ end
48
+ local.get 3
49
+ i32.const 1
50
+ i32.shl
51
+ local.set 5
52
+ local.get 2
53
+ i32.const 1
54
+ i32.shl
55
+ local.set 2
56
+ i32.const 0
57
+ local.set 3
58
+ loop ;; label = @2
59
+ local.get 0
60
+ local.get 3
61
+ i32.eq
62
+ br_if 1 (;@1;)
63
+ local.get 4
64
+ local.get 1
65
+ local.get 5
66
+ i32.const 2
67
+ i32.shl
68
+ i32.add
69
+ local.tee 6
70
+ f32.load
71
+ f32.abs
72
+ local.get 6
73
+ f32.load offset=4
74
+ f32.abs
75
+ f32.add
76
+ f32.add
77
+ local.set 4
78
+ local.get 3
79
+ i32.const 1
80
+ i32.add
81
+ local.set 3
82
+ local.get 2
83
+ local.get 5
84
+ i32.add
85
+ local.set 5
86
+ br 0 (;@2;)
87
+ end
88
+ unreachable
89
+ end
90
+ local.get 4)
91
+ (export "__wasm_call_ctors" (func 0))
92
+ (export "c_scasum" (func 1))
93
+ (export "c_scasum_ndarray" (func 2)))