Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Sep 14, 2024
1 parent 4ecdfd9 commit 9771160
Show file tree
Hide file tree
Showing 15 changed files with 829 additions and 146 deletions.
1 change: 0 additions & 1 deletion .github/.keepalive

This file was deleted.

45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,51 @@

> Package changelog.
<section class="release" id="unreleased">

## Unreleased (2024-09-14)

<section class="features">

### Features

- [`2d7e925`](https://github.com/stdlib-js/stdlib/commit/2d7e9251e02cba556ad7e8b40ef90d5190d0d719) - add support for stacks in `blas/sswap` [(#2898)](https://github.com/stdlib-js/stdlib/pull/2898)

</section>

<!-- /.features -->

<section class="commits">

### Commits

<details>

- [`2d7e925`](https://github.com/stdlib-js/stdlib/commit/2d7e9251e02cba556ad7e8b40ef90d5190d0d719) - **feat:** add support for stacks in `blas/sswap` [(#2898)](https://github.com/stdlib-js/stdlib/pull/2898) _(by Aman Bhansali, Athan Reines)_

</details>

</section>

<!-- /.commits -->

<section class="contributors">

### Contributors

A total of 2 people contributed to this release. Thank you to the following contributors:

- Aman Bhansali
- Athan Reines

</section>

<!-- /.contributors -->

</section>

<!-- /.release -->

<section class="release" id="v0.2.2">

## 0.2.2 (2024-07-28)
Expand Down
5 changes: 5 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com>
Frank Kovacs <fran70kk@gmail.com>
Golden Kumar <103646877+AuenKr@users.noreply.github.com>
Gunj Joshi <gunjjoshi8372@gmail.com>
HarshaNP <96897754+GittyHarsha@users.noreply.github.com>
Harshita Kalani <harshitakalani02@gmail.com>
Hridyanshu <124202756+HRIDYANSHU054@users.noreply.github.com>
Jaimin Godhani <112328542+Jai0401@users.noreply.github.com>
James Gelok <jdgelok@gmail.com>
Jaysukh Makvana <jaysukhmakvana2004@gmail.com>
Jenish Thapa <141203631+jenish-thapa@users.noreply.github.com>
Jithin KS <jithinks112@gmail.com>
Joel Mathew Koshy <joelmathewkoshy@gmail.com>
Joey Reed <joeyrreed@gmail.com>
Expand Down Expand Up @@ -86,8 +88,10 @@ Stephannie Jiménez Gacha <steff456@hotmail.com>
Suraj kumar <125961509+kumarsuraj212003@users.noreply.github.com>
Tirtadwipa Manunggal <tirtadwipa.manunggal@gmail.com>
Tudor Pagu <104032457+tudor-pagu@users.noreply.github.com>
Tufailahmed Bargir <142114244+Tufailahmed-Bargir@users.noreply.github.com>
Utkarsh <http://utkarsh11105@gmail.com>
Utkarsh Raj <rajutkarsh2505@gmail.com>
Vaibhav Patel <98279986+noobCoderVP@users.noreply.github.com>
Varad Gupta <varadgupta21@gmail.com>
Xiaochuan Ye <tap91624@gmail.com>
Yernar Yergaziyev <yernar.yergaziyev@erg.kz>
Expand All @@ -96,3 +100,4 @@ nishant-s7 <97207366+nishant-s7@users.noreply.github.com>
orimiles5 <97595296+orimiles5@users.noreply.github.com>
rainn <88160429+AmCodesLame@users.noreply.github.com>
rei2hu <reimu@reimu.ws>
yaswanth <116426380+yaswanthkosuru@users.noreply.github.com>
85 changes: 51 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ To view installation and usage instructions specific to each branch build, be su
var sswap = require( '@stdlib/blas-sswap' );
```

#### sswap( x, y )
#### sswap( x, y\[, dim] )

Interchanges two single-precision floating-point vectors `x` and `y`.

Expand All @@ -91,8 +91,36 @@ var ybuf = y.data;

The function has the following parameters:

- **x**: a 1-dimensional [`ndarray`][@stdlib/ndarray/array] whose underlying data type is `float32`.
- **y**: a 1-dimensional [`ndarray`][@stdlib/ndarray/array] whose underlying data type is `float32`.
- **x**: a non-zero-dimensional [`ndarray`][@stdlib/ndarray/ctor] whose underlying data type is `float32`. Must have the same shape as `y`.
- **y**: a non-zero-dimensional [`ndarray`][@stdlib/ndarray/ctor] whose underlying data type is `float32`. Must have the same shape as `x`.
- **dim**: dimension along which to interchange vectors. Must be a negative integer. Negative indices are resolved relative to the last array dimension, with the last dimension corresponding to `-1`. Default: `-1`.

For multi-dimensional input [`ndarrays`][@stdlib/ndarray/ctor], the function performs batched computation, such that the function interchanges each pair of vectors in `x` and `y` according to the specified dimension index.

```javascript
var Float32Array = require( '@stdlib/array-float32' );
var array = require( '@stdlib/ndarray-array' );

var opts = {
'shape': [ 2, 3 ]
};
var x = array( new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 3.0 ] ), opts );
var y = array( new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 2.0 ] ), opts );

