Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 28 additions & 0 deletions lib/node_modules/@stdlib/blas/base/scasum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,28 @@ The function accepts the following arguments:
float c_scasum( const CBLAS_INT N, const void *CX, const CBLAS_INT strideX );
```

#### c_scasum_ndarray( N, \*CX, strideX, offsetX )

Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector using alternative indexing semantics.

```c
const float cx[] = { 0.3f, 0.1f, 0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.2f };

float out = c_scasum_ndarray( 4, (void *)cx, 1, 0 );
// returns 1.6f
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **CX**: `[in] void*` input array.
- **strideX**: `[in] CBLAS_INT` index increment for `CX`.
- **offsetX**: `[in] CBLAS_INT` starting index for `CX`.

```c
float c_scasum_ndarray( const CBLAS_INT N, const void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX );
```

</section>

<!-- /.usage -->
Expand Down Expand Up @@ -231,6 +253,12 @@ int main( void ) {

// Print the result:
printf( "out: %f\n", out );

// Compute the sum of the absolute values of real and imaginary components using alternative indexing semantics:
out = c_scasum_ndarray( N, (void *)cx, -strideX, N-1 );

// Print the result:
printf( "out: %f\n", out );
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static float rand_float( void ) {
* @param len array length
* @return elapsed time in seconds
*/
static double benchmark( int iterations, int len ) {
static double benchmark1( int iterations, int len ) {
float cx[ len*2 ];
double elapsed;
float out;
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 ) {
float cx[ len*2 ];
double elapsed;
float out;
double t;
int i;

for ( i = 0; i < len*2; i += 2 ) {
cx[ i ] = ( rand_float()*10000.0f ) - 5000.0f;
cx[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f;
}
out = 0.0f;
t = tic();
for ( i = 0; i < iterations; i++ ) {
out = c_scasum_ndarray( len, (void *)cx, 1, 0 );
if ( out != out ) {
printf( "should not return NaN\n" );
break;
}
}
elapsed = tic() - t;
if ( out != out ) {
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
2 changes: 1 addition & 1 deletion lib/node_modules/@stdlib/blas/base/scasum/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Indexing is relative to the first index. To introduce an offset, use typed
array views.

If `N <= 0` or `strideX <= 0`, the function returns `0.0`.
If `N <= 0`, the function returns `0.0`.

Parameters
----------
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( "out: %f\n", out );

// Compute the sum of the absolute values of real and imaginary components using alternative indexing semantics:
out = c_scasum_ndarray( N, (void *)cx, -strideX, N-1 );

// Print the result:
printf( "out: %f\n", out );
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ extern "C" {
*/
float API_SUFFIX(c_scasum)( const CBLAS_INT N, const void *CX, const CBLAS_INT strideX );

/**
* Computes the sum of the absolute values of the real and imaginary components of a single-precision complex floating-point vector using alternative indexing semantics.
*/
float API_SUFFIX(c_scasum_ndarray)( const CBLAS_INT N, const void *CX, const CBLAS_INT strideX, const CBLAS_INT offsetX );

#ifdef __cplusplus
}
#endif
Expand Down
7 changes: 4 additions & 3 deletions lib/node_modules/@stdlib/blas/base/scasum/lib/ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

var absf = require( '@stdlib/math/base/special/absf' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );
var f32 = require( '@stdlib/number/float64/base/to-float32' );


// MAIN //
Expand All @@ -31,7 +32,7 @@
*
* @param {PositiveInteger} N - number of indexed elements
* @param {Complex64Array} cx - input array
* @param {PositiveInteger} strideX - `cx` stride length
* @param {integer} strideX - `cx` stride length
* @param {NonNegativeInteger} offsetX - starting index for `cx`
* @returns {number} result
*
Expand All @@ -51,14 +52,14 @@
var i;

stemp = 0.0;
if ( N <= 0 || strideX <= 0 ) {
if ( N <= 0 ) {
return stemp;
}
viewX = reinterpret( cx, 0 );
sx = strideX * 2;
ix = offsetX * 2;
for ( i = 0; i < N; i++ ) {
stemp += absf( viewX[ ix ] ) + absf( viewX[ ix+1 ] );
stemp = f32( stemp + f32( absf( viewX[ ix ] ) + absf( viewX[ ix+1 ] ) ) );

Check warning on line 62 in lib/node_modules/@stdlib/blas/base/scasum/lib/ndarray.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 82. Maximum allowed is 80
ix += sx;
}
return stemp;
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-complex64' );
var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' );
var addon = require( './../src/addon.node' );


Expand All @@ -32,7 +31,7 @@ var addon = require( './../src/addon.node' );
*
* @param {PositiveInteger} N - number of indexed elements
* @param {Complex64Array} cx - input array
* @param {PositiveInteger} strideX - `cx` stride length
* @param {integer} strideX - `cx` stride length
* @param {NonNegativeInteger} offsetX - starting index for `cx`
* @returns {number} result
*
Expand All @@ -45,10 +44,8 @@ var addon = require( './../src/addon.node' );
* // returns 14.0
*/
function scasum( N, cx, strideX, offsetX ) {
var viewX;
offsetX = minViewBufferIndex( N, strideX, offsetX );
viewX = reinterpret( cx, offsetX );
return addon( N, viewX, strideX );
var viewX = reinterpret( cx, 0 );
return addon.ndarray( N, viewX, strideX, offsetX );
}


Expand Down
6 changes: 4 additions & 2 deletions lib/node_modules/@stdlib/blas/base/scasum/lib/scasum.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

// MODULES //

var stride2offset = require( '@stdlib/strided/base/stride2offset' );
var ndarray = require( './ndarray.js' );


Expand All @@ -30,7 +31,7 @@ var ndarray = require( './ndarray.js' );
*
* @param {PositiveInteger} N - number of indexed elements
* @param {Complex64Array} cx - input array
* @param {PositiveInteger} strideX - `cx` stride length
* @param {integer} strideX - `cx` stride length
* @returns {number} result
*
* @example
Expand All @@ -42,7 +43,8 @@ var ndarray = require( './ndarray.js' );
* // returns 18.0
*/
function scasum( N, cx, strideX ) {
return ndarray( N, cx, strideX, 0 );
var ox = stride2offset( N, strideX );
return ndarray( N, cx, strideX, ox );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var addon = require( './../src/addon.node' );
*
* @param {PositiveInteger} N - number of indexed elements
* @param {Complex64Array} cx - input array
* @param {PositiveInteger} strideX - `cx` stride length
* @param {integer} strideX - `cx` stride length
* @returns {number} result
*
* @example
Expand Down
Loading
Loading