Skip to content

Commit

Permalink
refactor: update implementation according to current project conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Dec 3, 2023
1 parent 85f4124 commit 0a89ff5
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 97 deletions.
54 changes: 13 additions & 41 deletions lib/node_modules/@stdlib/blas/base/gscal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,25 @@ The function has the following parameters:
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to multiply every other value by a constant

```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 );
var alpha = 5.0;
var stride = 2;

gscal( N, alpha, x, stride );
gscal( 4, 5.0, x, 2 );
// x => [ -10.0, 1.0, 15.0, -5.0, 20.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...
// Initial array:
var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );

// Create an offset view...
// 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 );
var alpha = 5.0;
var stride = 2;

// Scale every other value...
gscal( N, alpha, x1, stride );
// Scale every other value:
gscal( 3, 5.0, x1, 2 );
// x0 => <Float64Array>[ 1.0, -10.0, 3.0, -20.0, 5.0, -30.0 ]
```

Expand All @@ -105,9 +94,8 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the

```javascript
var x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ];
var alpha = 5.0;

gscal.ndarray( 3, alpha, x, 1, x.length-3 );
gscal.ndarray( 3, 5.0, x, 1, x.length-3 );
// x => [ 1.0, -2.0, 3.0, -20.0, 25.0, -30.0 ]
```

Expand All @@ -133,27 +121,11 @@ gscal.ndarray( 3, alpha, x, 1, x.length-3 );
<!-- eslint no-undef: "error" -->

