diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill/README.md b/lib/node_modules/@stdlib/blas/ext/base/gfill/README.md index 941ea9fc0e5e..d9f66d3d61d9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill/README.md @@ -30,9 +30,9 @@ limitations under the License. var gfill = require( '@stdlib/blas/ext/base/gfill' ); ``` -#### gfill( N, alpha, x, stride ) +#### gfill( N, alpha, x, strideX ) -Fills a strided array `x` with a specified scalar constant `alpha`. +Fills a strided array with a specified scalar constant. ```javascript var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; @@ -46,17 +46,14 @@ The function has the following parameters: - **N**: number of indexed elements. - **alpha**: scalar constant. - **x**: input array. -- **stride**: index increment. +- **strideX**: stride length. -The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to fill every other element +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to fill every other element: ```javascript -var floor = require( '@stdlib/math/base/special/floor' ); - var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; -var N = floor( x.length / 2 ); -gfill( N, 5.0, x, 2 ); +gfill( 4, 5.0, x, 2 ); // x => [ 5.0, 1.0, 5.0, -5.0, 5.0, 0.0, 5.0, -3.0 ] ``` @@ -64,23 +61,21 @@ 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 array... var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] ); // Create an offset view... var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element -var N = floor( x0.length/2 ); // Fill every other element... -gfill( N, 5.0, x1, 2 ); +gfill( 3, 5.0, x1, 2 ); // x0 => [ 1.0, 5.0, 3.0, 5.0, 5.0, 5.0 ] ``` -#### gfill.ndarray( N, alpha, x, stride, offset ) +#### gfill.ndarray( N, alpha, x, strideX, offsetX ) -Fills a strided array `x` with a specified scalar constant `alpha` using alternative indexing semantics. +Fills a strided array with a specified scalar constant using alternative indexing semantics. ```javascript var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; @@ -91,9 +86,9 @@ gfill.ndarray( x.length, 5.0, x, 1, 0 ); The function has the following additional parameters: -- **offset**: starting index. +- **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 only the last three elements of `x` +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements: ```javascript var x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ]; @@ -125,15 +120,12 @@ gfill.ndarray( 3, 5.0, x, 1, x.length-3 ); ```javascript -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); -var Float64Array = require( '@stdlib/array/float64' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var gfill = require( '@stdlib/blas/ext/base/gfill' ); -var x = new Float64Array( 10 ); -var i; -for ( i = 0; i < x.length; i++ ) { - x[ i ] = discreteUniform( -100, 100 ); -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); gfill( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gfill/benchmark/benchmark.js index a05478082b6a..cbffef414d02 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill/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 gfill = require( './../lib/main.js' ); +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; + + // FUNCTIONS // /** @@ -38,13 +45,7 @@ var gfill = 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/gfill/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gfill/benchmark/benchmark.ndarray.js index 2f27e35112f7..06c7d889bbc9 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill/benchmark/benchmark.ndarray.js @@ -21,11 +21,18 @@ // 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 gfill = require( './../lib/main.js' ).ndarray; +var gfill = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'generic' +}; // FUNCTIONS // @@ -38,13 +45,7 @@ var gfill = require( './../lib/main.js' ).ndarray; * @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/gfill/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gfill/docs/repl.txt index ec2109992757..f15e3a00ded1 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill/docs/repl.txt @@ -1,9 +1,9 @@ -{{alias}}( N, alpha, x, stride ) - Fills a strided array with a specified scalar value. +{{alias}}( N, alpha, x, strideX ) + Fills a strided array with a specified scalar constant. - 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 typed array views. @@ -16,18 +16,18 @@ Number of indexed elements. alpha: any - Constant. + Scalar constant. x: ArrayLikeObject Input array. - stride: integer - Index increment for `x`. + strideX: integer + Stride length. Returns ------- x: ArrayLikeObject - Input array `x`. + Input array. Examples -------- @@ -36,29 +36,27 @@ > {{alias}}( x.length, 5.0, x, 1 ) [ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 ] - // Using `N` and `stride` parameters: + // Using `N` and stride parameters: > x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ]; - > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 ); - > {{alias}}( N, 5.0, x, 2 ) + > {{alias}}( 3, 5.0, x, 2 ) [ 5.0, 1.0, 5.0, -5.0, 5.0, -1.0, -3.0 ] // Using view offsets: > var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.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 ); - > {{alias}}( N, 5.0, x1, 2 ) + > {{alias}}( 3, 5.0, x1, 2 ) [ 5.0, 3.0, 5.0, 5.0, 5.0 ] > x0 [ 1.0, 5.0, 3.0, 5.0, 5.0, 5.0 ] -{{alias}}.ndarray( N, alpha, x, stride, offset ) - Fills a strided array with a specified scalar value using alternative +{{alias}}.ndarray( N, alpha, x, strideX, offsetX ) + Fills a strided array with a specified scalar constant using 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 parameter supports indexing semantics based on a starting + index. Parameters ---------- @@ -66,21 +64,21 @@ Number of indexed elements. alpha: any - Constant. + Scalar constant. x: ArrayLikeObject Input array. - stride: integer - Index increment for `x`. + strideX: integer + Stride length. - offset: integer - Starting index of `x`. + offsetX: integer + Starting index. Returns ------- x: ArrayLikeObject - Input array `x`. + Input array. Examples -------- @@ -91,8 +89,7 @@ // Using an index offset: > x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.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 ) [ 1.0, 5.0, 3.0, 5.0, 5.0, 5.0 ] See Also diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gfill/docs/types/index.d.ts index 62517e66a40a..276ab00a434d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill/docs/types/index.d.ts @@ -27,12 +27,12 @@ import { Collection } from '@stdlib/types/array'; */ interface Routine { /** - * Fills a strided array with a specified scalar value. + * Fills a strided array with a specified scalar constant. * * @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 `x` * * @example @@ -41,16 +41,16 @@ interface Routine { * gfill( x.length, 5.0, x, 1 ); * // x => [ 5.0, 5.0, 5.0, 0.0, 5.0, 5.0, 5.0, 5.0 ] */ - ( N: number, alpha: T, x: Collection, stride: number ): Collection; + ( N: number, alpha: T, x: Collection, strideX: number ): Collection; /** - * Fills a strided array with a specified scalar value using alternative indexing semantics. + * Fills a strided array with a specified scalar constant using 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 `x` * * @example @@ -59,16 +59,16 @@ interface Routine { * gfill.ndarray( x.length, 5.0, x, 1, 0 ); * // x => [ 5.0, 5.0, 5.0, 0.0, 5.0, 5.0, 5.0, 5.0 ] */ - ndarray( N: number, alpha: T, x: Collection, stride: number, offset: number ): Collection; + ndarray( N: number, alpha: T, x: Collection, strideX: number, offsetX: number ): Collection; } /** -* Fills a strided array with a specified scalar value. +* Fills a strided array with a specified scalar constant. * * @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 `x` * * @example diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gfill/examples/index.js index c425be3a422b..bfb935521b34 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill/examples/index.js @@ -18,15 +18,12 @@ 'use strict'; -var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); -var Float64Array = require( '@stdlib/array/float64' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var gfill = require( './../lib' ); -var x = new Float64Array( 10 ); -var i; -for ( i = 0; i < x.length; i++ ) { - x[ i ] = discreteUniform( -100, 100 ); -} +var x = discreteUniform( 10, -100, 100, { + 'dtype': 'float64' +}); console.log( x ); gfill( x.length, 5.0, x, 1 ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gfill/lib/accessors.js index 754240cbe30c..fea2e2d554fe 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill/lib/accessors.js @@ -25,12 +25,12 @@ * * @private * @param {PositiveInteger} N - number of indexed elements -* @param {*} alpha - scalar +* @param {*} alpha - scalar constant * @param {Object} x - input array object * @param {Collection} x.data - input array data * @param {Array} x.accessors - array element accessors -* @param {integer} stride - index increment -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {Object} input array object * * @example @@ -56,7 +56,7 @@ * var view = reinterpret64( x.data, 0 ); * // view => [ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 ] */ -function gfill( N, alpha, x, stride, offset ) { +function gfill( N, alpha, x, strideX, offsetX ) { var xbuf; var set; var ix; @@ -68,10 +68,10 @@ function gfill( N, alpha, x, stride, offset ) { // Cache a reference to the element accessor: set = x.accessors[ 1 ]; - ix = offset; + ix = offsetX; for ( i = 0; i < N; i++ ) { set( xbuf, ix, alpha ); - ix += stride; + ix += strideX; } return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gfill/lib/main.js index f4ec682c81c1..bdd504c34edd 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill/lib/main.js @@ -20,13 +20,8 @@ // MODULES // -var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -var accessors = require( './accessors.js' ); - - -// VARIABLES // - -var M = 8; +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -35,9 +30,9 @@ var M = 8; * Fills a strided array with a specified scalar constant. * * @param {PositiveInteger} N - number of indexed elements -* @param {*} alpha - scalar +* @param {*} alpha - scalar constant * @param {Collection} x - input array -* @param {integer} stride - index increment +* @param {integer} strideX - stride length * @returns {Collection} input array * * @example @@ -46,60 +41,8 @@ var M = 8; * gfill( x.length, 5.0, x, 1 ); * // x => [ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 ] */ -function gfill( N, alpha, x, stride ) { - var ix; - var i; - var m; - var o; - - if ( N <= 0 ) { - return x; - } - o = arraylike2object( x ); - if ( o.accessorProtocol ) { - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - accessors( N, alpha, o, stride, ix ); - return o.data; - } - // Use loop unrolling if the stride is equal to `1`... - 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++ ) { - x[ i ] = alpha; - } - } - if ( N < M ) { - return x; - } - for ( i = m; i < N; i += M ) { - x[ i ] = alpha; - x[ i+1 ] = alpha; - x[ i+2 ] = alpha; - x[ i+3 ] = alpha; - x[ i+4 ] = alpha; - x[ i+5 ] = alpha; - x[ i+6 ] = alpha; - x[ i+7 ] = alpha; - } - return x; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - for ( i = 0; i < N; i++ ) { - x[ ix ] = alpha; - ix += stride; - } - return x; +function gfill( N, alpha, x, strideX ) { + return ndarray( N, alpha, x, strideX, stride2offset( N, strideX ) ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gfill/lib/ndarray.js index dd50ce87cabb..a226a2ec6d2b 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill/lib/ndarray.js @@ -35,10 +35,10 @@ var M = 8; * Fills a strided array with a specified scalar constant. * * @param {PositiveInteger} N - number of indexed elements -* @param {*} alpha - scalar +* @param {*} alpha - scalar constant * @param {Collection} x - input array -* @param {integer} stride - index increment -* @param {NonNegativeInteger} offset - starting index +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index * @returns {Collection} input array * * @example @@ -47,7 +47,7 @@ var M = 8; * gfill( 3, 5.0, x, 1, x.length-3 ); * // x => [ 1.0, -2.0, 3.0, 5.0, 5.0, 5.0 ] */ -function gfill( N, alpha, x, stride, offset ) { +function gfill( N, alpha, x, strideX, offsetX ) { var ix; var m; var o; @@ -58,20 +58,20 @@ function gfill( N, alpha, x, stride, offset ) { } o = arraylike2object( x ); if ( o.accessorProtocol ) { - accessors( N, alpha, o, stride, offset ); + accessors( N, alpha, o, strideX, offsetX ); return o.data; } - ix = offset; + ix = offsetX; // Use loop unrolling if the stride is equal to `1`... - 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++ ) { x[ ix ] = alpha; - ix += stride; + ix += strideX; } } if ( N < M ) { @@ -92,7 +92,7 @@ function gfill( N, alpha, x, stride, offset ) { } for ( i = 0; i < N; i++ ) { x[ ix ] = alpha; - ix += stride; + ix += strideX; } return x; }