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
66 changes: 33 additions & 33 deletions lib/node_modules/@stdlib/blas/ext/base/gwxsa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ limitations under the License.

# gwxsa

> Subtract a scalar constant from each element in a strided array `x` and assign the results to elements in a strided array `y`.
> Subtract a scalar constant from each element in a strided array `x` and assign the results to elements in a strided array `w`.

<section class="intro">

This BLAS extension implements the operation

<!-- <equation class="equation" label="eq:wxsa" align="center" raw="\mathbf{y} = \mathbf{x} - \alpha" alt="Equation for wxsa operation."> -->
<!-- <equation class="equation" label="eq:wxsa" align="center" raw="\mathbf{w} = \mathbf{x} - \alpha" alt="Equation for wxsa operation."> -->

```math
\mathbf{y} = \mathbf{x} - \alpha
\mathbf{w} = \mathbf{x} - \alpha
```

<!-- </equation> -->
Expand All @@ -48,16 +48,16 @@ This API is complementary to the package [`@stdlib/blas/ext/base/gwapx`][@stdlib
var gwxsa = require( '@stdlib/blas/ext/base/gwxsa' );
```

#### gwxsa( N, alpha, x, strideX, y, strideY )
#### gwxsa( N, alpha, x, strideX, w, strideW )

Subtracts a scalar constant from each element in a strided array `x` and assigns the results to elements in a strided array `y`.
Subtracts a scalar constant from each element in a strided array `x` and assigns the results to elements in a strided array `w`.

```javascript
var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ];
var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ];

gwxsa( x.length, 5.0, x, 1, y, 1 );
// y => [ -4.0, -3.0, -2.0, -1.0, 0.0 ]
gwxsa( x.length, 5.0, x, 1, w, 1 );
// w => [ -4.0, -3.0, -2.0, -1.0, 0.0 ]
```

The function has the following parameters:
Expand All @@ -66,17 +66,17 @@ The function has the following parameters:
- **alpha**: scalar constant.
- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
- **strideX**: stride length for `x`.
- **y**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
- **strideY**: stride length for `y`.
- **w**: output [`Array`][mdn-array] or [`typed array`][mdn-typed-array].
- **strideW**: stride length for `w`.

The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to subtract `alpha` from every other element in `x` and assign the results to every other element in `y`:
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to subtract `alpha` from every other element in `x` and assign the results to every other element in `w`:

```javascript
var x = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];

gwxsa( 3, 5.0, x, 2, y, 2 );
// y => [ -4.0, 0.0, -2.0, 0.0, 0.0, 0.0 ]
gwxsa( 3, 5.0, x, 2, w, 2 );
// w => [ -4.0, 0.0, -2.0, 0.0, 0.0, 0.0 ]
```

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
Expand All @@ -86,41 +86,41 @@ var Float64Array = require( '@stdlib/array/float64' );

// Initial arrays...
var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var y0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
var w0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

// Create offset views...
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*2 ); // start at 3rd element
var w1 = new Float64Array( w0.buffer, w0.BYTES_PER_ELEMENT*2 ); // start at 3rd element

gwxsa( 3, 5.0, x1, 1, y1, 1 );
// y0 => <Float64Array>[ 0.0, 0.0, -3.0, -2.0, -1.0, 0.0 ]
gwxsa( 3, 5.0, x1, 1, w1, 1 );
// w0 => <Float64Array>[ 0.0, 0.0, -3.0, -2.0, -1.0, 0.0 ]
```

#### gwxsa.ndarray( N, alpha, x, strideX, offsetX, y, strideY, offsetY )
#### gwxsa.ndarray( N, alpha, x, strideX, offsetX, w, strideW, offsetW )

Subtracts a scalar constant from each element in a strided array `x` and assigns the results to elements in a strided array `y` using alternative indexing semantics.
Subtracts a scalar constant from each element in a strided array `x` and assigns the results to elements in a strided array `w` using alternative indexing semantics.

```javascript
var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ];
var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ];

gwxsa.ndarray( x.length, 5.0, x, 1, 0, y, 1, 0 );
// y => [ -4.0, -3.0, -2.0, -1.0, 0.0 ]
gwxsa.ndarray( x.length, 5.0, x, 1, 0, w, 1, 0 );
// w => [ -4.0, -3.0, -2.0, -1.0, 0.0 ]
```

The function has the following additional parameters:

- **offsetX**: starting index for `x`.
- **offsetY**: starting index for `y`.
- **offsetW**: starting index for `w`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to subtract `alpha` from the last three elements of `x` and assign the results to the last three elements of `y`:
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to subtract `alpha` from the last three elements of `x` and assign the results to the last three elements of `w`:

```javascript
var x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ];
var w = [ 0.0, 0.0, 0.0, 0.0, 0.0 ];

gwxsa.ndarray( 3, 5.0, x, 1, x.length-3, y, 1, y.length-3 );
// y => [ 0.0, 0.0, -2.0, -1.0, 0.0 ]
gwxsa.ndarray( 3, 5.0, x, 1, x.length-3, w, 1, w.length-3 );
// w => [ 0.0, 0.0, -2.0, -1.0, 0.0 ]
```

</section>
Expand All @@ -131,7 +131,7 @@ gwxsa.ndarray( 3, 5.0, x, 1, x.length-3, y, 1, y.length-3 );

## Notes

- If `N <= 0`, both functions return `y` unchanged.
- If `N <= 0`, both functions return `w` unchanged.
- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]).

</section>
Expand All @@ -153,13 +153,13 @@ var x = discreteUniform( 10, -100, 100, {
});
console.log( x );