var v1 = x.get( 0, 0 );
// returns 4.0

var v2 = y.get( 0, 0 );
// returns 2.0

sswap( x, y );

v1 = x.get( 0, 0 );
// returns 2.0

v2 = y.get( 0, 0 );
// returns 4.0
```

</section>

Expand All @@ -102,6 +130,9 @@ The function has the following parameters:

## Notes

- Both input [`ndarrays`][@stdlib/ndarray/ctor] must have the same shape.
- Negative indices are resolved relative to the last [`ndarray`][@stdlib/ndarray/ctor] dimension, with the last dimension corresponding to `-1`.
- For multi-dimensional [`ndarrays`][@stdlib/ndarray/ctor], batched computation effectively means swapping all of `x` with all of `y`; however, the choice of `dim` will significantly affect performance. For best performance, specify a `dim` which best aligns with the [memory layout][@stdlib/ndarray/orders] of provided [`ndarrays`][@stdlib/ndarray/ctor].
- `sswap()` provides a higher-level interface to the [BLAS][blas] level 1 function [`sswap`][@stdlib/blas/base/sswap].

</section>
Expand All @@ -115,28 +146,28 @@ The function has the following parameters:
<!-- eslint no-undef: "error" -->

```javascript
var discreteUniform = require( '@stdlib/random-base-discrete-uniform' );
var Float32Array = require( '@stdlib/array-float32' );
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var ndarray2array = require( '@stdlib/ndarray-to-array' );
var array = require( '@stdlib/ndarray-array' );
var sswap = require( '@stdlib/blas-sswap' );

var x = array( new Float32Array( 10 ) );
var y = array( new Float32Array( 10 ) );
var opts = {
'dtype': 'float32'
};

var rand1 = discreteUniform.factory( 0, 100 );
var rand2 = discreteUniform.factory( 0, 10 );
var x = array( discreteUniform( 10, 0, 100, opts ), {
'shape': [ 5, 2 ]
});
console.log( ndarray2array( x ) );

var i;
for ( i = 0; i < x.length; i++ ) {
x.set( i, rand1() );
y.set( i, rand2() );
}
console.log( x.data );
console.log( y.data );
var y = array( discreteUniform( 10, 0, 10, opts ), {
'shape': x.shape
});
console.log( ndarray2array( y ) );

sswap( x, y );
console.log( x.data );
console.log( y.data );
console.log( ndarray2array( x ) );
console.log( ndarray2array( y ) );
```

</section>
Expand All @@ -147,14 +178,6 @@ console.log( y.data );

<section class="related">

* * *

## See Also

- <span class="package-name">[`@stdlib/blas-base/sswap`][@stdlib/blas/base/sswap]</span><span class="delimiter">: </span><span class="description">interchange two single-precision floating-point vectors.</span>
- <span class="package-name">[`@stdlib/blas-dswap`][@stdlib/blas/dswap]</span><span class="delimiter">: </span><span class="description">interchange two double-precision floating-point vectors.</span>
- <span class="package-name">[`@stdlib/blas-gswap`][@stdlib/blas/gswap]</span><span class="delimiter">: </span><span class="description">interchange two vectors.</span>

</section>

<!-- /.related -->
Expand Down Expand Up @@ -233,18 +256,12 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].

[blas]: http://www.netlib.org/blas

[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor

<!-- <related-links> -->
[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray-orders

[@stdlib/blas/base/sswap]: https://github.com/stdlib-js/blas-base-sswap

[@stdlib/blas/dswap]: https://github.com/stdlib-js/blas-dswap

[@stdlib/blas/gswap]: https://github.com/stdlib-js/blas-gswap

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

</section>

<!-- /.links -->
35 changes: 18 additions & 17 deletions 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-harness' );
var randu = require( '@stdlib/random-base-randu' );
var isnan = require( '@stdlib/math-base-assert-is-nan' );
var pow = require( '@stdlib/math-base-special-pow' );
var Float32Array = require( '@stdlib/array-float32' );
var uniform = require( '@stdlib/random-array-uniform' );
var array = require( '@stdlib/ndarray-array' );
var pkg = require( './../package.json' ).name;
var sswap = require( './../lib/main.js' );


// VARIABLES //

var opts = {
'dtype': 'float32'
};


// FUNCTIONS //

/**
Expand All @@ -40,34 +46,29 @@ var sswap = require( './../lib/main.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float32Array( len );
y = new Float32Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( randu()*10.0 ) - 20.0;
y[ i ] = ( randu()*10.0 ) - 20.0;
}
x = array( x );
y = array( y );

var x = array( uniform( len, -100.0, 100.0, opts ) );
var y = array( uniform( len, -100.0, 100.0, opts ) );
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var d;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
d = sswap( x, y );
if ( isnan( d[ i%x.length ] ) ) {
if ( isnan( d.data[ i%len ] ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( d ) ) {
if ( isnan( d.data[ i%len ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
Expand Down
Loading

0 comments on commit 9771160

Please sign in to comment.