Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion lib/node_modules/@stdlib/blas/base/dznrm2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,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 @@ -227,7 +249,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
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
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 );
}
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
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