Skip to content

Commit 58829a5

Browse files
committed
feat: add examples
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 7f2e898 commit 58829a5

File tree

3 files changed

+171
-0
lines changed

3 files changed

+171
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' );
22+
var oneTo = require( '@stdlib/array/one-to' );
23+
var dasumpw = require( './../lib' );
24+
25+
function main() {
26+
if ( !hasWebAssemblySupport() ) {
27+
console.error( 'Environment does not support WebAssembly.' );
28+
return;
29+
}
30+
// Specify a vector length:
31+
var N = 3;
32+
33+
// Create an input array:
34+
var x = oneTo( N, 'float64' );
35+
36+
// Perform computation:
37+
var sum = dasumpw.ndarray( N, x, 1, 0 );
38+
39+
// Print the result:
40+
console.log( sum );
41+
}
42+
43+
main();
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' );
22+
var Memory = require( '@stdlib/wasm/memory' );
23+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
24+
var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' );
25+
var Float64ArrayLE = require( '@stdlib/array/little-endian-float64' );
26+
var dasumpw = require( './../lib' );
27+
28+
function main() {
29+
if ( !hasWebAssemblySupport() ) {
30+
console.error( 'Environment does not support WebAssembly.' );
31+
return;
32+
}
33+
// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
34+
var mem = new Memory({
35+
'initial': 10,
36+
'maximum': 100
37+
});
38+
39+
// Create a BLAS routine:
40+
var mod = new dasumpw.Module( mem );
41+
// returns <Module>
42+
43+
// Initialize the routine:
44+
mod.initializeSync(); // eslint-disable-line node/no-sync
45+
46+
// Specify a vector length:
47+
var N = 3;
48+
49+
// Define a pointer (i.e., byte offset) for storing the input vector:
50+
var xptr = 0;
51+
52+
// Create a typed array view over module memory:
53+
var x = new Float64ArrayLE( mod.memory.buffer, xptr, N );
54+
55+
// Write values to module memory:
56+
gfillBy( N, x, 1, discreteUniform( -10.0, 10.0 ) );
57+
58+
// Perform computation:
59+
var sum = mod.ndarray( N, xptr, 1, 0 );
60+
61+
// Print the result:
62+
console.log( sum );
63+
}
64+
65+
main();
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
var hasWebAssemblySupport = require( '@stdlib/assert/has-wasm-support' );
22+
var Memory = require( '@stdlib/wasm/memory' );
23+
var oneTo = require( '@stdlib/array/one-to' );
24+
var dasumpw = require( './../lib' );
25+
26+
function main() {
27+
if ( !hasWebAssemblySupport() ) {
28+
console.error( 'Environment does not support WebAssembly.' );
29+
return;
30+
}
31+
// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
32+
var mem = new Memory({
33+
'initial': 10,
34+
'maximum': 100
35+
});
36+
37+
// Create a BLAS routine:
38+
var mod = new dasumpw.Module( mem );
39+
// returns <Module>
40+
41+
// Initialize the routine:
42+
mod.initializeSync(); // eslint-disable-line node/no-sync
43+
44+
// Define a vector data type:
45+
var dtype = 'float64';
46+
47+
// Specify a vector length:
48+
var N = 3;
49+
50+
// Define a pointer (i.e., byte offset) for storing the input vector:
51+
var xptr = 0;
52+
53+
// Write vector values to module memory:
54+
mod.write( xptr, oneTo( N, dtype ) );
55+
56+
// Perform computation:
57+
var sum = mod.ndarray( N, xptr, 1, 0 );
58+
59+
// Print the result:
60+
console.log( sum );
61+
}
62+
63+
main();

0 commit comments

Comments
 (0)