Repository navigation
feat: add C implementation for stats/base/ndarray/smeankbn
#10157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
899866b
6ee861e
16624ec
861ca08
2147e7a
69e1aef
0ddb50f
2900f03
917eb76
010c5d5
43cc426
e8967f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,11 +22,11 @@ | |||||
|
|
||||||
| var bench = require( '@stdlib/bench' ); | ||||||
| var uniform = require( '@stdlib/random/uniform' ); | ||||||
| var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||||||
| var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); | ||||||
| var pow = require( '@stdlib/math/base/special/pow' ); | ||||||
| var format = require( '@stdlib/string/format' ); | ||||||
| var pkg = require( './../package.json' ).name; | ||||||
| var smeankbn = require( './../lib' ); | ||||||
| var smeankbn = require( './../lib/main.js' ); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @0PrashantYadav0 Your suggestion here is wrong. This path does need to be updated to |
||||||
|
|
||||||
|
|
||||||
| // VARIABLES // | ||||||
|
|
@@ -62,12 +62,12 @@ function createBenchmark( len ) { | |||||
| b.tic(); | ||||||
| for ( i = 0; i < b.iterations; i++ ) { | ||||||
| v = smeankbn( [ x ] ); | ||||||
| if ( isnan( v ) ) { | ||||||
| if ( isnanf( v ) ) { | ||||||
| b.fail( 'should not return NaN' ); | ||||||
| } | ||||||
| } | ||||||
| b.toc(); | ||||||
| if ( isnan( v ) ) { | ||||||
| if ( isnanf( v ) ) { | ||||||
| b.fail( 'should not return NaN' ); | ||||||
| } | ||||||
| b.pass( 'benchmark finished' ); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,114 @@ | ||||||
| /** | ||||||
| * @license Apache-2.0 | ||||||
| * | ||||||
| * Copyright (c) 2026 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' ); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); | ||||||
| var pow = require( '@stdlib/math/base/special/pow' ); | ||||||
| var ndarray = require( '@stdlib/ndarray/base/ctor' ); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| var format = require( '@stdlib/string/format' ); | ||||||
| var tryRequire = require( '@stdlib/utils/try-require' ); | ||||||
| var pkg = require( './../package.json' ).name; | ||||||
|
|
||||||
|
|
||||||
| // VARIABLES // | ||||||
|
|
||||||
| var smeankbn = tryRequire( resolve( __dirname, './../lib/native.js' ) ); | ||||||
| var opts = { | ||||||
| 'skip': ( smeankbn instanceof Error ) | ||||||
| }; | ||||||
| var options = { | ||||||
| 'dtype': 'float32' | ||||||
| }; | ||||||
|
|
||||||
|
|
||||||
| // FUNCTIONS // | ||||||
|
|
||||||
| /** | ||||||
| * Creates a benchmark function. | ||||||
| * | ||||||
| * @private | ||||||
| * @param {PositiveInteger} len - array length | ||||||
| * @returns {Function} benchmark function | ||||||
| */ | ||||||
| function createBenchmark( len ) { | ||||||
| var xbuf; | ||||||
| var x; | ||||||
|
|
||||||
| xbuf = uniform( len, -10.0, 10.0, options ); | ||||||
| x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' ); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| return benchmark; | ||||||
|
|
||||||
| /** | ||||||
| * Benchmark function. | ||||||
| * | ||||||
| * @private | ||||||
| * @param {Benchmark} b - benchmark instance | ||||||
| */ | ||||||
| function benchmark( b ) { | ||||||
| var v; | ||||||
| var i; | ||||||
|
|
||||||
| b.tic(); | ||||||
| for ( i = 0; i < b.iterations; i++ ) { | ||||||
| v = smeankbn( [ x ] ); | ||||||
| if ( isnanf( v ) ) { | ||||||
| b.fail( 'should not return NaN' ); | ||||||
| } | ||||||
| } | ||||||
| b.toc(); | ||||||
| if ( isnanf( v ) ) { | ||||||
| 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 = pow( 10, i ); | ||||||
| f = createBenchmark( len ); | ||||||
| bench( format( '%s::native:len=%d', pkg, len ), opts, f ); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| main(); | ||||||
Uh oh!
There was an error while loading. Please reload this page.