var y = discreteUniform( 10, -100, 100, {
var w = discreteUniform( 10, -100, 100, {
'dtype': 'float64'
});
console.log( y );
console.log( w );

gwxsa( x.length, 5.0, x, 1, y, 1 );
console.log( y );
gwxsa( x.length, 5.0, x, 1, w, 1 );
console.log( w );
```

</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var options = {
*/
function createBenchmark( len ) {
var x = uniform( len, -100, 100, options );
var y = uniform( len, -100, 100, options );
var w = uniform( len, -100, 100, options );
return benchmark;

/**
Expand All @@ -62,7 +62,7 @@ function createBenchmark( len ) {

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = gwxsa( x.length, 5.0, x, 1, y, 1 );
z = gwxsa( x.length, 5.0, x, 1, w, 1 );
if ( isnan( z[ i%x.length ] ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var options = {
*/
function createBenchmark( len ) {
var x = uniform( len, -100, 100, options );
var y = uniform( len, -100, 100, options );
var w = uniform( len, -100, 100, options );
return benchmark;

/**
Expand All @@ -62,7 +62,7 @@ function createBenchmark( len ) {

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
z = gwxsa( x.length, 5.0, x, 1, 0, y, 1, 0 );
z = gwxsa( x.length, 5.0, x, 1, 0, w, 1, 0 );
if ( isnan( z[ i%x.length ] ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
58 changes: 29 additions & 29 deletions lib/node_modules/@stdlib/blas/ext/base/gwxsa/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

{{alias}}( N, alpha, x, strideX, y, strideY )
{{alias}}( N, alpha, x, strideX, w, strideW )
Subtracts a scalar constant from each element in a strided array `x` and
assigns the results to elements in a strided array `y`.
assigns the results to elements in a strided array `w`.

The `N` and stride parameters determine which elements in the strided
arrays are accessed at runtime.

Indexing is relative to the first index. To introduce an offset, use typed
array views.

If `N <= 0`, the function returns `y` unchanged.
If `N <= 0`, the function returns `w` unchanged.

Parameters
----------
Expand All @@ -25,49 +25,49 @@
strideX: integer
Stride length for `x`.

y: Array<number>|TypedArray
w: Array<number>|TypedArray
Output array.

strideY: integer
Stride length for `y`.
strideW: integer
Stride length for `w`.

Returns
-------
y: Array<number>|TypedArray
w: Array<number>|TypedArray
Output array.

Examples
--------
// Standard Usage:
> var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
> var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
> {{alias}}( x.length, 5.0, x, 1, y, 1 )
> var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
> {{alias}}( x.length, 5.0, x, 1, w, 1 )
[ -7.0, -4.0, -2.0, -10.0, -1.0, -5.0, -6.0, -8.0 ]

// Using `N` and stride parameters:
> x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
> y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
> {{alias}}( 4, 5.0, x, 2, y, 2 )
> w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
> {{alias}}( 4, 5.0, x, 2, w, 2 )
[ -7.0, 0.0, -2.0, 0.0, -1.0, 0.0, -6.0, 0.0 ]

// Using view offsets:
> var bufX = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ];
> var bufY = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
> var bufW = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
> var x0 = new {{alias:@stdlib/array/float64}}( bufX );
> var y0 = new {{alias:@stdlib/array/float64}}( bufY );
> var w0 = new {{alias:@stdlib/array/float64}}( bufW );
> var offsetX = x0.BYTES_PER_ELEMENT * 1;
> var offsetY = y0.BYTES_PER_ELEMENT * 1;
> var offsetW = w0.BYTES_PER_ELEMENT * 1;
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, offsetX );
> var y1 = new {{alias:@stdlib/array/float64}}( y0.buffer, offsetY );
> {{alias}}( 3, 5.0, x1, 2, y1, 2 )
> var w1 = new {{alias:@stdlib/array/float64}}( w0.buffer, offsetW );
> {{alias}}( 3, 5.0, x1, 2, w1, 2 )
<Float64Array>[ -7.0, 0.0, -9.0, 0.0, -11.0 ]
> y0
> w0
<Float64Array>[ 0.0, -7.0, 0.0, -9.0, 0.0, -11.0 ]


{{alias}}.ndarray( N, alpha, x, strideX, offsetX, y, strideY, offsetY )
{{alias}}.ndarray( N, alpha, x, strideX, offsetX, w, strideW, offsetW )
Subtracts a scalar constant from each element in a strided array `x` and
assigns the results to elements in a strided array `y` using alternative
assigns the results to elements in a strided array `w` using alternative
indexing semantics.

While typed array views mandate a view offset based on the underlying
Expand All @@ -91,32 +91,32 @@
offsetX: integer
Starting index for `x`.

y: Array<number>|TypedArray
w: Array<number>|TypedArray
Output array.

strideY: integer
Stride length for `y`.
strideW: integer
Stride length for `w`.

offsetY: integer
Starting index for `y`.
offsetW: integer
Starting index for `w`.

Returns
-------
y: Array<number>|TypedArray
w: Array<number>|TypedArray
Output array.

Examples
--------
// Standard Usage:
> var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
> var y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
> {{alias}}.ndarray( x.length, 5.0, x, 1, 0, y, 1, 0 )
> var w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
> {{alias}}.ndarray( x.length, 5.0, x, 1, 0, w, 1, 0 )
[ -7.0, -4.0, -2.0, -10.0, -1.0, -5.0, -6.0, -8.0 ]

// Using index offsets:
> x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ];
> y = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
> {{alias}}.ndarray( 3, 5.0, x, 1, x.length-3, y, 1, y.length-3 )
> w = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];
> {{alias}}.ndarray( 3, 5.0, x, 1, x.length-3, w, 1, w.length-3 )
[ 0.0, 0.0, 0.0, -9.0, 0.0, -11.0 ]

See Also
Expand Down
Loading
Loading