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 17, 2024
1 parent 05fb4ab commit 587770d
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 78 deletions.
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<section class="release" id="unreleased">

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

<section class="packages">

Expand Down Expand Up @@ -76,6 +76,28 @@

<!-- /.package -->

<section class="package" id="blas-base-dcopy-unreleased">

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

<details>

<section class="features">

##### Features

- [`40502bb`](https://github.com/stdlib-js/stdlib/commit/40502bb62ccef0eecf1132430422a35ae9e5dd3a) - add C `ndarray` implementation for `blas/base/dcopy` [(#2906)](https://github.com/stdlib-js/stdlib/pull/2906)

</section>

<!-- /.features -->

</details>

</section>

<!-- /.package -->

<section class="package" id="blas-base-dspr-unreleased">

#### [@stdlib/blas/base/dspr](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/dspr)
Expand Down Expand Up @@ -382,6 +404,7 @@ A total of 6 people contributed to this release. Thank you to the following cont

<details>

- [`40502bb`](https://github.com/stdlib-js/stdlib/commit/40502bb62ccef0eecf1132430422a35ae9e5dd3a) - **feat:** add C `ndarray` implementation for `blas/base/dcopy` [(#2906)](https://github.com/stdlib-js/stdlib/pull/2906) _(by Aman Bhansali, Athan Reines)_
- [`7e11338`](https://github.com/stdlib-js/stdlib/commit/7e11338ae6642c1389e51557262710bd6ebe44aa) - **feat:** add `blas/ext/base/zfill` [(#2907)](https://github.com/stdlib-js/stdlib/pull/2907) _(by Muhammad Haris, Athan Reines)_
- [`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)_
- [`6c769ad`](https://github.com/stdlib-js/stdlib/commit/6c769ad65cf528389012efc400b29b6e57a4f352) - **fix:** update error message _(by Athan Reines)_
Expand Down
33 changes: 33 additions & 0 deletions base/dcopy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,31 @@ The function accepts the following arguments:
void c_dcopy( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY );
```

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

Copies values from `x` into `y` using alternative indexing semantics.

```c
double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0 };

c_dcopy_ndarray( 3, x, 1, 2, y, 1, 2 );
```
The function accepts the following arguments:
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] double*` input array.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **Y**: `[out] double*` output array.
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
```c
void c_dcopy_ndarray( const CBLAS_INT N, const 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 @@ -248,6 +273,14 @@ int main( void ) {
for ( int i = 0; i < 8; i++ ) {
printf( "y[ %i ] = %lf\n", i, y[ i ] );
}

// Copy elements:
c_dcopy_ndarray( N, x, strideX, 0, y, strideY, 6 );

// Print the result:
for ( int i = 0; i < 8; i++ ) {
printf( "y[ %i ] = %lf\n", i, y[ i ] );
}
}
```
Expand Down
44 changes: 42 additions & 2 deletions base/dcopy/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_dcopy_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
8 changes: 8 additions & 0 deletions base/dcopy/examples/c/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ int main( void ) {
for ( int i = 0; i < 8; i++ ) {
printf( "y[ %i ] = %lf\n", i, y[ i ] );
}

// Copy elements:
c_dcopy_ndarray( N, x, strideX, 0, y, strideY, 6 );

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

/**
* Copies values from `X` into `Y` using alternative indexing semantics.
*/
void API_SUFFIX(c_dcopy_ndarray)( const CBLAS_INT N, const 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 base/dcopy/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( './dcopy.native.js' );
var addon = require( './../src/addon.node' );


// MAIN //
Expand All @@ -49,16 +47,7 @@ var addon = require( './dcopy.native.js' );
* // y => <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0 ]
*/
function dcopy( 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 587770d

Please sign in to comment.