diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-by/README.md b/lib/node_modules/@stdlib/blas/ext/base/gfill-by/README.md index 47f81ebe3805..bc2f09f11a9e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill-by/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-by/README.md @@ -30,9 +30,9 @@ limitations under the License. var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' ); ``` -#### gfillBy( N, x, stride, clbk\[, thisArg] ) +#### gfillBy( N, x, strideX, clbk\[, thisArg] ) -Fills a strided array `x` according to a provided callback function. +Fills a strided array according to a provided callback function. ```javascript function fill( v, i ) { @@ -48,17 +48,17 @@ gfillBy( x.length, x, 1, fill ); The function has the following parameters: - **N**: number of indexed elements. -- **x**: input array. -- **stride**: index increment. +- **x**: input array. +- **strideX**: stride length. - **clbk**: callback function. - **thisArg**: execution context (_optional_). -The invoked callback is provided four arguments: +The callback function is provided the following arguments: -- **value**: array element. +- **value**: current array element. - **aidx**: array index. - **sidx**: strided index (`offset + aidx*stride`). -- **array**: input array/collection. +- **array**: the input array. To set the callback execution context, provide a `thisArg`. @@ -81,19 +81,16 @@ var cnt = context.count; // returns 8 ``` -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' ); - function fill( v, i ) { return v * i; } var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ]; -var N = floor( x.length / 2 ); -gfillBy( N, x, 2, fill ); +gfillBy( 4, x, 2, fill ); // x => [ 0.0, 1.0, 3.0, -5.0, 8.0, 0.0, -3.0, -3.0 ] ``` @@ -101,7 +98,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' ); function fill( v, i ) { return v * i; @@ -112,16 +108,15 @@ 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... -gfillBy( N, x1, 2, fill ); +gfillBy( 3, x1, 2, fill ); // x0 => [ 1.0, 0.0, 3.0, -4.0, 5.0, -12.0 ] ``` -#### gfillBy.ndarray( N, x, stride, offset, clbk\[, thisArg] ) +#### gfillBy.ndarray( N, x, strideX, offsetX, clbk\[, thisArg] ) -Fills a strided array `x` according to a provided callback function and using alternative indexing semantics. +Fills a strided array according to a provided callback function and using alternative indexing semantics. ```javascript function fill( v, i ) { @@ -136,9 +131,9 @@ gfillBy.ndarray( x.length, x, 1, 0, fill ); 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 function fill( v, i ) { @@ -174,26 +169,14 @@ gfillBy.ndarray( 3, x, 1, x.length-3, fill ); ```javascript -var round = require( '@stdlib/math/base/special/round' ); -var randu = require( '@stdlib/random/base/randu' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; var Float64Array = require( '@stdlib/array/float64' ); var gfillBy = require( '@stdlib/blas/ext/base/gfill-by' ); -function fill() { - var rand = round( randu()*100.0 ); - var sign = randu(); - if ( sign < 0.5 ) { - sign = -1.0; - } else { - sign = 1.0; - } - return sign * rand; -} - var x = new Float64Array( 10 ); console.log( x ); -gfillBy( x.length, x, 1, fill ); +gfillBy( x.length, x, 1, discreteUniform( -100, 100 ) ); console.log( x ); ``` diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-by/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gfill-by/docs/repl.txt index 6a9e76775f60..7888808c44a2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-by/docs/repl.txt @@ -1,9 +1,9 @@ -{{alias}}( N, x, stride, clbk[, thisArg] ) +{{alias}}( N, x, strideX, clbk[, thisArg] ) Fills a strided array according to a provided callback function. - 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. @@ -12,7 +12,7 @@ The callback function is provided four arguments: - - value: array element. + - value: current array element. - aidx: array index. - sidx: strided index (offset + aidx*stride). - array: the input array. @@ -28,8 +28,8 @@ x: ArrayLikeObject Input array. - stride: integer - Index increment for `x`. + strideX: integer + Stride length. clbk: Function Callback function. @@ -40,7 +40,7 @@ Returns ------- x: ArrayLikeObject - Input array `x`. + Input array. Examples -------- @@ -50,28 +50,26 @@ > {{alias}}( x.length, x, 1, fill ) [ 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, x, 2, fill ) + > {{alias}}( 3, x, 2, fill ) [ 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, x1, 2, fill ) + > {{alias}}( 3, x1, 2, fill ) [ 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, x, stride, offset, clbk[, thisArg] ) +{{alias}}.ndarray( N, x, strideX, offsetX, clbk[, thisArg] ) Fills a strided array according to a provided callback function and 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 + buffer, the offset parameter supports indexing semantics based on a starting index. Parameters @@ -82,11 +80,11 @@ x: ArrayLikeObject Input array. - stride: integer - Index increment for `x`. + strideX: integer + Stride length. - offset: integer - Starting index of `x`. + offsetX: integer + Starting index. clbk: Function Callback function. @@ -97,7 +95,7 @@ Returns ------- x: ArrayLikeObject - Input array `x`. + Input array. Examples -------- @@ -109,8 +107,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, x, 2, 1, fill ) + > {{alias}}.ndarray( 3, x, 2, 1, fill ) [ 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-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gfill-by/docs/types/index.d.ts index 8f7efefe5fe4..656fb4f3160c 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-by/docs/types/index.d.ts @@ -98,8 +98,8 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length - * @param clbk - callback + * @param strideX - stride length + * @param clbk - callback function * @param thisArg - execution context * @returns `x` * @@ -113,7 +113,7 @@ interface Routine { * gfillBy( x.length, x, 1, fill ); * // x => [ 5.0, 5.0, 5.0, 0.0, 5.0, 5.0, 5.0, 5.0 ] */ - ( N: number, x: Collection, stride: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; + ( N: number, x: Collection, strideX: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; /** * Fills a strided array according to a provided callback function and using alternative indexing semantics. @@ -131,9 +131,9 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array - * @param stride - stride length - * @param offset - starting index - * @param clbk - callback + * @param strideX - stride length + * @param offsetX - starting index + * @param clbk - callback function * @param thisArg - execution context * @returns `x` * @@ -147,7 +147,7 @@ interface Routine { * gfillBy.ndarray( x.length, x, 1, 0, fill ); * // x => [ 5.0, 5.0, 5.0, 0.0, 5.0, 5.0, 5.0, 5.0 ] */ - ndarray( N: number, x: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; + ndarray( N: number, x: Collection, strideX: number, offsetX: number, clbk: Callback, thisArg?: ThisParameterType> ): Collection; } /** @@ -166,8 +166,8 @@ interface Routine { * * @param N - number of indexed elements * @param x - input array -* @param stride - stride length -* @param clbk - callback +* @param strideX - stride length +* @param clbk - callback function * @param thisArg - execution context * @returns `x` * diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-by/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gfill-by/examples/index.js index 3377025ad13c..a4bd6b6a33f3 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill-by/examples/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-by/examples/index.js @@ -18,24 +18,12 @@ 'use strict'; -var round = require( '@stdlib/math/base/special/round' ); -var randu = require( '@stdlib/random/base/randu' ); +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; var Float64Array = require( '@stdlib/array/float64' ); var gfillBy = require( './../lib' ); -function fill() { - var rand = round( randu()*100.0 ); - var sign = randu(); - if ( sign < 0.5 ) { - sign = -1.0; - } else { - sign = 1.0; - } - return sign * rand; -} - var x = new Float64Array( 10 ); console.log( x ); -gfillBy( x.length, x, 1, fill ); +gfillBy( x.length, x, 1, discreteUniform( -100, 100 ) ); console.log( x ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-by/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gfill-by/lib/accessors.js index 4bc24a1cb009..6465058b2ff0 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill-by/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-by/lib/accessors.js @@ -28,9 +28,9 @@ * @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 {Callback} clbk - callback +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @param {Callback} clbk - callback function * @param {*} thisArg - execution context * @returns {Object} input array object * @@ -63,7 +63,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 gfillBy( N, x, stride, offset, clbk, thisArg ) { +function gfillBy( N, x, strideX, offsetX, clbk, thisArg ) { var xbuf; var set; var get; @@ -77,10 +77,10 @@ function gfillBy( N, x, stride, offset, clbk, thisArg ) { get = x.accessors[ 0 ]; set = x.accessors[ 1 ]; - ix = offset; + ix = offsetX; for ( i = 0; i < N; i++ ) { set( xbuf, ix, clbk.call( thisArg, get( xbuf, ix ), i, ix, x ) ); - ix += stride; + ix += strideX; } return x; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-by/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gfill-by/lib/main.js index 7bcd62d0e229..1ab9a636f1ca 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill-by/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-by/lib/main.js @@ -20,8 +20,8 @@ // MODULES // -var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -var accessors = require( './accessors.js' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -31,8 +31,8 @@ var accessors = require( './accessors.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Collection} x - input array -* @param {integer} stride - index increment -* @param {Callback} clbk - callback +* @param {integer} strideX - stride length +* @param {Callback} clbk - callback function * @param {*} [thisArg] - execution context * @returns {Collection} input array * @@ -46,29 +46,8 @@ var accessors = require( './accessors.js' ); * gfillBy( x.length, x, 1, fill ); * // x => [ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0 ] */ -function gfillBy( N, x, stride, clbk, thisArg ) { - var ix; - var o; - var i; - - if ( N <= 0 ) { - return x; - } - if ( stride < 0 ) { - ix = (1-N) * stride; - } else { - ix = 0; - } - o = arraylike2object( x ); - if ( o.accessorProtocol ) { - accessors( N, o, stride, ix, clbk, thisArg ); - return o.data; - } - for ( i = 0; i < N; i++ ) { - x[ ix ] = clbk.call( thisArg, x[ ix ], i, ix, x ); - ix += stride; - } - return x; +function gfillBy( N, x, strideX, clbk, thisArg ) { + return ndarray( N, x, strideX, stride2offset( N, strideX ), clbk, thisArg ); } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gfill-by/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gfill-by/lib/ndarray.js index fc0448641d7f..9b8e89b2b5ef 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gfill-by/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gfill-by/lib/ndarray.js @@ -31,9 +31,9 @@ var accessors = require( './accessors.js' ); * * @param {PositiveInteger} N - number of indexed elements * @param {Collection} x - input array -* @param {integer} stride - index increment -* @param {NonNegativeInteger} offset - starting index -* @param {Callback} clbk - callback +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @param {Callback} clbk - callback function * @param {*} [thisArg] - execution context * @returns {Collection} input array * @@ -47,7 +47,7 @@ var accessors = require( './accessors.js' ); * gfillBy( 3, x, 1, x.length-3, fill ); * // x => [ 1.0, -2.0, 3.0, 5.0, 5.0, 5.0 ] */ -function gfillBy( N, x, stride, offset, clbk, thisArg ) { +function gfillBy( N, x, strideX, offsetX, clbk, thisArg ) { var ix; var o; var i; @@ -57,13 +57,13 @@ function gfillBy( N, x, stride, offset, clbk, thisArg ) { } o = arraylike2object( x ); if ( o.accessorProtocol ) { - accessors( N, o, stride, offset, clbk, thisArg ); + accessors( N, o, strideX, offsetX, clbk, thisArg ); return o.data; } - ix = offset; + ix = offsetX; for ( i = 0; i < N; i++ ) { x[ ix ] = clbk.call( thisArg, x[ ix ], i, ix, x ); - ix += stride; + ix += strideX; } return x; }