From a766b97b4b8de3f9a2f06827a86c97b18a1a8677 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 23 Dec 2024 02:20:45 +0500 Subject: [PATCH 01/15] feat: add `eslint/rules/eol-open-bracket-spacing` PR-URL: https://github.com/stdlib-js/stdlib/pull/4061 Private-ref: https://github.com/stdlib-js/todo/issues/2324 Reviewed-by: Athan Reines --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: passed - task: run_c_examples status: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: failed --- --- etc/eslint/rules/stdlib.js | 46 ++++ .../rules/eol-open-bracket-spacing/README.md | 163 +++++++++++++ .../examples/index.js | 66 +++++ .../eol-open-bracket-spacing/lib/index.js | 39 +++ .../eol-open-bracket-spacing/lib/main.js | 156 ++++++++++++ .../eol-open-bracket-spacing/package.json | 63 +++++ .../test/fixtures/invalid.js | 230 ++++++++++++++++++ .../test/fixtures/unvalidated.js | 41 ++++ .../test/fixtures/valid.js | 97 ++++++++ .../eol-open-bracket-spacing/test/test.js | 86 +++++++ .../@stdlib/_tools/eslint/rules/lib/index.js | 9 + 11 files changed, 996 insertions(+) create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/README.md create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/examples/index.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/index.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/main.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/package.json create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/invalid.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/unvalidated.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/valid.js create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/test.js diff --git a/etc/eslint/rules/stdlib.js b/etc/eslint/rules/stdlib.js index 5304d3895a5c..0de07ac30f90 100644 --- a/etc/eslint/rules/stdlib.js +++ b/etc/eslint/rules/stdlib.js @@ -200,6 +200,52 @@ rules[ 'stdlib/doctest-quote-props' ] = 'error'; */ rules[ 'stdlib/empty-line-before-comment' ] = 'error'; +/** +* Disallow spaces between an opening parenthesis or bracket and a nested object or array expression at the end of a line. +* +* @name eol-open-bracket-spacing +* @memberof rules +* @type {string} +* @default 'error' +* +* @example +* // Bad... +* var log = require( '@stdlib/console/log' ); +* +* log( { +* 'foo': true +* }); +* +* log( [ +* 1, +* 2, +* 3 +* ]); +* +* log( [ { +* 'bar': true +* }]); +* +* @example +* // Good... +* var log = require( '@stdlib/console/log' ); +* +* log({ +* 'foo': true +* }); +* +* log([ +* 1, +* 2, +* 3 +* ]); +* +* log([{ +* 'bar': true +* }]); +*/ +rules[ 'stdlib/eol-open-bracket-spacing' ] = 'error'; + /** * Require blockquotes to have `2` character indentation. * diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/README.md b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/README.md new file mode 100644 index 000000000000..721f820dae72 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/README.md @@ -0,0 +1,163 @@ + + +# eol-open-bracket-spacing + +> [ESLint rule][eslint-rules] to enforce that no spaces are present between an opening parenthesis or bracket and a nested object or array expression at the end of a line. + +
+ +
+ + + +
+ +## Usage + +```javascript +var rule = require( '@stdlib/_tools/eslint/rules/eol-open-bracket-spacing' ); +``` + +#### rule + +[ESLint rule][eslint-rules] to enforce that no spaces are present between an opening parenthesis or bracket and a nested object or array expression at the end of a line. + +**Bad**: + + + +```javascript +var log = require( '@stdlib/console/log' ); + +log( { + 'foo': true +}); + +log( [ + 1, + 2, + 3 +]); + +log( [ { + 'bar': true +}]); +``` + +**Good**: + +```javascript +var log = require( '@stdlib/console/log' ); + +log({ + 'foo': true +}); + +log([ + 1, + 2, + 3 +]); + +log([{ + 'bar': true +}]); +``` + +
+ + + +
+ +## Examples + + + +```javascript +var Linter = require( 'eslint' ).Linter; +var rule = require( '@stdlib/_tools/eslint/rules/eol-open-bracket-spacing' ); + +var linter = new Linter(); + +var code = [ + 'function test() {', + ' var log = require( \'@stdlib/console/log\' );', + ' log( {', + ' "key": "value"', + ' });', + ' var arr = [ {', + ' "nested": true', + ' }];', + ' log( arr );', + '}' +].join( '\n' ); + +linter.defineRule( 'eol-open-bracket-spacing', rule ); + +var result = linter.verify( code, { + 'rules': { + 'eol-open-bracket-spacing': 'error' + } +}); +/* returns + [ + { + 'ruleId': 'eol-open-bracket-spacing', + 'severity': 2, + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'line': 3, + 'column': 3, + 'nodeType': 'CallExpression' + }, + { + 'ruleId': 'eol-open-bracket-spacing', + 'severity': 2, + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'line': 6, + 'column': 13, + 'nodeType': 'ArrayExpression' + } + ] +*/ +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/examples/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/examples/index.js new file mode 100644 index 000000000000..9645f73f936d --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/examples/index.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +var Linter = require( 'eslint' ).Linter; +var rule = require( './../lib' ); + +var linter = new Linter(); + +var code = [ + 'function test() {', + ' var log = require( \'@stdlib/console/log\' );', + ' log( {', + ' "key": "value"', + ' });', + ' var arr = [ {', + ' "nested": true', + ' }];', + ' log( arr );', + '}' +].join( '\n' ); + +linter.defineRule( 'eol-open-bracket-spacing', rule ); + +var result = linter.verify( code, { + 'rules': { + 'eol-open-bracket-spacing': 'error' + } +}); +console.log( result ); +/* => + [ + { + 'ruleId': 'eol-open-bracket-spacing', + 'severity': 2, + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'line': 3, + 'column': 3, + 'nodeType': 'CallExpression' + }, + { + 'ruleId': 'eol-open-bracket-spacing', + 'severity': 2, + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'line': 6, + 'column': 13, + 'nodeType': 'ArrayExpression' + } + ] +*/ diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/index.js new file mode 100644 index 000000000000..2353d04e43c6 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/index.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +/** +* ESLint rule to enforce that no spaces are present between an opening parenthesis or bracket and a nested object or array expression at the end of a line. +* +* @module @stdlib/_tools/eslint/rules/eol-open-bracket-spacing +* +* @example +* var rule = require( '@stdlib/_tools/eslint/rules/eol-open-bracket-spacing' ); +* +* console.log( rule ); +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/main.js b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/main.js new file mode 100644 index 000000000000..59474cccfef8 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/lib/main.js @@ -0,0 +1,156 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +// VARIABLES // + +var rule; + + +// FUNCTIONS // + +/** +* Rule for validating that no spaces are present between an opening parenthesis or bracket and a nested object or array expression at the end of a line. +* +* @private +* @param {Object} context - ESLint context +* @returns {Object} validators +*/ +function main( context ) { + var source = context.getSourceCode(); + + /** + * Reports the error message. + * + * @private + * @param {ASTNode} node - node to report + * @param {Object} prevToken - token before the space + * @param {Object} tokenAfter - token after the space + */ + function report( node, prevToken, tokenAfter ) { + context.report({ + 'node': node, + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'fix': fix + }); + + /** + * Fixes lint the error by removing the space before the object or array expression. + * + * @private + * @param {Object} fixer - ESLint fixer + * @returns {Object} fix + */ + function fix( fixer ) { + var afterIdx; + var prevIdx; + + prevIdx = source.getIndexFromLoc( prevToken.loc.end ); + afterIdx = source.getIndexFromLoc( tokenAfter.loc.start ); + return fixer.replaceTextRange( [ prevIdx, afterIdx ], '' ); + } + } + + /** + * Checks whether there are spaces present between an opening parenthesis or bracket and a nested object or array expression at the end of a line. + * + * @private + * @param {ASTNode} node - node to examine + */ + function validate( node ) { + var tokenAfter; + var nextToken; + var prevToken; + var elem; + var args; + + if ( + node.type === 'CallExpression' && + node.arguments.length > 0 + ) { + args = node.arguments; + if ( args[ 0 ].type === 'ObjectExpression' ) { + prevToken = source.getTokenBefore( args[ 0 ] ); + tokenAfter = source.getFirstToken( args[ 0 ] ); + if ( source.isSpaceBetween( prevToken, tokenAfter ) ) { + report( node, prevToken, tokenAfter ); + } + } else if ( args[ 0 ].type === 'ArrayExpression' ) { + elem = args[ 0 ].elements[ 0 ]; + if ( elem.type === 'ObjectExpression' ) { + prevToken = source.getTokenBefore( args[ 0 ] ); + tokenAfter = source.getFirstToken( args[ 0 ] ); + if ( source.isSpaceBetween( prevToken, tokenAfter ) ) { + report( node, prevToken, tokenAfter ); + } + } else { + prevToken = source.getTokenBefore( args[ 0 ] ); + tokenAfter = source.getFirstToken( args[ 0 ] ); + nextToken = source.getTokenAfter( tokenAfter ); + if ( + tokenAfter.loc.end.line !== nextToken.loc.end.line && + source.isSpaceBetween( prevToken, tokenAfter ) + ) { + report( node, prevToken, tokenAfter ); + } + } + } + } + + if ( + node.type === 'ArrayExpression' && + node.elements.length > 0 + ) { + elem = node.elements[ 0 ]; + if ( elem.type === 'ObjectExpression' ) { + prevToken = source.getFirstToken( node ); + tokenAfter = source.getFirstToken( elem ); + + if ( source.isSpaceBetween( prevToken, tokenAfter ) ) { + report( node, prevToken, tokenAfter ); + } + } + } + } + + return { + 'CallExpression': validate, + 'ArrayExpression': validate + }; +} + + +// MAIN // + +rule = { + 'meta': { + 'type': 'layout', + 'docs': { + 'description': 'disallow spaces between an opening parenthesis or bracket and a nested object or array expression at the end of a line' + }, + 'schema': [], + 'fixable': 'whitespace' + }, + 'create': main +}; + + +// EXPORTS // + +module.exports = rule; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/package.json b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/package.json new file mode 100644 index 000000000000..4773e06bbbbd --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/package.json @@ -0,0 +1,63 @@ +{ + "name": "@stdlib/_tools/eslint/rules/eol-open-bracket-spacing", + "version": "0.0.0", + "description": "ESLint rule to enforce that no spaces are present between an opening parenthesis or bracket and a nested object or array expression at the end of a line.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "bin": {}, + "main": "./lib", + "directories": { + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "tools", + "tool", + "eslint", + "lint", + "custom", + "rules", + "rule", + "array", + "object", + "plugin", + "whitespace" + ] +} diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/invalid.js b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/invalid.js new file mode 100644 index 000000000000..30fe652a99aa --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/invalid.js @@ -0,0 +1,230 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +var valid = []; +var test; + +test = { + 'code': [ + 'var arr = [ {', + ' key1: "value1",', + ' key2: "value2"', + '}];' + ].join( '\n' ), + 'errors': [{ + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }], + 'output': [ + 'var arr = [{', + ' key1: "value1",', + ' key2: "value2"', + '}];' + ].join( '\n' ) +}; +valid.push( test ); + +test = { + 'code': [ + 'function sum( x ) {', + ' var sum = 0;', + ' for ( var i = 0; i < x.length; i++ ) {', + ' sum += x[ i ];', + ' }', + ' return sum;', + '}', + 'var arrSum = sum( [', + ' 1,', + ' 2,', + ' 3,', + ' 4', + ']);' + ].join( '\n' ), + 'errors': [{ + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }], + 'output': [ + 'function sum( x ) {', + ' var sum = 0;', + ' for ( var i = 0; i < x.length; i++ ) {', + ' sum += x[ i ];', + ' }', + ' return sum;', + '}', + 'var arrSum = sum([', + ' 1,', + ' 2,', + ' 3,', + ' 4', + ']);' + ].join( '\n' ) +}; +valid.push( test ); + +test = { + 'code': [ + 'function log( x ) {', + ' for ( var i = 0; i < x.length; i++ ) {', + ' console.log( x[ i ] );', + ' }', + '}', + 'log( [{', + ' a: 1,', + ' b: 2', + '}]);' + ].join( '\n' ), + 'errors': [{ + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }], + 'output': [ + 'function log( x ) {', + ' for ( var i = 0; i < x.length; i++ ) {', + ' console.log( x[ i ] );', + ' }', + '}', + 'log([{', + ' a: 1,', + ' b: 2', + '}]);' + ].join( '\n' ) +}; +valid.push( test); + +test = { + 'code': [ + 'function log( x ) {', + ' for ( var i = 0; i < x.length; i++ ) {', + ' console.log( x[ i ] );', + ' }', + '}', + 'log([ {', + ' a: 1,', + ' b: 2', + '}]);' + ].join( '\n' ), + 'errors': [{ + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }], + 'output': [ + 'function log( x ) {', + ' for ( var i = 0; i < x.length; i++ ) {', + ' console.log( x[ i ] );', + ' }', + '}', + 'log([{', + ' a: 1,', + ' b: 2', + '}]);' + ].join( '\n' ) +}; +valid.push( test); + +test = { + 'code': [ + 'function log( x ) {', + ' for ( var i = 0; i < x.length; i++ ) {', + ' console.log( x[ i ] );', + ' }', + '}', + 'log( [ {', + ' a: 1,', + ' b: 2', + '}]);' + ].join( '\n' ), + 'errors': [{ + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }, { + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }], + 'output': [ + 'function log( x ) {', + ' for ( var i = 0; i < x.length; i++ ) {', + ' console.log( x[ i ] );', + ' }', + '}', + 'log([{', + ' a: 1,', + ' b: 2', + '}]);' + ].join( '\n' ) +}; +valid.push( test); + +test = { + 'code': [ + 'console.log( [', + ' Math.random(),', + ' Math.random()', + ']);', + '/* e.g., =>', + ' [', + ' 0.2580887012988746,', + ' 0.128454513229588', + ' ]', + '*/' + ].join( '\n' ), + 'errors': [{ + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }], + 'output': [ + 'console.log([', + ' Math.random(),', + ' Math.random()', + ']);', + '/* e.g., =>', + ' [', + ' 0.2580887012988746,', + ' 0.128454513229588', + ' ]', + '*/' + ].join( '\n' ) +}; +valid.push( test ); + +test = { + 'code': [ + 'console.log( {', + ' a: Math.random(),', + ' b: Math.random()', + '});' + ].join( '\n' ), + 'errors': [{ + 'message': 'No spaces allowed between an opening parenthesis or bracket and a nested object or array expression at the end of a line', + 'type': null + }], + 'output': [ + 'console.log({', + ' a: Math.random(),', + ' b: Math.random()', + '});' + ].join( '\n' ) +}; +valid.push( test ); + + +// EXPORTS // + +module.exports = valid; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/unvalidated.js b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/unvalidated.js new file mode 100644 index 000000000000..c6c33b1faa84 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/unvalidated.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +var valid = []; +var test; + +test = { + 'code': [ + 'function sum( x ) {', + ' var sum = 0;', + ' for ( var i = 0; i < x.length; i++ ) {', + ' sum += x[ i ];', + ' }', + ' return sum;', + '}', + 'var arrSum = sum( [ 1, 2, 3, 4 ] );' + ].join( '\n' ) +}; +valid.push( test); + + +// EXPORTS // + +module.exports = valid; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/valid.js b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/valid.js new file mode 100644 index 000000000000..761141fd2b28 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/fixtures/valid.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +var valid = []; +var test; + +test = { + 'code': [ + 'var arr = [{', + ' key1: "value1",', + ' key2: "value2"', + '}];' + ].join( '\n' ) +}; +valid.push( test ); + +test = { + 'code': [ + 'function sum( x ) {', + ' var sum = 0;', + ' for ( var i = 0; i < x.length; i++ ) {', + ' sum += x[ i ];', + ' }', + ' return sum;', + '}', + 'var arrSum = sum([', + ' 1,', + ' 2,', + ' 3,', + ' 4', + ']);' + ].join( '\n' ) +}; +valid.push( test); + +test = { + 'code': [ + 'function log( x ) {', + ' for ( var i = 0; i < x.length; i++ ) {', + ' console.log( x[ i ] );', + ' }', + '}', + 'log([{', + ' a: 1,', + ' b: 2', + '}]);' + ].join( '\n' ) +}; +valid.push( test); + +test = { + 'code': [ + 'console.log([', + ' Math.random(),', + ' Math.random()', + ']);', + '/* e.g., =>', + ' [', + ' 0.2580887012988746,', + ' 0.128454513229588', + ' ]', + '*/' + ].join( '\n' ) +}; +valid.push( test ); + +test = { + 'code': [ + 'console.log({', + ' a: Math.random(),', + ' b: Math.random()', + '});' + ].join( '\n' ) +}; +valid.push( test ); + + +// EXPORTS // + +module.exports = valid; diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/test.js b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/test.js new file mode 100644 index 000000000000..43153651efa8 --- /dev/null +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/eol-open-bracket-spacing/test/test.js @@ -0,0 +1,86 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 tape = require( 'tape' ); +var RuleTester = require( 'eslint' ).RuleTester; +var rule = require( './../lib' ); + + +// FIXTURES // + +var valid = require( './fixtures/valid.js' ); +var invalid = require( './fixtures/invalid.js' ); +var unvalidated = require( './fixtures/unvalidated.js' ); + + +// TESTS // + +tape( 'main export is an object', function test( t ) { + t.ok( true, __filename ); + t.equal( typeof rule, 'object', 'main export is an object' ); + t.end(); +}); + +tape( 'the function positively validates code where no spaces are present between an opening parenthesis or bracket and a nested object or array expression at the end of a line', function test( t ) { + var tester = new RuleTester(); + + try { + tester.run( 'eol-open-bracket-spacing', rule, { + 'valid': valid, + 'invalid': [] + }); + t.pass( 'passed without errors' ); + } catch ( err ) { + t.fail( 'encountered an error: ' + err.message ); + } + t.end(); +}); + +tape( 'the function negatively validates code where spaces are present between an opening parenthesis or bracket and a nested object or array expression at the end of a line', function test( t ) { + var tester = new RuleTester(); + + try { + tester.run( 'eol-open-bracket-spacing', rule, { + 'valid': [], + 'invalid': invalid + }); + t.pass( 'passed without errors' ); + } catch ( err ) { + t.fail( 'encountered an error: ' + err.message ); + } + t.end(); +}); + +tape( 'the function does not validate non-object or non-array or inline array expressions', function test( t ) { + var tester = new RuleTester(); + + try { + tester.run( 'eol-open-bracket-spacing', rule, { + 'valid': unvalidated, + 'invalid': [] + }); + t.pass( 'passed without errors' ); + } catch ( err ) { + t.fail( 'encountered an error: ' + err.message ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js index 3a8df9a27024..221f82484546 100644 --- a/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js +++ b/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js @@ -81,6 +81,15 @@ setReadOnly( rules, 'doctest-quote-props', require( '@stdlib/_tools/eslint/rules */ setReadOnly( rules, 'empty-line-before-comment', require( '@stdlib/_tools/eslint/rules/empty-line-before-comment' ) ); +/** +* @name eol-open-bracket-spacing +* @memberof rules +* @readonly +* @type {Function} +* @see {@link module:@stdlib/_tools/eslint/rules/eol-open-bracket-spacing} +*/ +setReadOnly( rules, 'eol-open-bracket-spacing', require( '@stdlib/_tools/eslint/rules/eol-open-bracket-spacing' ) ); + /** * @name first-unit-test * @memberof rules From 91b0b7465caae15b8f3819fe091cd52b2f4dfde8 Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Mon, 30 Dec 2024 06:12:53 +0000 Subject: [PATCH 02/15] feat: add C ndarray interface and refactor implementation for stats/base/svariancewd --- 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: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/stats/base/svariancewd/README.md | 161 +++++++++++++++--- .../base/svariancewd/benchmark/benchmark.js | 16 +- .../svariancewd/benchmark/benchmark.native.js | 12 +- .../benchmark/benchmark.ndarray.js | 16 +- .../benchmark/benchmark.ndarray.native.js | 12 +- .../benchmark/c/benchmark.length.c | 48 +++++- .../stats/base/svariancewd/docs/repl.txt | 26 ++- .../base/svariancewd/docs/types/index.d.ts | 12 +- .../base/svariancewd/examples/c/example.c | 9 +- .../stats/base/svariancewd/examples/index.js | 12 +- .../include/stdlib/stats/base/svariancewd.h | 9 +- .../stats/base/svariancewd/lib/index.js | 6 +- .../stats/base/svariancewd/lib/ndarray.js | 15 +- .../base/svariancewd/lib/ndarray.native.js | 19 +-- .../stats/base/svariancewd/lib/svariancewd.js | 15 +- .../svariancewd/lib/svariancewd.native.js | 9 +- .../stats/base/svariancewd/manifest.json | 38 ++++- .../stats/base/svariancewd/src/addon.c | 27 ++- .../svariancewd/src/{svariancewd.c => main.c} | 53 +++++- .../base/svariancewd/test/test.ndarray.js | 13 +- .../svariancewd/test/test.ndarray.native.js | 13 +- .../base/svariancewd/test/test.svariancewd.js | 13 +- .../test/test.svariancewd.native.js | 13 +- 23 files changed, 380 insertions(+), 187 deletions(-) rename lib/node_modules/@stdlib/stats/base/svariancewd/src/{svariancewd.c => main.c} (70%) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/README.md b/lib/node_modules/@stdlib/stats/base/svariancewd/README.md index 3c0591778073..5cb1b82b84b4 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/README.md +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/README.md @@ -98,7 +98,7 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note, var svariancewd = require( '@stdlib/stats/base/svariancewd' ); ``` -#### svariancewd( N, correction, x, stride ) +#### svariancewd( N, correction, x, strideX ) Computes the [variance][variance] of a single-precision floating-point strided array `x` using Welford's algorithm. @@ -106,9 +106,8 @@ Computes the [variance][variance] of a single-precision floating-point strided a var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = svariancewd( N, 1, x, 1 ); +var v = svariancewd( x.length, 1, x, 1 ); // returns ~4.3333 ``` @@ -117,18 +116,16 @@ The function has the following parameters: - **N**: number of indexed elements. - **correction**: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). - **x**: input [`Float32Array`][@stdlib/array/float32]. -- **stride**: index increment for `x`. +- **strideX**: stride length for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, +The `N` and stride parameters determine which elements in `x` are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] ); -var N = floor( x.length / 2 ); -var v = svariancewd( N, 1, x, 2 ); +var v = svariancewd( 4, 1, x, 2 ); // returns 6.25 ``` @@ -138,18 +135,15 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = svariancewd( N, 1, x1, 2 ); +var v = svariancewd( 4, 1, x1, 2 ); // returns 6.25 ``` -#### svariancewd.ndarray( N, correction, x, stride, offset ) +#### svariancewd.ndarray( N, correction, x, strideX, offsetX ) Computes the [variance][variance] of a single-precision floating-point strided array using Welford's algorithm and alternative indexing semantics. @@ -157,26 +151,24 @@ Computes the [variance][variance] of a single-precision floating-point strided a var Float32Array = require( '@stdlib/array/float32' ); var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -var N = x.length; -var v = svariancewd.ndarray( N, 1, x, 1, 0 ); +var v = svariancewd.ndarray( x.length, 1, x, 1, 0 ); // returns ~4.33333 ``` The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other value in `x` starting from the second value +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element ```javascript var Float32Array = require( '@stdlib/array/float32' ); var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -var N = floor( x.length / 2 ); -var v = svariancewd.ndarray( N, 1, x, 2, 1 ); +var v = svariancewd.ndarray( 4, 1, x, 2, 1 ); // returns 6.25 ``` @@ -202,18 +194,12 @@ var v = svariancewd.ndarray( N, 1, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var svariancewd = require( '@stdlib/stats/base/svariancewd' ); var x; -var i; -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +x = discreteUniform( 10, -50, 50 ); console.log( x ); var v = svariancewd( x.length, 1, x, 1 ); @@ -224,10 +210,131 @@ console.log( v ); + + * * * +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/svariancewd.h" +``` + +#### stdlib_strided_svariancewd( N, correction, \*X, strideX ) + +Computes the [variance][variance] of a single-precision floating-point strided array `x` using Welford's algorithm. + +```c +const float x[] = { 1.0f, -2.0f, 2.0f }; + +float v = stdlib_strided_svariancewd( 3, 1, x, 1 ); +// returns ~4.3333f +``` + +The function accepts the following arguments: + +- **N**: `[In] CBLAS_INT` number of indexed elements. +- **correction**: `[In] FLOAT` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. + +The `N` and stride parameters determine which elements in `x` are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, + +```c +float stdlib_strided_svariancewd( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ); +``` + +#### stdlib_strided_svariancewd_ndarray( N, correction, \*X, strideX, offsetX ) + +Computes the [variance][variance] of a single-precision floating-point strided array using Welford's algorithm and alternative indexing semantics. + +```c +const float x[] = { 1.0f, -2.0f, 2.0f }; + +float v = stdlib_strided_svariancewd_ndarray( 3, 1, x, 1, 0 ); +// returns ~4.33333f +``` + +The function accepts the following arguments: + +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **correction** `[in] float`: degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **X**: `[in] float*` input array. +- **strideX**: `[in] CBLAS_INT` stride length for `X`. +- **offsetX**: `[in] CBLAS_INT` starting index for `X`. + +```c +float stdlib_strided_svariancewd_ndarray( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/svariancewd.h" +#include + +int main( void ) { + // Create a strided array: + const float x[] = { 2.0f, 1.0f, 2.0f, -2.0f, -2.0f, 2.0f, 3.0f, 4.0f }; + + // Specify the number of elements: + const int N = 4; + + // Specify the stride length: + const int strideX = 2; + + // Compute the variance: + float v = stdlib_strided_svariancewd( N, 1.0f, x, strideX ); + + // Print the result: + printf( "sample variance: %f\n", v ); +} +``` + +
+ + + +
+ + +
+* * * + ## References - Welford, B. P. 1962. "Note on a Method for Calculating Corrected Sums of Squares and Products." _Technometrics_ 4 (3). Taylor & Francis: 419–20. doi:[10.1080/00401706.1962.10490022][@welford:1962a]. diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.js index 9de6d16cf228..6943c1ad44eb 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.js @@ -21,14 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var pkg = require( './../package.json' ).name; var svariancewd = require( './../lib/svariancewd.js' ); +// VARIABLES // + +var option = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -40,12 +46,8 @@ var svariancewd = require( './../lib/svariancewd.js' ); */ function createBenchmark( len ) { var x; - var i; - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + x = uniform( len, -10, 10, option ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.native.js index 58f617f53e3b..f6fc3fc9a6f8 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.native.js @@ -21,11 +21,10 @@ // MODULES // var resolve = require( 'path' ).resolve; +var uniform = require( '@stdlib/random/array/uniform' ); var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); var pkg = require( './../package.json' ).name; @@ -36,6 +35,9 @@ var svariancewd = tryRequire( resolve( __dirname, './../lib/svariancewd.native.j var opts = { 'skip': ( svariancewd instanceof Error ) }; +var option = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -49,12 +51,8 @@ var opts = { */ function createBenchmark( len ) { var x; - var i; - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + x = uniform( len, -10, 10, option); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js index 6ab33165870b..df61ac10292c 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js @@ -21,14 +21,20 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); +var uniform = require( '@stdlib/random/array/uniform' ); var pkg = require( './../package.json' ).name; var svariancewd = require( './../lib/ndarray.js' ); +// VARIABLES // + +var option = { + 'dtype': 'float32' +}; + + // FUNCTIONS // /** @@ -40,12 +46,8 @@ var svariancewd = require( './../lib/ndarray.js' ); */ function createBenchmark( len ) { var x; - var i; - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + x = uniform( len, -10, 10, option ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.native.js index 21f0d6030c23..155bd0becf16 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.native.js @@ -22,11 +22,10 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); -var Float32Array = require( '@stdlib/array/float32' ); var tryRequire = require( '@stdlib/utils/try-require' ); +var uniform = require( '@stdlib/random/array/uniform' ); var pkg = require( './../package.json' ).name; @@ -36,6 +35,9 @@ var svariancewd = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) var opts = { 'skip': ( svariancewd instanceof Error ) }; +var option = { + 'dtype': 'float32' +}; // FUNCTIONS // @@ -49,12 +51,8 @@ var opts = { */ function createBenchmark( len ) { var x; - var i; - x = new Float32Array( len ); - for ( i = 0; i < x.length; i++ ) { - x[ i ] = ( randu()*20.0 ) - 10.0; - } + x = uniform( len, -10, 10, option ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/c/benchmark.length.c index edb48f2ca5f2..0e3ff9977242 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/c/benchmark.length.c @@ -94,7 +94,7 @@ static float rand_float( void ) { * @param len array length * @return elapsed time in seconds */ -static double benchmark( int iterations, int len ) { +static double benchmark1( int iterations, int len ) { double elapsed; float x[ len ]; float v; @@ -120,6 +120,39 @@ static double benchmark( int iterations, int len ) { return elapsed; } +/** +* Runs a benchmark. +* +* @param iterations number of iterations +* @param len array length +* @return elapsed time in seconds +*/ +static double benchmark2( int iterations, int len ) { + double elapsed; + float x[ len ]; + float v; + double t; + int i; + + for ( i = 0; i < len; i++ ) { + x[ i ] = ( rand_float() * 20000.0f ) - 10000.0f; + } + v = 0.0f; + t = tic(); + for ( i = 0; i < iterations; i++ ) { + v = stdlib_strided_svariancewd_ndarray( len, 1.0f, x, 1, 0 ); + if ( v != v ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( v != v ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + /** * Main execution sequence. */ @@ -142,7 +175,18 @@ int main( void ) { for ( j = 0; j < REPEATS; j++ ) { count += 1; printf( "# c::%s:len=%d\n", NAME, len ); - elapsed = benchmark( iter, len ); + elapsed = benchmark1( iter, len ); + print_results( iter, elapsed ); + printf( "ok %d benchmark finished\n", count ); + } + } + for ( i = MIN; i <= MAX; i++ ) { + len = pow( 10, i ); + iter = ITERATIONS / pow( 10, i-1 ); + for ( j = 0; j < REPEATS; j++ ) { + count += 1; + printf( "# c::%s:ndarray:len=%d\n", NAME, len ); + elapsed = benchmark2( iter, len ); print_results( iter, elapsed ); printf( "ok %d benchmark finished\n", count ); } diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt index b557226efdfb..8186af916db0 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt @@ -1,9 +1,9 @@ -{{alias}}( N, correction, x, stride ) +{{alias}}( N, correction, x, strideX ) Computes the variance of a single-precision floating-point strided array using Welford's algorithm. - The `N` and `stride` parameters determine which elements in `x` are accessed + The `N` and stride parameters determine which elements in x are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed @@ -31,7 +31,7 @@ x: Float32Array Input array. - stride: integer + strideX: integer Index increment. Returns @@ -48,20 +48,17 @@ // Using `N` and `stride` parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, 1, x, stride ) + > {{alias}}( 3, 1, x, 2 ) ~4.3333 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); > var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, 1, x1, stride ) + > {{alias}}( 3, 1, x1, 2 ) ~4.3333 -{{alias}}.ndarray( N, correction, x, stride, offset ) + +{{alias}}.ndarray( N, correction, x, strideX, offsetX ) Computes the variance of a single-precision floating-point strided array using Welford's algorithm and alternative indexing semantics. @@ -89,10 +86,10 @@ x: Float32Array Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -109,8 +106,7 @@ // Using offset parameter: > var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] ); - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, 1, x, 2, 1 ) + > {{alias}}.ndarray( 3, 1, x, 2, 1 ) ~4.3333 See Also diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/svariancewd/docs/types/index.d.ts index 09da14499bba..216fbcf61002 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/docs/types/index.d.ts @@ -28,7 +28,7 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns variance * * @example @@ -39,7 +39,7 @@ interface Routine { * var v = svariancewd( x.length, 1, x, 1 ); * // returns ~4.3333 */ - ( N: number, correction: number, x: Float32Array, stride: number ): number; + ( N: number, correction: number, x: Float32Array, strideX: number ): number; /** * Computes the variance of a single-precision floating-point strided array using Welford's algorithm and alternative indexing semantics. @@ -47,8 +47,8 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns variance * * @example @@ -59,7 +59,7 @@ interface Routine { * var v = svariancewd.ndarray( x.length, 1, x, 1, 0 ); * // returns ~4.3333 */ - ndarray( N: number, correction: number, x: Float32Array, stride: number, offset: number ): number; + ndarray( N: number, correction: number, x: Float32Array, strideX: number, offsetX: number ): number; } /** @@ -68,7 +68,7 @@ interface Routine { * @param N - number of indexed elements * @param correction - degrees of freedom adjustment * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns variance * * @example diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/svariancewd/examples/c/example.c index c0b34dc3f8d5..0175cbeda9d4 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/examples/c/example.c @@ -17,21 +17,20 @@ */ #include "stdlib/stats/base/svariancewd.h" -#include #include int main( void ) { // Create a strided array: - float x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 }; + float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; // Specify the number of elements: - int64_t N = 4; + const int N = 4; // Specify the stride length: - int64_t stride = 2; + const int strideX = 2; // Compute the variance: - float v = stdlib_strided_svariancewd( N, 1.0f, x, stride ); + float v = stdlib_strided_svariancewd( N, 1.0f, x, strideX ); // Print the result: printf( "sample variance: %f\n", v ); diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js b/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js index f66be086a7fa..7c4a38673c43 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js @@ -18,18 +18,14 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float32Array = require( '@stdlib/array/float32' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var svariancewd = require( './../lib' ); var x; -var i; -x = new Float32Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( (randu()*100.0) - 50.0 ); -} +x = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); console.log( x ); var v = svariancewd( x.length, 1, x, 1 ); diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/include/stdlib/stats/base/svariancewd.h b/lib/node_modules/@stdlib/stats/base/svariancewd/include/stdlib/stats/base/svariancewd.h index 9471b1686b01..1904cb8a797d 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/include/stdlib/stats/base/svariancewd.h +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/include/stdlib/stats/base/svariancewd.h @@ -19,7 +19,7 @@ #ifndef STDLIB_STATS_BASE_SVARIANCEWD_H #define STDLIB_STATS_BASE_SVARIANCEWD_H -#include +#include "stdlib/blas/base/shared.h" /* * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. @@ -31,7 +31,12 @@ extern "C" { /** * Computes the variance of a single-precision floating-point strided array using Welford's algorithm. */ -float stdlib_strided_svariancewd( const int64_t N, const float correction, const float *X, const int64_t stride ); +float API_SUFFIX(stdlib_strided_svariancewd)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ); + +/** +* Computes the variance of a single-precision floating-point strided array using Welford's algorithm and using alternative indexing semantics.. +*/ +float API_SUFFIX(stdlib_strided_svariancewd_ndarray)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); #ifdef __cplusplus } diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/index.js b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/index.js index c1ad7958454d..18127e0e54ba 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/index.js @@ -28,9 +28,8 @@ * var svariancewd = require( '@stdlib/stats/base/svariancewd' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* var N = x.length; * -* var v = svariancewd( N, 1, x, 1 ); +* var v = svariancewd( x.length, 1, x, 1 ); * // returns ~4.3333 * * @example @@ -39,9 +38,8 @@ * var svariancewd = require( '@stdlib/stats/base/svariancewd' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* var N = floor( x.length / 2 ); * -* var v = svariancewd.ndarray( N, 1, x, 2, 1 ); +* var v = svariancewd.ndarray( 4, 1, x, 2, 1 ); * // returns 6.25 */ diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.js index 5bb2372d7672..1577176e68af 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.js @@ -70,8 +70,8 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float32Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} variance * * @example @@ -79,12 +79,11 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); * var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* var N = floor( x.length / 2 ); * -* var v = svariancewd( N, 1, x, 2, 1 ); +* var v = svariancewd( 4, 1, x, 2, 1 ); * // returns 6.25 */ -function svariancewd( N, correction, x, stride, offset ) { +function svariancewd( N, correction, x, strideX, offsetX ) { var delta; var mu; var M2; @@ -97,10 +96,10 @@ function svariancewd( N, correction, x, stride, offset ) { if ( N <= 0 || n <= 0.0 ) { return NaN; } - if ( N === 1 || stride === 0 ) { + if ( N === 1 || strideX === 0 ) { return 0.0; } - ix = offset; + ix = offsetX; M2 = 0.0; mu = 0.0; for ( i = 0; i < N; i++ ) { @@ -108,7 +107,7 @@ function svariancewd( N, correction, x, stride, offset ) { delta = float64ToFloat32( v - mu ); mu = float64ToFloat32( mu + float64ToFloat32( delta / (i+1) ) ); M2 = float64ToFloat32( M2 + float64ToFloat32( delta * float64ToFloat32( v - mu ) ) ); // eslint-disable-line max-len - ix += stride; + ix += strideX; } return float64ToFloat32( M2 / n ); } diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.native.js index f6563dd97d52..2f3b2c686d36 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.native.js @@ -20,8 +20,7 @@ // MODULES // -var Float32Array = require( '@stdlib/array/float32' ); -var addon = require( './svariancewd.native.js' ); +var addon = require( './../src/addon.node' ); // MAIN // @@ -32,8 +31,8 @@ var addon = require( './svariancewd.native.js' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float32Array} x - input array -* @param {integer} stride - stride length -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {number} variance * * @example @@ -41,18 +40,12 @@ var addon = require( './svariancewd.native.js' ); * var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); -* var N = floor( x.length / 2 ); * -* var v = svariancewd( N, 1, x, 2, 1 ); +* var v = svariancewd( 4, 1, x, 2, 1 ); * // returns 6.25 */ -function svariancewd( N, correction, x, stride, offset ) { - var view; - if ( stride < 0 ) { - offset += (N-1) * stride; - } - view = new Float32Array( x.buffer, x.byteOffset+(x.BYTES_PER_ELEMENT*offset), x.length-offset ); // eslint-disable-line max-len - return addon( N, correction, view, stride ); +function svariancewd( N, correction, x, strideX, offsetX ) { + return addon.ndarray( N, correction, x, strideX, offsetX ); } diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/svariancewd.js b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/svariancewd.js index 4ca602ab1764..81f95732fecd 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/svariancewd.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/svariancewd.js @@ -70,19 +70,18 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float32Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} variance * * @example * var Float32Array = require( '@stdlib/array/float32' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* var N = x.length; * -* var v = svariancewd( N, 1, x, 1 ); +* var v = svariancewd( x.length, 1, x, 1 ); * // returns ~4.3333 */ -function svariancewd( N, correction, x, stride ) { +function svariancewd( N, correction, x, strideX ) { var delta; var mu; var M2; @@ -95,11 +94,11 @@ function svariancewd( N, correction, x, stride ) { if ( N <= 0 || n <= 0.0 ) { return NaN; } - if ( N === 1 || stride === 0 ) { + if ( N === 1 || strideX === 0 ) { return 0.0; } - if ( stride < 0 ) { - ix = (1-N) * stride; + if ( strideX < 0 ) { + ix = (1-N) * strideX; } else { ix = 0; } @@ -110,7 +109,7 @@ function svariancewd( N, correction, x, stride ) { delta = float64ToFloat32( v - mu ); mu = float64ToFloat32( mu + float64ToFloat32( delta / (i+1) ) ); M2 = float64ToFloat32( M2 + float64ToFloat32( delta * float64ToFloat32( v - mu ) ) ); // eslint-disable-line max-len - ix += stride; + ix += strideX; } return float64ToFloat32( M2 / n ); } diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/svariancewd.native.js b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/svariancewd.native.js index a2b8431dcfe8..96641e148f95 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/svariancewd.native.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/svariancewd.native.js @@ -31,20 +31,19 @@ var addon = require( './../src/addon.node' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} correction - degrees of freedom adjustment * @param {Float32Array} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} variance * * @example * var Float32Array = require( '@stdlib/array/float32' ); * * var x = new Float32Array( [ 1.0, -2.0, 2.0 ] ); -* var N = x.length; * -* var v = svariancewd( N, 1, x, 1 ); +* var v = svariancewd( x.length, 1, x, 1 ); * // returns ~4.3333 */ -function svariancewd( N, correction, x, stride ) { - return addon( N, correction, x, stride ); +function svariancewd( N, correction, x, strideX ) { + return addon( N, correction, x, strideX ); } diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json b/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json index 79097ed7ab3d..e093d3100a91 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json @@ -1,6 +1,7 @@ { "options": { - "task": "build" + "task": "build", + "wasm": false }, "fields": [ { @@ -27,8 +28,9 @@ "confs": [ { "task": "build", + "wasm": false, "src": [ - "./src/svariancewd.c" + "./src/main.c" ], "include": [ "./include" @@ -38,6 +40,7 @@ ], "libpath": [], "dependencies": [ + "@stdlib/blas/base/shared", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -48,8 +51,9 @@ }, { "task": "benchmark", + "wasm": false, "src": [ - "./src/svariancewd.c" + "./src/main.c" ], "include": [ "./include" @@ -58,12 +62,15 @@ "-lm" ], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared" + ] }, { "task": "examples", + "wasm": false, "src": [ - "./src/svariancewd.c" + "./src/main.c" ], "include": [ "./include" @@ -72,7 +79,26 @@ "-lm" ], "libpath": [], - "dependencies": [] + "dependencies": [ + "@stdlib/blas/base/shared" + ] + }, + { + "task": "", + "wasm": true, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [ + "-lm" + ], + "libpath": [], + "dependencies": [ + "@stdlib/blas/base/shared" + ] } ] } diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/src/addon.c b/lib/node_modules/@stdlib/stats/base/svariancewd/src/addon.c index c1a77fe33e6f..b2e581f92154 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/src/addon.c @@ -32,14 +32,33 @@ * @param info callback data * @return Node-API value */ +float API_SUFFIX(stdlib_strided_svariancewd)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ); static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); - STDLIB_NAPI_ARGV_INT64( env, stride, argv, 3 ); - STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, stride, argv, 2 ) - STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_strided_svariancewd( N, correction, X, stride ), v ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ) + STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_strided_svariancewd( N, correction, X, strideX ), v ); return v; } -STDLIB_NAPI_MODULE_EXPORT_FCN( addon ) +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon_method( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 5 ); + STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); + STDLIB_NAPI_ARGV_FLOAT( env, correction, argv, 1 ); + STDLIB_NAPI_ARGV_INT64( env, strideX, argv, 3 ); + STDLIB_NAPI_ARGV_STRIDED_FLOAT32ARRAY( env, X, N, strideX, argv, 2 ); + STDLIB_NAPI_ARGV_INT64( env, offsetX, argv, 4 ); + STDLIB_NAPI_CREATE_DOUBLE( env, (double)stdlib_strided_svariancewd_ndarray( N, correction, X, strideX, offsetX ), v ); + return v; +} + +STDLIB_NAPI_MODULE_EXPORT_FCN_WITH_METHOD( addon, "ndarray", addon_method ) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/src/svariancewd.c b/lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c similarity index 70% rename from lib/node_modules/@stdlib/stats/base/svariancewd/src/svariancewd.c rename to lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c index 5e58b1ecead5..68cecec37717 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/src/svariancewd.c +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c @@ -17,6 +17,7 @@ */ #include "stdlib/stats/base/svariancewd.h" +#include "stdlib/blas/base/shared.h" #include /** @@ -64,10 +65,10 @@ * @param N number of indexed elements * @param correction degrees of freedom adjustment * @param X input array -* @param stride stride length +* @param strideX stride length * @return output value */ -float stdlib_strided_svariancewd( const int64_t N, const float correction, const float *X, const int64_t stride ) { +float API_SUFFIX(stdlib_strided_svariancewd)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ) { float delta; int64_t ix; int64_t i; @@ -80,11 +81,11 @@ float stdlib_strided_svariancewd( const int64_t N, const float correction, const if ( N <= 0 || n <= 0.0f ) { return 0.0f / 0.0f; // NaN } - if ( N == 1 || stride == 0 ) { + if ( N == 1 || strideX == 0 ) { return 0.0f; } - if ( stride < 0 ) { - ix = (1-N) * stride; + if ( strideX < 0 ) { + ix = (1-N) * strideX; } else { ix = 0; } @@ -95,7 +96,47 @@ float stdlib_strided_svariancewd( const int64_t N, const float correction, const delta = v - mu; mu += (float)((double)delta / (double)(i+1)); M2 += delta * ( v - mu ); - ix += stride; + ix += strideX; + } + return (double)M2 / n; +} + + +/** +* Computes the variance of a single-precision floating-point strided array using Welford's algorithm. +* +* @param N number of indexed elements +* @param correction degrees of freedom adjustment +* @param X input array +* @param strideX stride length +* @param offsetX starting index of X +* @return output value +*/ +float API_SUFFIX(stdlib_strided_svariancewd_ndarray)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ) { + float delta; + int64_t ix; + int64_t i; + double n; + float mu; + float M2; + float v; + + n = (double)N - (double)correction; + if ( N <= 0 || n <= 0.0f ) { + return 0.0f / 0.0f; // NaN + } + if ( N == 1 || strideX == 0 ) { + return 0.0f; + } + ix = offsetX; + M2 = 0.0f; + mu = 0.0f; + for ( i = 0; i < N; i++ ) { + v = X[ ix ]; + delta = v - mu; + mu += (float)((double)delta / (double)(i+1)); + M2 += delta * ( v - mu ); + ix += strideX; } return (double)M2 / n; } diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.ndarray.js index 836f4ca4881d..af6b061ce266 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -122,7 +121,6 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -137,15 +135,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = svariancewd( N, 1, x, 2, 0 ); + v = svariancewd( 4, 1, x, 2, 0 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -160,8 +156,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = svariancewd( N, 1, x, -2, 6 ); + v = svariancewd( 4, 1, x, -2, 6 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -180,7 +175,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -194,9 +188,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); - v = svariancewd( N, 1, x, 2, 1 ); + v = svariancewd( 4, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.ndarray.native.js index 17b4832d957b..401e1f394236 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.ndarray.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -131,7 +130,6 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -146,15 +144,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = svariancewd( N, 1, x, 2, 0 ); + v = svariancewd( 4, 1, x, 2, 0 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -169,8 +165,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = svariancewd( N, 1, x, -2, 6 ); + v = svariancewd( 4, 1, x, -2, 6 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -189,7 +184,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', }); tape( 'the function supports an `offset` parameter', opts, function test( t ) { - var N; var x; var v; @@ -203,9 +197,8 @@ tape( 'the function supports an `offset` parameter', opts, function test( t ) { 3.0, 4.0 // 3 ]); - N = floor( x.length / 2 ); - v = svariancewd( N, 1, x, 2, 1 ); + v = svariancewd( 4, 1, x, 2, 1 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.svariancewd.js b/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.svariancewd.js index 4ebfe149776c..dda4c4b9a993 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.svariancewd.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.svariancewd.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -122,7 +121,6 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -137,15 +135,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = svariancewd( N, 1, x, 2 ); + v = svariancewd( 4, 1, x, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -160,8 +156,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]); - N = floor( x.length / 2 ); - v = svariancewd( N, 1, x, -2 ); + v = svariancewd( 4, 1, x, -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -182,7 +177,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float32Array([ @@ -198,9 +192,8 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = svariancewd( N, 1, x1, 2 ); + v = svariancewd( 4, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.svariancewd.native.js b/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.svariancewd.native.js index d94564f0f176..20b6ca48207a 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.svariancewd.native.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/test/test.svariancewd.native.js @@ -22,7 +22,6 @@ var resolve = require( 'path' ).resolve; var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); var Float32Array = require( '@stdlib/array/float32' ); @@ -131,7 +130,6 @@ tape( 'if provided a `correction` parameter yielding `N-correction` less than or }); tape( 'the function supports a `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -146,15 +144,13 @@ tape( 'the function supports a `stride` parameter', opts, function test( t ) { 2.0 ]); - N = floor( x.length / 2 ); - v = svariancewd( N, 1, x, 2 ); + v = svariancewd( 4, 1, x, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', opts, function test( t ) { - var N; var x; var v; @@ -169,8 +165,7 @@ tape( 'the function supports a negative `stride` parameter', opts, function test 2.0 ]); - N = floor( x.length / 2 ); - v = svariancewd( N, 1, x, -2 ); + v = svariancewd( 4, 1, x, -2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); @@ -191,7 +186,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns `0`', tape( 'the function supports view offsets', opts, function test( t ) { var x0; var x1; - var N; var v; x0 = new Float32Array([ @@ -207,9 +201,8 @@ tape( 'the function supports view offsets', opts, function test( t ) { ]); x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = svariancewd( N, 1, x1, 2 ); + v = svariancewd( 4, 1, x1, 2 ); t.strictEqual( v, 6.25, 'returns expected value' ); t.end(); From 6136228658adfde62218b9a93bd742e33c3aff58 Mon Sep 17 00:00:00 2001 From: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Date: Mon, 30 Dec 2024 12:08:17 +0530 Subject: [PATCH 03/15] clean up Signed-off-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> --- .../@stdlib/stats/base/svariancewd/examples/c/example.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/svariancewd/examples/c/example.c index 0175cbeda9d4..937b9845e7dc 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/examples/c/example.c @@ -21,7 +21,7 @@ int main( void ) { // Create a strided array: - float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; + const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f }; // Specify the number of elements: const int N = 4; From d17258e96925111e9f5292b1ed68452fdbfe5409 Mon Sep 17 00:00:00 2001 From: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Date: Mon, 30 Dec 2024 12:18:05 +0530 Subject: [PATCH 04/15] fixes in readme Signed-off-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/base/svariancewd/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/README.md b/lib/node_modules/@stdlib/stats/base/svariancewd/README.md index 5cb1b82b84b4..9c93b2976269 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/README.md +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/README.md @@ -118,7 +118,7 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **strideX**: stride length for `x`. -The `N` and stride parameters determine which elements in `x` are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, +The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -160,7 +160,7 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -249,8 +249,8 @@ float v = stdlib_strided_svariancewd( 3, 1, x, 1 ); The function accepts the following arguments: -- **N**: `[In] CBLAS_INT` number of indexed elements. -- **correction**: `[In] FLOAT` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **N**: `[in] CBLAS_INT` number of indexed elements. +- **correction**: `[in] FLOAT` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). - **X**: `[in] float*` input array. - **strideX**: `[in] CBLAS_INT` stride length for `X`. From cfdf1a7e7ddec240c88fe825183ca95c943ecf72 Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Mon, 30 Dec 2024 09:22:47 +0000 Subject: [PATCH 05/15] fix: fixing cpp error --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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: passed - 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: passed - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: failed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: passed - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../stats/base/svariancewd/benchmark/c/benchmark.length.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/c/benchmark.length.c b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/c/benchmark.length.c index 0e3ff9977242..1ab41a1e8939 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/c/benchmark.length.c +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/c/benchmark.length.c @@ -107,6 +107,7 @@ static double benchmark1( int iterations, int len ) { v = 0.0f; t = tic(); for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar v = stdlib_strided_svariancewd( len, 1.0f, x, 1 ); if ( v != v ) { printf( "should not return NaN\n" ); @@ -140,6 +141,7 @@ static double benchmark2( int iterations, int len ) { v = 0.0f; t = tic(); for ( i = 0; i < iterations; i++ ) { + // cppcheck-suppress uninitvar v = stdlib_strided_svariancewd_ndarray( len, 1.0f, x, 1, 0 ); if ( v != v ) { printf( "should not return NaN\n" ); From 3af0a092a7bb70241afc9f1bc5244359cfd81d5e Mon Sep 17 00:00:00 2001 From: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Date: Sat, 4 Jan 2025 10:07:02 +0530 Subject: [PATCH 06/15] Apply suggestions from code review Co-authored-by: Aayush Khanna <96649223+aayush0325@users.noreply.github.com> Signed-off-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/base/svariancewd/README.md | 4 +--- .../stats/base/svariancewd/benchmark/benchmark.ndarray.js | 2 +- lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt | 2 +- .../@stdlib/stats/base/svariancewd/examples/index.js | 2 +- .../base/svariancewd/include/stdlib/stats/base/svariancewd.h | 2 +- .../@stdlib/stats/base/svariancewd/lib/ndarray.js | 1 - .../@stdlib/stats/base/svariancewd/lib/ndarray.native.js | 1 - lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json | 4 +--- lib/node_modules/@stdlib/stats/base/svariancewd/src/addon.c | 1 - lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c | 3 +-- 10 files changed, 7 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/README.md b/lib/node_modules/@stdlib/stats/base/svariancewd/README.md index 9c93b2976269..5b966e08bb17 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/README.md +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/README.md @@ -118,7 +118,7 @@ The function has the following parameters: - **x**: input [`Float32Array`][@stdlib/array/float32]. - **strideX**: stride length for `x`. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, ```javascript var Float32Array = require( '@stdlib/array/float32' ); @@ -164,7 +164,6 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the ```javascript var Float32Array = require( '@stdlib/array/float32' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); @@ -254,7 +253,6 @@ The function accepts the following arguments: - **X**: `[in] float*` input array. - **strideX**: `[in] CBLAS_INT` stride length for `X`. -The `N` and stride parameters determine which elements in `x` are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, ```c float stdlib_strided_svariancewd( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ); diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js index df61ac10292c..97f9c4572d34 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js @@ -30,7 +30,7 @@ var svariancewd = require( './../lib/ndarray.js' ); // VARIABLES // -var option = { +var options = { 'dtype': 'float32' }; diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt index 8186af916db0..570f439d374d 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt @@ -32,7 +32,7 @@ Input array. strideX: integer - Index increment. + Stride Length. Returns ------- diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js b/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js index 7c4a38673c43..d20cce95478a 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js @@ -23,7 +23,7 @@ var svariancewd = require( './../lib' ); var x; -x = discreteUniform( 10, -50, 50, { +var x = discreteUniform( 10, -50, 50, { 'dtype': 'float32' }); console.log( x ); diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/include/stdlib/stats/base/svariancewd.h b/lib/node_modules/@stdlib/stats/base/svariancewd/include/stdlib/stats/base/svariancewd.h index 1904cb8a797d..5b27f4962249 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/include/stdlib/stats/base/svariancewd.h +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/include/stdlib/stats/base/svariancewd.h @@ -34,7 +34,7 @@ extern "C" { float API_SUFFIX(stdlib_strided_svariancewd)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ); /** -* Computes the variance of a single-precision floating-point strided array using Welford's algorithm and using alternative indexing semantics.. +* Computes the variance of a single-precision floating-point strided array using Welford's algorithm and using alternative indexing semantics. */ float API_SUFFIX(stdlib_strided_svariancewd_ndarray)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.js index 1577176e68af..24fb556e7a2f 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.js @@ -76,7 +76,6 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); * * @example * var Float32Array = require( '@stdlib/array/float32' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.native.js b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.native.js index 2f3b2c686d36..2f823ed4201f 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/ndarray.native.js @@ -37,7 +37,6 @@ var addon = require( './../src/addon.node' ); * * @example * var Float32Array = require( '@stdlib/array/float32' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); * diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json b/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json index e093d3100a91..aac9d6528ab6 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json @@ -92,9 +92,7 @@ "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/blas/base/shared" diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/src/addon.c b/lib/node_modules/@stdlib/stats/base/svariancewd/src/addon.c index b2e581f92154..ddf808c1f2de 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/src/addon.c @@ -32,7 +32,6 @@ * @param info callback data * @return Node-API value */ -float API_SUFFIX(stdlib_strided_svariancewd)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ); static napi_value addon( napi_env env, napi_callback_info info ) { STDLIB_NAPI_ARGV( env, info, argv, argc, 4 ); STDLIB_NAPI_ARGV_INT64( env, N, argv, 0 ); diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c b/lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c index 68cecec37717..7489f4cdeb0a 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c @@ -18,7 +18,6 @@ #include "stdlib/stats/base/svariancewd.h" #include "stdlib/blas/base/shared.h" -#include /** * Computes the variance of a single-precision floating-point strided array using Welford's algorithm. @@ -103,7 +102,7 @@ float API_SUFFIX(stdlib_strided_svariancewd)( const CBLAS_INT N, const float cor /** -* Computes the variance of a single-precision floating-point strided array using Welford's algorithm. +* Computes the variance of a single-precision floating-point strided array using Welford's algorithm using alternative indexing semantics. * * @param N number of indexed elements * @param correction degrees of freedom adjustment From 1b7b920d5fd2b6a1e4615b780aa791d935dc8cac Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Sat, 4 Jan 2025 11:10:35 +0530 Subject: [PATCH 07/15] fix: fixing mistakes --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - 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: passed - 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 --- --- .../base/svariancewd/benchmark/benchmark.js | 4 +-- .../svariancewd/benchmark/benchmark.native.js | 4 +-- .../benchmark/benchmark.ndarray.js | 2 +- .../benchmark/benchmark.ndarray.native.js | 4 +-- .../stats/base/svariancewd/lib/index.js | 1 - .../stats/base/svariancewd/lib/svariancewd.js | 34 ++----------------- .../stats/base/svariancewd/manifest.json | 22 ++++++------ .../@stdlib/stats/base/svariancewd/src/main.c | 33 ++---------------- 8 files changed, 23 insertions(+), 81 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.js index 6943c1ad44eb..2d813311091e 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.js @@ -30,7 +30,7 @@ var svariancewd = require( './../lib/svariancewd.js' ); // VARIABLES // -var option = { +var options = { 'dtype': 'float32' }; @@ -47,7 +47,7 @@ var option = { function createBenchmark( len ) { var x; - x = uniform( len, -10, 10, option ); + x = uniform( len, -10, 10, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.native.js index f6fc3fc9a6f8..0bb5d08e0af8 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.native.js @@ -35,7 +35,7 @@ var svariancewd = tryRequire( resolve( __dirname, './../lib/svariancewd.native.j var opts = { 'skip': ( svariancewd instanceof Error ) }; -var option = { +var options = { 'dtype': 'float32' }; @@ -52,7 +52,7 @@ var option = { function createBenchmark( len ) { var x; - x = uniform( len, -10, 10, option); + x = uniform( len, -10, 10, options); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js index 97f9c4572d34..d6ebf9e3f904 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js @@ -47,7 +47,7 @@ var options = { function createBenchmark( len ) { var x; - x = uniform( len, -10, 10, option ); + x = uniform( len, -10, 10, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.native.js index 155bd0becf16..07d27e0f8dcb 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.native.js @@ -35,7 +35,7 @@ var svariancewd = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) var opts = { 'skip': ( svariancewd instanceof Error ) }; -var option = { +var options = { 'dtype': 'float32' }; @@ -52,7 +52,7 @@ var option = { function createBenchmark( len ) { var x; - x = uniform( len, -10, 10, option ); + x = uniform( len, -10, 10, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/index.js b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/index.js index 18127e0e54ba..a3dc58abe743 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/index.js @@ -34,7 +34,6 @@ * * @example * var Float32Array = require( '@stdlib/array/float32' ); -* var floor = require( '@stdlib/math/base/special/floor' ); * var svariancewd = require( '@stdlib/stats/base/svariancewd' ); * * var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/svariancewd.js b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/svariancewd.js index 81f95732fecd..75125b0e0d0c 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/lib/svariancewd.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/lib/svariancewd.js @@ -20,7 +20,8 @@ // MODULES // -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -82,36 +83,7 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); * // returns ~4.3333 */ function svariancewd( N, correction, x, strideX ) { - var delta; - var mu; - var M2; - var ix; - var v; - var n; - var i; - - n = N - correction; - if ( N <= 0 || n <= 0.0 ) { - return NaN; - } - if ( N === 1 || strideX === 0 ) { - return 0.0; - } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } - M2 = 0.0; - mu = 0.0; - for ( i = 0; i < N; i++ ) { - v = x[ ix ]; - delta = float64ToFloat32( v - mu ); - mu = float64ToFloat32( mu + float64ToFloat32( delta / (i+1) ) ); - M2 = float64ToFloat32( M2 + float64ToFloat32( delta * float64ToFloat32( v - mu ) ) ); // eslint-disable-line max-len - ix += strideX; - } - return float64ToFloat32( M2 / n ); + return ndarray( N, correction, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json b/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json index aac9d6528ab6..2ce0247e6166 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json @@ -35,12 +35,11 @@ "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset", "@stdlib/napi/export", "@stdlib/napi/argv", "@stdlib/napi/argv-int64", @@ -58,12 +57,11 @@ "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -75,12 +73,11 @@ "include": [ "./include" ], - "libraries": [ - "-lm" - ], + "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] }, { @@ -95,7 +92,8 @@ "libraries": [], "libpath": [], "dependencies": [ - "@stdlib/blas/base/shared" + "@stdlib/blas/base/shared", + "@stdlib/strided/base/stride2offset" ] } ] diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c b/lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c index 7489f4cdeb0a..93f09a1efffd 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c @@ -18,6 +18,7 @@ #include "stdlib/stats/base/svariancewd.h" #include "stdlib/blas/base/shared.h" +#include "stdlib/strided/base/stride2offset.h" /** * Computes the variance of a single-precision floating-point strided array using Welford's algorithm. @@ -68,36 +69,8 @@ * @return output value */ float API_SUFFIX(stdlib_strided_svariancewd)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ) { - float delta; - int64_t ix; - int64_t i; - double n; - float mu; - float M2; - float v; - - n = (double)N - (double)correction; - if ( N <= 0 || n <= 0.0f ) { - return 0.0f / 0.0f; // NaN - } - if ( N == 1 || strideX == 0 ) { - return 0.0f; - } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } - M2 = 0.0f; - mu = 0.0f; - for ( i = 0; i < N; i++ ) { - v = X[ ix ]; - delta = v - mu; - mu += (float)((double)delta / (double)(i+1)); - M2 += delta * ( v - mu ); - ix += strideX; - } - return (double)M2 / n; + const CBLAS_INT ox = stdlib_strided_stride2offset( N, strideX ); + return API_SUFFIX(stdlib_strided_svariancewd_ndarray)( N, correction, X, strideX, ox ); } From 5fa1989e53f32825ca93b5e990028f0313b4f69e Mon Sep 17 00:00:00 2001 From: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Date: Sat, 4 Jan 2025 12:17:10 +0530 Subject: [PATCH 08/15] fix : removing multiple variable declaration Signed-off-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> --- .../@stdlib/stats/base/svariancewd/examples/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js b/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js index d20cce95478a..54db2bcf1d9a 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js @@ -21,7 +21,6 @@ var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var svariancewd = require( './../lib' ); -var x; var x = discreteUniform( 10, -50, 50, { 'dtype': 'float32' From 9479d535b82adf16b05e7c2eae9e485fd972bc26 Mon Sep 17 00:00:00 2001 From: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Date: Sat, 4 Jan 2025 12:31:09 +0530 Subject: [PATCH 09/15] style: removing extra line Signed-off-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> --- .../@stdlib/stats/base/svariancewd/examples/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js b/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js index 54db2bcf1d9a..bc6ca16f9511 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/examples/index.js @@ -21,7 +21,6 @@ var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var svariancewd = require( './../lib' ); - var x = discreteUniform( 10, -50, 50, { 'dtype': 'float32' }); From e4dd9d200e3ff6184f6995ac382a4bb35f565d16 Mon Sep 17 00:00:00 2001 From: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Date: Sat, 4 Jan 2025 21:58:25 +0530 Subject: [PATCH 10/15] fix: set the datatype to be float32 explicitly Signed-off-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> --- lib/node_modules/@stdlib/stats/base/svariancewd/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/README.md b/lib/node_modules/@stdlib/stats/base/svariancewd/README.md index 5b966e08bb17..349595eab192 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/README.md +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/README.md @@ -198,7 +198,9 @@ var svariancewd = require( '@stdlib/stats/base/svariancewd' ); var x; -x = discreteUniform( 10, -50, 50 ); +x = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' +}); console.log( x ); var v = svariancewd( x.length, 1, x, 1 ); From db27322d8039c62d79dc870573ab8e7d65d2e138 Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Sat, 4 Jan 2025 22:07:06 +0530 Subject: [PATCH 11/15] fix: declare and assign variables --- 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: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: passed - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/stats/base/svariancewd/README.md | 6 ++---- .../@stdlib/stats/base/svariancewd/benchmark/benchmark.js | 4 +--- .../stats/base/svariancewd/benchmark/benchmark.native.js | 4 +--- .../stats/base/svariancewd/benchmark/benchmark.ndarray.js | 4 +--- .../base/svariancewd/benchmark/benchmark.ndarray.native.js | 4 +--- 5 files changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/README.md b/lib/node_modules/@stdlib/stats/base/svariancewd/README.md index 349595eab192..94623118a419 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/README.md +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/README.md @@ -196,10 +196,8 @@ var v = svariancewd.ndarray( 4, 1, x, 2, 1 ); var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var svariancewd = require( '@stdlib/stats/base/svariancewd' ); -var x; - -x = discreteUniform( 10, -50, 50, { - 'dtype': 'float32' +var x = discreteUniform( 10, -50, 50, { + 'dtype': 'float32' }); console.log( x ); diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.js index 2d813311091e..e7ae2e8fe21c 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.js @@ -45,9 +45,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - - x = uniform( len, -10, 10, options ); + var x = uniform( len, -10, 10, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.native.js index 0bb5d08e0af8..f0f56f7589bf 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.native.js @@ -50,9 +50,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - - x = uniform( len, -10, 10, options); + var x = uniform( len, -10, 10, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js index d6ebf9e3f904..d480fe631629 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.js @@ -45,9 +45,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - - x = uniform( len, -10, 10, options ); + var x = uniform( len, -10, 10, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.native.js b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.native.js index 07d27e0f8dcb..65cdb8dc48ef 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.native.js +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/benchmark/benchmark.ndarray.native.js @@ -50,9 +50,7 @@ var options = { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - - x = uniform( len, -10, 10, options ); + var x = uniform( len, -10, 10, options ); return benchmark; function benchmark( b ) { From c26883f3acba743bb0be06cb64c589f1b716623c Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 6 Jan 2025 01:17:09 -0800 Subject: [PATCH 12/15] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/stats/base/svariancewd/README.md | 4 ++-- .../base/svariancewd/include/stdlib/stats/base/svariancewd.h | 2 +- lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/README.md b/lib/node_modules/@stdlib/stats/base/svariancewd/README.md index 94623118a419..42e516002d54 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/README.md +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/README.md @@ -237,7 +237,7 @@ console.log( v ); #### stdlib_strided_svariancewd( N, correction, \*X, strideX ) -Computes the [variance][variance] of a single-precision floating-point strided array `x` using Welford's algorithm. +Computes the [variance][variance] of a single-precision floating-point strided array using Welford's algorithm. ```c const float x[] = { 1.0f, -2.0f, 2.0f }; @@ -249,7 +249,7 @@ float v = stdlib_strided_svariancewd( 3, 1, x, 1 ); The function accepts the following arguments: - **N**: `[in] CBLAS_INT` number of indexed elements. -- **correction**: `[in] FLOAT` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). +- **correction**: `[in] float` degrees of freedom adjustment. Setting this parameter to a value other than `0` has the effect of adjusting the divisor during the calculation of the [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction). - **X**: `[in] float*` input array. - **strideX**: `[in] CBLAS_INT` stride length for `X`. diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/include/stdlib/stats/base/svariancewd.h b/lib/node_modules/@stdlib/stats/base/svariancewd/include/stdlib/stats/base/svariancewd.h index 5b27f4962249..bf9a969a728e 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/include/stdlib/stats/base/svariancewd.h +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/include/stdlib/stats/base/svariancewd.h @@ -34,7 +34,7 @@ extern "C" { float API_SUFFIX(stdlib_strided_svariancewd)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX ); /** -* Computes the variance of a single-precision floating-point strided array using Welford's algorithm and using alternative indexing semantics. +* Computes the variance of a single-precision floating-point strided array using Welford's algorithm and alternative indexing semantics. */ float API_SUFFIX(stdlib_strided_svariancewd_ndarray)( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX ); diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c b/lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c index 93f09a1efffd..8ddd4a52727d 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/src/main.c @@ -73,9 +73,8 @@ float API_SUFFIX(stdlib_strided_svariancewd)( const CBLAS_INT N, const float cor return API_SUFFIX(stdlib_strided_svariancewd_ndarray)( N, correction, X, strideX, ox ); } - /** -* Computes the variance of a single-precision floating-point strided array using Welford's algorithm using alternative indexing semantics. +* Computes the variance of a single-precision floating-point strided array using Welford's algorithm and alternative indexing semantics. * * @param N number of indexed elements * @param correction degrees of freedom adjustment From 7497f94a58dad488cd0b8972d1b471c648ae3447 Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Mon, 6 Jan 2025 16:59:36 +0530 Subject: [PATCH 13/15] fix: fixing repl txt --- 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: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- .../@stdlib/stats/base/svariancewd/docs/repl.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt index 570f439d374d..c9109e48ee3c 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt @@ -3,8 +3,8 @@ Computes the variance of a single-precision floating-point strided array using Welford's algorithm. - The `N` and stride parameters determine which elements in x are accessed - at runtime. + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -46,7 +46,7 @@ > {{alias}}( x.length, 1, x, 1 ) ~4.3333 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] ); > {{alias}}( 3, 1, x, 2 ) ~4.3333 @@ -111,4 +111,3 @@ See Also -------- - From 37e93e4321451f2208e03d0becc02b51060601d4 Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Mon, 6 Jan 2025 15:19:52 +0000 Subject: [PATCH 14/15] style: fixing space in manifest json --- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json b/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json index 2ce0247e6166..9014680cde0c 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/manifest.json @@ -27,8 +27,8 @@ ], "confs": [ { - "task": "build", - "wasm": false, + "task": "build", + "wasm": false, "src": [ "./src/main.c" ], From eee5b55654517d07e66438fe3cfd058dca2bf16c Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Wed, 15 Jan 2025 17:44:39 +0000 Subject: [PATCH 15/15] fix: add trailing space in repl txt --- 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: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na --- --- lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt index c9109e48ee3c..e77f7145d918 100644 --- a/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/svariancewd/docs/repl.txt @@ -111,3 +111,4 @@ See Also -------- +