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
35 changes: 35 additions & 0 deletions lib/node_modules/@stdlib/blas/base/drotm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,33 @@ The function accepts the following arguments:
void c_drotm( const CBLAS_INT N, double *X, const CBLAS_INT strideX, double *Y, const CBLAS_INT strideY, const double *param );
```

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

Applies a modified Givens plane rotation using alternative indexing semantics.

```c
double x[] = { 1.0, 2.0, 3.0, 4.0, 5.0 };
double y[] = { 6.0, 7.0, 8.0, 9.0, 10.0 };
const double param[5] = { 0.0, 0.0, 2.0, -3.0, 0.0 };

c_drotm_ndarray( 5, x, -1, 4, y, -1, 4, param );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **X**: `[inout] double*` first input array.
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **Y**: `[inout] double*` second input array.
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
- **param**: `[in] double` parameters for the modified Givens transformation.

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

</section>

<!-- /.usage -->
Expand Down Expand Up @@ -267,6 +294,14 @@ int main( void ) {
for ( int i = 0; i < 5; i++ ) {
printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] );
}

// Apply plane rotation:
c_drotm_ndarray( N, x, -strideX, N-1, y, -strideY, N-1, param );

// Print the result:
for ( int i = 0; i < 5; i++ ) {
printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] );
}
}
```

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[ len ];
double y[ len ];
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;
double x[ len ];
double y[ len ];
double t;
int i;

const double param[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
for ( i = 0; i < len; i++ ) {
x[ i ] = ( rand_double()*200.0 ) - 100.0;
y[ i ] = ( rand_double()*200.0 ) - 100.0;
}

t = tic();
for ( i = 0; i < iterations; i++ ) {
c_drotm_ndarray( len, x, 1, 0, y, 1, 0, param );
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/drotm/examples/c/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ int main( void ) {
for ( int i = 0; i < 5; i++ ) {
printf( "x[ %i ] = %lf, y[ %i ] = %lf\n", i, x[ i ], i, y[ i ] );
}

// Apply plane rotation:
c_drotm_ndarray( N, x, -strideX, N-1, y, -strideY, N-1, param );

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

/**
* Applies a modified Givens plane rotation using alternative indexing semantics.
*/
void API_SUFFIX(c_drotm_ndarray)( const CBLAS_INT N, double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, const double *param );

#ifdef __cplusplus
}
#endif
Expand Down
12 changes: 2 additions & 10 deletions lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,8 @@ var ndarray = require( './ndarray.js' );
* // y => <Float64Array>[ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ]
*/
function drotm( N, x, strideX, y, strideY, param ) {
var dflag;
var ix;
var iy;

dflag = param[ 0 ];
if ( N <= 0 || dflag === -2.0 ) {
return y;
}
ix = stride2offset( N, strideX );
iy = stride2offset( N, strideY );
var ix = stride2offset( N, strideX );
var iy = stride2offset( N, strideY );
return ndarray( N, x, strideX, ix, y, strideY, iy, param );
}

Expand Down
4 changes: 2 additions & 2 deletions lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
* @param {PositiveInteger} N - number of indexed elements
* @param {Float64Array} x - first input array
* @param {integer} strideX - `x` stride length
* @param {NonNegativeInteger} offsetX - starting `x` index
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @param {Float64Array} y - second input array
* @param {integer} strideY - `y` stride length
* @param {NonNegativeInteger} offsetY - starting `y` index
* @param {NonNegativeInteger} offsetY - starting index for `y`
* @param {Float64Array} param - parameters for the modified Givens transformation
* @returns {Float64Array} `y`
*
Expand Down
19 changes: 4 additions & 15 deletions lib/node_modules/@stdlib/blas/base/drotm/lib/ndarray.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

// MODULES //

var minViewBufferIndex = require( '@stdlib/strided/base/min-view-buffer-index' );
var offsetView = require( '@stdlib/strided/base/offset-view' );
var addon = require( './drotm.native.js' );
var addon = require( './../src/addon.node' );


// MAIN //
Expand All @@ -33,10 +31,10 @@ var addon = require( './drotm.native.js' );
* @param {PositiveInteger} N - number of indexed elements
* @param {Float64Array} x - first input array
* @param {integer} strideX - `x` stride length
* @param {NonNegativeInteger} offsetX - starting `x` index
* @param {NonNegativeInteger} offsetX - starting index for `x`
* @param {Float64Array} y - second input array
* @param {integer} strideY - `y` stride length
* @param {NonNegativeInteger} offsetY - starting `y` index
* @param {NonNegativeInteger} offsetY - starting index for `y`
* @param {Float64Array} param - parameters for the modified Givens transformation
* @returns {Float64Array} `y`
*
Expand All @@ -52,16 +50,7 @@ var addon = require( './drotm.native.js' );
* // y => <Float64Array>[ 1.7, -0.9, 0.5, 0.7, -1.6, 0.2, 2.4 ]
*/
function drotm( N, x, strideX, offsetX, y, strideY, offsetY, param ) {
var viewX;
var viewY;

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

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

addon( N, viewX, strideX, viewY, strideY, param );
addon.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, param );
return y;
}

Expand Down
Loading
Loading