Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 33 additions & 0 deletions lib/node_modules/@stdlib/blas/base/ccopy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,31 @@ The function accepts the following arguments:
void c_ccopy( const CBLAS_INT N, const void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY );
```

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

Copies values from `X` into `Y` using alternative indexing semantics.

```c
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f }; // interleaved real and imaginary components
float y[] = { 0.0f, 0.0f, 0.0f, 0.0f };

c_ccopy_ndarray( 2, (void *)x, 1, 0, (void *)y, 1, 0 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[in] void*` input array.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **Y**: `[out] void*` output array.
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.

```c
void c_ccopy_ndarray( const CBLAS_INT N, const void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, void *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
```

</section>

<!-- /.usage -->
Expand Down Expand Up @@ -301,6 +326,14 @@ int main( void ) {
for ( int i = 0; i < N; i++ ) {
printf( "y[ %i ] = %f + %fj\n", i, y[ i*2 ], y[ (i*2)+1 ] );
}

// Copy elements using alternative indexing semantics:
c_ccopy_ndarray( N, (void *)x, -strideX, N-1, (void *)y, strideY, N-1 );

// Print the result:
for ( int i = 0; i < N; i++ ) {
printf( "y[ %i ] = %f + %fj\n", i, y[ i*2 ], y[ (i*2)+1 ] );
}
}
```

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 ) {
double elapsed;
float x[ len*2 ];
float y[ len*2 ];
Expand Down Expand Up @@ -122,6 +122,41 @@ 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;
float x[ len*2 ];
float y[ len*2 ];
double t;
int i;

for ( i = 0; i < len; i++ ) {
x[ i ] = ( rand_float()*10000.0f ) - 5000.0f;
x[ i+1 ] = ( rand_float()*10000.0f ) - 5000.0f;
y[ i ] = 0.0f;
y[ i+1 ] = 0.0f;
}
t = tic();
for ( i = 0; i < iterations; i++ ) {
c_ccopy_ndarray( len, (void *)x, 1, 0, (void *)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 @@ -144,7 +179,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 lib/node_modules/@stdlib/blas/base/ccopy/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 < N; i++ ) {
printf( "y[ %i ] = %f + %fj\n", i, y[ i*2 ], y[ (i*2)+1 ] );
}

// Copy elements using alternative indexing semantics:
c_ccopy_ndarray( N, (void *)x, -strideX, N-1, (void *)y, strideY, N-1 );

// Print the result:
for ( int i = 0; i < N; i++ ) {
printf( "y[ %i ] = %f + %fj\n", i, y[ i*2 ], y[ (i*2)+1 ] );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ extern "C" {
*/
void API_SUFFIX(c_ccopy)( const CBLAS_INT N, const void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY );

/**
* Copies values from one complex single-precision floating-point vector to another complex single-precision floating-point vector using alternative indexing semantics.
*/
void API_SUFFIX(c_ccopy_ndarray)( const CBLAS_INT N, const void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, void *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );

#ifdef __cplusplus
}
#endif
Expand Down
45 changes: 5 additions & 40 deletions lib/node_modules/@stdlib/blas/base/ccopy/lib/ccopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

// MODULES //

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


// MAIN //
Expand Down Expand Up @@ -55,45 +56,9 @@ var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );
* // returns 2.0
*/
function ccopy( N, x, strideX, y, strideY ) {
var viewX;
var viewY;
var sx;
var sy;
var ix;
var iy;
var i;

if ( N <= 0 ) {
return y;
}
viewX = reinterpret( x, 0 );
viewY = reinterpret( y, 0 );
if ( strideX === 1 && strideY === 1 ) {
for ( i = 0; i < N*2; i += 2 ) {
viewY[ i ] = viewX[ i ];
viewY[ i+1 ] = viewX[ i+1 ];
}
return y;
}
if ( strideX < 0 ) {
ix = 2 * (1-N) * strideX;
} else {
ix = 0;
}
if ( strideY < 0 ) {
iy = 2 * (1-N) * strideY;
} else {
iy = 0;
}
sx = strideX * 2;
sy = strideY * 2;
for ( i = 0; i < N; i++ ) {
viewY[ iy ] = viewX[ ix ];
viewY[ iy+1 ] = viewX[ ix+1 ];
ix += sx;
iy += sy;
}
return y;
var ox = stride2offset( N, strideX );
var oy = stride2offset( N, strideY );
return ndarray( N, x, strideX, ox, y, strideY, oy );
}


Expand Down
14 changes: 3 additions & 11 deletions lib/node_modules/@stdlib/blas/base/ccopy/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-complex64' );
var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' );
var addon = require( './../src/addon.node' );


Expand Down Expand Up @@ -59,16 +58,9 @@ var addon = require( './../src/addon.node' );
* // returns 2.0
*/
function ccopy( N, x, strideX, offsetX, y, strideY, offsetY ) {
var viewX;
var viewY;

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

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

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

Expand Down
Loading
Loading