diff --git a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/README.md b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/README.md index a79be6a84319..7c6b99ebe5af 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/README.md @@ -20,7 +20,7 @@ limitations under the License. # gapxsumors -> Add a constant to each strided array element and compute the sum using ordinary recursive summation. +> Add a scalar constant to each strided array element and compute the sum using ordinary recursive summation.
@@ -36,15 +36,14 @@ limitations under the License. var gapxsumors = require( '@stdlib/blas/ext/base/gapxsumors' ); ``` -#### gapxsumors( N, alpha, x, stride ) +#### gapxsumors( N, alpha, x, strideX ) -Adds a constant to each strided array element and computes the sum using ordinary recursive summation. +Adds a scalar constant to each strided array element and computes the sum using ordinary recursive summation. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var N = x.length; -var v = gapxsumors( N, 5.0, x, 1 ); +var v = gapxsumors( x.length, 5.0, x, 1 ); // returns 16.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 access every other element in `x`, +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access 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 = gapxsumors( N, 5.0, x, 2 ); +var v = gapxsumors( 4, 5.0, x, 2 ); // returns 25.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 = gapxsumors( N, 5.0, x1, 2 ); +var v = gapxsumors( 4, 5.0, x1, 2 ); // returns 25.0 ``` -#### gapxsumors.ndarray( N, alpha, x, stride, offset ) +#### gapxsumors.ndarray( N, alpha, x, strideX, offsetX ) -Adds a constant to each strided array element and computes the sum using ordinary recursive summation and alternative indexing semantics. +Adds a scalar constant to each strided array element and computes the sum using ordinary recursive summation and alternative indexing semantics. ```javascript var x = [ 1.0, -2.0, 2.0 ]; -var N = x.length; -var v = gapxsumors.ndarray( N, 5.0, x, 1, 0 ); +var v = gapxsumors.ndarray( x.length, 5.0, x, 1, 0 ); // returns 16.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 access 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 access 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 = gapxsumors.ndarray( N, 5.0, x, 2, 1 ); +var v = gapxsumors.ndarray( 4, 5.0, x, 2, 1 ); // returns 25.0 ``` @@ -134,18 +123,12 @@ var v = gapxsumors.ndarray( N, 5.0, 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 gapxsumors = require( '@stdlib/blas/ext/base/gapxsumors' ); -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 = gapxsumors( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/benchmark/benchmark.js index f44aa320d8b2..8884e5a6381a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/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 gapxsumors = require( './../lib/main.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var gapxsumors = 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()*20.0 ) - 10.0 ); - } + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/benchmark/benchmark.ndarray.js index 64d4e7fd4df1..68402416b5aa 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/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 gapxsumors = require( './../lib/ndarray.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var gapxsumors = 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()*20.0 ) - 10.0 ); - } + var x = uniform( len, -100, 100, options ); return benchmark; function benchmark( b ) { diff --git a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/docs/repl.txt index ed12670ff1de..10e7c551114c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/docs/repl.txt @@ -1,10 +1,10 @@ -{{alias}}( N, alpha, x, stride ) - Adds a constant to each strided array element and computes the sum using - ordinary recursive summation. +{{alias}}( N, alpha, x, strideX ) + Adds a scalar constant to each strided array element and computes the sum + 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. @@ -17,13 +17,13 @@ Number of indexed elements. alpha: number - Constant. + Scalar constant. x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. Returns ------- @@ -37,27 +37,24 @@ > {{alias}}( x.length, 5.0, x, 1 ) 16.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, 5.0, x, stride ) + > {{alias}}( 3, 5.0, x, 2 ) 16.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, 5.0, x1, stride ) + > {{alias}}( 3, 5.0, x1, 2 ) 14.0 -{{alias}}.ndarray( N, alpha, x, stride, offset ) - Adds a constant to each strided array element and computes the sum using - ordinary recursive summation and alternative indexing semantics. + +{{alias}}.ndarray( N, alpha, x, strideX, offsetX ) + Adds a scalar constant to each strided array element and computes the sum + 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 @@ -66,15 +63,15 @@ Number of indexed elements. alpha: number - Constant. + Scalar constant. x: Array|TypedArray Input array. - stride: integer - Index increment. + strideX: integer + Stride length. - offset: integer + offsetX: integer Starting index. Returns @@ -91,8 +88,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, 5.0, x, 2, 1 ) + > {{alias}}.ndarray( 3, 5.0, x, 2, 1 ) 14.0 See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/docs/types/index.d.ts index b5dd156bb983..b75a10f3e60f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/docs/types/index.d.ts @@ -27,12 +27,12 @@ import { NumericArray } from '@stdlib/types/array'; */ interface Routine { /** - * Adds a constant to each strided array element and computes the sum using ordinary recursive summation. + * Adds a scalar constant to each strided array element and computes the sum using ordinary recursive summation. * * @param N - number of indexed elements - * @param alpha - constant + * @param alpha - scalar constant * @param x - input array - * @param stride - stride length + * @param strideX - stride length * @returns sum * * @example @@ -41,16 +41,16 @@ interface Routine { * var v = gapxsumors( x.length, 5.0, x, 1 ); * // returns 16.0 */ - ( N: number, alpha: number, x: NumericArray, stride: number ): number; + ( N: number, alpha: number, x: NumericArray, strideX: number ): number; /** - * Adds a constant to each strided array element and computes the sum using ordinary recursive summation and alternative indexing semantics. + * Adds a scalar constant to each strided array element and computes the sum using ordinary recursive summation and alternative indexing semantics. * * @param N - number of indexed elements - * @param alpha - constant + * @param alpha - scalar constant * @param x - input array - * @param stride - stride length - * @param offset - starting index + * @param strideX - stride length + * @param offsetX - starting index * @returns sum * * @example @@ -59,16 +59,16 @@ interface Routine { * var v = gapxsumors.ndarray( x.length, 5.0, x, 1, 0 ); * // returns 16.0 */ - ndarray( N: number, alpha: number, x: NumericArray, stride: number, offset: number ): number; + ndarray( N: number, alpha: number, x: NumericArray, strideX: number, offsetX: number ): number; } /** -* Adds a constant to each strided array element and computes the sum using ordinary recursive summation. +* Adds a scalar constant to each strided array element and computes the sum using ordinary recursive summation. * * @param N - number of indexed elements -* @param alpha - constant +* @param alpha - scalar constant * @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/gapxsumors/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/examples/index.js index 07f86556ab1b..8410c2ca8431 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var gapxsumors = require( './../lib' ); -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 = gapxsumors( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/lib/index.js index a70c48f27988..0ab8269f877f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Add a constant to each strided array element and compute the sum using ordinary recursive summation. +* Add a scalar constant to each strided array element and compute the sum using ordinary recursive summation. * * @module @stdlib/blas/ext/base/gapxsumors * @@ -27,19 +27,16 @@ * var gapxsumors = require( '@stdlib/blas/ext/base/gapxsumors' ); * * var x = [ 1.0, -2.0, 2.0 ]; -* var N = x.length; * -* var v = gapxsumors( N, 5.0, x, 1 ); +* var v = gapxsumors( x.length, 5.0, x, 1 ); * // returns 16.0 * * @example -* var floor = require( '@stdlib/math/base/special/floor' ); * var gapxsumors = require( '@stdlib/blas/ext/base/gapxsumors' ); * * 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 = gapxsumors.ndarray( N, 5.0, x, 2, 1 ); +* var v = gapxsumors.ndarray( 4, 5.0, x, 2, 1 ); * // returns 25.0 */ diff --git a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/lib/main.js index 383768ea5dd9..cf0608e0d8f6 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/lib/main.js @@ -18,46 +18,31 @@ 'use strict'; +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + // MAIN // /** -* Adds a constant to each strided array element and computes the sum using ordinary recursive summation. +* Adds a scalar constant to each strided array element and computes the sum using ordinary recursive summation. * * @param {PositiveInteger} N - number of indexed elements -* @param {number} alpha - constant +* @param {number} alpha - scalar constant * @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 = gapxsumors( N, 5.0, x, 1 ); +* var v = gapxsumors( x.length, 5.0, x, 1 ); * // returns 16.0 */ -function gapxsumors( N, alpha, x, stride ) { - var sum; - var ix; - var i; - - if ( N <= 0 ) { - return 0.0; - } - if ( N === 1 || stride === 0 ) { - return alpha + x[ 0 ]; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - sum = 0.0; - for ( i = 0; i < N; i++ ) { - sum += alpha + x[ ix ]; - ix += stride; - } - return sum; +function gapxsumors( N, alpha, x, strideX ) { + return ndarray( N, alpha, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/lib/ndarray.js index dcc55d4082f5..f12eff019fbb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/lib/ndarray.js @@ -21,25 +21,22 @@ // MAIN // /** -* Adds a constant to each strided array element and computes the sum using ordinary recursive summation. +* Adds a scalar constant to each strided array element and computes the sum using ordinary recursive summation. * * @param {PositiveInteger} N - number of indexed elements -* @param {number} alpha - constant +* @param {number} alpha - scalar constant * @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 = gapxsumors( N, 5.0, x, 2, 1 ); +* var v = gapxsumors( 4, 5.0, x, 2, 1 ); * // returns 25.0 */ -function gapxsumors( N, alpha, x, stride, offset ) { +function gapxsumors( N, alpha, x, strideX, offsetX ) { var sum; var ix; var i; @@ -47,14 +44,14 @@ function gapxsumors( N, alpha, x, stride, offset ) { if ( N <= 0 ) { return 0.0; } - if ( N === 1 || stride === 0 ) { - return alpha + x[ offset ]; + ix = offsetX; + if ( strideX === 0 ) { + return N * ( alpha + x[ ix ] ); } - ix = offset; sum = 0.0; for ( i = 0; i < N; i++ ) { sum += alpha + x[ ix ]; - ix += stride; + ix += strideX; } return sum; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/package.json b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/package.json index 9fc5d2d92216..2c84a5937479 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/package.json +++ b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/blas/ext/base/gapxsumors", "version": "0.0.0", - "description": "Add a constant to each strided array element and compute the sum using ordinary recursive summation.", + "description": "Add a scalar constant to each strided array element and compute the sum using ordinary recursive summation.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/test/test.main.js index 6282fefc209d..5e5f5a33f797 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/test/test.main.js @@ -140,14 +140,14 @@ tape( 'the function supports a negative `stride` parameter', function test( t ) t.end(); }); -tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element plus a constant', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element plus a constant repeated N times', function test( t ) { var x; var v; x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; v = gapxsumors( x.length, 5.0, x, 0 ); - t.strictEqual( v, 6.0, 'returns expected value' ); + t.strictEqual( v, x.length * (x[0]+5.0), 'returns expected value' ); t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/test/test.ndarray.js index b94a3e501a36..1ee4065a41fb 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gapxsumors/test/test.ndarray.js @@ -139,14 +139,14 @@ 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 plus a constant', function test( t ) { +tape( 'if provided a `stride` parameter equal to `0`, the function returns the first element plus a constant repeated N times', function test( t ) { var x; var v; x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ]; v = gapxsumors( x.length, 5.0, x, 0, 0 ); - t.strictEqual( v, 6.0, 'returns expected value' ); + t.strictEqual( v, x.length * (x[0]+5.0), 'returns expected value' ); t.end(); });