Skip to content

Commit 69ccb2a

Browse files
headlessNodekgryte
andauthored
feat: add blas/ext/base/cindex-of-row
PR-URL: #11233 Closes: stdlib-js/metr-issue-tracker#222 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent d479058 commit 69ccb2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+5491
-0
lines changed

lib/node_modules/@stdlib/blas/ext/base/cindex-of-row/README.md

Lines changed: 450 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var zeros = require( '@stdlib/array/zeros' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var floor = require( '@stdlib/math/base/special/floor' );
29+
var Complex64Array = require( '@stdlib/array/complex64' );
30+
var format = require( '@stdlib/string/format' );
31+
var pkg = require( './../package.json' ).name;
32+
var cindexOfRow = require( './../lib/cindex_of_row.js' );
33+
34+
35+
// VARIABLES //
36+
37+
var LAYOUTS = [
38+
'row-major',
39+
'column-major'
40+
];
41+
var options = {
42+
'dtype': 'float32'
43+
};
44+
45+
46+
// FUNCTIONS //
47+
48+
/**
49+
* Creates a benchmark function.
50+
*
51+
* @private
52+
* @param {string} order - storage layout
53+
* @param {PositiveInteger} N - number of elements along each dimension
54+
* @returns {Function} benchmark function
55+
*/
56+
function createBenchmark( order, N ) {
57+
var workspace;
58+
var abuf;
59+
var xbuf;
60+
var A;
61+
var x;
62+
63+
workspace = zeros( N, 'uint8' );
64+
abuf = uniform( N*N*2, -100.0, 100.0, options );
65+
A = new Complex64Array( abuf.buffer );
66+
xbuf = uniform( N*2, 200.0, 300.0, options );
67+
x = new Complex64Array( xbuf.buffer );
68+
69+
return benchmark;
70+
71+
/**
72+
* Benchmark function.
73+
*
74+
* @private
75+
* @param {Benchmark} b - benchmark instance
76+
*/
77+
function benchmark( b ) {
78+
var z;
79+
var i;
80+
81+
b.tic();
82+
for ( i = 0; i < b.iterations; i++ ) {
83+
z = cindexOfRow( order, N, N, A, N, x, 1, workspace, 1 );
84+
if ( isnanf( z ) ) {
85+
b.fail( 'should not return NaN' );
86+
}
87+
}
88+
b.toc();
89+
if ( isnanf( z ) ) {
90+
b.fail( 'should not return NaN' );
91+
}
92+
b.pass( 'benchmark finished' );
93+
b.end();
94+
}
95+
}
96+
97+
98+
// MAIN //
99+
100+
/**
101+
* Main execution sequence.
102+
*
103+
* @private
104+
*/
105+
function main() {
106+
var min;
107+
var max;
108+
var ord;
109+
var N;
110+
var f;
111+
var i;
112+
var k;
113+
114+
min = 1; // 10^min
115+
max = 6; // 10^max
116+
117+
for ( k = 0; k < LAYOUTS.length; k++ ) {
118+
ord = LAYOUTS[ k ];
119+
for ( i = min; i <= max; i++ ) {
120+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
121+
f = createBenchmark( ord, N );
122+
bench( format( '%s::square_matrix:order=%s,size=%d', pkg, ord, N*N ), f );
123+
}
124+
}
125+
}
126+
127+
main();
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var uniform = require( '@stdlib/random/array/uniform' );
27+
var zeros = require( '@stdlib/array/zeros' );
28+
var pow = require( '@stdlib/math/base/special/pow' );
29+
var floor = require( '@stdlib/math/base/special/floor' );
30+
var Complex64Array = require( '@stdlib/array/complex64' );
31+
var tryRequire = require( '@stdlib/utils/try-require' );
32+
var format = require( '@stdlib/string/format' );
33+
var pkg = require( './../package.json' ).name;
34+
35+
36+
// VARIABLES //
37+
38+
var cindexOfRow = tryRequire( resolve( __dirname, './../lib/cindex_of_row.native.js' ) );
39+
var opts = {
40+
'skip': ( cindexOfRow instanceof Error )
41+
};
42+
var LAYOUTS = [
43+
'row-major',
44+
'column-major'
45+
];
46+
var options = {
47+
'dtype': 'float32'
48+
};
49+
50+
51+
// FUNCTIONS //
52+
53+
/**
54+
* Creates a benchmark function.
55+
*
56+
* @private
57+
* @param {string} order - storage layout
58+
* @param {PositiveInteger} N - number of elements along each dimension
59+
* @returns {Function} benchmark function
60+
*/
61+
function createBenchmark( order, N ) {
62+
var workspace;
63+
var abuf;
64+
var xbuf;
65+
var A;
66+
var x;
67+
68+
workspace = zeros( N, 'uint8' );
69+
abuf = uniform( N*N*2, -100.0, 100.0, options );
70+
A = new Complex64Array( abuf.buffer );
71+
xbuf = uniform( N*2, 200.0, 300.0, options );
72+
x = new Complex64Array( xbuf.buffer );
73+
74+
return benchmark;
75+
76+
/**
77+
* Benchmark function.
78+
*
79+
* @private
80+
* @param {Benchmark} b - benchmark instance
81+
*/
82+
function benchmark( b ) {
83+
var z;
84+
var i;
85+
86+
b.tic();
87+
for ( i = 0; i < b.iterations; i++ ) {
88+
z = cindexOfRow( order, N, N, A, N, x, 1, workspace, 1 );
89+
if ( isnanf( z ) ) {
90+
b.fail( 'should not return NaN' );
91+
}
92+
}
93+
b.toc();
94+
if ( isnanf( z ) ) {
95+
b.fail( 'should not return NaN' );
96+
}
97+
b.pass( 'benchmark finished' );
98+
b.end();
99+
}
100+
}
101+
102+
103+
// MAIN //
104+
105+
/**
106+
* Main execution sequence.
107+
*
108+
* @private
109+
*/
110+
function main() {
111+
var min;
112+
var max;
113+
var ord;
114+
var N;
115+
var f;
116+
var i;
117+
var k;
118+
119+
min = 1; // 10^min
120+
max = 6; // 10^max
121+
122+
for ( k = 0; k < LAYOUTS.length; k++ ) {
123+
ord = LAYOUTS[ k ];
124+
for ( i = min; i <= max; i++ ) {
125+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
126+
f = createBenchmark( ord, N );
127+
bench( format( '%s::native,square_matrix:order=%s,size=%d', pkg, ord, N*N ), opts, f );
128+
}
129+
}
130+
}
131+
132+
main();
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var zeros = require( '@stdlib/array/zeros' );
29+
var Complex64Array = require( '@stdlib/array/complex64' );
30+
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
31+
var format = require( '@stdlib/string/format' );
32+
var pkg = require( './../package.json' ).name;
33+
var cindexOfRow = require( './../lib/ndarray.js' );
34+
35+
36+
// VARIABLES //
37+
38+
var LAYOUTS = [
39+
'row-major',
40+
'column-major'
41+
];
42+
var options = {
43+
'dtype': 'float32'
44+
};
45+
46+
47+
// FUNCTIONS //
48+
49+
/**
50+
* Creates a benchmark function.
51+
*
52+
* @private
53+
* @param {string} order - storage layout
54+
* @param {PositiveInteger} N - number of elements along each dimension
55+
* @returns {Function} benchmark function
56+
*/
57+
function createBenchmark( order, N ) {
58+
var workspace;
59+
var abuf;
60+
var xbuf;
61+
var A;
62+
var x;
63+
64+
workspace = zeros( N, 'uint8' );
65+
abuf = uniform( N*N*2, -100.0, 100.0, options );
66+
A = new Complex64Array( abuf.buffer );
67+
xbuf = uniform( N*2, 200.0, 300.0, options );
68+
x = new Complex64Array( xbuf.buffer );
69+
70+
return benchmark;
71+
72+
/**
73+
* Benchmark function.
74+
*
75+
* @private
76+
* @param {Benchmark} b - benchmark instance
77+
*/
78+
function benchmark( b ) {
79+
var sa1;
80+
var sa2;
81+
var z;
82+
var i;
83+
84+
if ( isColumnMajor( order ) ) {
85+
sa1 = 1;
86+
sa2 = N;
87+
} else { // order === 'row-major'
88+
sa1 = N;
89+
sa2 = 1;
90+
}
91+
92+
b.tic();
93+
for ( i = 0; i < b.iterations; i++ ) {
94+
z = cindexOfRow( N, N, A, sa1, sa2, 0, x, 1, 0, workspace, 1, 0 );
95+
if ( isnanf( z ) ) {
96+
b.fail( 'should not return NaN' );
97+
}
98+
}
99+
b.toc();
100+
if ( isnanf( z ) ) {
101+
b.fail( 'should not return NaN' );
102+
}
103+
b.pass( 'benchmark finished' );
104+
b.end();
105+
}
106+
}
107+
108+
109+
// MAIN //
110+
111+
/**
112+
* Main execution sequence.
113+
*
114+
* @private
115+
*/
116+
function main() {
117+
var min;
118+
var max;
119+
var ord;
120+
var N;
121+
var f;
122+
var i;
123+
var k;
124+
125+
min = 1; // 10^min
126+
max = 6; // 10^max
127+
128+
for ( k = 0; k < LAYOUTS.length; k++ ) {
129+
ord = LAYOUTS[ k ];
130+
for ( i = min; i <= max; i++ ) {
131+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
132+
f = createBenchmark( ord, N );
133+
bench( format( '%s::square_matrix:ndarray:order=%s,size=%d', pkg, ord, N*N ), f );
134+
}
135+
}
136+
}
137+
138+
main();

0 commit comments

Comments
 (0)