From 1c7531d124447beccd5492e5ae85bc53fee8a9a0 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Tue, 7 Jan 2025 15:12:54 +0000 Subject: [PATCH 1/3] refactor: update to follow current project conventions --- 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: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: 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 --- --- .../blas/ext/base/gnansumkbn2/README.md | 54 ++++++---------- .../base/gnansumkbn2/benchmark/benchmark.js | 29 +++++---- .../benchmark/benchmark.ndarray.js | 29 +++++---- .../blas/ext/base/gnansumkbn2/docs/repl.txt | 34 +++++------ .../base/gnansumkbn2/docs/types/index.d.ts | 12 ++-- .../ext/base/gnansumkbn2/examples/index.js | 23 +++---- .../blas/ext/base/gnansumkbn2/lib/index.js | 7 +-- .../blas/ext/base/gnansumkbn2/lib/main.js | 61 ++----------------- .../blas/ext/base/gnansumkbn2/lib/ndarray.js | 21 +++---- .../ext/base/gnansumkbn2/test/test.main.js | 16 ++++- .../ext/base/gnansumkbn2/test/test.ndarray.js | 16 ++++- 11 files changed, 130 insertions(+), 172 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/README.md b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/README.md index b3556d9cf6ec..d27596f23764 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/README.md @@ -36,15 +36,14 @@ limitations under the License. var gnansumkbn2 = require( '@stdlib/blas/ext/base/gnansumkbn2' ); ``` -#### gnansumkbn2( N, x, stride ) +#### gnansumkbn2( N, x, strideX ) Computes the sum of strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm. ```javascript var x = [ 1.0, -2.0, NaN, 2.0 ]; -var N = x.length; -var v = gnansumkbn2( N, x, 1 ); +var v = gnansumkbn2( x.length, x, 1 ); // returns 1.0 ``` @@ -52,17 +51,14 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. -- **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 sum 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 sum of every other element: ```javascript -var floor = require( '@stdlib/math/base/special/floor' ); - var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN, NaN ]; -var N = floor( x.length / 2 ); -var v = gnansumkbn2( N, x, 2 ); +var v = gnansumkbn2( 5, x, 2 ); // returns 5.0 ``` @@ -72,42 +68,35 @@ Note that indexing is relative to the first index. To introduce an offset, use [ ```javascript var Float64Array = require( '@stdlib/array/float64' ); -var floor = require( '@stdlib/math/base/special/floor' ); var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length / 2 ); - -var v = gnansumkbn2( N, x1, 2 ); +var v = gnansumkbn2( 4, x1, 2 ); // returns 5.0 ``` -#### gnansumkbn2.ndarray( N, x, stride, offset ) +#### gnansumkbn2.ndarray( N, x, strideX, offsetX ) Computes the sum of strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics. ```javascript var x = [ 1.0, -2.0, NaN, 2.0 ]; -var N = x.length; -var v = gnansumkbn2.ndarray( N, x, 1, 0 ); +var v = gnansumkbn2.ndarray( x.length, x, 1, 0 ); // returns 1.0 ``` 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 sum of 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 sum of every other element starting from the second element: ```javascript -var floor = require( '@stdlib/math/base/special/floor' ); - var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ]; -var N = floor( x.length / 2 ); -var v = gnansumkbn2.ndarray( N, x, 2, 1 ); +var v = gnansumkbn2.ndarray( 5, x, 2, 1 ); // returns 5.0 ``` @@ -133,22 +122,19 @@ var v = gnansumkbn2.ndarray( N, x, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var gnansumkbn2 = require( '@stdlib/blas/ext/base/gnansumkbn2' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = round( randu()*100.0 ); +function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return discreteUniform( 0, 100 ); } + return NaN; } + +var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = gnansumkbn2( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.js index 809e7ed517ee..09eb26c1becf 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.js @@ -21,7 +21,9 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; @@ -30,6 +32,19 @@ var gnansumkbn2 = require( './../lib/main.js' ); // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( -10.0, 10.0 ); + } + return NaN; +} + /** * Creates a benchmark function. * @@ -38,17 +53,7 @@ var gnansumkbn2 = require( './../lib/main.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - if ( randu() < 0.2 ) { - x.push( NaN ); - } else { - x.push( ( randu()*10.0 ) - 20.0 ); - } - } + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.ndarray.js index 1e49f9d343b8..fd89ed9eaacd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.ndarray.js @@ -21,7 +21,9 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var randu = require( '@stdlib/random/base/randu' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var pkg = require( './../package.json' ).name; @@ -30,6 +32,19 @@ var gnansumkbn2 = require( './../lib/ndarray.js' ); // FUNCTIONS // +/** +* Returns a random number. +* +* @private +* @returns {number} random number +*/ +function rand() { + if ( bernoulli( 0.7 ) > 0 ) { + return discreteUniform( -10.0, 10.0 ); + } + return NaN; +} + /** * Creates a benchmark function. * @@ -38,17 +53,7 @@ var gnansumkbn2 = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - if ( randu() < 0.2 ) { - x.push( NaN ); - } else { - x.push( ( randu()*10.0 ) - 20.0 ); - } - } + var x = filledarrayBy( len, 'float64', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/docs/repl.txt index d07302742133..67d538b3dd8a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the sum of strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška 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. @@ -19,8 +19,8 @@ x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. Returns ------- @@ -34,28 +34,25 @@ > {{alias}}( x.length, x, 1 ) 1.0 - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0, NaN, NaN ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, x, stride ) + > {{alias}}( 4, x, 2 ) 1.0 // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ] ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > stride = 2; - > {{alias}}( N, x1, stride ) + > {{alias}}( 4, x1, 2 ) -1.0 -{{alias}}.ndarray( N, x, stride, offset ) + +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the sum of strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics. While typed array views mandate a view offset based on the underlying - buffer, the `offset` parameter supports indexing semantics based on a + buffer, the offset parameter supports indexing semantics based on a starting index. Parameters @@ -66,10 +63,10 @@ x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -86,8 +83,7 @@ // Using offset parameter: > var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0, NaN, NaN ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, x, 2, 1 ) + > {{alias}}.ndarray( 4, x, 2, 1 ) -1.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/docs/types/index.d.ts index 5da01246333c..c7f1de9324d8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/docs/types/index.d.ts @@ -31,7 +31,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns sum * * @example @@ -40,15 +40,15 @@ interface Routine { * var v = gnansumkbn2( x.length, x, 1 ); * // returns 1.0 */ - ( N: number, x: NumericArray, stride: number ): number; + ( N: number, x: NumericArray, strideX: number ): number; /** * Computes the sum of strided array elements, ignoring `NaN` values and using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics. * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns sum * * @example @@ -57,7 +57,7 @@ interface Routine { * var v = gnansumkbn2.ndarray( x.length, x, 1, 0 ); * // returns 1.0 */ - ndarray( N: number, x: NumericArray, stride: number, offset: number ): number; + ndarray( N: number, x: NumericArray, strideX: number, offsetX: number ): number; } /** @@ -65,7 +65,7 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array -* @param stride - stride length +* @param strideX - stride length * @returns sum * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/examples/index.js index c92c67bc5e9c..fadc6162a5f0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/examples/index.js @@ -18,22 +18,19 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); -var gnansumkbn2 = require( './../lib' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); +var gnansumkbn2 = require( '@stdlib/blas/ext/base/gnansumkbn2' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - if ( randu() < 0.2 ) { - x[ i ] = NaN; - } else { - x[ i ] = round( randu()*100.0 ); +function rand() { + if ( bernoulli( 0.8 ) > 0 ) { + return discreteUniform( 0, 100 ); } + return NaN; } + +var x = filledarrayBy( 10, 'float64', rand ); console.log( x ); var v = gnansumkbn2( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/lib/index.js index ecafea2ef182..706090a51b1d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/lib/index.js @@ -27,19 +27,16 @@ * var gnansumkbn2 = require( '@stdlib/blas/ext/base/gnansumkbn2' ); * * var x = [ 1.0, -2.0, NaN, 2.0 ]; -* var N = x.length; * -* var v = gnansumkbn2( N, x, 1 ); +* var v = gnansumkbn2( x.length, x, 1 ); * // returns 1.0 * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); * var gnansumkbn2 = require( '@stdlib/blas/ext/base/gnansumkbn2' ); * * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ]; -* var N = floor( x.length / 2 ); * -* var v = gnansumkbn2.ndarray( N, x, 2, 1 ); +* var v = gnansumkbn2.ndarray( 5, x, 2, 1 ); * // returns 5.0 */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/lib/main.js index 70f41b142fa4..1014794a3008 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/lib/main.js @@ -20,8 +20,8 @@ // MODULES // -var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var abs = require( '@stdlib/math/base/special/abs' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -39,66 +39,17 @@ var abs = require( '@stdlib/math/base/special/abs' ); * * @param {PositiveInteger} N - number of indexed elements * @param {NumericArray} x - input array -* @param {integer} stride - stride length +* @param {integer} strideX - stride length * @returns {number} sum * * @example * var x = [ 1.0, -2.0, NaN, 2.0 ]; -* var N = x.length; * -* var v = gnansumkbn2( N, x, 1 ); +* var v = gnansumkbn2( x.length, x, 1 ); * // returns 1.0 */ -function gnansumkbn2( N, x, stride ) { - var sum; - var ccs; - var ix; - var cs; - var cc; - var v; - var t; - var c; - var i; - - if ( N <= 0 ) { - return 0.0; - } - if ( N === 1 || stride === 0 ) { - if ( isnan( x[ 0 ] ) ) { - return 0.0; - } - return x[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - sum = 0.0; - ccs = 0.0; // second order correction term for lost low order bits - cs = 0.0; // first order correction term for lost low order bits - for ( i = 0; i < N; i++ ) { - v = x[ ix ]; - if ( isnan( v ) === false ) { - t = sum + v; - if ( abs( sum ) >= abs( v ) ) { - c = (sum-t) + v; - } else { - c = (v-t) + sum; - } - sum = t; - t = cs + c; - if ( abs( cs ) >= abs( c ) ) { - cc = (cs-t) + c; - } else { - cc = (c-t) + cs; - } - cs = t; - ccs += cc; - } - ix += stride; - } - return sum + cs + ccs; +function gnansumkbn2( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/lib/ndarray.js index 2eff8dfb04ee..9a6efa538350 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/lib/ndarray.js @@ -39,20 +39,17 @@ var abs = require( '@stdlib/math/base/special/abs' ); * * @param {PositiveInteger} N - number of indexed elements * @param {NumericArray} 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} sum * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); -* * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; -* var N = floor( x.length / 2 ); * -* var v = gnansumkbn2( N, x, 2, 1 ); +* var v = gnansumkbn2( 4, x, 2, 1 ); * // returns 5.0 */ -function gnansumkbn2( N, x, stride, offset ) { +function gnansumkbn2( N, x, strideX, offsetX ) { var sum; var ccs; var ix; @@ -66,13 +63,13 @@ function gnansumkbn2( N, x, stride, offset ) { if ( N <= 0 ) { return 0.0; } - if ( N === 1 || stride === 0 ) { - if ( isnan( x[ offset ] ) ) { + ix = offsetX; + if ( strideX === 0 ) { + if ( isnan( x[ ix ] ) ) { return 0.0; } - return x[ offset ]; + return N * x[ ix ]; } - ix = offset; sum = 0.0; ccs = 0.0; // second order correction term for lost low order bits cs = 0.0; // first order correction term for lost low order bits @@ -95,7 +92,7 @@ function gnansumkbn2( N, x, stride, offset ) { cs = t; ccs += cc; } - ix += stride; + ix += strideX; } return sum + cs + ccs; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.main.js index 499a81fba060..94a66b8c89aa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.main.js @@ -151,14 +151,26 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) { var x; var v; x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; v = gnansumkbn2( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0` and the first element is NaN, the function returns 0', function test( t ) { + var x; + var v; + + x = [ NaN, -2.0, -4.0, 5.0, 3.0 ]; + + v = gnansumkbn2( x.length, x, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.ndarray.js index a403de537710..2391d0865ac8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.ndarray.js @@ -150,14 +150,26 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first indexed element', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the sum of the first element repeated N times', function test( t ) { var x; var v; x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; v = gnansumkbn2( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0` and the first element is NaN, the function returns 0', function test( t ) { + var x; + var v; + + x = [ NaN, -2.0, -4.0, 5.0, 3.0 ]; + + v = gnansumkbn2( x.length, x, 0, 0 ); + t.strictEqual( v, 0.0, 'returns expected value' ); t.end(); }); From 34cbfba6fb2f5a0a7b0eb7db0468cf3f9963850f Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 8 Jan 2025 04:23:36 +0000 Subject: [PATCH 2/3] fix: apply code review suggestion --- 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: 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: na - 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 --- --- .../@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.js | 2 +- .../blas/ext/base/gnansumkbn2/benchmark/benchmark.ndarray.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.js index 09eb26c1becf..d88d8cbe937f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.js @@ -53,7 +53,7 @@ function rand() { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x = filledarrayBy( len, 'generic', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.ndarray.js index fd89ed9eaacd..118d8e0dc9ac 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/benchmark/benchmark.ndarray.js @@ -53,7 +53,7 @@ function rand() { * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filledarrayBy( len, 'float64', rand ); + var x = filledarrayBy( len, 'generic', rand ); return benchmark; function benchmark( b ) { From b1944c5f98e7fede44e9fb65d0603429726dbf78 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Wed, 8 Jan 2025 04:34:50 +0000 Subject: [PATCH 3/3] refactor: apply code review suggestion --- 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: passed - 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: passed --- --- .../blas/ext/base/gnansumkbn2/test/test.main.js | 13 +++---------- .../blas/ext/base/gnansumkbn2/test/test.ndarray.js | 13 +++---------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.main.js index 94a66b8c89aa..951898d41296 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.main.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var Float64Array = require( '@stdlib/array/float64' ); var gnansumkbn2 = require( './../lib' ); @@ -102,7 +101,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -119,15 +117,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]; - N = floor( x.length / 2 ); - v = gnansumkbn2( N, x, 2 ); + v = gnansumkbn2( 5, x, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -144,8 +140,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = gnansumkbn2( N, x, -2 ); + v = gnansumkbn2( 5, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -178,7 +173,6 @@ tape( 'if provided a `stride` parameter equal to `0` and the first element is Na tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -196,9 +190,8 @@ tape( 'the function supports view offsets', function test( t ) { ]); x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element - N = floor(x1.length / 2); - v = gnansumkbn2( N, x1, 2 ); + v = gnansumkbn2( 5, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.ndarray.js index 2391d0865ac8..4f47cddca8c6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnansumkbn2/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var gnansumkbn2 = require( './../lib/ndarray.js' ); @@ -101,7 +100,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first }); tape( 'the function supports a `stride` parameter', function test( t ) { - var N; var x; var v; @@ -118,15 +116,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { NaN ]; - N = floor( x.length / 2 ); - v = gnansumkbn2( N, x, 2, 0 ); + v = gnansumkbn2( 5, x, 2, 0 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports a negative `stride` parameter', function test( t ) { - var N; var x; var v; @@ -143,8 +139,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = gnansumkbn2( N, x, -2, 8 ); + v = gnansumkbn2( 5, x, -2, 8 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); @@ -175,7 +170,6 @@ tape( 'if provided a `stride` parameter equal to `0` and the first element is Na }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -191,9 +185,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { NaN, NaN // 4 ]; - N = floor( x.length / 2 ); - v = gnansumkbn2( N, x, 2, 1 ); + v = gnansumkbn2( 5, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end();