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 Nov 18, 2024
1 parent 7ced187 commit 7231764
Show file tree
Hide file tree
Showing 15 changed files with 341 additions and 127 deletions.
1 change: 0 additions & 1 deletion .github/.keepalive

This file was deleted.

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

## Unreleased (2024-11-01)
## Unreleased (2024-11-18)

<section class="features">

### Features

- [`d05d7b3`](https://github.com/stdlib-js/stdlib/commit/d05d7b352455ff537847cd081aafd1fb77c67c3e) - add C `ndarray` implementation for `blas/base/dznrm2` [(#3130)](https://github.com/stdlib-js/stdlib/pull/3130)

</section>

<!-- /.features -->

<section class="issues">

Expand All @@ -24,6 +34,7 @@ This release closes the following issue:

<details>

- [`d05d7b3`](https://github.com/stdlib-js/stdlib/commit/d05d7b352455ff537847cd081aafd1fb77c67c3e) - **feat:** add C `ndarray` implementation for `blas/base/dznrm2` [(#3130)](https://github.com/stdlib-js/stdlib/pull/3130) _(by Aman Bhansali, Athan Reines)_
- [`c0a5dbe`](https://github.com/stdlib-js/stdlib/commit/c0a5dbe868b88f8bcf770e128833d5768c041919) - **test:** achieve complete code coverage in `blas/base/dznrm2` and `blas/base/scnrm2` [(#2977)](https://github.com/stdlib-js/stdlib/pull/2977) _(by Gururaj Gurram)_

</details>
Expand All @@ -36,8 +47,10 @@ This release closes the following issue:

### Contributors

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

- Aman Bhansali
- Athan Reines
- Gururaj Gurram

</section>
Expand Down
3 changes: 3 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Mohammad Kaif <[email protected]>
Momtchil Momtchev <[email protected]>
Muhammad Haris <[email protected]>
Naresh Jagadeesan <[email protected]>
Neeraj Pathak <[email protected]>
NightKnight <[email protected]>
Nithin Katta <[email protected]>
Nourhan Hasan <[email protected]>
Expand All @@ -69,6 +70,7 @@ Prajwal Kulkarni <[email protected]>
Pranav Goswami <[email protected]>
Praneki <[email protected]>
Pratik <[email protected]>
Pratyush Kumar Chouhan <[email protected]>
Priyansh <[email protected]>
Pushpendra Chandravanshi <[email protected]>
RISHAV <[email protected]>
Expand All @@ -79,6 +81,7 @@ Ridam Garg <[email protected]>
Robert Gislason <[email protected]>
Roman Stetsyk <[email protected]>
Rutam <[email protected]>
Ruthwik Chikoti <[email protected]>
Ryan Seal <[email protected]>
Sai Srikar Dumpeti <[email protected]>
SarthakPaandey <[email protected]>
Expand Down
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,28 @@ The function accepts the following arguments:
double c_dznrm2( const CBLAS_INT N, const void *ZX, const CBLAS_INT strideX );
```

#### c_dznrm2_ndarray( N, \*ZX, strideX, offsetX )

Computes the L2-norm of a complex double-precision floating-point vector using alternative indexing semantics.

```c
const double zx[] = { 0.3, 0.1, 0.5, 0.0, 0.0, 0.5, 0.0, 0.2 };

double norm = c_dznrm2_ndarray( 4, (void *)zx, 1, 0 );
// returns 0.8
```
The function accepts the following arguments:
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **ZX**: `[in] void*` input array.
- **strideX**: `[in] CBLAS_INT` index increment for `ZX`.
- **offsetX**: `[in] CBLAS_INT` starting index for `ZX`.
```c
double c_dznrm2_ndarray( const CBLAS_INT N, const void *ZX, const CBLAS_INT strideX, const CBLAS_INT offsetX );
```

</section>

<!-- /.usage -->
Expand Down Expand Up @@ -260,7 +282,13 @@ int main( void ) {
const int strideX = 1;

// Compute the L2-norm:
c_dznrm2( N, (void *)zx, strideX );
double norm = c_dznrm2( N, (void *)zx, strideX );

// Print the result:
printf( "L2-norm: %lf\n", norm );

// Compute the L2-norm using alternative indexing semantics:
norm = c_dznrm2_ndarray( N, (void *)zx, -strideX, N-1 );

// Print the result:
printf( "L2-norm: %lf\n", norm );
Expand Down
45 changes: 43 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 zx[ len*2 ];
double elapsed;
double norm;
Expand All @@ -121,6 +121,40 @@ 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 zx[ len*2 ];
double elapsed;
double norm;
double t;
int i;

for ( i = 0; i < len*2; i += 2 ) {
zx[ i ] = ( rand_double()*10000.0 ) - 5000.0;
zx[ i+1 ] = ( rand_double()*10000.0 ) - 5000.0;
}
norm = 0.0;
t = tic();
for ( i = 0; i < iterations; i++ ) {
norm = c_dznrm2_ndarray( len, (void *)zx, 1, 0 );
if ( norm != norm ) {
printf( "should not return NaN\n" );
break;
}
}
elapsed = tic() - t;
if ( norm != norm ) {
printf( "should not return NaN\n" );
}
return elapsed;
}

/**
* Main execution sequence.
*/
Expand All @@ -143,7 +177,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
6 changes: 6 additions & 0 deletions examples/c/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ int main( void ) {

// Print the result:
printf( "L2-norm: %lf\n", norm );

// Compute the L2-norm using alternative indexing semantics:
norm = c_dznrm2_ndarray( N, (void *)zx, -strideX, N-1 );

// Print the result:
printf( "L2-norm: %lf\n", norm );
}
5 changes: 5 additions & 0 deletions include/stdlib/blas/base/dznrm2.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ extern "C" {
*/
double API_SUFFIX(c_dznrm2)( const CBLAS_INT N, const void *ZX, const CBLAS_INT strideX );

/**
* Computes the L2-norm of a complex double-precision floating-point vector using alternative indexing semantics.
*/
double API_SUFFIX(c_dznrm2_ndarray)( const CBLAS_INT N, const void *ZX, const CBLAS_INT strideX, const CBLAS_INT offsetX );

#ifdef __cplusplus
}
#endif
Expand Down
7 changes: 2 additions & 5 deletions lib/ndarray.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
// MODULES //

var reinterpret = require( '@stdlib/strided-base-reinterpret-complex128' );
var minViewBufferIndex = require( '@stdlib/strided-base-min-view-buffer-index' );
var addon = require( './../src/addon.node' );


Expand All @@ -46,10 +45,8 @@ var addon = require( './../src/addon.node' );
* // returns ~0.8
*/
function dznrm2( N, zx, strideX, offsetX ) {
var viewZX;
offsetX = minViewBufferIndex( N, strideX, offsetX );
viewZX = reinterpret( zx, offsetX );
return addon( N, viewZX, strideX );
var viewZX = reinterpret( zx, 0 );
return addon.ndarray( N, viewZX, strideX, offsetX );
}


Expand Down
Loading

0 comments on commit 7231764

Please sign in to comment.