Skip to content

Commit

Permalink
refactor: update implementation in accordance with current project co…
Browse files Browse the repository at this point in the history
…nventions

Ref: #788
  • Loading branch information
kgryte committed Dec 1, 2023
1 parent 2ed14aa commit 3c82fe7
Show file tree
Hide file tree
Showing 20 changed files with 384 additions and 459 deletions.
34 changes: 14 additions & 20 deletions lib/node_modules/@stdlib/blas/base/cswap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,22 @@ im = imagf( z );
The function has the following parameters:

- **N**: number of indexed elements.
- **x**: input [`Complex64Array`][@stdlib/array/complex64].
- **x**: first input [`Complex64Array`][@stdlib/array/complex64].
- **strideX**: index increment for `x`.
- **y**: destination [`Complex64Array`][@stdlib/array/complex64].
- **y**: second input [`Complex64Array`][@stdlib/array/complex64].
- **strideY**: index increment for `y`.

The `N` and `stride` parameters determine how values from `x` are interchanged with values from `y`. For example, to interchange in reverse order every other value in `x` into the first `N` elements of `y`,
The `N` and stride parameters determine how values from `x` are interchanged with values from `y`. For example, to interchange in reverse order every other value in `x` into the first `N` elements of `y`,

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );
var floor = require( '@stdlib/math/base/special/floor' );
var realf = require( '@stdlib/complex/realf' );
var imagf = require( '@stdlib/complex/imagf' );

var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var y = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

var N = floor( x.length / 2 );

cswap( N, x, -2, y, 1 );
cswap( 2, x, -2, y, 1 );

var z = y.get( 0 );
// returns <Complex64>
Expand Down Expand Up @@ -182,7 +179,7 @@ The function has the following additional parameters:
- **offsetX**: starting index for `x`.
- **offsetY**: starting index for `y`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offsetX` and `offsetY` parameters support indexing semantics based on starting indices. For example, to interchange every other value in `x` starting from the second value into the last `N` elements in `y` where `x[i] = y[n]`, `x[i+2] = y[n-1]`,...,
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 interchange every other value in `x` starting from the second value into the last `N` elements in `y` where `x[i] = y[n]`, `x[i+2] = y[n-1]`,...,

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );
Expand Down Expand Up @@ -236,24 +233,21 @@ im = imagf( z );

```javascript
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var Complex64Array = require( '@stdlib/array/complex64' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var Complex64 = require( '@stdlib/complex/float32' );
var cswap = require( '@stdlib/blas/base/cswap' );

var re = discreteUniform.factory( 0, 10 );
var im = discreteUniform.factory( -5, 5 );

var x = new Complex64Array( 10 );
var y = new Complex64Array( 10 );

var i;
for ( i = 0; i < x.length; i++ ) {
x.set( [ re(), im() ], i );
y.set( [ re(), im() ], i );
function rand() {
return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) );
}

var x = filledarrayBy( 10, 'complex64', rand );
console.log( x.get( 0 ).toString() );

var y = filledarrayBy( 10, 'complex64', rand );
console.log( y.get( 0 ).toString() );

