Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
134 changes: 134 additions & 0 deletions lib/node_modules/@stdlib/blas/base/zcopy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,140 @@ console.log( y.get( y.length-1 ).toString() );

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/blas/base/zcopy.h"
```

#### c_zcopy( N, \*X, strideX, \*Y, strideY )

Copies values from `X` into `Y`.

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

c_zcopy( 2, (void *)x, 1, (void *)Y, 1 );
```

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`.
- **Y**: `[out] void*` output array.
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.

```c
void c_zcopy( const CBLAS_INT N, const void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY );
```

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

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

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

c_zcopy_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_zcopy_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 -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
#include "stdlib/blas/base/zcopy.h"
#include <stdio.h>

int main( void ) {
// Create strided arrays:
const double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 };
double y[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

// Specify the number of elements:
const int N = 4;

// Specify stride lengths:
const int strideX = 1;
const int strideY = -1;

// Copy elements:
c_zcopy( N, (void *)x, strideX, (void *)y, strideY );

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

// Copy elements using alternative indexing semantics:
c_zcopy_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 ] = %lf + %lfj\n", i, y[ i*2 ], y[ (i*2)+1 ] );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">
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 elapsed;
double *x;
double *y;
Expand Down Expand Up @@ -127,6 +127,46 @@ 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;
double *y;
double t;
int i;

x = (double *) malloc( len*2 * sizeof( double ) );
y = (double *) malloc( len*2 * sizeof( double ) );
for ( i = 0; i < len; i++ ) {
x[ i ] = ( rand_double()*10000.0 ) - 5000.0;
x[ i+1 ] = ( rand_double()*10000.0 ) - 5000.0;
y[ i ] = 0.0;
y[ i+1 ] = 0.0;
}
t = tic();
for ( i = 0; i < iterations; i++ ) {
c_zcopy_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" );
}
free( x );
free( y );

return elapsed;
}

/**
* Main execution sequence.
*/
Expand All @@ -149,7 +189,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/zcopy/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 ] = %lf + %lfj\n", i, y[ i*2 ], y[ (i*2)+1 ] );
}

// Copy elements using alternative indexing semantics:
c_zcopy_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 ] = %lf + %lfj\n", i, y[ i*2 ], y[ (i*2)+1 ] );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef ZCOPY_H
#define ZCOPY_H

#include "stdlib/blas/base/shared.h"

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
Expand All @@ -32,7 +34,12 @@ extern "C" {
/**
* Copies values from one complex double-precision floating-point vector to another complex double-precision floating-point vector.
*/
void c_zcopy( const int N, const void *X, const int strideX, void *Y, const int strideY );
void API_SUFFIX(c_zcopy)( const CBLAS_INT N, const void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY );

/**
* Copies values from one complex double-precision floating-point vector to another complex double-precision floating-point vector using alternative indexing semantics.
*/
void API_SUFFIX(c_zcopy_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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef ZCOPY_CBLAS_H
#define ZCOPY_CBLAS_H

#include "stdlib/blas/base/shared.h"

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
Expand All @@ -32,7 +34,7 @@ extern "C" {
/**
* Copies values from one complex double-precision floating-point vector to another complex double-precision floating-point vector.
*/
void cblas_zcopy( const int N, const void *X, const int strideX, void *Y, const int strideY );
void API_SUFFIX(cblas_zcopy)( const CBLAS_INT N, const void *X, const CBLAS_INT strideX, void *Y, const CBLAS_INT strideY );

#ifdef __cplusplus
}
Expand Down
14 changes: 3 additions & 11 deletions lib/node_modules/@stdlib/blas/base/zcopy/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 Down Expand Up @@ -59,16 +58,9 @@ var addon = require( './../src/addon.node' );
* // returns 2.0
*/
function zcopy( 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 viewZX = reinterpret( x, 0 );
var viewZY = reinterpret( y, 0 );
addon.ndarray( N, viewZX, strideX, offsetX, viewZY, strideY, offsetY );
return y;
}

Expand Down
45 changes: 5 additions & 40 deletions lib/node_modules/@stdlib/blas/base/zcopy/lib/zcopy.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-complex128' );
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-complex128' );
* // returns 2.0
*/
function zcopy( 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
Loading
Loading