Skip to content

Commit 7696b4b

Browse files
feat: added ext/base/wasm/dnanasumors
--- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed ---
1 parent befe02c commit 7696b4b

33 files changed

+4284
-1
lines changed

lib/node_modules/@stdlib/blas/ext/base/dnanasumors/manifest.json

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"options": {
3-
"task": "build"
3+
"task": "build",
4+
"wasm": false
45
},
56
"fields": [
67
{
@@ -27,6 +28,7 @@
2728
"confs": [
2829
{
2930
"task": "build",
31+
"wasm": false,
3032
"src": [
3133
"./src/main.c"
3234
],
@@ -49,6 +51,7 @@
4951
},
5052
{
5153
"task": "benchmark",
54+
"wasm": false,
5255
"src": [
5356
"./src/main.c"
5457
],
@@ -66,6 +69,25 @@
6669
},
6770
{
6871
"task": "examples",
72+
"wasm": false,
73+
"src": [
74+
"./src/main.c"
75+
],
76+
"include": [
77+
"./include"
78+
],
79+
"libraries": [],
80+
"libpath": [],
81+
"dependencies": [
82+
"@stdlib/math/base/assert/is-nan",
83+
"@stdlib/math/base/special/abs",
84+
"@stdlib/blas/base/shared",
85+
"@stdlib/strided/base/stride2offset"
86+
]
87+
},
88+
{
89+
"task": "build",
90+
"wasm": true,
6991
"src": [
7092
"./src/main.c"
7193
],
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' );
25+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
26+
var uniform = require( '@stdlib/random/base/uniform' );
27+
var filledarrayBy = require( '@stdlib/array/filled-by' );
28+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
29+
var pow = require( '@stdlib/math/base/special/pow' );
30+
var pkg = require( './../package.json' ).name;
31+
var dnanasumors = require( './../lib' );
32+
33+
34+
// VARIABLES //
35+
36+
var opts = {
37+
'skip': !hasWebAssemblySupport()
38+
};
39+
40+
41+
// FUNCTIONS //
42+
43+
/**
44+
* Returns a random number.
45+
*
46+
* @private
47+
* @returns {number} random number
48+
*/
49+
function rand() {
50+
if ( bernoulli( 0.5 ) < 1 ) {
51+
return uniform( -10.0, 10.0 );
52+
}
53+
return NaN;
54+
}
55+
56+
/**
57+
* Creates a benchmark function.
58+
*
59+
* @private
60+
* @param {PositiveInteger} len - array length
61+
* @returns {Function} benchmark function
62+
*/
63+
function createBenchmark( len ) {
64+
var x = filledarrayBy( len, 'float64', rand );
65+
return benchmark;
66+
67+
/**
68+
* Benchmark function.
69+
*
70+
* @private
71+
* @param {Benchmark} b - benchmark instance
72+
*/
73+
function benchmark( b ) {
74+
var sum;
75+
var i;
76+
77+
b.tic();
78+
for ( i = 0; i < b.iterations; i++ ) {
79+
sum = dnanasumors.main( x.length, x, 1 );
80+
if ( isnan( sum ) ) {
81+
b.fail( 'should not return NaN' );
82+
}
83+
}
84+
b.toc();
85+
if ( isnan( sum ) ) {
86+
b.fail( 'should not return NaN' );
87+
}
88+
b.pass( 'benchmark finished' );
89+
b.end();
90+
}
91+
}
92+
93+
94+
// MAIN //
95+
96+
/**
97+
* Main execution sequence.
98+
*
99+
* @private
100+
*/
101+
function main() {
102+
var len;
103+
var min;
104+
var max;
105+
var f;
106+
var i;
107+
108+
min = 1; // 10^min
109+
max = 6; // 10^max
110+
111+
for ( i = min; i <= max; i++ ) {
112+
len = pow( 10, i );
113+
f = createBenchmark( len );
114+
bench( pkg+':len='+len, opts, f );
115+
}
116+
}
117+
118+
main();
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
'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 dnanasumors = 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 dnanasumors.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+
});
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var bytesPerElement = require( '@stdlib/ndarray/base/bytes-per-element' );
25+
var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' );
26+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
27+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
28+
var pow = require( '@stdlib/math/base/special/pow' );
29+
var filledarrayBy = require( '@stdlib/array/filled-by' );
30+
var uniform = require( '@stdlib/random/base/uniform' );
31+
var Memory = require( '@stdlib/wasm/memory' );
32+
var pkg = require( './../package.json' ).name;
33+
var dnanasumors = require( './../lib' );
34+
35+
36+
// VARIABLES //
37+
38+
var opts = {
39+
'skip': !hasWebAssemblySupport()
40+
};
41+
var options = {
42+
'dtype': 'float64'
43+
};
44+
45+
46+
// FUNCTIONS //
47+
48+
/**
49+
* Returns a random number.
50+
*
51+
* @private
52+
* @returns {number} random number
53+
*/
54+
function rand() {
55+
if ( bernoulli( 0.5 ) < 1 ) {
56+
return uniform( -10.0, 10.0 );
57+
}
58+
return NaN;
59+
}
60+
61+
/**
62+
* Creates a benchmark function.
63+
*
64+
* @private
65+
* @param {PositiveInteger} len - array length
66+
* @returns {Function} benchmark function
67+
*/
68+
function createBenchmark( len ) {
69+
return benchmark;
70+
71+
/**
72+
* Benchmark function.
73+
*
74+
* @private
75+
* @param {Benchmark} b - benchmark instance
76+
*/
77+
function benchmark( b ) {
78+
var xptr;
79+
var mod;
80+
var mem;
81+
var sum;
82+
var nb;
83+
var i;
84+
85+
// Create a new BLAS routine interface:
86+
mem = new Memory({
87+
'initial': 0
88+
});
89+
mod = new dnanasumors.Module( mem );
90+
91+
// Initialize the module:
92+
mod.initializeSync(); // eslint-disable-line node/no-sync
93+
94+
// Reallocate the underlying memory to allow storing a vector:
95+
nb = bytesPerElement( options.dtype );
96+
mod.realloc( len * nb );
97+
98+
// Define a pointer (i.e., byte offset) to the first vector element:
99+
xptr = 0;
100+
101+
// Write random values to module memory:
102+
mod.write( xptr, filledarrayBy( len, options.dtype, rand ) );
103+
104+
b.tic();
105+
for ( i = 0; i < b.iterations; i++ ) {
106+
sum = mod.main( len, xptr, 1 );
107+
if ( isnan( sum ) ) {
108+
b.fail( 'should not return NaN' );
109+
}
110+
}
111+
b.toc();
112+
if ( isnan( sum ) ) {
113+
b.fail( 'should not return NaN' );
114+
}
115+
b.pass( 'benchmark finished' );
116+
b.end();
117+
}
118+
}
119+
120+
121+
// MAIN //
122+
123+
/**
124+
* Main execution sequence.
125+
*
126+
* @private
127+
*/
128+
function main() {
129+
var len;
130+
var min;
131+
var max;
132+
var f;
133+
var i;
134+
135+
min = 1; // 10^min
136+
max = 6; // 10^max
137+
138+
for ( i = min; i <= max; i++ ) {
139+
len = pow( 10, i );
140+
f = createBenchmark( len );
141+
bench( pkg+'::module,pointers:len='+len, opts, f );
142+
}
143+
}
144+
145+
main();

0 commit comments

Comments
 (0)