```javascript
var round = require( '@stdlib/math/base/special/round' );
var randu = require( '@stdlib/random/base/randu' );
var Float64Array = require( '@stdlib/array/float64' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var gscal = require( '@stdlib/blas/base/gscal' );

var rand;
var sign;
var x;
var i;

x = new Float64Array( 100 );
for ( i = 0; i < x.length; i++ ) {
rand = round( randu()*100.0 );
sign = randu();
if ( sign < 0.5 ) {
sign = -1.0;
} else {
sign = 1.0;
}
x[ i ] = sign * rand;
}
var x = filledarrayBy( 10, 'float64', discreteUniform( -100, 100 ) );
console.log( x );

gscal( x.length, 5.0, x, 1 );
Expand Down Expand Up @@ -192,14 +164,14 @@ console.log( x );

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

<!-- <related-links> -->

[@stdlib/blas/base/dscal]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/dscal

[@stdlib/blas/base/gaxpy]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/gaxpy

[@stdlib/blas/base/sscal]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/sscal

<!-- <related-links> -->

[@stdlib/blas/base/gaxpy]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/gaxpy

<!-- </related-links> -->

</section>
Expand Down
16 changes: 8 additions & 8 deletions lib/node_modules/@stdlib/blas/base/gscal/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
var gscal = require( './../lib' );


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -38,13 +44,7 @@ var gscal = require( './../lib' );
* @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 = filledarrayBy( len, 'generic', rand );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
var gscal = require( './../lib' ).ndarray;


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -38,13 +44,7 @@ var gscal = require( './../lib' ).ndarray;
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;

x = [];
for ( i = 0; i < len; i++ ) {
x.push( ( randu()*10.0 ) - 20.0 );
}
var x = filledarrayBy( len, 'generic', rand );
return benchmark;

function benchmark( b ) {
Expand Down
19 changes: 5 additions & 14 deletions lib/node_modules/@stdlib/blas/base/gscal/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,18 @@

// 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 );
> alpha = 5.0;
> var stride = 2;
> {{alias}}( N, alpha, x, stride )
> {{alias}}( 3, 5.0, x, 2 )
[ -10.0, 1.0, 15.0, -5.0, 20.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 );
> alpha = 5.0;
> stride = 2;
> {{alias}}( N, alpha, x1, stride )
> {{alias}}( 3, 5.0, x1, 2 )
<Float64Array>[ -10.0, 3.0, -20.0, 5.0, -30.0 ]
> x0
<Float64Array>[ 1.0, -10.0, 3.0, -20.0, 5.0, -30.0 ]


{{alias}}.ndarray( N, alpha, x, stride, offset )
Multiplies `x` by a constant `alpha` using alternative indexing semantics.

Expand Down Expand Up @@ -89,16 +84,12 @@
--------
// Standard Usage:
> var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ];
> var alpha = 5.0;
> {{alias}}.ndarray( x.length, alpha, x, 1, 0 )
> {{alias}}.ndarray( x.length, 5.0, x, 1, 0 )
[ -10.0, 5.0, 15.0, -25.0, 20.0, -5.0, -15.0 ]

// 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 );
> alpha = 5.0;
> var stride = 2;
> {{alias}}.ndarray( N, alpha, x, stride, 1 )
> {{alias}}.ndarray( 3, 5.0, x, 2, 1 )
[ 1.0, -10.0, 3.0, -20.0, 5.0, -30.0 ]

See Also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface Routine {
* @param alpha - constant
* @param x - input array
* @param stride - stride length
* @returns `y`
* @returns input array
*
* @example
* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
Expand All @@ -51,7 +51,7 @@ interface Routine {
* @param x - input array
* @param stride - stride length
* @param offset - starting index
* @returns `x`
* @returns input array
*
* @example
* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
Expand All @@ -69,7 +69,7 @@ interface Routine {
* @param alpha - constant
* @param x - input array
* @param stride - stride length
* @returns `x`
* @returns input array
*
* @example
* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
Expand Down
23 changes: 4 additions & 19 deletions lib/node_modules/@stdlib/blas/base/gscal/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,12 @@

'use strict';

var round = require( '@stdlib/math/base/special/round' );
var randu = require( '@stdlib/random/base/randu' );
var Float64Array = require( '@stdlib/array/float64' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var gscal = require( './../lib' );

var rand;
var sign;
var x;
var i;

x = new Float64Array( 100 );
for ( i = 0; i < x.length; i++ ) {
rand = round( randu()*100.0 );
sign = randu();
if ( sign < 0.5 ) {
sign = -1.0;
} else {
sign = 1.0;
}
x[ i ] = sign * rand;
}
var x = filledarrayBy( 10, 'float64', discreteUniform( -100, 100 ) );
console.log( x );

gscal( x.length, 5.0, x, 1 );
console.log( x );
4 changes: 2 additions & 2 deletions lib/node_modules/@stdlib/blas/base/gscal/test/test.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ tape( 'main export is a function', function test( t ) {
});

tape( 'the function has an arity of 4', function test( t ) {
t.strictEqual( gscal.length, 4, 'has expected arity' );
t.strictEqual( gscal.length, 4, 'returns expected value' );
t.end();
});

Expand Down Expand Up @@ -82,7 +82,7 @@ tape( 'the function returns a reference to the input array', function test( t )
x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
out = gscal( x.length, 3.0, x, 1 );

t.strictEqual( out, x, 'same reference' );
t.strictEqual( out, x, 'returns expected value' );
t.end();
});

Expand Down
4 changes: 2 additions & 2 deletions lib/node_modules/@stdlib/blas/base/gscal/test/test.ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ tape( 'main export is a function', function test( t ) {
});

tape( 'the function has an arity of 5', function test( t ) {
t.strictEqual( gscal.length, 5, 'has expected arity' );
t.strictEqual( gscal.length, 5, 'returns expected value' );
t.end();
});

Expand Down Expand Up @@ -82,7 +82,7 @@ tape( 'the function returns a reference to the input array', function test( t )
x = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
out = gscal( x.length, 3.0, x, 1, 0 );

t.strictEqual( out, x, 'same reference' );
t.strictEqual( out, x, 'returns expected value' );
t.end();
});

Expand Down

0 comments on commit 0a89ff5

Please sign in to comment.