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 16, 2024
1 parent fe68057 commit d70e12d
Show file tree
Hide file tree
Showing 15 changed files with 318 additions and 125 deletions.
1 change: 0 additions & 1 deletion .github/.keepalive

This file was deleted.

16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@
<section class="release" id="unreleased">

## Unreleased (2024-09-01)
## Unreleased (2024-09-16)

<section class="features">

### Features

- [`edcea47`](https://github.com/stdlib-js/stdlib/commit/edcea4761bc3065f9c5218c162b38ebec4a6c423) - add C `ndarray` implementation for `blas/base/sswap` and `blas/base/dswap` [(#2905)](https://github.com/stdlib-js/stdlib/pull/2905)

</section>

<!-- /.features -->

<section class="commits">

### Commits

<details>

- [`edcea47`](https://github.com/stdlib-js/stdlib/commit/edcea4761bc3065f9c5218c162b38ebec4a6c423) - **feat:** add C `ndarray` implementation for `blas/base/sswap` and `blas/base/dswap` [(#2905)](https://github.com/stdlib-js/stdlib/pull/2905) _(by Aman Bhansali, Athan Reines)_
- [`2777e4b`](https://github.com/stdlib-js/stdlib/commit/2777e4be161869d09406e3b17947d24c64b47af2) - **bench:** resolve lint errors in benchmarks _(by Athan Reines)_

</details>
Expand All @@ -24,8 +35,9 @@

### Contributors

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

- Aman Bhansali
- Athan Reines

</section>
Expand Down
6 changes: 6 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# Contributors listed in alphabetical order.

Aayush Khanna <[email protected]>
Adarsh Palaskar <[email protected]>
Aditya Sapra <[email protected]>
AgPriyanshu18 <[email protected]>
Expand All @@ -26,11 +27,13 @@ EuniceSim142 <[email protected]>
Frank Kovacs <[email protected]>
Golden Kumar <[email protected]>
Gunj Joshi <[email protected]>
HarshaNP <[email protected]>
Harshita Kalani <[email protected]>
Hridyanshu <[email protected]>
Jaimin Godhani <[email protected]>
James Gelok <[email protected]>
Jaysukh Makvana <[email protected]>
Jenish Thapa <[email protected]>
Jithin KS <[email protected]>
Joel Mathew Koshy <[email protected]>
Joey Reed <[email protected]>
Expand Down Expand Up @@ -86,8 +89,10 @@ Stephannie Jiménez Gacha <[email protected]>
Suraj kumar <[email protected]>
Tirtadwipa Manunggal <[email protected]>
Tudor Pagu <[email protected]>
Tufailahmed Bargir <[email protected]>
Utkarsh <http://[email protected]>
Utkarsh Raj <[email protected]>
Vaibhav Patel <[email protected]>
Varad Gupta <[email protected]>
Xiaochuan Ye <[email protected]>
Yernar Yergaziyev <[email protected]>
Expand All @@ -96,3 +101,4 @@ nishant-s7 <[email protected]>
orimiles5 <[email protected]>
rainn <[email protected]>
rei2hu <[email protected]>
yaswanth <[email protected]>
65 changes: 39 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,49 @@ console.log( y );
Interchanges two double-precision floating-point vectors.

```c
double x[] = { 1.0, 2.0, 3.0, 4.0 };
double y[] = { 0.0, 0.0, 0.0, 0.0 };
double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
double y[] = { 6.0, 7.0, 8.0, 9.0, 10.0 };

c_dswap( 4, x, 1, y, 1 );
c_dswap( 5, x, 1, y, 1 );
```
The function accepts the following arguments:
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[inout] double*` first input array.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
- **Y**: `[inout] double*` first input array.
- **Y**: `[inout] double*` second input array.
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
```c
void c_dswap( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY );
```

#### c_dswap_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY )

Interchanges two double-precision floating-point vectors using alternative indexing semantics.

```c
double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
double y[] = { 6.0, 7.0, 8.0, 9.0, 10.0 };

c_dswap_ndarray( 3, x, 1, 2, y, 1, 2 );
```
The function accepts the following arguments:
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[inout] double*` first input array.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **Y**: `[inout] double*` second input array.
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
```c
void c_dswap_ndarray( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
```

</section>

<!-- /.usage -->
Expand Down Expand Up @@ -273,7 +298,7 @@ int main( void ) {
double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

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

// Specify stride lengths:
Expand All @@ -288,6 +313,15 @@ int main( void ) {
printf( "x[ %i ] = %lf\n", i, x[ i ] );
printf( "y[ %i ] = %lf\n", i, y[ i ] );
}

// Interchange elements:
c_dswap_ndarray( N, x, strideX, 0, y, strideY, 6 );

// Print the result:
for ( int i = 0; i < 8; i++ ) {
printf( "x[ %i ] = %lf\n", i, x[ i ] );
printf( "y[ %i ] = %lf\n", i, y[ i ] );
}
}
```
Expand All @@ -303,15 +337,6 @@ int main( void ) {
<section class="related">
* * *
## See Also
- <span class="package-name">[`@stdlib/blas-base/dcopy`][@stdlib/blas/base/dcopy]</span><span class="delimiter">: </span><span class="description">copy values from x into y.</span>
- <span class="package-name">[`@stdlib/blas-base/gswap`][@stdlib/blas/base/gswap]</span><span class="delimiter">: </span><span class="description">interchange two vectors.</span>
- <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>
</section>
<!-- /.related -->
Expand Down Expand Up @@ -396,18 +421,6 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
<!-- <related-links> -->
[@stdlib/blas/base/dcopy]: https://github.com/stdlib-js/blas-base-dcopy
[@stdlib/blas/base/gswap]: https://github.com/stdlib-js/blas-base-gswap
[@stdlib/blas/base/sswap]: https://github.com/stdlib-js/blas-base-sswap
[@stdlib/blas/dswap]: https://github.com/stdlib-js/blas-dswap
<!-- </related-links> -->
</section>
<!-- /.links -->
44 changes: 42 additions & 2 deletions benchmark/c/benchmark.length.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static double rand_double( void ) {
* @param len array length
* @return elapsed time in seconds
*/
static double benchmark( int iterations, int len ) {
static double benchmark1( int iterations, int len ) {
double elapsed;
double x[ len ];
double y[ len ];
Expand All @@ -120,6 +120,39 @@ static double benchmark( int iterations, int len ) {
return elapsed;
}

/**
* Runs a benchmark.
*
* @param iterations number of iterations
* @param len array length
* @return elapsed time in seconds
*/
static double benchmark2( int iterations, int len ) {
double elapsed;
double x[ len ];
double y[ len ];
double t;
int i;

for ( i = 0; i < len; i++ ) {
x[ i ] = ( rand_double()*20000.0 ) - 10000.0;
y[ i ] = 0.0;
}
t = tic();
for ( i = 0; i < iterations; i++ ) {
c_dswap_ndarray( len, x, 1, 0, y, 1, 0 );
if ( y[ 0 ] != y[ 0 ] ) {
printf( "should not return NaN\n" );
break;
}
}
elapsed = tic() - t;
if ( y[ 0 ] != y[ 0 ] ) {
printf( "should not return NaN\n" );
}
return elapsed;
}

/**
* Main execution sequence.
*/
Expand All @@ -142,7 +175,14 @@ int main( void ) {
for ( j = 0; j < REPEATS; j++ ) {
count += 1;
printf( "# c::%s:len=%d\n", NAME, len );
elapsed = benchmark( iter, len );
elapsed = benchmark1( iter, len );
print_results( iter, elapsed );
printf( "ok %d benchmark finished\n", count );
}
for ( j = 0; j < REPEATS; j++ ) {
count += 1;
printf( "# c::%s:ndarray:len=%d\n", NAME, len );
elapsed = benchmark2( iter, len );
print_results( iter, elapsed );
printf( "ok %d benchmark finished\n", count );
}
Expand Down
9 changes: 9 additions & 0 deletions examples/c/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,13 @@ int main( void ) {
printf( "x[ %i ] = %lf\n", i, x[ i ] );
printf( "y[ %i ] = %lf\n", i, y[ i ] );
}

// Interchange elements:
c_dswap_ndarray( N, x, strideX, 0, y, strideY, 6 );

// Print the result:
for ( int i = 0; i < 8; i++ ) {
printf( "x[ %i ] = %lf\n", i, x[ i ] );
printf( "y[ %i ] = %lf\n", i, y[ i ] );
}
}
5 changes: 5 additions & 0 deletions include/stdlib/blas/base/dswap.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ extern "C" {
*/
void API_SUFFIX(c_dswap)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY );

/**
* Interchanges two double-precision floating-point vectors using alternative indexing semantics.
*/
void API_SUFFIX(c_dswap_ndarray)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );

#ifdef __cplusplus
}
#endif
Expand Down
15 changes: 2 additions & 13 deletions lib/ndarray.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

// MODULES //

var minViewBufferIndex = require( '@stdlib/strided-base-min-view-buffer-index' );
var offsetView = require( '@stdlib/strided-base-offset-view' );
var addon = require( './dswap.native.js' );
var addon = require( './../src/addon.node' );


// MAIN //
Expand Down Expand Up @@ -50,16 +48,7 @@ var addon = require( './dswap.native.js' );
* // y => <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0 ]
*/
function dswap( N, x, strideX, offsetX, y, strideY, offsetY ) {
var viewX;
var viewY;

offsetX = minViewBufferIndex( N, strideX, offsetX );
offsetY = minViewBufferIndex( N, strideY, offsetY );

viewX = offsetView( x, offsetX );
viewY = offsetView( y, offsetY );

addon( N, viewX, strideX, viewY, strideY );
addon.ndarray( N, x, strideX, offsetX, y, strideY, offsetY );
return y;
}

Expand Down
Loading

0 comments on commit d70e12d

Please sign in to comment.