Skip to content

Commit c18d344

Browse files
committed
feat: add blas/base/wasm/cscal
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 3fc841d commit c18d344

33 files changed

+5761
-0
lines changed

lib/node_modules/@stdlib/blas/base/wasm/cscal/README.md

+430
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 bench = require( '@stdlib/bench' );
24+
var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var Complex64Array = require( '@stdlib/array/complex64' );
29+
var Complex64 = require( '@stdlib/complex/float32/ctor' );
30+
var pkg = require( './../package.json' ).name;
31+
var cscal = require( './../lib' );
32+
33+
34+
// VARIABLES //
35+
36+
var opts = {
37+
'skip': !hasWebAssemblySupport()
38+
};
39+
var options = {
40+
'dtype': 'float32'
41+
};
42+
43+
44+
// FUNCTIONS //
45+
46+
/**
47+
* Creates a benchmark function.
48+
*
49+
* @private
50+
* @param {PositiveInteger} len - array length
51+
* @returns {Function} benchmark function
52+
*/
53+
function createBenchmark( len ) {
54+
var xbuf;
55+
var x;
56+
var z;
57+
58+
xbuf = uniform( len*2, -100.0, 100.0, options );
59+
x = new Complex64Array( xbuf.buffer );
60+
61+
z = new Complex64( 1.0, 0.0 );
62+
63+
return benchmark;
64+
65+
/**
66+
* Benchmark function.
67+
*
68+
* @private
69+
* @param {Benchmark} b - benchmark instance
70+
*/
71+
function benchmark( b ) {
72+
var i;
73+
74+
b.tic();
75+
for ( i = 0; i < b.iterations; i++ ) {
76+
cscal.main( x.length, z, x, 1 );
77+
if ( isnanf( xbuf[ i%(len*2) ] ) ) {
78+
b.fail( 'should not return NaN' );
79+
}
80+
}
81+
b.toc();
82+
if ( isnanf( xbuf[ i%(len*2) ] ) ) {
83+
b.fail( 'should not return NaN' );
84+
}
85+
b.pass( 'benchmark finished' );
86+
b.end();
87+
}
88+
}
89+
90+
91+
// MAIN //
92+
93+
/**
94+
* Main execution sequence.
95+
*
96+
* @private
97+
*/
98+
function main() {
99+
var len;
100+
var min;
101+
var max;
102+
var f;
103+
var i;
104+
105+
min = 1; // 10^min
106+
max = 6; // 10^max
107+
108+
for ( i = min; i <= max; i++ ) {
109+
len = pow( 10, i );
110+
f = createBenchmark( len );
111+
bench( pkg+':len='+len, opts, f );
112+
}
113+
}
114+
115+
main();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 bench = require( '@stdlib/bench' );
24+
var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' );
25+
var Memory = require( '@stdlib/wasm/memory' );
26+
var pkg = require( './../package.json' ).name;
27+
var cscal = require( './../lib' );
28+
29+
30+
// VARIABLES //
31+
32+
var opts = {
33+
'skip': !hasWebAssemblySupport()
34+
};
35+
36+
37+
// MAIN //
38+
39+
bench( pkg+':Module:constructor', opts, function benchmark( b ) {
40+
var values;
41+
var o;
42+
var v;
43+
var i;
44+
45+
o = {
46+
'initial': 0
47+
};
48+
values = [
49+
new Memory( o ),
50+
new Memory( o )
51+
];
52+
53+
b.tic();
54+
for ( i = 0; i < b.iterations; i++ ) {
55+
v = new cscal.Module( values[ i%values.length ] );
56+
if ( typeof v !== 'object' ) {
57+
b.fail( 'should return an object' );
58+
}
59+
}
60+
b.toc();
61+
if ( typeof v !== 'object' ) {
62+
b.fail( 'should return an object' );
63+
}
64+
b.pass( 'benchmark finished' );
65+
b.end();
66+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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 bench = require( '@stdlib/bench' );
24+
var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' );
25+
var Memory = require( '@stdlib/wasm/memory' );
26+
var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' );
27+
var uniform = require( '@stdlib/random/array/uniform' );
28+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
29+
var pow = require( '@stdlib/math/base/special/pow' );
30+
var Float32Array = require( '@stdlib/array/float32' );
31+
var pkg = require( './../package.json' ).name;
32+
var cscal = require( './../lib' );
33+
34+
35+
// VARIABLES //
36+
37+
var opts = {
38+
'skip': !hasWebAssemblySupport()
39+
};
40+
var options = {
41+
'dtype': 'float32'
42+
};
43+
44+
45+
// FUNCTIONS //
46+
47+
/**
48+
* Creates a benchmark function.
49+
*
50+
* @private
51+
* @param {PositiveInteger} len - array length
52+
* @returns {Function} benchmark function
53+
*/
54+
function createBenchmark( len ) {
55+
return benchmark;
56+
57+
/**
58+
* Benchmark function.
59+
*
60+
* @private
61+
* @param {Benchmark} b - benchmark instance
62+
*/
63+
function benchmark( b ) {
64+
var byteOffset;
65+
var view;
66+
var xptr;
67+
var zptr;
68+
var mod;
69+
var mem;
70+
var nb;
71+
var N;
72+
var i;
73+
74+
N = len * 2;
75+
76+
// Create a new BLAS routine interface:
77+
mem = new Memory({
78+
'initial': 0
79+
});
80+
mod = new cscal.Module( mem );
81+
82+
// Initialize the module:
83+
mod.initializeSync(); // eslint-disable-line node/no-sync
84+
85+
// Reallocate the underlying memory to allow storing one vector and a complex number:
86+
nb = bytesPerElement( 'complex64' );
87+
mod.realloc( (N*nb)+nb );
88+
89+
// Define a pointer (i.e., byte offset) to the first vector element:
90+
xptr = 0;
91+
92+
// Define a pointer to a complex number:
93+
zptr = N * nb;
94+
95+
// Write random values to module memory:
96+
mod.write( xptr, uniform( N, -100.0, 100.0, options ) );
97+
mod.write( zptr, new Float32Array( [ 1.0, 0.0 ] ) );
98+
99+
// Retrieve a DataView of module memory:
100+
view = mod.view;
101+
102+
b.tic();
103+
for ( i = 0; i < b.iterations; i++ ) {
104+
mod.main( len, zptr, xptr, 1 );
105+
byteOffset = xptr + ( (i%len)*nb );
106+
if ( isnanf( view.getFloat32( byteOffset, true ) ) ) {
107+
b.fail( 'should not return NaN' );
108+
}
109+
}
110+
b.toc();
111+
if ( isnanf( view.getFloat32( byteOffset, true ) ) ) {
112+
b.fail( 'should not return NaN' );
113+
}
114+
b.pass( 'benchmark finished' );
115+
b.end();
116+
}
117+
}
118+
119+
120+
// MAIN //
121+
122+
/**
123+
* Main execution sequence.
124+
*
125+
* @private
126+
*/
127+
function main() {
128+
var len;
129+
var min;
130+
var max;
131+
var f;
132+
var i;
133+
134+
min = 1; // 10^min
135+
max = 6; // 10^max
136+
137+
for ( i = min; i <= max; i++ ) {
138+
len = pow( 10, i );
139+
f = createBenchmark( len );
140+
bench( pkg+'::module,pointers:len='+len, opts, f );
141+
}
142+
}
143+
144+
main();

0 commit comments

Comments
 (0)