diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/README.md b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/README.md index 2c082e484954..d8d36cad837f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/README.md @@ -52,20 +52,17 @@ The function has the following parameters: - **N**: number of indexed elements. - **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. -- **strideX**: index increment for `x`. +- **strideX**: stride length for `x`. - **out**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array] whose first element is the sum and whose second element is the number of non-NaN elements. -- **strideOut**: index increment for `out`. +- **strideOut**: stride length for `out`. -The `N` and `stride` parameters determine which elements are accessed at runtime. For example, to compute the sum of every other element in `x`, +The `N` and stride parameters determine which elements 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, NaN, -7.0, NaN, 3.0, 4.0, 2.0 ]; var out = [ 0.0, 0 ]; -var N = floor( x.length / 2 ); -var v = gnannsumkbn( N, x, 2, out, 1 ); +var v = gnannsumkbn( 4, x, 2, out, 1 ); // returns [ 5.0, 2 ] ``` @@ -75,7 +72,6 @@ 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, NaN, -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 @@ -83,9 +79,7 @@ var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd var out0 = new Float64Array( 4 ); var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*2 ); // start at 3rd element -var N = floor( x0.length / 2 ); - -var v = gnannsumkbn( N, x1, 2, out1, 1 ); +var v = gnannsumkbn( 4, x1, 2, out1, 1 ); // returns [ 5.0, 4 ] ``` @@ -106,16 +100,13 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetOut**: starting index for `out`. -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 parameters support indexing semantics based on starting indices. 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, NaN, -2.0, -2.0, 2.0, 3.0, 4.0 ]; var out = [ 0.0, 0.0, 0.0, 0 ]; -var N = floor( x.length / 2 ); -var v = gnannsumkbn.ndarray( N, x, 2, 1, out, 2, 1 ); +var v = gnannsumkbn.ndarray( 4, x, 2, 1, out, 2, 1 ); // returns [ 0.0, 5.0, 0.0, 4 ] ``` @@ -140,22 +131,20 @@ var v = gnannsumkbn.ndarray( N, x, 2, 1, out, 2, 1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var Float64Array = require( '@stdlib/array/float64' ); var gnannsumkbn = require( '@stdlib/blas/ext/base/gnannsumkbn' ); -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 out = new Float64Array( 2 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/benchmark/benchmark.js index 16729be1aa14..5032733667b3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/benchmark/benchmark.js @@ -21,15 +21,31 @@ // 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 zeros = require( '@stdlib/array/base/zeros' ); var pkg = require( './../package.json' ).name; var gnannsumkbn = 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,19 +54,8 @@ var gnannsumkbn = require( './../lib/main.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var out; - 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 ); - } - } - out = [ 0.0, 0 ]; + var out = zeros( 2 ); + var x = filledarrayBy( len, 'generic', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/benchmark/benchmark.ndarray.js index fdffbb52fa7c..e745ede588ee 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/benchmark/benchmark.ndarray.js @@ -21,15 +21,31 @@ // 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 zeros = require( '@stdlib/array/base/zeros' ); var pkg = require( './../package.json' ).name; var gnannsumkbn = 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,19 +54,8 @@ var gnannsumkbn = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var out; - 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 ); - } - } - out = [ 0.0, 0 ]; + var out = zeros( 2 ); + var x = filledarrayBy( len, 'generic', rand ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/docs/repl.txt index 37e78bd71688..ff1eb7a20322 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/docs/repl.txt @@ -3,7 +3,7 @@ Computes the sum of strided array elements, ignoring `NaN` values and using an improved Kahan–Babuška algorithm. - The `N` and `stride` parameters determine which elements are accessed at + The `N` and stride parameters determine which elements are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed @@ -20,13 +20,13 @@ Input array. strideX: integer - Index increment for `x`. + Stride length for `x`. out: Array|TypedArray Output array. strideOut: integer - Index increment for `out`. + Stride length for `out`. Returns ------- @@ -42,28 +42,27 @@ > {{alias}}( x.length, x, 1, out, 1 ) [ 1.0, 3 ] - // 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 ]; > out = [ 0.0, 0 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}( N, x, 2, out, 1 ) + > {{alias}}( 4, x, 2, out, 1 ) [ 1.0, 3 ] // 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 ); > out = [ 0.0, 0 ]; - > {{alias}}( N, x1, 2, out, 1 ) + > {{alias}}( 4, x1, 2, out, 1 ) [ 1.0, 3 ] + {{alias}}.ndarray( N, x, strideX, offsetX, out, strideOut, offsetOut ) Computes the sum of strided array elements, ignoring `NaN` values and using an improved 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 - starting index. + buffer, the offset parameters support indexing semantics based on a starting + indices. Parameters ---------- @@ -74,7 +73,7 @@ Input array. strideX: integer - Index increment for `x`. + Stride length for `x`. offsetX: integer Starting index for `x`. @@ -83,7 +82,7 @@ Output array. strideOut: integer - Index increment for `out`. + Stride length for `out`. offsetOut: integer Starting index for `out`. @@ -104,9 +103,8 @@ // 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 ); > out = [ 0.0, 0 ]; - > {{alias}}.ndarray( N, x, 2, 1, out, 1, 0 ) + > {{alias}}.ndarray( 4, x, 2, 1, out, 1, 0 ) [ 1.0, 3 ] See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/docs/types/index.d.ts index e38292bfc73c..ccec623bb8d4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/docs/types/index.d.ts @@ -31,9 +31,9 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param strideX - `x` stride length + * @param strideX - stride length for `x` * @param out - output array whose first element is the sum and whose second element is the number of non-NaN elements - * @param strideOut - `out` stride length + * @param strideOut - stride length for `out` * @returns output array * * @example @@ -50,11 +50,11 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param strideX - `x` stride length - * @param offsetX - `x` starting index + * @param strideX - stride length for `x` + * @param offsetX - starting index for `x` * @param out - output array whose first element is the sum and whose second element is the number of non-NaN elements - * @param strideOut - `out` stride length - * @param offsetOut - `out` starting index + * @param strideOut - stride length for `out` + * @param offsetOut - starting index for `out` * @returns output array * * @example @@ -72,9 +72,9 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array -* @param strideX - `x` stride length +* @param strideX - stride length for `x` * @param out - output array whose first element is the sum and whose second element is the number of non-NaN elements -* @param strideOut - `out` stride length +* @param strideOut - stride length for `out` * @returns output array * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/examples/index.js index 3695ba3f287e..8b293afebf6a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/examples/index.js @@ -18,25 +18,22 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var bernoulli = require( '@stdlib/random/base/bernoulli' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var filledarrayBy = require( '@stdlib/array/filled-by' ); var Float64Array = require( '@stdlib/array/float64' ); var gnannsumkbn = require( './../lib' ); -var out; -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 ); -out = new Float64Array( 2 ); +var out = new Float64Array( 2 ); gnannsumkbn( x.length, x, 1, out, 1 ); console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/lib/index.js index 8a2ceed5040f..5d63097f7793 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/lib/index.js @@ -33,15 +33,12 @@ * // returns [ 1.0, 3 ] * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); * var gnannsumkbn = require( '@stdlib/blas/ext/base/gnannsumkbn' ); * * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ]; * var out = [ 0.0, 0 ]; * -* var N = floor( x.length / 2 ); -* -* var v = gnannsumkbn.ndarray( N, x, 2, 1, out, 1, 0 ); +* var v = gnannsumkbn.ndarray( 5, x, 2, 1, out, 1, 0 ); * // returns [ 5.0, 4 ] */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/lib/main.js index da1eca5a14d2..c65bfa3179d7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/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,9 +39,9 @@ var abs = require( '@stdlib/math/base/special/abs' ); * * @param {PositiveInteger} N - number of indexed elements * @param {NumericArray} x - input array -* @param {integer} strideX - `x` stride length +* @param {integer} strideX - stride length for `x` * @param {NumericArray} out - output array -* @param {integer} strideOut - `out` stride length +* @param {integer} strideOut - stride length for `out` * @returns {NumericArray} output array * * @example @@ -52,60 +52,9 @@ var abs = require( '@stdlib/math/base/special/abs' ); * // returns [ 1.0, 3 ] */ function gnannsumkbn( N, x, strideX, out, strideOut ) { - var sum; - var ix; - var io; - var v; - var t; - var c; - var n; - var i; - - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } - if ( strideOut < 0 ) { - io = -strideOut; - } else { - io = 0; - } - sum = 0.0; - if ( N <= 0 ) { - out[ io ] = sum; - out[ io+strideOut ] = 0; - return out; - } - if ( N === 1 || strideX === 0 ) { - if ( isnan( x[ ix ] ) ) { - out[ io ] = sum; - out[ io+strideOut ] = 0; - return out; - } - out[ io ] = x[ ix ]; - out[ io+strideOut ] = 1; - return out; - } - c = 0.0; - n = 0; - 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; - n += 1; - } - ix += strideX; - } - out[ io ] = sum + c; - out[ io+strideOut ] = n; - return out; + var ix = stride2offset( N, strideX ); + var io = stride2offset( 2, strideOut ); + return ndarray( N, x, strideX, ix, out, strideOut, io ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/lib/ndarray.js index 976fa79aa64c..1c2cc2d86869 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/lib/ndarray.js @@ -39,51 +39,44 @@ var abs = require( '@stdlib/math/base/special/abs' ); * * @param {PositiveInteger} N - number of indexed elements * @param {NumericArray} x - input array -* @param {integer} strideX - `x` stride length -* @param {NonNegativeInteger} offsetX - `x` starting index +* @param {integer} strideX - stride length for `x` +* @param {NonNegativeInteger} offsetX - starting index for `x` * @param {NumericArray} out - output array -* @param {integer} strideOut - `out` stride length -* @param {NonNegativeInteger} offsetOut - `out` starting index +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index for `out` * @returns {NumericArray} output array * * @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, NaN, NaN ]; * var out = [ 0.0, 0 ]; * -* var N = floor( x.length / 2 ); -* -* var v = gnannsumkbn( N, x, 2, 1, out, 1, 0 ); +* var v = gnannsumkbn( 5, x, 2, 1, out, 1, 0 ); * // returns [ 5.0, 4 ] */ function gnannsumkbn( N, x, strideX, offsetX, out, strideOut, offsetOut ) { var sum; var ix; - var io; var v; var t; var c; var n; var i; - ix = offsetX; - io = offsetOut; - sum = 0.0; if ( N <= 0 ) { - out[ io ] = sum; - out[ io+strideOut ] = 0; + out[ offsetOut ] = sum; + out[ offsetOut+strideOut ] = 0; return out; } - if ( N === 1 || strideX === 0 ) { + ix = offsetX; + if ( strideX === 0 ) { if ( isnan( x[ ix ] ) ) { - out[ io ] = sum; - out[ io+strideOut ] = 0; + out[ offsetOut ] = sum; + out[ offsetOut+strideOut ] = 0; return out; } - out[ io ] = x[ ix ]; - out[ io+strideOut ] = 1; + out[ offsetOut ] = x[ ix ] * N; + out[ offsetOut+strideOut ] = N; return out; } c = 0.0; @@ -102,8 +95,8 @@ function gnannsumkbn( N, x, strideX, offsetX, out, strideOut, offsetOut ) { } ix += strideX; } - out[ io ] = sum + c; - out[ io+strideOut ] = n; + out[ offsetOut ] = sum + c; + out[ offsetOut+strideOut ] = n; return out; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/test/test.main.js index e72184b62b7c..42f172749130 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/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 gnannsumkbn = require( './../lib' ); @@ -163,7 +162,6 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns a sum equ tape( 'the function supports `stride` parameters', function test( t ) { var expected; var out; - var N; var x; var v; @@ -181,8 +179,7 @@ tape( 'the function supports `stride` parameters', function test( t ) { ]; out = [ 0.0, 0.0, 0.0, 0.0 ]; - N = floor( x.length / 2 ); - v = gnannsumkbn( N, x, 2, out, 2 ); + v = gnannsumkbn( 5, x, 2, out, 2 ); expected = [ 5.0, 0.0, 4.0, 0.0 ]; t.deepEqual( v, expected, 'returns expected value' ); @@ -193,7 +190,6 @@ tape( 'the function supports `stride` parameters', function test( t ) { tape( 'the function supports negative `stride` parameters', function test( t ) { var expected; var out; - var N; var x; var v; @@ -211,8 +207,7 @@ tape( 'the function supports negative `stride` parameters', function test( t ) { ]; out = [ 0.0, 0.0, 0.0, 0.0 ]; - N = floor( x.length / 2 ); - v = gnannsumkbn( N, x, -2, out, -2 ); + v = gnannsumkbn( 5, x, -2, out, -2 ); expected = [ 4.0, 0.0, 5.0, 0.0 ]; t.deepEqual( v, expected, 'returns expected value' ); @@ -220,7 +215,7 @@ tape( 'the function supports negative `stride` parameters', function test( t ) { t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns a sum equal to the first element', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the of the first element repeated N times', function test( t ) { var expected; var out; var x; @@ -231,7 +226,24 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns a sum out = [ 0.0, 0.0 ]; v = gnannsumkbn( x.length, x, 0, out, 1 ); - expected = [ 1.0, 1.0 ]; + expected = [ 5.0, 5.0 ]; + t.deepEqual( v, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0` and the first element is `NaN`, the function returns `0.0`', function test( t ) { + var expected; + var out; + var x; + var v; + + x = [ NaN, -2.0, -4.0, 5.0, 3.0 ]; + + out = [ 0.0, 0.0 ]; + v = gnannsumkbn( x.length, x, 0, out, 1 ); + + expected = [ 0.0, 0.0 ]; t.deepEqual( v, expected, 'returns expected value' ); t.end(); @@ -244,7 +256,6 @@ tape( 'the function supports view offsets', function test( t ) { var out1; var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -264,9 +275,8 @@ tape( 'the function supports view offsets', function test( t ) { x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*2 ); // start at the 3rd element - N = floor(x1.length / 2); - v = gnannsumkbn( N, x1, 2, out1, 1 ); + v = gnannsumkbn( 5, x1, 2, out1, 1 ); expected0 = new Float64Array( [ 0.0, 0.0, 5.0, 4.0 ] ); expected1 = new Float64Array( [ 5.0, 4.0 ] ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/test/test.ndarray.js index d1b61d27cea5..b3fb5364bf72 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gnannsumkbn/test/test.ndarray.js @@ -21,7 +21,6 @@ // MODULES // var tape = require( 'tape' ); -var floor = require( '@stdlib/math/base/special/floor' ); var gnannsumkbn = require( './../lib/ndarray.js' ); @@ -162,7 +161,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 expected; var out; - var N; var x; var v; @@ -180,8 +178,7 @@ tape( 'the function supports a `stride` parameter', function test( t ) { ]; out = [ 0.0, 0.0, 0.0, 0.0 ]; - N = floor( x.length / 2 ); - v = gnannsumkbn( N, x, 2, 0, out, 2, 0 ); + v = gnannsumkbn( 5, x, 2, 0, out, 2, 0 ); expected = [ 5.0, 0.0, 4.0, 0.0 ]; t.deepEqual( v, expected, 'returns expected value' ); @@ -192,7 +189,6 @@ tape( 'the function supports a `stride` parameter', function test( t ) { tape( 'the function supports a negative `stride` parameter', function test( t ) { var expected; var out; - var N; var x; var v; @@ -210,8 +206,7 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) ]; out = [ 0.0, 0.0, 0.0, 0.0 ]; - N = floor( x.length / 2 ); - v = gnannsumkbn( N, x, -2, 8, out, -2, 2 ); + v = gnannsumkbn( 5, x, -2, 8, out, -2, 2 ); expected = [ 4.0, 0.0, 5.0, 0.0 ]; t.deepEqual( v, expected, 'returns expected value' ); @@ -219,7 +214,7 @@ 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 of the first element repeated N times', function test( t ) { var expected; var out; var x; @@ -230,7 +225,24 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f out = [ 0.0, 0.0 ]; v = gnannsumkbn( x.length, x, 0, 0, out, 1, 0 ); - expected = [ 1.0, 1.0 ]; + expected = [ 5.0, 5.0 ]; + t.deepEqual( v, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a `stride` parameter equal to `0` and the first element is `NaN`, the function returns `0.0`', function test( t ) { + var expected; + var out; + var x; + var v; + + x = [ NaN, -2.0, -4.0, 5.0, 3.0 ]; + + out = [ 0.0, 0.0 ]; + v = gnannsumkbn( x.length, x, 0, 0, out, 1, 0 ); + + expected = [ 0.0, 0.0 ]; t.deepEqual( v, expected, 'returns expected value' ); t.end(); @@ -239,7 +251,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports `offset` parameters', function test( t ) { var expected; var out; - var N; var x; var v; @@ -256,9 +267,8 @@ tape( 'the function supports `offset` parameters', function test( t ) { NaN // 4 ]; out = [ 0.0, 0.0, 0.0, 0.0 ]; - N = floor( x.length / 2 ); - v = gnannsumkbn( N, x, 2, 1, out, 2, 1 ); + v = gnannsumkbn( 5, x, 2, 1, out, 2, 1 ); expected = [ 0.0, 5.0, 0.0, 4.0 ]; t.deepEqual( v, expected, 'returns expected value' ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/README.md b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/README.md index a5f21c5005fe..3b8154e30e0e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/README.md @@ -36,15 +36,14 @@ limitations under the License. var gsumkbn2 = require( '@stdlib/blas/ext/base/gsumkbn2' ); ``` -#### gsumkbn2( N, x, stride ) +#### gsumkbn2( N, x, strideX ) Computes the sum of strided array elements using a second-order iterative Kahan–Babuška algorithm. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var N = x.length; -var v = gsumkbn2( N, x, 1 ); +var v = gsumkbn2( 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. -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 ]; -var N = floor( x.length / 2 ); -var v = gsumkbn2( N, x, 2 ); +var v = gsumkbn2( 4, 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 = gsumkbn2( N, x1, 2 ); +var v = gsumkbn2( 4, x1, 2 ); // returns 5.0 ``` -#### gsumkbn2.ndarray( N, x, stride, offset ) +#### gsumkbn2.ndarray( N, x, strideX, offsetX ) Computes the sum of strided array elements using a second-order iterative Kahan–Babuška algorithm and alternative indexing semantics. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var N = x.length; -var v = gsumkbn2.ndarray( N, x, 1, 0 ); +var v = gsumkbn2.ndarray( x.length, x, 1, 0 ); // returns 1.0 ``` The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index. -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 ]; -var N = floor( x.length / 2 ); -var v = gsumkbn2.ndarray( N, x, 2, 1 ); +var v = gsumkbn2.ndarray( 4, x, 2, 1 ); // returns 5.0 ``` @@ -133,18 +122,12 @@ var v = gsumkbn2.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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var gsumkbn2 = require( '@stdlib/blas/ext/base/gsumkbn2' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); var v = gsumkbn2( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/benchmark/benchmark.js index 26f6f9d82172..1e5bdccbb002 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/benchmark/benchmark.js @@ -21,13 +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 pkg = require( './../package.json' ).name; var gsumkbn2 = require( './../lib/main.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var gsumkbn2 = require( './../lib/main.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - x.push( ( randu()*10.0 ) - 20.0 ); - } + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/benchmark/benchmark.ndarray.js index df2d56c12dfd..46b132d35ac1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/benchmark/benchmark.ndarray.js @@ -21,13 +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 pkg = require( './../package.json' ).name; var gsumkbn2 = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var gsumkbn2 = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - x.push( ( randu()*10.0 ) - 20.0 ); - } + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/docs/repl.txt index a61b5a69caff..693e00569a99 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the sum of strided array elements 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,27 +34,24 @@ > {{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 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, x, stride ) + > {{alias}}( 3, 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 ] ); > 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}}( 3, x1, 2 ) -1.0 -{{alias}}.ndarray( N, x, stride, offset ) + +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the sum of strided array elements 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 @@ -65,10 +62,10 @@ x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -85,8 +82,7 @@ // Using offset parameter: > var x = [ 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, x, 2, 1 ) + > {{alias}}.ndarray( 3, x, 2, 1 ) -1.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/docs/types/index.d.ts index d74432975d29..3261965b1b8d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/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 = gsumkbn2( 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 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 = gsumkbn2.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/gsumkbn2/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/examples/index.js index 7f8d48c4ed46..c7a76cac7de8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/examples/index.js @@ -18,18 +18,12 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); -var gsumkbn2 = require( './../lib' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gsumkbn2 = require( '@stdlib/blas/ext/base/gsumkbn2' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); var v = gsumkbn2( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/lib/index.js index 5181d9324c48..0b453539d3af 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/lib/index.js @@ -27,19 +27,16 @@ * var gsumkbn2 = require( '@stdlib/blas/ext/base/gsumkbn2' ); * * var x = [ 1.0, -2.0, 2.0 ]; -* var N = x.length; * -* var v = gsumkbn2( N, x, 1 ); +* var v = gsumkbn2( x.length, x, 1 ); * // returns 1.0 * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); * var gsumkbn2 = require( '@stdlib/blas/ext/base/gsumkbn2' ); * * 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 = gsumkbn2.ndarray( N, x, 2, 1 ); +* var v = gsumkbn2.ndarray( 4, x, 2, 1 ); * // returns 5.0 */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/lib/main.js index a52edc223707..d453c794ded9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/lib/main.js @@ -20,7 +20,8 @@ // MODULES // -var abs = require( '@stdlib/math/base/special/abs' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -38,61 +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, 2.0 ]; -* var N = x.length; * -* var v = gsumkbn2( N, x, 1 ); +* var v = gsumkbn2( x.length, x, 1 ); * // returns 1.0 */ -function gsumkbn2( 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 ) { - 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 ]; - 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 gsumkbn2( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/lib/ndarray.js index 595fa2b765ad..8f27c12b53e3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/lib/ndarray.js @@ -38,20 +38,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 = gsumkbn2( N, x, 2, 1 ); +* var v = gsumkbn2( 4, x, 2, 1 ); * // returns 5.0 */ -function gsumkbn2( N, x, stride, offset ) { +function gsumkbn2( N, x, strideX, offsetX ) { var sum; var ccs; var ix; @@ -65,10 +62,10 @@ function gsumkbn2( N, x, stride, offset ) { if ( N <= 0 ) { return 0.0; } - if ( N === 1 || stride === 0 ) { - return x[ offset ]; + ix = offsetX; + if ( strideX === 0 ) { + 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 @@ -89,7 +86,7 @@ function gsumkbn2( 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/gsumkbn2/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/test/test.main.js index 55c146330eb6..53d5401653da 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/test/test.main.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 Float64Array = require( '@stdlib/array/float64' ); var gsumkbn2 = require( './../lib' ); @@ -95,7 +94,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; @@ -110,15 +108,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - N = floor( x.length / 2 ); - v = gsumkbn2( N, x, 2 ); + v = gsumkbn2( 4, 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; @@ -133,21 +129,20 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = gsumkbn2( N, x, -2 ); + v = gsumkbn2( 4, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); 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 = gsumkbn2( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); @@ -155,7 +150,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -171,9 +165,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 = gsumkbn2( N, x1, 2 ); + v = gsumkbn2( 4, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/test/test.ndarray.js index c238735b790c..a6b0b7f76d9a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumkbn2/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 gsumkbn2 = require( './../lib/ndarray.js' ); @@ -94,7 +93,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; @@ -109,15 +107,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - N = floor( x.length / 2 ); - v = gsumkbn2( N, x, 2, 0 ); + v = gsumkbn2( 4, 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; @@ -132,27 +128,25 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = gsumkbn2( N, x, -2, 6 ); + v = gsumkbn2( 4, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); 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 = gsumkbn2( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -166,9 +160,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]; - N = floor( x.length / 2 ); - v = gsumkbn2( N, x, 2, 1 ); + v = gsumkbn2( 4, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumors/README.md b/lib/node_modules/@stdlib/blas/ext/base/gsumors/README.md index 5c9f837a28e0..d1da2101506c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumors/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumors/README.md @@ -36,15 +36,14 @@ limitations under the License. var gsumors = require( '@stdlib/blas/ext/base/gsumors' ); ``` -#### gsumors( N, x, stride ) +#### gsumors( N, x, strideX ) Computes the sum of strided array elements using ordinary recursive summation. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var N = x.length; -var v = gsumors( N, x, 1 ); +var v = gsumors( 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. -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 ]; -var N = floor( x.length / 2 ); -var v = gsumors( N, x, 2 ); +var v = gsumors( 4, 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 = gsumors( N, x1, 2 ); +var v = gsumors( 4, x1, 2 ); // returns 5.0 ``` -#### gsumors.ndarray( N, x, stride, offset ) +#### gsumors.ndarray( N, x, strideX, offsetX ) Computes the sum of strided array elements using ordinary recursive summation and alternative indexing semantics. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var N = x.length; -var v = gsumors.ndarray( N, x, 1, 0 ); +var v = gsumors.ndarray( x.length, x, 1, 0 ); // returns 1.0 ``` The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index. -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 ]; -var N = floor( x.length / 2 ); -var v = gsumors.ndarray( N, x, 2, 1 ); +var v = gsumors.ndarray( 4, x, 2, 1 ); // returns 5.0 ``` @@ -134,18 +123,12 @@ var v = gsumors.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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var gsumors = require( '@stdlib/blas/ext/base/gsumors' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); var v = gsumors( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumors/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gsumors/benchmark/benchmark.js index e44baae57ada..8c8569fa7c1d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumors/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumors/benchmark/benchmark.js @@ -21,13 +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 pkg = require( './../package.json' ).name; var gsumors = require( './../lib/main.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var gsumors = require( './../lib/main.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - x.push( ( randu()*10.0 ) - 20.0 ); - } + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumors/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gsumors/benchmark/benchmark.ndarray.js index 3137bb3c8756..e02cb4d4cf9f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumors/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumors/benchmark/benchmark.ndarray.js @@ -21,13 +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 pkg = require( './../package.json' ).name; var gsumors = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var gsumors = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - x.push( ( randu()*10.0 ) - 20.0 ); - } + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumors/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gsumors/docs/repl.txt index bc444de93ba4..4b70411c19f9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumors/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumors/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the sum of strided array elements using ordinary recursive summation. - 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,27 +34,24 @@ > {{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 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, x, stride ) + > {{alias}}( 3, 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 ] ); > 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}}( 3, x1, 2 ) -1.0 -{{alias}}.ndarray( N, x, stride, offset ) + +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the sum of strided array elements using ordinary recursive summation 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 @@ -65,10 +62,10 @@ x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -85,8 +82,7 @@ // Using offset parameter: > var x = [ 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, x, 2, 1 ) + > {{alias}}.ndarray( 3, x, 2, 1 ) -1.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumors/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gsumors/docs/types/index.d.ts index 49ef98625baf..ff63315f2dfd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumors/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumors/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 = gsumors( 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 using ordinary recursive summation 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 = gsumors.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/gsumors/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gsumors/examples/index.js index 10b952560fd5..79adcca67f3a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumors/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumors/examples/index.js @@ -18,18 +18,12 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); -var gsumors = require( './../lib' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gsumors = require( '@stdlib/blas/ext/base/gsumors' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); var v = gsumors( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumors/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gsumors/lib/index.js index 5a179a1ff795..a3638810c056 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumors/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumors/lib/index.js @@ -27,19 +27,16 @@ * var gsumors = require( '@stdlib/blas/ext/base/gsumors' ); * * var x = [ 1.0, -2.0, 2.0 ]; -* var N = x.length; * -* var v = gsumors( N, x, 1 ); +* var v = gsumors( x.length, x, 1 ); * // returns 1.0 * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); * var gsumors = require( '@stdlib/blas/ext/base/gsumors' ); * * 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 = gsumors.ndarray( N, x, 2, 1 ); +* var v = gsumors.ndarray( 4, x, 2, 1 ); * // returns 5.0 */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumors/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gsumors/lib/main.js index c9f5d676000c..83c47f0a9373 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumors/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumors/lib/main.js @@ -18,9 +18,10 @@ 'use strict'; -// VARIABLES // +// MODULES // -var M = 6; +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -30,57 +31,17 @@ var M = 6; * * @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, 2.0 ]; -* var N = x.length; * -* var v = gsumors( N, x, 1 ); +* var v = gsumors( x.length, x, 1 ); * // returns 1.0 */ -function gsumors( N, x, stride ) { - var ix; - var m; - var s; - var i; - - s = 0.0; - if ( N <= 0 ) { - return s; - } - if ( N === 1 || stride === 0 ) { - return x[ 0 ]; - } - // If the stride is equal to `1`, use unrolled loops... - if ( stride === 1 ) { - m = N % M; - - // If we have a remainder, run a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - s += x[ i ]; - } - } - if ( N < M ) { - return s; - } - for ( i = m; i < N; i += M ) { - s += x[i] + x[i+1] + x[i+2] + x[i+3] + x[i+4] + x[i+5]; - } - return s; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - for ( i = 0; i < N; i++ ) { - s += x[ ix ]; - ix += stride; - } - return s; +function gsumors( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumors/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gsumors/lib/ndarray.js index 7cfa91e0e46f..5db573bec6b4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumors/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumors/lib/ndarray.js @@ -30,20 +30,17 @@ var M = 6; * * @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 = gsumors( N, x, 2, 1 ); +* var v = gsumors( 4, x, 2, 1 ); * // returns 5.0 */ -function gsumors( N, x, stride, offset ) { +function gsumors( N, x, strideX, offsetX ) { var ix; var m; var s; @@ -53,20 +50,20 @@ function gsumors( N, x, stride, offset ) { if ( N <= 0 ) { return s; } - if ( N === 1 || stride === 0 ) { - return x[ offset ]; + ix = offsetX; + if ( strideX === 0 ) { + return N * x[ ix ]; } - ix = offset; // If the stride is equal to `1`, use unrolled loops... - if ( stride === 1 ) { + if ( strideX === 1 ) { m = N % M; // If we have a remainder, run a clean-up loop... if ( m > 0 ) { for ( i = 0; i < m; i++ ) { s += x[ ix ]; - ix += stride; + ix += strideX; } } if ( N < M ) { @@ -80,7 +77,7 @@ function gsumors( N, x, stride, offset ) { } for ( i = 0; i < N; i++ ) { s += x[ ix ]; - ix += stride; + ix += strideX; } return s; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumors/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gsumors/test/test.main.js index 376ffe054bce..9b1ac5591ac8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumors/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumors/test/test.main.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 Float64Array = require( '@stdlib/array/float64' ); var gsumors = require( './../lib' ); @@ -95,7 +94,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; @@ -110,15 +108,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - N = floor( x.length / 2 ); - v = gsumors( N, x, 2 ); + v = gsumors( 4, 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; @@ -133,21 +129,20 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = gsumors( N, x, -2 ); + v = gsumors( 4, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); 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 = gsumors( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); @@ -155,7 +150,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -171,9 +165,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 = gsumors( N, x1, 2 ); + v = gsumors( 4, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumors/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gsumors/test/test.ndarray.js index 6ab3872f7900..26fea87f0864 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumors/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumors/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 gsumors = require( './../lib/ndarray.js' ); @@ -94,7 +93,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; @@ -109,15 +107,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - N = floor( x.length / 2 ); - v = gsumors( N, x, 2, 0 ); + v = gsumors( 4, 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; @@ -132,27 +128,25 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = gsumors( N, x, -2, 6 ); + v = gsumors( 4, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); 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 = gsumors( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -166,9 +160,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]; - N = floor( x.length / 2 ); - v = gsumors( N, x, 2, 1 ); + v = gsumors( 4, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/README.md b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/README.md index 6761c1510b75..6180eba328e2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/README.md @@ -36,15 +36,14 @@ limitations under the License. var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ); ``` -#### gsumpw( N, x, stride ) +#### gsumpw( N, x, strideX ) Computes the sum of strided array elements using pairwise summation. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var N = x.length; -var v = gsumpw( N, x, 1 ); +var v = gsumpw( 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. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the gsumpw 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 ]; -var N = floor( x.length / 2 ); -var v = gsumpw( N, x, 2 ); +var v = gsumpw( 4, 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 = gsumpw( N, x1, 2 ); +var v = gsumpw( 4, x1, 2 ); // returns 5.0 ``` -#### gsumpw.ndarray( N, x, stride, offset ) +#### gsumpw.ndarray( N, x, strideX, offsetX ) Computes the sum of strided array elements using pairwise summation and alternative indexing semantics. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var N = x.length; -var v = gsumpw.ndarray( N, x, 1, 0 ); +var v = gsumpw.ndarray( x.length, x, 1, 0 ); // returns 1.0 ``` The function has the following additional parameters: -- **offset**: starting index for `x`. +- **offsetX**: starting index. -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 ]; -var N = floor( x.length / 2 ); -var v = gsumpw.ndarray( N, x, 2, 1 ); +var v = gsumpw.ndarray( 4, x, 2, 1 ); // returns 5.0 ``` @@ -134,18 +123,12 @@ var v = gsumpw.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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); var v = gsumpw( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/benchmark/benchmark.js index 0cbbdae1f151..1d11248c7631 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/benchmark/benchmark.js @@ -21,13 +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 pkg = require( './../package.json' ).name; var gsumpw = require( './../lib/main.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var gsumpw = require( './../lib/main.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - x.push( ( randu()*10.0 ) - 20.0 ); - } + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/benchmark/benchmark.ndarray.js index 3d59be8f2eb5..8fe3f267e2bd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/benchmark/benchmark.ndarray.js @@ -21,13 +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 pkg = require( './../package.json' ).name; var gsumpw = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var gsumpw = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var i; - - x = []; - for ( i = 0; i < len; i++ ) { - x.push( ( randu()*10.0 ) - 20.0 ); - } + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/docs/repl.txt index 2defa985eb45..822329805f51 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/docs/repl.txt @@ -1,9 +1,9 @@ -{{alias}}( N, x, stride ) +{{alias}}( N, x, strideX ) Computes the sum of strided array elements using pairwise summation. - 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. @@ -18,8 +18,8 @@ x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. Returns ------- @@ -33,27 +33,24 @@ > {{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 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > var stride = 2; - > {{alias}}( N, x, stride ) + > {{alias}}( 3, 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 ] ); > 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}}( 3, x1, 2 ) -1.0 -{{alias}}.ndarray( N, x, stride, offset ) + +{{alias}}.ndarray( N, x, strideX, offsetX ) Computes the sum of strided array elements using pairwise summation 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 @@ -64,10 +61,10 @@ x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -84,8 +81,7 @@ // Using offset parameter: > var x = [ 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, x, 2, 1 ) + > {{alias}}.ndarray( 3, x, 2, 1 ) -1.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/docs/types/index.d.ts index ba4683be6b7d..aad0cc753de4 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/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 = gsumpw( 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 using pairwise summation 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 = gsumpw.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/gsumpw/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/examples/index.js index 77e2022e86cb..53cd0cd896e7 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/examples/index.js @@ -18,18 +18,12 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); -var Float64Array = require( '@stdlib/array/float64' ); -var gsumpw = require( './../lib' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ); -var x; -var i; - -x = new Float64Array( 10 ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); var v = gsumpw( x.length, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/lib/index.js index c62ccbdee843..229a4b11a815 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/lib/index.js @@ -27,19 +27,16 @@ * var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ); * * var x = [ 1.0, -2.0, 2.0 ]; -* var N = x.length; * -* var v = gsumpw( N, x, 1 ); +* var v = gsumpw( x.length, x, 1 ); * // returns 1.0 * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); * var gsumpw = require( '@stdlib/blas/ext/base/gsumpw' ); * * 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 = gsumpw.ndarray( N, x, 2, 1 ); +* var v = gsumpw.ndarray( 4, x, 2, 1 ); * // returns 5.0 */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/lib/main.js index a82cda55ae36..da5e4fbbc04a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/lib/main.js @@ -20,7 +20,8 @@ // MODULES // -var sum = require( './ndarray.js' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -38,42 +39,17 @@ var sum = require( './ndarray.js' ); * * @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, 2.0 ]; -* var N = x.length; * -* var v = gsumpw( N, x, 1 ); +* var v = gsumpw( x.length, x, 1 ); * // returns 1.0 */ -function gsumpw( N, x, stride ) { - var ix; - var s; - var i; - - if ( N <= 0 ) { - return 0.0; - } - if ( N === 1 || stride === 0 ) { - return x[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - if ( N < 8 ) { - // Use simple summation... - s = 0.0; - for ( i = 0; i < N; i++ ) { - s += x[ ix ]; - ix += stride; - } - return s; - } - return sum( N, x, stride, ix ); +function gsumpw( N, x, strideX ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/lib/ndarray.js index 04c36cde0078..6c433c5d65f9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/lib/ndarray.js @@ -44,20 +44,17 @@ var BLOCKSIZE = 128; * * @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 = gsumpw( N, x, 2, 1 ); +* var v = gsumpw( 4, x, 2, 1 ); * // returns 5.0 */ -function gsumpw( N, x, stride, offset ) { +function gsumpw( N, x, strideX, offsetX ) { var ix; var s0; var s1; @@ -75,57 +72,57 @@ function gsumpw( N, x, stride, offset ) { if ( N <= 0 ) { return 0.0; } - if ( N === 1 || stride === 0 ) { - return x[ offset ]; + ix = offsetX; + if ( strideX === 0 ) { + return N * x[ ix ]; } - ix = offset; if ( N < 8 ) { // Use simple summation... s = 0.0; for ( i = 0; i < N; i++ ) { s += x[ ix ]; - ix += stride; + ix += strideX; } return s; } if ( N <= BLOCKSIZE ) { // Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)... s0 = x[ ix ]; - s1 = x[ ix+stride ]; - s2 = x[ ix+(2*stride) ]; - s3 = x[ ix+(3*stride) ]; - s4 = x[ ix+(4*stride) ]; - s5 = x[ ix+(5*stride) ]; - s6 = x[ ix+(6*stride) ]; - s7 = x[ ix+(7*stride) ]; - ix += 8 * stride; + s1 = x[ ix+strideX ]; + s2 = x[ ix+(2*strideX) ]; + s3 = x[ ix+(3*strideX) ]; + s4 = x[ ix+(4*strideX) ]; + s5 = x[ ix+(5*strideX) ]; + s6 = x[ ix+(6*strideX) ]; + s7 = x[ ix+(7*strideX) ]; + ix += 8 * strideX; M = N % 8; for ( i = 8; i < N-M; i += 8 ) { s0 += x[ ix ]; - s1 += x[ ix+stride ]; - s2 += x[ ix+(2*stride) ]; - s3 += x[ ix+(3*stride) ]; - s4 += x[ ix+(4*stride) ]; - s5 += x[ ix+(5*stride) ]; - s6 += x[ ix+(6*stride) ]; - s7 += x[ ix+(7*stride) ]; - ix += 8 * stride; + s1 += x[ ix+strideX ]; + s2 += x[ ix+(2*strideX) ]; + s3 += x[ ix+(3*strideX) ]; + s4 += x[ ix+(4*strideX) ]; + s5 += x[ ix+(5*strideX) ]; + s6 += x[ ix+(6*strideX) ]; + s7 += x[ ix+(7*strideX) ]; + ix += 8 * strideX; } // Pairwise sum the accumulators: - s = ((s0+s1) + (s2+s3)) + ((s4+s5) + (s6+s7)); + s = ( (s0+s1) + (s2+s3) ) + ( (s4+s5) + (s6+s7) ); // Clean-up loop... for ( i; i < N; i++ ) { s += x[ ix ]; - ix += stride; + ix += strideX; } return s; } // Recurse by dividing by two, but avoiding non-multiples of unroll factor... n = floor( N/2 ); n -= n % 8; - return gsumpw( n, x, stride, ix ) + gsumpw( N-n, x, stride, ix+(n*stride) ); + return gsumpw( n, x, strideX, ix ) + gsumpw( N-n, x, strideX, ix+(n*strideX) ); // eslint-disable-line max-len } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/test/test.main.js index ff9f6391d9f6..2aea27f8afbd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/test/test.main.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 Float64Array = require( '@stdlib/array/float64' ); var gsumpw = require( './../lib' ); @@ -103,7 +102,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 ) { 2.0 ]; - N = floor( x.length / 2 ); - v = gsumpw( N, x, 2 ); + v = gsumpw( 4, 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; @@ -141,21 +137,20 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = gsumpw( N, x, -2 ); + v = gsumpw( 4, x, -2 ); t.strictEqual( v, 5.0, 'returns expected value' ); 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 = gsumpw( x.length, x, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); @@ -163,7 +158,6 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f tape( 'the function supports view offsets', function test( t ) { var x0; var x1; - var N; var v; x0 = new Float64Array([ @@ -179,9 +173,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 = gsumpw( N, x1, 2 ); + v = gsumpw( 4, x1, 2 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/test/test.ndarray.js index ce8a24431dea..021815a2a0cd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gsumpw/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gsumpw/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 gsumpw = require( './../lib/ndarray.js' ); @@ -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; @@ -117,15 +115,13 @@ tape( 'the function supports a `stride` parameter', function test( t ) { 2.0 ]; - N = floor( x.length / 2 ); - v = gsumpw( N, x, 2, 0 ); + v = gsumpw( 4, 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; @@ -140,27 +136,25 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) 2.0 ]; - N = floor( x.length / 2 ); - v = gsumpw( N, x, -2, 6 ); + v = gsumpw( 4, x, -2, 6 ); t.strictEqual( v, 5.0, 'returns expected value' ); 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 = gsumpw( x.length, x, 0, 0 ); - t.strictEqual( v, 1.0, 'returns expected value' ); + t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); }); tape( 'the function supports an `offset` parameter', function test( t ) { - var N; var x; var v; @@ -174,9 +168,8 @@ tape( 'the function supports an `offset` parameter', function test( t ) { 3.0, 4.0 // 3 ]; - N = floor( x.length / 2 ); - v = gsumpw( N, x, 2, 1 ); + v = gsumpw( 4, x, 2, 1 ); t.strictEqual( v, 5.0, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/iter/until-each/README.md b/lib/node_modules/@stdlib/iter/until-each/README.md index ac20fdd4d579..2b791ac9eb2f 100644 --- a/lib/node_modules/@stdlib/iter/until-each/README.md +++ b/lib/node_modules/@stdlib/iter/until-each/README.md @@ -220,6 +220,12 @@ while ( true ) { @@ -228,6 +234,12 @@ while ( true ) { diff --git a/lib/node_modules/@stdlib/math/base/special/asindf/README.md b/lib/node_modules/@stdlib/math/base/special/asindf/README.md index 355f0ccb6457..18a2f8b08668 100644 --- a/lib/node_modules/@stdlib/math/base/special/asindf/README.md +++ b/lib/node_modules/@stdlib/math/base/special/asindf/README.md @@ -178,6 +178,13 @@ int main( void ) { @@ -190,6 +197,10 @@ int main( void ) { +[@stdlib/math/base/special/asinf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/asinf + +[@stdlib/math/base/special/asind]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/asind + diff --git a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-min/README.md b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-min/README.md index 07289198dc11..43a3a14918d6 100644 --- a/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-min/README.md +++ b/lib/node_modules/@stdlib/math/base/special/fast/alpha-max-plus-beta-min/README.md @@ -159,12 +159,12 @@ for ( i = 0; i < 100; i++ ) { #include "stdlib/math/base/special/fast/alpha_max_plus_beta_min.h" ``` -#### stdlib_base_fast_ampbm( x, y ) +#### stdlib_base_fast_ampbm( x, y ) Computes the hypotenuse using the alpha max plus beta min algorithm. ```c -double h = stdlib_base_fast_ampbm( -5.0, 12.0 ); +double h = stdlib_base_fast_ampbm( -5.0, 12.0 ); // returns ~13.5 ``` diff --git a/lib/node_modules/@stdlib/repl/data/contributor.json b/lib/node_modules/@stdlib/repl/data/contributor.json index 30b806df2564..c90a500502d3 100644 --- a/lib/node_modules/@stdlib/repl/data/contributor.json +++ b/lib/node_modules/@stdlib/repl/data/contributor.json @@ -1 +1 @@ -["Aadish Jain","Aayush Khanna","Abhijit Raut","Adarsh Palaskar","Aditya Sapra","Ahmed Atwa","Ahmed Kashkoush","Ahmed Khaled","Aleksandr","Ali Salesi","Aman Bhansali","Amit Jimiwal","Anudeep Sanapala","Athan Reines","Ayaka","Brendan Graetz","Bruno Fenzl","Bryan Elee","Chinmay Joshi","Christopher Dambamuromo","Dan Rose","Daniel Killenberger","Daniel Yu","Debashis Maharana","Desh Deepak Kant","Dhruv Arvind Singh","Divyansh Seth","Dominic Lim","Dominik Moritz","Dorrin Sotoudeh","EuniceSim142","Frank Kovacs","Golden Kumar","Gunj Joshi","Gururaj Gurram","HarshaNP","Harshita Kalani","Hridyanshu","Jaimin Godhani","James Gelok","Jaysukh Makvana","Jenish Thapa","Jithin KS","Joel Mathew Koshy","Joey Reed","Jordan Gallivan","Joris Labie","Justin Dennison","Karthik Prakash","Kohantika Nath","Krishnendu Das","Kshitij-Dale","Lovelin Dhoni J B","Manik Sharma","Manvith M","Marcus Fantham","Matt Cochrane","Mihir Pandit","Milan Raj","Mohammad Kaif","Momtchil Momtchev","Muhammad Haris","Naresh Jagadeesan","Naveen Kumar","Neeraj Pathak","Nishant Shinde","Nithin Katta","Nourhan Hasan","Ognjen Jevremović","Oneday12323","Ori Miles","Philipp Burckhardt","Prajwal Kulkarni","Pranav Goswami","Pranjal Jha","Prashant Kumar Yadav","Pratik Singh","Pratyush Kumar Chouhan","Priyansh Prajapati","Priyanshu Agarwal","Pushpendra Chandravanshi","Raunak Kumar Gupta","Rejoan Sardar","Ricky Reusser","Ridam Garg","Rishav","Robert Gislason","Roman Stetsyk","Rutam Kathale","Ruthwik Chikoti","Ryan Seal","Rylan Yang","Sai Srikar Dumpeti","Sarthak Paandey","Saurabh Singh","Seyyed Parsa Neshaei","Shashank Shekhar Singh","Shivam Ahir","Shraddheya Shendre","Shubh Mehta","Shubham Mishra","Sivam Das","Snehil Shah","Soumajit Chatterjee","Spandan Barve","Stephannie Jiménez Gacha","Suraj Kumar","Tirtadwipa Manunggal","Tudor Pagu","Tufailahmed Bargir","Utkarsh","Utkarsh Raj","UtkershBasnet","Vaibhav Patel","Varad Gupta","Vinit Pandit","Vivek Maurya","Xiaochuan Ye","Yaswanth Kosuru","Yernar Yergaziyev","olenkabilonizhka","rainn","rei2hu"] +["Aadish Jain","Aayush Khanna","Abhijit Raut","Adarsh Palaskar","Aditya Sapra","Ahmed Atwa","Ahmed Kashkoush","Ahmed Khaled","Aleksandr","Ali Salesi","Aman Bhansali","Amit Jimiwal","Anudeep Sanapala","Athan Reines","Ayaka","Brendan Graetz","Bruno Fenzl","Bryan Elee","Chinmay Joshi","Christopher Dambamuromo","Dan Rose","Daniel Killenberger","Daniel Yu","Debashis Maharana","Desh Deepak Kant","Dhruv Arvind Singh","Divyansh Seth","Dominic Lim","Dominik Moritz","Dorrin Sotoudeh","EuniceSim142","Frank Kovacs","Golden Kumar","Gunj Joshi","Gururaj Gurram","HarshaNP","Harshita Kalani","Hridyanshu","Jaimin Godhani","James Gelok","Jaysukh Makvana","Jenish Thapa","Jithin KS","Joel Mathew Koshy","Joey Reed","Jordan Gallivan","Joris Labie","Justin Dennison","Karan Anand","Karthik Prakash","Kohantika Nath","Krishnendu Das","Kshitij-Dale","Lovelin Dhoni J B","Manik Sharma","Manvith M","Marcus Fantham","Matt Cochrane","Mihir Pandit","Milan Raj","Mohammad Kaif","Momtchil Momtchev","Muhammad Haris","Naresh Jagadeesan","Naveen Kumar","Neeraj Pathak","Nishant Shinde","Nithin Katta","Nourhan Hasan","Ognjen Jevremović","Oneday12323","Ori Miles","Philipp Burckhardt","Prajwal Kulkarni","Pranav Goswami","Pranjal Jha","Prashant Kumar Yadav","Pratik Singh","Pratyush Kumar Chouhan","Priyansh Prajapati","Priyanshu Agarwal","Pushpendra Chandravanshi","Raunak Kumar Gupta","Rejoan Sardar","Ricky Reusser","Ridam Garg","Rishav","Robert Gislason","Roman Stetsyk","Rutam Kathale","Ruthwik Chikoti","Ryan Seal","Rylan Yang","Sai Srikar Dumpeti","Sarthak Paandey","Saurabh Singh","Seyyed Parsa Neshaei","Shashank Shekhar Singh","Shivam Ahir","Shraddheya Shendre","Shubh Mehta","Shubham Mishra","Sivam Das","Snehil Shah","Soumajit Chatterjee","Spandan Barve","Stephannie Jiménez Gacha","Suraj Kumar","Tirtadwipa Manunggal","Tudor Pagu","Tufailahmed Bargir","Utkarsh","Utkarsh Raj","UtkershBasnet","Vaibhav Patel","Varad Gupta","Vinit Pandit","Vivek Maurya","Xiaochuan Ye","Yaswanth Kosuru","Yernar Yergaziyev","olenkabilonizhka","rainn","rei2hu"] diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/README.md b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/README.md index c2eabc1f4494..4e52553339b2 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/README.md @@ -108,6 +108,98 @@ for ( i = 0; i < 10; i++ ) { + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/degenerate/mode.h" +``` + +#### stdlib_base_dists_degenerate_mode( mu ) + +Returns the [mode][mode] of a [degenerate][degenerate-distribution] distribution with constant value `mu`. + +```c +double out = stdlib_base_dists_degenerate_mode( 0.1 ); +// returns 0.1 +``` + +The function accepts the following arguments: + +- **mu**: `[in] double` constant value of the distribution. + +```c +double stdlib_base_dists_degenerate_mode( const double mu ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/degenerate/mode.h" +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v * ( max - min ) ); +} + +int main( void ) { + double mu; + double m; + int i; + + for ( i = 0; i < 10; i++ ) { + mu = random_uniform( 0.0, 20.0 ); + m = stdlib_base_dists_degenerate_mode( mu ); + printf( "µ: %lf, mode(X;µ): %lf\n", mu, m ); + } +} +``` + +
+ + + +
+ + +
diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/benchmark/benchmark.native.js new file mode 100644 index 000000000000..8ab66c9835f7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/benchmark/benchmark.native.js @@ -0,0 +1,67 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var Float64Array = require( '@stdlib/array/float64' ); +var randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var mode = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( mode instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var len; + var mu; + var y; + var i; + + len = 100; + mu = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + mu[ i ] = ( randu() * 40.0 ) - 20.0; + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mode( mu[ i % len ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/benchmark/c/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/benchmark/c/benchmark.c new file mode 100644 index 000000000000..0f177a8993e4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/benchmark/c/benchmark.c @@ -0,0 +1,138 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/base/dists/degenerate/mode.h" +#include +#include +#include +#include +#include + +#define NAME "degenerate-mode" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec / 1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v * ( max - min ) ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double mu[ 100 ]; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + mu[ i ] = random_uniform( -20.0, 20.0 ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_dists_degenerate_mode( mu[ i % 100 ] ); + if ( y != y ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y != y ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i + 1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/examples/c/example.c new file mode 100644 index 000000000000..fd2cecdf99e1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/examples/c/example.c @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/base/dists/degenerate/mode.h" +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v * ( max - min ) ); +} + +int main( void ) { + double mu; + double m; + int i; + + for ( i = 0; i < 10; i++ ) { + mu = random_uniform( 0.0, 20.0 ); + m = stdlib_base_dists_degenerate_mode( mu ); + printf( "µ: %lf, mode(X;µ): %lf\n", mu, m ); + } +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/degenerate/mode/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/lognormal/cdf.h" +``` + +#### stdlib_base_dists_lognormal_cdf( x, a, b ) + +Evaluates the cumulative distribution function (CDF) for an lognormal distribution. + +```c +double out = stdlib_base_dists_lognormal_cdf( 0.5, 0.0, 2.0 ); +// returns ~0.333 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **a**: `[in] double` minimum support. +- **b**: `[in] double` maximum support. + +```c +double stdlib_base_dists_lognormal_cdf( const double x, const double a, const double b ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/lognormal/cdf.h" +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +int main( void ) { + double x; + double a; + double b; + double y; + int i; + + for ( i = 0; i < 25; i++ ) { + x = random_uniform( -10.0, 10.0 ); + a = random_uniform( -20.0, 0.0 ); + b = random_uniform( a, a+40.0 ); + y = stdlib_base_dists_lognormal_cdf( x, a, b ); + printf( "x: %lf, a: %lf, b: %lf, F(x;a,b): %lf\n", x, a, b, y ); + } +} +``` + +
+ + + +
+ + +