diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/README.md b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/README.md index 7a662798cd91..d91a5a5af5e2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/README.md @@ -59,21 +59,17 @@ The function has the following parameters: - **N**: number of indexed elements. - **sum**: initial sum. - **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. -- **strideX**: index increment for `x`. +- **strideX**: stride length for `x`. - **y**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. -- **strideY**: index increment for `y`. +- **strideY**: stride length for `y`. -The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to compute the cumulative sum of every other element in `x`, +The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the cumulative 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 y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; -var N = floor( x.length / 2 ); - -var v = gcusumkbn2( N, 0.0, x, 2, y, 1 ); +var v = gcusumkbn2( 4, 0.0, x, 2, y, 1 ); // y => [ 1.0, 3.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] ``` @@ -83,7 +79,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' ); // Initial arrays... var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] ); @@ -93,9 +88,7 @@ var y0 = new Float64Array( x0.length ); var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element -var N = floor( x0.length / 2 ); - -gcusumkbn2( N, 0.0, x1, -2, y1, 1 ); +gcusumkbn2( 4, 0.0, x1, -2, y1, 1 ); // y0 => [ 0.0, 0.0, 0.0, 4.0, 6.0, 4.0, 5.0, 0.0 ] ``` @@ -116,17 +109,13 @@ The function has the following additional parameters: - **offsetX**: starting index for `x`. - **offsetY**: starting index for `y`. -While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, `offsetX` and `offsetY` parameters support indexing semantics based on a starting indices. For example, to calculate the cumulative sum of every other value in `x` starting from the second value and to store in the last `N` elements of `y` starting from the last element +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to calculate the cumulative sum of every other element in the strided input array starting from the second element and to store in the last `N` elements of the strided output array starting from the last 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 y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; -var N = floor( x.length / 2 ); - -gcusumkbn2.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ); +gcusumkbn2.ndarray( 4, 0.0, x, 2, 1, y, -1, y.length-1 ); // y => [ 0.0, 0.0, 0.0, 0.0, 5.0, 1.0, -1.0, 1.0 ] ``` @@ -152,20 +141,14 @@ gcusumkbn2.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var Float64Array = require( '@stdlib/array/float64' ); var gcusumkbn2 = require( '@stdlib/blas/ext/base/gcusumkbn2' ); -var y; -var x; -var i; - -x = new Float64Array( 10 ); -y = new Float64Array( x.length ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); +var y = new Float64Array( x.length ); console.log( x ); console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/benchmark/benchmark.js index f2df7232bb92..ea7e0232ceaa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/benchmark/benchmark.js @@ -21,14 +21,22 @@ // 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 gfill = require( '@stdlib/blas/ext/base/gfill' ); +var zeros = require( '@stdlib/array/zeros' ); var pkg = require( './../package.json' ).name; var gcusumkbn2 = require( './../lib/main.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -39,16 +47,8 @@ var gcusumkbn2 = require( './../lib/main.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var y; - var x; - var i; - - x = []; - y = []; - for ( i = 0; i < len; i++ ) { - x.push( ( randu()*20.0 ) - 10.0 ); - y.push( 0.0 ); - } + var x = uniform( len, -100, 100, options ); + var y = zeros( len, options.dtype ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/benchmark/benchmark.ndarray.js index b1d8df7fedfa..f13401fd9831 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/benchmark/benchmark.ndarray.js @@ -21,14 +21,22 @@ // 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 gfill = require( '@stdlib/blas/ext/base/gfill' ); +var zeros = require( '@stdlib/array/zeros' ); var pkg = require( './../package.json' ).name; var gcusumkbn2 = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -39,16 +47,8 @@ var gcusumkbn2 = require( './../lib/ndarray.js' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x; - var y; - var i; - - x = []; - y = []; - for ( i = 0; i < len; i++ ) { - x.push( ( randu()*20.0 ) - 10.0 ); - y.push( 0.0 ); - } + var x = uniform( len, -100, 100, options ); + var y = zeros( len, options.dtype ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/docs/repl.txt index cb80f70df98a..2b273b222e27 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/docs/repl.txt @@ -3,8 +3,8 @@ Computes the cumulative sum of strided array elements using a second-order iterative Kahan–Babuška algorithm. - The `N` and `stride` parameters determine which elements in `x` and `y` are - accessed at runtime. + The `N` and stride parameters determine which elements in the strided arrays + are accessed at runtime. Indexing is relative to the first index. To introduce an offset, use a typed array view. @@ -23,13 +23,13 @@ Input array. strideX: integer - Index increment for `x`. + Stride length for `x`. y: Array|TypedArray Output array. strideY: integer - Index increment for `y`. + Stride length for `y`. Returns ------- @@ -44,11 +44,10 @@ > {{alias}}( x.length, 0.0, x, 1, y, 1 ) [ 1.0, -1.0, 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 ]; > y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}( N, 0.0, x, 2, y, 2 ) + > {{alias}}( 3, 0.0, x, 2, y, 2 ) [ -2.0, 0.0, -1.0, 0.0, 1.0, 0.0 ] // Using view offsets: @@ -56,19 +55,19 @@ > var y0 = new {{alias:@stdlib/array/float64}}( x0.length ); > var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); > var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); - > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 ); - > {{alias}}( N, 0.0, x1, 2, y1, 1 ) + > {{alias}}( 3, 0.0, x1, 2, y1, 1 ) [ -2.0, 0.0, -1.0 ] > y0 [ 0.0, 0.0, 0.0, -2.0, 0.0, -1.0 ] + {{alias}}.ndarray( N, sum, x, strideX, offsetX, y, strideY, offsetY ) Computes the cumulative 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 - starting index. + buffer, the offset parameters support indexing semantics based on starting + indices. Parameters ---------- @@ -82,7 +81,7 @@ Input array. strideX: integer - Index increment for `x`. + Stride length for `x`. offsetX: integer Starting index for `x`. @@ -91,7 +90,7 @@ Output array. strideY: integer - Index increment for `y`. + Stride length for `y`. offsetY: integer Starting index for `y`. @@ -107,14 +106,13 @@ > var x = [ 1.0, -2.0, 2.0 ]; > var y = [ 0.0, 0.0, 0.0 ]; > {{alias}}.ndarray( x.length, 0.0, x, 1, 0, y, 1, 0 ) - [ 1.0, -1.0, 1.0 ] + [ 1.0, -1.0, 1.0 ] // Advanced indexing: > x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ]; > y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}.ndarray( N, 0.0, x, 2, 1, y, -1, y.length-1 ) - [ 0.0, 0.0, 0.0, -1.0, 0.0, -2.0 ] + > {{alias}}.ndarray( 3, 0.0, x, 2, 1, y, -1, y.length-1 ) + [ 0.0, 0.0, 0.0, -1.0, 0.0, -2.0 ] See Also -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/docs/types/index.d.ts index 773d9f71b0f0..d295706b2420 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/docs/types/index.d.ts @@ -32,9 +32,9 @@ interface Routine { * @param N - number of indexed elements * @param sum - initial sum * @param x - input array - * @param strideX - `x` stride length + * @param strideX - stride length for `x` * @param y - output array - * @param strideY - `y` stride length + * @param strideY - stride length for `y` * @returns output array * * @example @@ -52,10 +52,10 @@ interface Routine { * @param N - number of indexed elements * @param sum - initial sum * @param x - input array - * @param strideX - `x` stride length + * @param strideX - stride length for `x` * @param offsetX - starting index for `x` * @param y - output array - * @param strideY - `y` stride length + * @param strideY - stride length for `y` * @param offsetY - starting index for `y` * @returns output array * @@ -75,9 +75,9 @@ interface Routine { * @param N - number of indexed elements * @param sum - initial sum * @param x - input array -* @param strideX - `x` stride length +* @param strideX - stride length for `x` * @param y - output array -* @param strideY - `y` stride length +* @param strideY - stride length for `y` * @returns output array * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/examples/index.js index cd0693af2302..96a82104dc63 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/examples/index.js @@ -18,20 +18,14 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var Float64Array = require( '@stdlib/array/float64' ); var gcusumkbn2 = require( './../lib' ); -var y; -var x; -var i; - -x = new Float64Array( 10 ); -y = new Float64Array( x.length ); -for ( i = 0; i < x.length; i++ ) { - x[ i ] = round( randu()*100.0 ); -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); +var y = new Float64Array( x.length ); console.log( x ); console.log( y ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/lib/index.js index 8c841ac321b8..d7bb8be5eb8a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/lib/index.js @@ -33,14 +33,12 @@ * // y => [ 1.0, -1.0, 1.0 ] * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); * var gcusumkbn2 = require( '@stdlib/blas/ext/base/gcusumkbn2' ); * * var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; * var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; -* var N = floor( x.length / 2 ); * -* gcusumkbn2.ndarray( N, 0.0, x, 2, 1, y, 1, 0 ); +* gcusumkbn2.ndarray( 4, 0.0, x, 2, 1, y, 1, 0 ); * // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/lib/main.js index e2ef6a26c249..2ba2615da8f8 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/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 // @@ -39,9 +40,9 @@ var abs = require( '@stdlib/math/base/special/abs' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} sum - initial sum * @param {NumericArray} x - input array -* @param {integer} strideX - `x` stride length +* @param {integer} strideX - stride length for `x` * @param {NumericArray} y - output array -* @param {integer} strideY - `y` stride length +* @param {integer} strideY - stride length for `y` * @returns {NumericArray} output array * * @example @@ -52,54 +53,9 @@ var abs = require( '@stdlib/math/base/special/abs' ); * // returns [ 1.0, -1.0, 1.0 ] */ function gcusumkbn2( N, sum, x, strideX, y, strideY ) { - var ccs; - var ix; - var iy; - var cs; - var cc; - var v; - var t; - var c; - var i; - - if ( N <= 0 ) { - return y; - } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = (1-N) * strideY; - } else { - iy = 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; - - y[ iy ] = sum + cs + ccs; - ix += strideX; - iy += strideY; - } - return y; + var ox = stride2offset( N, strideX ); + var oy = stride2offset( N, strideY ); + return ndarray( N, sum, x, strideX, ox, y, strideY, oy ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/lib/ndarray.js index d027b1a83ac2..762d2127c58b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gcusumkbn2/lib/ndarray.js @@ -39,21 +39,18 @@ var abs = require( '@stdlib/math/base/special/abs' ); * @param {PositiveInteger} N - number of indexed elements * @param {number} sum - initial sum * @param {NumericArray} x - input array -* @param {integer} strideX - `x` stride length +* @param {integer} strideX - stride length for `x` * @param {NonNegativeInteger} offsetX - starting index for `x` * @param {NumericArray} y - output array -* @param {integer} strideY - `y` stride length +* @param {integer} strideY - stride length for `y` * @param {NonNegativeInteger} offsetY - starting index for `y` * @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 ]; * var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ]; -* var N = floor( x.length / 2 ); * -* gcusumkbn2( N, 0.0, x, 2, 1, y, 1, 0 ); +* gcusumkbn2( 4, 0.0, x, 2, 1, y, 1, 0 ); * // y => [ 1.0, -1.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0 ] */ function gcusumkbn2( N, sum, x, strideX, offsetX, y, strideY, offsetY ) {