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
36 changes: 14 additions & 22 deletions lib/node_modules/@stdlib/blas/ext/base/gfill/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand All @@ -46,41 +46,36 @@ 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 ]
```

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

// 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 => <Float64Array>[ 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 ];
Expand All @@ -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 ];
Expand Down Expand Up @@ -125,15 +120,12 @@ gfill.ndarray( 3, 5.0, x, 1, x.length-3 );
<!-- eslint no-undef: "error" -->

```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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 //

/**
Expand All @@ -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 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 //
Expand All @@ -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 ) {
Expand Down
47 changes: 22 additions & 25 deletions lib/node_modules/@stdlib/blas/ext/base/gfill/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
--------
Expand All @@ -36,51 +36,49 @@
> {{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 )
<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, 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
----------
N: integer
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
--------
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions lib/node_modules/@stdlib/blas/ext/base/gfill/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ]
*/
<T = unknown, U = unknown>( N: number, alpha: T, x: Collection<U>, stride: number ): Collection<T | U>;
<T = unknown, U = unknown>( N: number, alpha: T, x: Collection<U>, strideX: number ): Collection<T | U>;

/**
* 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
Expand All @@ -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<T = unknown, U = unknown>( N: number, alpha: T, x: Collection<U>, stride: number, offset: number ): Collection<T | U>;
ndarray<T = unknown, U = unknown>( N: number, alpha: T, x: Collection<U>, strideX: number, offsetX: number ): Collection<T | U>;
}

/**
* 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
Expand Down
11 changes: 4 additions & 7 deletions lib/node_modules/@stdlib/blas/ext/base/gfill/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
12 changes: 6 additions & 6 deletions lib/node_modules/@stdlib/blas/ext/base/gfill/lib/accessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Function>} 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
Expand All @@ -56,7 +56,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 gfill( N, alpha, x, stride, offset ) {
function gfill( N, alpha, x, strideX, offsetX ) {
var xbuf;
var set;
var ix;
Expand All @@ -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;
}
Expand Down
Loading
Loading