-
-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add C implementation for
blas/base/sspr
PR-URL: #4491 Ref: #2039 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Co-authored-by: stdlib-bot <[email protected]>
- Loading branch information
1 parent
7cfb8f7
commit 8d34c0c
Showing
26 changed files
with
2,824 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
lib/node_modules/@stdlib/blas/base/sspr/benchmark/benchmark.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2025 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var resolve = require( 'path' ).resolve; | ||
var bench = require( '@stdlib/bench' ); | ||
var uniform = require( '@stdlib/random/array/uniform' ); | ||
var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); | ||
var pow = require( '@stdlib/math/base/special/pow' ); | ||
var floor = require( '@stdlib/math/base/special/floor' ); | ||
var tryRequire = require( '@stdlib/utils/try-require' ); | ||
var pkg = require( './../package.json' ).name; | ||
|
||
|
||
// VARIABLES // | ||
|
||
var sspr = tryRequire( resolve( __dirname, './../lib/sspr.native.js' ) ); | ||
var opts = { | ||
'skip': ( sspr instanceof Error ) | ||
}; | ||
var options = { | ||
'dtype': 'float32' | ||
}; | ||
|
||
|
||
// FUNCTIONS // | ||
|
||
/** | ||
* Creates a benchmark function. | ||
* | ||
* @private | ||
* @param {PositiveInteger} N - number of elements along each dimension | ||
* @returns {Function} benchmark function | ||
*/ | ||
function createBenchmark( N ) { | ||
var AP = uniform( N * ( N + 1 ) / 2, -10.0, 10.0, options ); | ||
var x = uniform( N, -10.0, 10.0, options ); | ||
return benchmark; | ||
|
||
/** | ||
* Benchmark function. | ||
* | ||
* @private | ||
* @param {Benchmark} b - benchmark instance | ||
*/ | ||
function benchmark( b ) { | ||
var z; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
z = sspr( 'row-major', 'upper', N, 1.0, x, 1, AP ); | ||
if ( isnanf( z[ i%z.length ] ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnanf( z[ i%z.length ] ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
} | ||
} | ||
|
||
|
||
// MAIN // | ||
|
||
/** | ||
* Main execution sequence. | ||
* | ||
* @private | ||
*/ | ||
function main() { | ||
var len; | ||
var min; | ||
var max; | ||
var f; | ||
var i; | ||
|
||
min = 1; // 10^min | ||
max = 6; // 10^max | ||
|
||
for ( i = min; i <= max; i++ ) { | ||
len = floor( pow( pow( 10, i ), 1.0/2.0 ) ); | ||
f = createBenchmark( len ); | ||
bench( pkg+'::native:size='+( len * ( len + 1 ) / 2 ), opts, f ); | ||
} | ||
} | ||
|
||
main(); |
109 changes: 109 additions & 0 deletions
109
lib/node_modules/@stdlib/blas/base/sspr/benchmark/benchmark.ndarray.native.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2025 The Stdlib Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var resolve = require( 'path' ).resolve; | ||
var bench = require( '@stdlib/bench' ); | ||
var uniform = require( '@stdlib/random/array/uniform' ); | ||
var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); | ||
var pow = require( '@stdlib/math/base/special/pow' ); | ||
var floor = require( '@stdlib/math/base/special/floor' ); | ||
var tryRequire = require( '@stdlib/utils/try-require' ); | ||
var pkg = require( './../package.json' ).name; | ||
|
||
|
||
// VARIABLES // | ||
|
||
var sspr = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) ); | ||
var opts = { | ||
'skip': ( sspr instanceof Error ) | ||
}; | ||
var options = { | ||
'dtype': 'float32' | ||
}; | ||
|
||
|
||
// FUNCTIONS // | ||
|
||
/** | ||
* Creates a benchmark function. | ||
* | ||
* @private | ||
* @param {PositiveInteger} N - number of elements along each dimension | ||
* @returns {Function} benchmark function | ||
*/ | ||
function createBenchmark( N ) { | ||
var AP = uniform( N * ( N + 1 ) / 2, -10.0, 10.0, options ); | ||
var x = uniform( N, -10.0, 10.0, options ); | ||
return benchmark; | ||
|
||
/** | ||
* Benchmark function. | ||
* | ||
* @private | ||
* @param {Benchmark} b - benchmark instance | ||
*/ | ||
function benchmark( b ) { | ||
var z; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
z = sspr( 'row-major', 'upper', N, 1.0, x, 1, 0, AP, 1, 0 ); | ||
if ( isnanf( z[ i%z.length ] ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnanf( z[ i%z.length ] ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
} | ||
} | ||
|
||
|
||
// MAIN // | ||
|
||
/** | ||
* Main execution sequence. | ||
* | ||
* @private | ||
*/ | ||
function main() { | ||
var len; | ||
var min; | ||
var max; | ||
var f; | ||
var i; | ||
|
||
min = 1; // 10^min | ||
max = 6; // 10^max | ||
|
||
for ( i = min; i <= max; i++ ) { | ||
len = floor( pow( pow( 10, i ), 1.0/2.0 ) ); | ||
f = createBenchmark( len ); | ||
bench( pkg+'::native:ndarray:size='+( len * ( len + 1 ) / 2 ), opts, f ); | ||
} | ||
} | ||
|
||
main(); |
Oops, something went wrong.
8d34c0c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report
The above coverage report was generated for the changes in this push.