Skip to content

Commit a08782b

Browse files
committed
feat: add examples, benchmarks, ts files
--- 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: passed - 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: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 1b0f881 commit a08782b

File tree

7 files changed

+915
-1
lines changed

7 files changed

+915
-1
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 dorg2r = require( './../lib/dorg2r.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 - matrix order (N-by-N)
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( order, N ) {
51+
var work;
52+
var opts;
53+
var tau;
54+
var A;
55+
56+
opts = {
57+
'dtype': 'float64'
58+
};
59+
60+
// Random input matrix and auxiliary arrays:
61+
A = uniform( N*N, -1.0, 1.0, opts );
62+
tau = uniform( N, 0.1, 1.0, opts );
63+
work = uniform( N, 0.0, 0.0, opts );
64+
65+
return benchmark;
66+
67+
/**
68+
* Benchmark function.
69+
*
70+
* @private
71+
* @param {Benchmark} b - benchmark instance
72+
*/
73+
function benchmark( b ) {
74+
var z;
75+
var i;
76+
77+
b.tic();
78+
for ( i = 0; i < b.iterations; i++ ) {
79+
z = dorg2r( order, N, N, 0, A, N, tau, work );
80+
if ( isnan( z[ i%z.length ] ) ) {
81+
b.fail( 'should not return NaN' );
82+
}
83+
}
84+
b.toc();
85+
if ( isnan( z[ i%z.length ] ) ) {
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 min;
103+
var max;
104+
var ord;
105+
var N;
106+
var f;
107+
var i;
108+
var k;
109+
110+
min = 1; // 10^min
111+
max = 6; // 10^max
112+
113+
for ( k = 0; k < LAYOUTS.length; k++ ) {
114+
ord = LAYOUTS[ k ];
115+
for ( i = min; i <= max; i++ ) {
116+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
117+
f = createBenchmark( ord, N );
118+
bench( pkg+':order='+ord+',size='+(N*N), f );
119+
}
120+
}
121+
}
122+
123+
main();
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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 dorg2r = 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 - matrix order (N-by-N)
49+
* @returns {Function} benchmark function
50+
*/
51+
function createBenchmark( order, N ) {
52+
var work;
53+
var sa1;
54+
var sa2;
55+
var tau;
56+
var A;
57+
58+
if ( isColumnMajor( order ) ) {
59+
sa1 = 1;
60+
sa2 = N;
61+
} else {
62+
sa1 = N;
63+
sa2 = 1;
64+
}
65+
66+
A = uniform( N*N, -1.0, 1.0, {
67+
'dtype': 'float64'
68+
});
69+
tau = uniform( N, 0.1, 1.0, {
70+
'dtype': 'float64'
71+
});
72+
work = uniform( N, 0.0, 0.0, {
73+
'dtype': 'float64'
74+
});
75+
76+
return benchmark;
77+
78+
/**
79+
* Benchmark function.
80+
*
81+
* @private
82+
* @param {Benchmark} b - benchmark instance
83+
*/
84+
function benchmark( b ) {
85+
var z;
86+
var i;
87+
88+
b.tic();
89+
for ( i = 0; i < b.iterations; i++ ) {
90+
z = dorg2r( N, N, 0, A, sa1, sa2, 0, tau, 1, 0, work, 1, 0 );
91+
if ( isnan( z[ i%z.length ] ) ) {
92+
b.fail( 'should not return NaN' );
93+
}
94+
}
95+
b.toc();
96+
if ( isnan( z[ i%z.length ] ) ) {
97+
b.fail( 'should not return NaN' );
98+
}
99+
b.pass( 'benchmark finished' );
100+
b.end();
101+
}
102+
}
103+
104+
105+
// MAIN //
106+
107+
/**
108+
* Main execution sequence.
109+
*
110+
* @private
111+
*/
112+
function main() {
113+
var min;
114+
var max;
115+
var ord;
116+
var N;
117+
var f;
118+
var i;
119+
var k;
120+
121+
min = 1; // 10^min
122+
max = 6; // 10^max
123+
124+
for ( k = 0; k < LAYOUTS.length; k++ ) {
125+
ord = LAYOUTS[ k ];
126+
for ( i = min; i <= max; i++ ) {
127+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
128+
f = createBenchmark( ord, N );
129+
bench( pkg+':ndarray:order='+ord+',size='+(N*N), f );
130+
}
131+
}
132+
}
133+
134+
main();
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { Layout } from '@stdlib/types/blas';
24+
25+
/**
26+
* Interface describing `dorg2r`.
27+
*/
28+
interface Routine {
29+
/**
30+
* Generates an `M`-by-`N` real matrix `Q` with orthonormal columns. The matrix `Q` is defined as the first `N` columns of a product of `K` elementary reflectors of order `M`. `Q = H(1) H(2) . . . H(K)` as returned by `dgeqrf`.
31+
*
32+
*
33+
* @param order - storage layout
34+
* @param M - number of rows in `A`
35+
* @param N - number of columns in `A`
36+
* @param K - number of elementary reflectors whose product defines the matrix `Q`
37+
* @param A - input matrix (overwritten with `Q` on output)
38+
* @param LDA - stride of the first dimension of `A` (leading dimension)
39+
* @param tau - vector of `K` scalar factors of the elementary reflectors
40+
* @param work - workspace array
41+
* @returns matrix `A` overwritten with the orthogonal matrix `Q`
42+
*
43+
* @example
44+
* var Float64Array = require( '@stdlib/array/float64' );
45+
* var dorg2r = require( '@stdlib/lapack/base/dorg2r' );
46+
*
47+
* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
48+
* var tau = new Float64Array( [ 0.0, 0.0 ] );
49+
* var work = new Float64Array( 10 );
50+
*
51+
* dorg2r( 'column-major', 3, 2, 2, A, 3, tau, work );
52+
* // A => <Float64Array>[ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 ]
53+
*/
54+
( order: Layout, M: number, N: number, K: number, A: Float64Array, LDA: number, tau: Float64Array, work: Float64Array ): Float64Array;
55+
56+
/**
57+
* Generates an `M`-by-`N` real matrix `Q` with orthonormal columns using alternative indexing semantics. The matrix `Q` is defined as the first `N` columns of a product of `K` elementary reflectors of order `M`. `Q = H(1) H(2) . . . H(K)` as returned by `dgeqrf`.
58+
*
59+
* @param M - number of rows in `A`
60+
* @param N - number of columns in `A`
61+
* @param K - number of elementary reflectors
62+
* @param A - input matrix
63+
* @param strideA1 - stride of the first dimension of `A`
64+
* @param strideA2 - stride of the second dimension of `A`
65+
* @param offsetA - index offset for `A`
66+
* @param tau - vector of scalar factors of the elementary reflectors
67+
* @param strideTau - stride length for `tau`
68+
* @param offsetTau - index offset for `tau`
69+
* @param work - workspace array
70+
* @param strideWork - stride length for `work`
71+
* @param offsetWork - index offset for `work`
72+
* @returns matrix `A` overwritten with the orthogonal matrix `Q`
73+
*
74+
* @example
75+
* var Float64Array = require( '@stdlib/array/float64' );
76+
* var dorg2r = require( '@stdlib/lapack/base/dorg2r' );
77+
*
78+
* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
79+
* var tau = new Float64Array( [ 0.0, 0.0 ] );
80+
* var work = new Float64Array( 10 );
81+
*
82+
* dorg2r.ndarray( 3, 2, 2, A, 1, 3, 0, tau, 1, 0, work, 1, 0 );
83+
* // A => <Float64Array>[ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 ]
84+
*/
85+
ndarray( M: number, N: number, K: number, A: Float64Array, strideA1: number, strideA2: number, offsetA: number, tau: Float64Array, strideTau: number, offsetTau: number, work: Float64Array, strideWork: number, offsetWork: number ): Float64Array; // eslint-disable-line max-len
86+
}
87+
88+
/**
89+
* Generates an `M`-by-`N` real matrix `Q` with orthonormal columns. The matrix `Q` is defined as the first `N` columns of a product of `K` elementary reflectors of order `M`. `Q = H(1) H(2) . . . H(K)` as returned by `dgeqrf`.
90+
*
91+
* @param order - storage layout
92+
* @param M - number of rows in `A`
93+
* @param N - number of columns in `A`
94+
* @param K - number of elementary reflectors whose product defines the matrix `Q`
95+
* @param A - input matrix (overwritten with `Q` on output)
96+
* @param LDA - stride of the first dimension of `A` (leading dimension)
97+
* @param tau - vector of `K` scalar factors of the elementary reflectors
98+
* @param work - workspace array
99+
* @returns matrix `A` overwritten with the orthogonal matrix `Q`
100+
*
101+
* @example
102+
* var Float64Array = require( '@stdlib/array/float64' );
103+
* var dorg2r = require( '@stdlib/lapack/base/dorg2r' );
104+
*
105+
* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
106+
* var tau = new Float64Array( [ 0.0, 0.0 ] );
107+
* var work = new Float64Array( 10 );
108+
*
109+
* dorg2r( 'column-major', 3, 2, 2, A, 3, tau, work );
110+
* // A => <Float64Array>[ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 ]
111+
*
112+
* @example
113+
* var Float64Array = require( '@stdlib/array/float64' );
114+
* var dorg2r = require( '@stdlib/lapack/base/dorg2r' );
115+
*
116+
* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
117+
* var tau = new Float64Array( [ 0.0, 0.0 ] );
118+
* var work = new Float64Array( 10 );
119+
*
120+
* dorg2r.ndarray( 3, 2, 2, A, 1, 3, 0, tau, 1, 0, work, 1, 0 );
121+
* // A => <Float64Array>[ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 ]
122+
*/
123+
declare var dorg2r: Routine;
124+
125+
126+
// EXPORTS //
127+
128+
export = dorg2r;

0 commit comments

Comments
 (0)