Skip to content

Commit 18a8394

Browse files
committed
feat: add examples and bench
--- 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: passed - 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: 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent deb41b8 commit 18a8394

File tree

4 files changed

+349
-0
lines changed

4 files changed

+349
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var pkg = require( './../package.json' ).name;
29+
var dlaset = require( './../lib/dlaset.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var LAYOUTS = [
35+
'row-major',
36+
'column-major'
37+
];
38+
39+
40+
// FUNCTIONS //
41+
42+
/**
43+
* Creates a benchmark function.
44+
*
45+
* @private
46+
* @param {string} order - storage layout
47+
* @param {PositiveInteger} N - number of elements along each dimension
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( order, N ) {
51+
var A;
52+
53+
A = uniform( N*N, -10.0, 10.0, {
54+
'dtype': 'float64'
55+
});
56+
return benchmark;
57+
58+
/**
59+
* Benchmark function.
60+
*
61+
* @private
62+
* @param {Benchmark} b - benchmark instance
63+
*/
64+
function benchmark( b ) {
65+
var z;
66+
var i;
67+
68+
b.tic();
69+
for ( i = 0; i < b.iterations; i++ ) {
70+
z = dlaset( order, 'all', N, N, A, N, 1.0, 0.0 );
71+
if ( isnan( z[ i%z.length ] ) ) {
72+
b.fail( 'should not return NaN' );
73+
}
74+
}
75+
b.toc();
76+
if ( isnan( z[ i%z.length ] ) ) {
77+
b.fail( 'should not return NaN' );
78+
}
79+
b.pass( 'benchmark finished' );
80+
b.end();
81+
}
82+
}
83+
84+
85+
// MAIN //
86+
87+
/**
88+
* Main execution sequence.
89+
*
90+
* @private
91+
*/
92+
function main() {
93+
var min;
94+
var max;
95+
var ord;
96+
var N;
97+
var f;
98+
var i;
99+
var k;
100+
101+
min = 1; // 10^min
102+
max = 6; // 10^max
103+
104+
for ( k = 0; k < LAYOUTS.length; k++ ) {
105+
ord = LAYOUTS[ k ];
106+
for ( i = min; i <= max; i++ ) {
107+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
108+
f = createBenchmark( ord, N );
109+
bench( pkg+'::square_matrix:order='+ord+',size='+(N*N), f );
110+
}
111+
}
112+
}
113+
114+
main();
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var floor = require( '@stdlib/math/base/special/floor' );
29+
var pkg = require( './../package.json' ).name;
30+
var dlaswp = require( './../lib/ndarray.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var LAYOUTS = [
36+
'row-major',
37+
'column-major'
38+
];
39+
40+
41+
// FUNCTIONS //
42+
43+
/**
44+
* Creates a benchmark function.
45+
*
46+
* @private
47+
* @param {string} order - storage layout
48+
* @param {PositiveInteger} N - number of elements along each dimension
49+
* @returns {Function} benchmark function
50+
*/
51+
function createBenchmark( order, N ) {
52+
var sa1;
53+
var sa2;
54+
var A;
55+
56+
if ( isColumnMajor( order ) ) {
57+
sa1 = 1;
58+
sa2 = N;
59+
} else { // order === 'row-major'
60+
sa1 = N;
61+
sa2 = 1;
62+
}
63+
A = uniform( N*N, -10.0, 10.0, {
64+
'dtype': 'float64'
65+
});
66+
return benchmark;
67+
68+
/**
69+
* Benchmark function.
70+
*
71+
* @private
72+
* @param {Benchmark} b - benchmark instance
73+
*/
74+
function benchmark( b ) {
75+
var z;
76+
var i;
77+
78+
b.tic();
79+
for ( i = 0; i < b.iterations; i++ ) {
80+
z = dlaswp( 'all', N, N, A, sa1, sa2, 0, 1.0, 0.0 );
81+
if ( isnan( z[ i%z.length ] ) ) {
82+
b.fail( 'should not return NaN' );
83+
}
84+
}
85+
b.toc();
86+
if ( isnan( z[ i%z.length ] ) ) {
87+
b.fail( 'should not return NaN' );
88+
}
89+
b.pass( 'benchmark finished' );
90+
b.end();
91+
}
92+
}
93+
94+
95+
// MAIN //
96+
97+
/**
98+
* Main execution sequence.
99+
*
100+
* @private
101+
*/
102+
function main() {
103+
var min;
104+
var max;
105+
var ord;
106+
var N;
107+
var f;
108+
var i;
109+
var k;
110+
111+
min = 1; // 10^min
112+
max = 6; // 10^max
113+
114+
for ( k = 0; k < LAYOUTS.length; k++ ) {
115+
ord = LAYOUTS[ k ];
116+
for ( i = min; i <= max; i++ ) {
117+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
118+
f = createBenchmark( ord, N );
119+
bench( pkg+'::square_matrix:order='+ord+',size='+(N*N), f );
120+
}
121+
}
122+
}
123+
124+
main();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
22+
var uniform = require( '@stdlib/random/array/discrete-uniform' );
23+
var numel = require( '@stdlib/ndarray/base/numel' );
24+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
25+
var dlaset = require( './../lib' );
26+
27+
var shape = [ 5, 8 ];
28+
var order = 'row-major';
29+
var strides = shape2strides( shape, order );
30+
31+
var N = numel( shape );
32+
33+
var A = uniform( N, -10, 10, {
34+
'dtype': 'float64'
35+
});
36+
console.log( ndarray2array( A, shape, strides, 0, order ) );
37+
38+
dlaset( order, 'all', shape[ 0 ], shape[ 1 ], A, strides[ 0 ], 2.0, 3.0 );
39+
console.log( ndarray2array( A, shape, strides, 0, order ) );
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"name": "@stdlib/lapack/base/dlaset",
3+
"version": "0.0.0",
4+
"description": "Initialises an M by N matrix `A` to `beta` on the diagonals and `alpha` on the off diagonals.",
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+
"directories": {
18+
"benchmark": "./benchmark",
19+
"doc": "./docs",
20+
"example": "./examples",
21+
"lib": "./lib",
22+
"test": "./test"
23+
},
24+
"types": "./docs/types",
25+
"scripts": {},
26+
"homepage": "https://github.com/stdlib-js/stdlib",
27+
"repository": {
28+
"type": "git",
29+
"url": "git://github.com/stdlib-js/stdlib.git"
30+
},
31+
"bugs": {
32+
"url": "https://github.com/stdlib-js/stdlib/issues"
33+
},
34+
"dependencies": {},
35+
"devDependencies": {},
36+
"engines": {
37+
"node": ">=0.10.0",
38+
"npm": ">2.7.0"
39+
},
40+
"os": [
41+
"aix",
42+
"darwin",
43+
"freebsd",
44+
"linux",
45+
"macos",
46+
"openbsd",
47+
"sunos",
48+
"win32",
49+
"windows"
50+
],
51+
"keywords": [
52+
"stdlib",
53+
"stdmath",
54+
"mathematics",
55+
"math",
56+
"lapack",
57+
"dlaset",
58+
"initialize",
59+
"set",
60+
"exchange",
61+
"permute",
62+
"permutedims",
63+
"linear",
64+
"algebra",
65+
"subroutines",
66+
"array",
67+
"ndarray",
68+
"float64",
69+
"double",
70+
"float64array"
71+
]
72+
}

0 commit comments

Comments
 (0)