// Swap elements in `x` and `y` starting from the end of `y`:
// Swap elements in `x` into `y` starting from the end of `y`:
cswap( x.length, x, 1, y, -1 );
console.log( x.get( x.length-1 ).toString() );
console.log( y.get( y.length-1 ).toString() );
Expand Down
25 changes: 15 additions & 10 deletions lib/node_modules/@stdlib/blas/base/cswap/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@
// 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 Complex64Array = require( '@stdlib/array/complex64' );
var Float32Array = require( '@stdlib/array/float32' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );
var pkg = require( './../package.json' ).name;
var cswap = require( './../lib/cswap.js' );


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -43,14 +49,13 @@ function createBenchmark( len ) {
var viewY;
var x;
var y;
var i;

x = new Complex64Array( len );
x = filledarrayBy( len*2, 'float32', rand );
x = new Complex64Array( x.buffer );

y = new Complex64Array( len );
for ( i = 0; i < len; i++ ) {
x.set( [ (randu()*10000.0)-5000.0, (randu()*10000.0)-5000.0 ], i );
}
viewY = new Float32Array( y.buffer, y.byteOffset, y.length*2 );
viewY = reinterpret( y, 0 );

return benchmark;

/**
Expand All @@ -62,8 +67,8 @@ function createBenchmark( len ) {
function benchmark( b ) {
var i;

for ( i = 0; i < len; i++ ) {
y.set( [ 0.0, 0.0 ], i );
for ( i = 0; i < len*2; i++ ) {
viewY[ i ] = 0.0;
}
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@

var resolve = require( 'path' ).resolve;
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 Complex64Array = require( '@stdlib/array/complex64' );
var Float32Array = require( '@stdlib/array/float32' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -37,6 +38,7 @@ var cswap = tryRequire( resolve( __dirname, './../lib/cswap.native.js' ) );
var opts = {
'skip': ( cswap instanceof Error )
};
var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //
Expand All @@ -52,14 +54,13 @@ function createBenchmark( len ) {
var viewY;
var x;
var y;
var i;

x = new Complex64Array( len );
x = filledarrayBy( len*2, 'float32', rand );
x = new Complex64Array( x.buffer );

y = new Complex64Array( len );
for ( i = 0; i < len; i++ ) {
x.set( [ (randu()*10000.0)-5000.0, (randu()*10000.0)-5000.0 ], i );
}
viewY = new Float32Array( y.buffer, y.byteOffset, y.length*2 );
viewY = reinterpret( y, 0 );

return benchmark;

/**
Expand All @@ -71,8 +72,8 @@ function createBenchmark( len ) {
function benchmark( b ) {
var i;

for ( i = 0; i < len; i++ ) {
y.set( [ 0.0, 0.0 ], i );
for ( i = 0; i < len*2; i++ ) {
viewY[ i ] = 0.0;
}
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@
// 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 Complex64Array = require( '@stdlib/array/complex64' );
var Float32Array = require( '@stdlib/array/float32' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );
var pkg = require( './../package.json' ).name;
var cswap = require( './../lib/ndarray.js' );


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -43,14 +49,13 @@ function createBenchmark( len ) {
var viewY;
var x;
var y;
var i;

x = new Complex64Array( len );
x = filledarrayBy( len*2, 'float32', rand );
x = new Complex64Array( x.buffer );

y = new Complex64Array( len );
for ( i = 0; i < len; i++ ) {
x.set( [ (randu()*10000.0)-5000.0, (randu()*10000.0)-5000.0 ], i );
}
viewY = new Float32Array( y.buffer, y.byteOffset, y.length*2 );
viewY = reinterpret( y, 0 );

return benchmark;

/**
Expand All @@ -62,8 +67,8 @@ function createBenchmark( len ) {
function benchmark( b ) {
var i;

for ( i = 0; i < len; i++ ) {
y.set( [ 0.0, 0.0 ], i );
for ( i = 0; i < len*2; i++ ) {
viewY[ i ] = 0.0;
}
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@

var resolve = require( 'path' ).resolve;
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 Complex64Array = require( '@stdlib/array/complex64' );
var Float32Array = require( '@stdlib/array/float32' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -37,6 +38,7 @@ var cswap = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
var opts = {
'skip': ( cswap instanceof Error )
};
var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //
Expand All @@ -52,14 +54,13 @@ function createBenchmark( len ) {
var viewY;
var x;
var y;
var i;

x = new Complex64Array( len );
x = filledarrayBy( len*2, 'float32', rand );
x = new Complex64Array( x.buffer );

y = new Complex64Array( len );
for ( i = 0; i < len; i++ ) {
x.set( [ (randu()*10000.0)-5000.0, (randu()*10000.0)-5000.0 ], i );
}
viewY = new Float32Array( y.buffer, y.byteOffset, y.length*2 );
viewY = reinterpret( y, 0 );

return benchmark;

/**
Expand All @@ -71,8 +72,8 @@ function createBenchmark( len ) {
function benchmark( b ) {
var i;

for ( i = 0; i < len; i++ ) {
y.set( [ 0.0, 0.0 ], i );
for ( i = 0; i < len*2; i++ ) {
viewY[ i ] = 0.0;
}
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
Expand Down
6 changes: 3 additions & 3 deletions lib/node_modules/@stdlib/blas/base/cswap/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{{alias}}( N, x, strideX, y, strideY )
Interchanges two complex single-precision floating-point vectors.

The `N` and `stride` parameters determine how values from `x` are swapped
with values from `y`.
The `N` and stride parameters determine how values from `x` are swapped with
values from `y`.

Indexing is relative to the first index. To introduce an offset, use typed
array views.
Expand Down Expand Up @@ -89,7 +89,7 @@
alternative indexing semantics.

While typed array views mandate a view offset based on the underlying
buffer, the `offset` parameters support indexing semantics based on starting
buffer, the offset parameters support indexing semantics based on starting
indices.

Parameters
Expand Down
6 changes: 3 additions & 3 deletions lib/node_modules/@stdlib/blas/base/cswap/examples/c/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ int main( void ) {
float y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

// Specify the number of elements:
int N = 4;
const int N = 4;

// Specify stride lengths:
int strideX = 1;
int strideY = -1;
const int strideX = 1;
const int strideY = -1;

// Copy elements:
c_cswap( N, (void *)x, strideX, (void *)y, strideY );
Expand Down
19 changes: 8 additions & 11 deletions lib/node_modules/@stdlib/blas/base/cswap/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,18 @@
'use strict';

var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var Complex64Array = require( '@stdlib/array/complex64' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var Complex64 = require( '@stdlib/complex/float32' );
var cswap = require( './../lib' );

var re = discreteUniform.factory( 0, 10 );
var im = discreteUniform.factory( -5, 5 );

var x = new Complex64Array( 10 );
var y = new Complex64Array( 10 );

var i;
for ( i = 0; i < x.length; i++ ) {
x.set( [ re(), im() ], i );
y.set( [ re(), im() ], i );
function rand() {
return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) );
}

var x = filledarrayBy( 10, 'complex64', rand );
console.log( x.get( 0 ).toString() );

var y = filledarrayBy( 10, 'complex64', rand );
console.log( y.get( 0 ).toString() );

// Swap elements in `x` into `y` starting from the end of `y`:
Expand Down
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/blas/base/cswap/include.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

# Source files:
'src_files': [
'<(src_dir)/addon.cpp',
'<(src_dir)/addon.c',
'<!@(node -e "var arr = require(\'@stdlib/utils/library-manifest\')(\'./manifest.json\',{\'os\':\'<(OS)\',\'blas\':\'<(blas)\'},{\'basedir\':process.cwd(),\'paths\':\'posix\'}).src; for ( var i = 0; i < arr.length; i++ ) { console.log( arr[ i ] ); }")',
],

Expand Down
6 changes: 3 additions & 3 deletions lib/node_modules/@stdlib/blas/base/cswap/lib/cswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

// MODULES //

var Float32Array = require( '@stdlib/array/float32' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );


// MAIN //
Expand Down Expand Up @@ -77,8 +77,8 @@ function cswap( N, x, strideX, y, strideY ) {
if ( N <= 0 ) {
return y;
}
viewX = new Float32Array( x.buffer, x.byteOffset, x.length*2 );
viewY = new Float32Array( y.buffer, y.byteOffset, y.length*2 );
viewX = reinterpret( x, 0 );
viewY = reinterpret( y, 0 );
if ( strideX === 1 && strideY === 1 ) {
for ( i = 0; i < N*2; i += 2 ) {
tmp = viewX[ i ];
Expand Down
Loading

1 comment on commit 3c82fe7

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
blas/base/cswap $\color{green}572/572$
$\color{green}+100.00\%$
$\color{green}31/31$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}572/572$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.