Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 16 additions & 33 deletions lib/node_modules/@stdlib/blas/ext/base/gfill-by/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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`.

Expand All @@ -81,27 +81,23 @@ 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 ]
```

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var floor = require( '@stdlib/math/base/special/floor' );

function fill( v, i ) {
return v * i;
Expand All @@ -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 => <Float64Array>[ 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 ) {
Expand All @@ -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 ) {
Expand Down Expand Up @@ -174,26 +169,14 @@ gfillBy.ndarray( 3, x, 1, x.length-3, fill );
<!-- eslint no-undef: "error" -->

```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 );
```

Expand Down
39 changes: 18 additions & 21 deletions lib/node_modules/@stdlib/blas/ext/base/gfill-by/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -28,8 +28,8 @@
x: ArrayLikeObject
Input array.

stride: integer
Index increment for `x`.
strideX: integer
Stride length.

clbk: Function
Callback function.
Expand All @@ -40,7 +40,7 @@
Returns
-------
x: ArrayLikeObject
Input array `x`.
Input array.

Examples
--------
Expand All @@ -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 )
<Float64Array>[ 5.0, 3.0, 5.0, 5.0, 5.0 ]
> x0
<Float64Array>[ 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
Expand All @@ -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.
Expand All @@ -97,7 +95,7 @@
Returns
-------
x: ArrayLikeObject
Input array `x`.
Input array.

Examples
--------
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
*
Expand All @@ -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 ]
*/
<T = unknown, U = unknown, V = unknown, W = unknown>( N: number, x: Collection<V>, stride: number, clbk: Callback<T, U, V, W>, thisArg?: ThisParameterType<Callback<T, U, V, W>> ): Collection<U | V>;
<T = unknown, U = unknown, V = unknown, W = unknown>( N: number, x: Collection<V>, strideX: number, clbk: Callback<T, U, V, W>, thisArg?: ThisParameterType<Callback<T, U, V, W>> ): Collection<U | V>;

/**
* Fills a strided array according to a provided callback function and using alternative indexing semantics.
Expand All @@ -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`
*
Expand All @@ -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<T = unknown, U = unknown, V = unknown, W = unknown>( N: number, x: Collection<V>, stride: number, offset: number, clbk: Callback<T, U, V, W>, thisArg?: ThisParameterType<Callback<T, U, V, W>> ): Collection<U | V>;
ndarray<T = unknown, U = unknown, V = unknown, W = unknown>( N: number, x: Collection<V>, strideX: number, offsetX: number, clbk: Callback<T, U, V, W>, thisArg?: ThisParameterType<Callback<T, U, V, W>> ): Collection<U | V>;
}

/**
Expand All @@ -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`
*
Expand Down
16 changes: 2 additions & 14 deletions lib/node_modules/@stdlib/blas/ext/base/gfill-by/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
12 changes: 6 additions & 6 deletions lib/node_modules/@stdlib/blas/ext/base/gfill-by/lib/accessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
* @param {Object} x - input array object
* @param {Collection} x.data - input array data
* @param {Array<Function>} 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
*
Expand Down Expand Up @@ -63,7 +63,7 @@
* var view = reinterpret64( x.data, 0 );
* // view => <Float32Array>[ 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;
Expand All @@ -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;
}
Expand Down
Loading
Loading