From 4e3169acc5168cdbc3895dbb77a3e1d20790843e Mon Sep 17 00:00:00 2001 From: aman-095 Date: Sat, 6 Jul 2024 10:07:45 +0530 Subject: [PATCH 1/2] refactor: update implementations for BLAS Level 1 routines --- .../@stdlib/blas/base/saxpy/lib/saxpy.js | 50 +-------- .../@stdlib/blas/base/scopy/lib/scopy.js | 51 ++------- .../@stdlib/blas/base/sdot/lib/sdot.js | 28 ++--- .../@stdlib/blas/base/sdsdot/lib/sdsdot.js | 51 ++------- .../@stdlib/blas/base/srot/lib/srot.js | 39 ++----- .../@stdlib/blas/base/srotm/lib/srotm.js | 101 +----------------- .../@stdlib/blas/base/sswap/lib/sswap.js | 62 ++--------- 7 files changed, 43 insertions(+), 339 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/saxpy/lib/saxpy.js b/lib/node_modules/@stdlib/blas/base/saxpy/lib/saxpy.js index ab9d1555dac..5fca6f5a3f8 100644 --- a/lib/node_modules/@stdlib/blas/base/saxpy/lib/saxpy.js +++ b/lib/node_modules/@stdlib/blas/base/saxpy/lib/saxpy.js @@ -20,12 +20,8 @@ // MODULES // -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); - - -// VARIABLES // - -var M = 4; +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -54,48 +50,12 @@ var M = 4; function saxpy( N, alpha, x, strideX, y, strideY ) { var ix; var iy; - var m; - var i; if ( N <= 0 || alpha === 0.0 ) { return y; } - // Use unrolled loops if both strides are equal to `1`... - if ( strideX === 1 && strideY === 1 ) { - m = N % M; - - // If we have a remainder, run a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - y[ i ] += float64ToFloat32( alpha * x[ i ] ); - } - } - if ( N < M ) { - return y; - } - for ( i = m; i < N; i += M ) { - y[ i ] += float64ToFloat32( alpha * x[ i ] ); - y[ i+1 ] += float64ToFloat32( alpha * x[ i+1 ] ); - y[ i+2 ] += float64ToFloat32( alpha * x[ i+2 ] ); - y[ i+3 ] += float64ToFloat32( alpha * x[ i+3 ] ); - } - return y; - } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = (1-N) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - y[ iy ] += float64ToFloat32( alpha * x[ ix ] ); - ix += strideX; - iy += strideY; - } - return y; + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, alpha, x, strideX, ix, y, strideY, iy ); } diff --git a/lib/node_modules/@stdlib/blas/base/scopy/lib/scopy.js b/lib/node_modules/@stdlib/blas/base/scopy/lib/scopy.js index d66bbac3f5b..941436fa914 100644 --- a/lib/node_modules/@stdlib/blas/base/scopy/lib/scopy.js +++ b/lib/node_modules/@stdlib/blas/base/scopy/lib/scopy.js @@ -18,9 +18,10 @@ 'use strict'; -// VARIABLES // +// MODULES // -var M = 8; +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -47,52 +48,12 @@ var M = 8; function scopy( N, x, strideX, y, strideY ) { var ix; var iy; - var m; - var i; if ( N <= 0 ) { return y; } - // Use unrolled loops if both strides are equal to `1`... - if ( strideX === 1 && strideY === 1 ) { - m = N % M; - - // If we have a remainder, run a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - y[ i ] = x[ i ]; - } - } - if ( N < M ) { - return y; - } - for ( i = m; i < N; i += M ) { - y[ i ] = x[ i ]; - y[ i+1 ] = x[ i+1 ]; - y[ i+2 ] = x[ i+2 ]; - y[ i+3 ] = x[ i+3 ]; - y[ i+4 ] = x[ i+4 ]; - y[ i+5 ] = x[ i+5 ]; - y[ i+6 ] = x[ i+6 ]; - y[ i+7 ] = x[ i+7 ]; - } - return y; - } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = (1-N) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - y[ iy ] = x[ ix ]; - ix += strideX; - iy += strideY; - } - return y; + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, x, strideX, ix, y, strideY, iy ); } diff --git a/lib/node_modules/@stdlib/blas/base/sdot/lib/sdot.js b/lib/node_modules/@stdlib/blas/base/sdot/lib/sdot.js index f3ce3f5e02e..c2195bcff32 100644 --- a/lib/node_modules/@stdlib/blas/base/sdot/lib/sdot.js +++ b/lib/node_modules/@stdlib/blas/base/sdot/lib/sdot.js @@ -20,7 +20,8 @@ // MODULES // -var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require('./ndarray.js'); // MAIN // @@ -45,31 +46,14 @@ var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); * // returns -5.0 */ function sdot( N, x, strideX, y, strideY ) { - var dot; var ix; var iy; - var i; - - dot = 0.0; if ( N <= 0 ) { - return dot; - } - if ( strideX < 0 ) { - ix = ( 1-N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1-N ) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - dot = float64ToFloat32( dot + float64ToFloat32( x[ ix ] * y[ iy ] ) ); - ix += strideX; - iy += strideY; + return 0.0; } - return dot; + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, x, strideX, ix, y, strideY, iy ); } diff --git a/lib/node_modules/@stdlib/blas/base/sdsdot/lib/sdsdot.js b/lib/node_modules/@stdlib/blas/base/sdsdot/lib/sdsdot.js index 0cf70457bf9..97ad4722dcd 100644 --- a/lib/node_modules/@stdlib/blas/base/sdsdot/lib/sdsdot.js +++ b/lib/node_modules/@stdlib/blas/base/sdsdot/lib/sdsdot.js @@ -21,11 +21,8 @@ // MODULES // var float64ToFloat32 = require( '@stdlib/number/float64/base/to-float32' ); - - -// VARIABLES // - -var M = 5; +var stride2offset = require('@stdlib/strided/base/stride2offset'); +var ndarray = require('./ndarray.js'); // MAIN // @@ -51,50 +48,14 @@ var M = 5; * // returns -5.0 */ function sdsdot( N, scalar, x, strideX, y, strideY ) { - var dot; var ix; var iy; - var m; - var i; - - dot = scalar; if ( N <= 0 ) { - return float64ToFloat32( dot ); - } - // Use unrolled loops if both strides are equal to `1`... - if ( strideX === 1 && strideY === 1 ) { - m = N % M; - - // If we have a remainder, run a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - dot += x[ i ] * y[ i ]; - } - } - if ( N < M ) { - return float64ToFloat32( dot ); - } - for ( i = m; i < N; i += M ) { - dot += ( x[i]*y[i] ) + ( x[i+1]*y[i+1] ) + ( x[i+2]*y[i+2] ) + ( x[i+3]*y[i+3] ) + ( x[i+4]*y[i+4] ); // eslint-disable-line max-len - } - return float64ToFloat32( dot ); - } - if ( strideX < 0 ) { - ix = ( 1-N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1-N ) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - dot += x[ ix ] * y[ iy ]; - ix += strideX; - iy += strideY; + return float64ToFloat32( scalar ); } - return float64ToFloat32( dot ); + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, scalar, x, strideX, ix, y, strideY, iy ); } diff --git a/lib/node_modules/@stdlib/blas/base/srot/lib/srot.js b/lib/node_modules/@stdlib/blas/base/srot/lib/srot.js index 4e4809ec40b..a338c0dda77 100644 --- a/lib/node_modules/@stdlib/blas/base/srot/lib/srot.js +++ b/lib/node_modules/@stdlib/blas/base/srot/lib/srot.js @@ -18,6 +18,12 @@ 'use strict'; +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require('./ndarray.js'); + + // MAIN // /** @@ -43,42 +49,15 @@ * // y => [ 5.0, 8.0, ~5.4, 10.0, ~5.8, 12.0 ] */ function srot( N, x, strideX, y, strideY, c, s ) { - var tmp; var ix; var iy; - var i; if ( N <= 0 ) { return y; } - // If both strides are equal to `1`... - if ( strideX === 1 && strideY === 1 ) { - for ( i = 0; i < N; i++ ) { - tmp = ( c * x[ i ] ) + ( s * y[ i ] ); - y[ i ] = ( c * y[ i ] ) - ( s * x[ i ] ); - x[ i ] = tmp; - } - return y; - } - // If both strides are not equal to `1`... - if ( strideX < 0 ) { - ix = ( 1 - N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1 - N ) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - tmp = ( c * x[ ix ] ) + ( s * y[ iy ] ); - y[ iy ] = ( c * y[ iy ] ) - ( s * x[ ix ] ); - x[ ix ] = tmp; - ix += strideX; - iy += strideY; - } - return y; + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, x, strideX, ix, y, strideY, iy, c, s ); } diff --git a/lib/node_modules/@stdlib/blas/base/srotm/lib/srotm.js b/lib/node_modules/@stdlib/blas/base/srotm/lib/srotm.js index 048dd30392e..aa95b01cd67 100644 --- a/lib/node_modules/@stdlib/blas/base/srotm/lib/srotm.js +++ b/lib/node_modules/@stdlib/blas/base/srotm/lib/srotm.js @@ -20,7 +20,8 @@ // MODULES // -var f32 = require( '@stdlib/number/float64/base/to-float32' ); +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require('./ndarray.js'); // MAIN // @@ -49,108 +50,16 @@ var f32 = require( '@stdlib/number/float64/base/to-float32' ); */ function srotm( N, x, strideX, y, strideY, param ) { var sflag; - var sh11; - var sh12; - var sh21; - var sh22; var ix; var iy; - var i; - var w; - var z; sflag = param[ 0 ]; if ( N <= 0 || sflag === -2.0 ) { return y; } - if ( strideX === strideY && strideX > 0 ) { - ix = 0; - if ( sflag < 0.0 ) { - sh11 = param[ 1 ]; - sh12 = param[ 3 ]; - sh21 = param[ 2 ]; - sh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = x[ ix ]; - z = y[ ix ]; - x[ ix ] = f32( f32( w * sh11 ) + f32( z * sh12 ) ); - y[ ix ] = f32( f32( w * sh21 ) + f32( z * sh22 ) ); - ix += strideX; - } - return y; - } - if ( sflag === 0.0 ) { - sh12 = param[ 3 ]; - sh21 = param[ 2 ]; - for ( i = 0; i < N; i++ ) { - w = x[ ix ]; - z = y[ ix ]; - x[ ix ] = f32( w + f32( z * sh12 ) ); - y[ ix ] = f32( f32( w * sh21 ) + z ); - ix += strideX; - } - return y; - } - sh11 = param[ 1 ]; - sh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = x[ ix ]; - z = y[ ix ]; - x[ ix ] = f32( f32( w * sh11 ) + z ); - y[ ix ] = f32( -w + f32( z * sh22 ) ); - ix += strideX; - } - return y; - } - if ( strideX < 0 ) { - ix = ( 1 - N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1 - N ) * strideY; - } else { - iy = 0; - } - if ( sflag < 0.0 ) { - sh11 = param[ 1 ]; - sh12 = param[ 3 ]; - sh21 = param[ 2 ]; - sh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = x[ ix ]; - z = y[ iy ]; - x[ ix ] = f32( f32( w * sh11 ) + f32( z * sh12 ) ); - y[ iy ] = f32( f32( w * sh21 ) + f32( z * sh22 ) ); - ix += strideX; - iy += strideY; - } - return y; - } - if ( sflag === 0.0 ) { - sh12 = param[ 3 ]; - sh21 = param[ 2 ]; - for ( i = 0; i < N; i++ ) { - w = x[ ix ]; - z = y[ iy ]; - x[ ix ] = f32( w + f32( z * sh12 ) ); - y[ iy ] = f32( f32( w * sh21 ) + z ); - ix += strideX; - iy += strideY; - } - return y; - } - sh11 = param[ 1 ]; - sh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = x[ ix ]; - z = y[ iy ]; - x[ ix ] = f32( f32( w * sh11 ) + z ); - y[ iy ] = f32( -w + f32( z * sh22 ) ); - ix += strideX; - iy += strideY; - } - return y; + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, x, strideX, ix, y, strideY, iy, param ); } diff --git a/lib/node_modules/@stdlib/blas/base/sswap/lib/sswap.js b/lib/node_modules/@stdlib/blas/base/sswap/lib/sswap.js index b3e0e2f51f7..f5ff4e32226 100644 --- a/lib/node_modules/@stdlib/blas/base/sswap/lib/sswap.js +++ b/lib/node_modules/@stdlib/blas/base/sswap/lib/sswap.js @@ -18,9 +18,10 @@ 'use strict'; -// VARIABLES // +// MODULES // -var M = 3; +var stride2offset = require('@stdlib/strided/base/stride2offset'); +var ndarray = require('./ndarray.js'); // MAIN // @@ -46,65 +47,14 @@ var M = 3; * // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] */ function sswap( N, x, strideX, y, strideY ) { - var tmp; var ix; var iy; - var m; - var i; - var j; if ( N <= 0 ) { return y; } - // Use unrolled loops if both strides are equal to `1`... - if ( strideX === 1 && strideY === 1 ) { - m = N % M; - - // If we have a remainder, run a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - tmp = x[ i ]; - x[ i ] = y[ i ]; - y[ i ] = tmp; - } - } - if ( N < M ) { - return y; - } - for ( i = m; i < N; i += M ) { - tmp = x[ i ]; - x[ i ] = y[ i ]; - y[ i ] = tmp; - - j = i + 1; - tmp = x[ j ]; - x[ j ] = y[ j ]; - y[ j ] = tmp; - - j += 1; - tmp = x[ j ]; - x[ j ] = y[ j ]; - y[ j ] = tmp; - } - return y; - } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = (1-N) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - tmp = x[ ix ]; - x[ ix ] = y[ iy ]; - y[ iy ] = tmp; - ix += strideX; - iy += strideY; - } - return y; + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, x, strideX, ix, y, strideY, iy ); } From cc274dc661044e403438e5f773d28dedb447ea47 Mon Sep 17 00:00:00 2001 From: aman-095 Date: Sat, 6 Jul 2024 11:08:12 +0530 Subject: [PATCH 2/2] refactor: update implementations for Level 1double-precision --- .../@stdlib/blas/base/daxpy/lib/daxpy.js | 47 +------- .../@stdlib/blas/base/ddot/lib/ddot.js | 49 ++------- .../@stdlib/blas/base/drot/lib/drot.js | 39 ++----- .../@stdlib/blas/base/drotm/lib/drotm.js | 104 ++---------------- .../@stdlib/blas/base/dsdot/lib/dsdot.js | 49 ++------- .../@stdlib/blas/base/dswap/lib/dswap.js | 62 +---------- 6 files changed, 44 insertions(+), 306 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/base/daxpy/lib/daxpy.js b/lib/node_modules/@stdlib/blas/base/daxpy/lib/daxpy.js index 326fff759b4..ec77f854553 100644 --- a/lib/node_modules/@stdlib/blas/base/daxpy/lib/daxpy.js +++ b/lib/node_modules/@stdlib/blas/base/daxpy/lib/daxpy.js @@ -18,9 +18,10 @@ 'use strict'; -// VARIABLES // +// MODULES // -var M = 4; +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require('./ndarray.js'); // MAIN // @@ -49,48 +50,12 @@ var M = 4; function daxpy( N, alpha, x, strideX, y, strideY ) { var ix; var iy; - var m; - var i; if ( N <= 0 || alpha === 0.0 ) { return y; } - // Use unrolled loops if both strides are equal to `1`... - if ( strideX === 1 && strideY === 1 ) { - m = N % M; - - // If we have a remainder, run a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - y[ i ] += alpha * x[ i ]; - } - } - if ( N < M ) { - return y; - } - for ( i = m; i < N; i += M ) { - y[ i ] += alpha * x[ i ]; - y[ i+1 ] += alpha * x[ i+1 ]; - y[ i+2 ] += alpha * x[ i+2 ]; - y[ i+3 ] += alpha * x[ i+3 ]; - } - return y; - } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = (1-N) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - y[ iy ] += alpha * x[ ix ]; - ix += strideX; - iy += strideY; - } - return y; + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, alpha, x, strideX, ix, y, strideY, iy ); } diff --git a/lib/node_modules/@stdlib/blas/base/ddot/lib/ddot.js b/lib/node_modules/@stdlib/blas/base/ddot/lib/ddot.js index 195d3a187f0..9e1b48d3e73 100644 --- a/lib/node_modules/@stdlib/blas/base/ddot/lib/ddot.js +++ b/lib/node_modules/@stdlib/blas/base/ddot/lib/ddot.js @@ -18,9 +18,10 @@ 'use strict'; -// VARIABLES // +// MODULES // -var M = 5; +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -45,50 +46,14 @@ var M = 5; * // returns -5.0 */ function ddot( N, x, strideX, y, strideY ) { - var dot; var ix; var iy; - var m; - var i; - - dot = 0.0; if ( N <= 0 ) { - return dot; - } - // Use unrolled loops if both strides are equal to `1`... - if ( strideX === 1 && strideY === 1 ) { - m = N % M; - - // If we have a remainder, run a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - dot += x[ i ] * y[ i ]; - } - } - if ( N < M ) { - return dot; - } - for ( i = m; i < N; i += M ) { - dot += ( x[ i ] * y[ i ] ) + ( x[ i+1 ] * y[ i+1 ] ) + ( x[ i+2 ] * y[ i+2 ] ) + ( x[ i+3 ] * y[ i+3 ] ) + ( x[ i+4 ] * y[ i+4 ] ); // eslint-disable-line max-len - } - return dot; - } - if ( strideX < 0 ) { - ix = ( 1-N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1-N ) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - dot += ( x[ ix ] * y[ iy ] ); - ix += strideX; - iy += strideY; + return 0.0; } - return dot; + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, x, strideX, ix, y, strideY, iy ); } diff --git a/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js b/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js index dff0ec2c6ec..1c2094fbefd 100644 --- a/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js +++ b/lib/node_modules/@stdlib/blas/base/drot/lib/drot.js @@ -18,6 +18,12 @@ 'use strict'; +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + // MAIN // /** @@ -43,42 +49,15 @@ * // y => [ ~4.2, 4.4, 4.6, 4.8, 5.0 ] */ function drot( N, x, strideX, y, strideY, c, s ) { - var tmp; var ix; var iy; - var i; if ( N <= 0 ) { return y; } - // If both strides are equal to `1`... - if ( strideX === 1 && strideY === 1 ) { - for ( i = 0; i < N; i++ ) { - tmp = ( c * x[ i ] ) + ( s * y[ i ] ); - y[ i ] = ( c * y[ i ] ) - ( s * x[ i ] ); - x[ i ] = tmp; - } - return y; - } - // If both strides are not equal to `1`... - if ( strideX < 0 ) { - ix = ( 1 - N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1 - N ) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - tmp = ( c * x[ ix ] ) + ( s * y[ iy ] ); - y[ iy ] = ( c * y[ iy ] ) - ( s * x[ ix ] ); - x[ ix ] = tmp; - ix += strideX; - iy += strideY; - } - return y; + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, x, strideX, ix, y, strideY, iy, c, s ); } diff --git a/lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.js b/lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.js index fed51987668..a529c9c5fc5 100644 --- a/lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.js +++ b/lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.js @@ -18,6 +18,12 @@ 'use strict'; +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + // MAIN // /** @@ -44,108 +50,16 @@ */ function drotm( N, x, strideX, y, strideY, param ) { var dflag; - var dh11; - var dh12; - var dh21; - var dh22; var ix; var iy; - var i; - var w; - var z; dflag = param[ 0 ]; if ( N <= 0 || dflag === -2.0 ) { return y; } - if ( strideX === strideY && strideX > 0 ) { - ix = 0; - if ( dflag < 0.0 ) { - dh11 = param[ 1 ]; - dh12 = param[ 3 ]; - dh21 = param[ 2 ]; - dh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = x[ ix ]; - z = y[ ix ]; - x[ ix ] = ( w * dh11 ) + ( z * dh12 ); - y[ ix ] = ( w * dh21 ) + ( z * dh22 ); - ix += strideX; - } - return y; - } - if ( dflag === 0.0 ) { - dh12 = param[ 3 ]; - dh21 = param[ 2 ]; - for ( i = 0; i < N; i++ ) { - w = x[ ix ]; - z = y[ ix ]; - x[ ix ] = w + ( z * dh12 ); - y[ ix ] = ( w * dh21 ) + z; - ix += strideX; - } - return y; - } - dh11 = param[ 1 ]; - dh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = x[ ix ]; - z = y[ ix ]; - x[ ix ] = ( w * dh11 ) + z; - y[ ix ] = -w + ( z * dh22 ); - ix += strideX; - } - return y; - } - if ( strideX < 0 ) { - ix = ( 1 - N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1 - N ) * strideY; - } else { - iy = 0; - } - if ( dflag < 0.0 ) { - dh11 = param[ 1 ]; - dh12 = param[ 3 ]; - dh21 = param[ 2 ]; - dh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = x[ ix ]; - z = y[ iy ]; - x[ ix ] = ( w * dh11 ) + ( z * dh12 ); - y[ iy ] = ( w * dh21 ) + ( z * dh22 ); - ix += strideX; - iy += strideY; - } - return y; - } - if ( dflag === 0.0 ) { - dh12 = param[ 3 ]; - dh21 = param[ 2 ]; - for ( i = 0; i < N; i++ ) { - w = x[ ix ]; - z = y[ iy ]; - x[ ix ] = w + ( z * dh12 ); - y[ iy ] = ( w * dh21 ) + z; - ix += strideX; - iy += strideY; - } - return y; - } - dh11 = param[ 1 ]; - dh22 = param[ 4 ]; - for ( i = 0; i < N; i++ ) { - w = x[ ix ]; - z = y[ iy ]; - x[ ix ] = ( w * dh11 ) + z; - y[ iy ] = -w + ( z * dh22 ); - ix += strideX; - iy += strideY; - } - return y; + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, x, strideX, ix, y, strideY, iy, param ); } diff --git a/lib/node_modules/@stdlib/blas/base/dsdot/lib/dsdot.js b/lib/node_modules/@stdlib/blas/base/dsdot/lib/dsdot.js index f3b99a4795d..aa417f514d2 100644 --- a/lib/node_modules/@stdlib/blas/base/dsdot/lib/dsdot.js +++ b/lib/node_modules/@stdlib/blas/base/dsdot/lib/dsdot.js @@ -18,9 +18,10 @@ 'use strict'; -// VARIABLES // +// MODULES // -var M = 5; +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -45,50 +46,14 @@ var M = 5; * // returns -5.0 */ function dsdot( N, x, strideX, y, strideY ) { - var dot; var ix; var iy; - var m; - var i; - - dot = 0.0; if ( N <= 0 ) { - return dot; - } - // Use unrolled loops if both strides are equal to `1`... - if ( strideX === 1 && strideY === 1 ) { - m = N % M; - - // If we have a remainder, run a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - dot += x[ i ] * y[ i ]; - } - } - if ( N < M ) { - return dot; - } - for ( i = m; i < N; i += M ) { - dot += ( x[i]*y[i] ) + ( x[i+1]*y[i+1] ) + ( x[i+2]*y[i+2] ) + ( x[i+3]*y[i+3] ) + ( x[i+4]*y[i+4] ); // eslint-disable-line max-len - } - return dot; - } - if ( strideX < 0 ) { - ix = ( 1-N ) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = ( 1-N ) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - dot += x[ ix ] * y[ iy ]; - ix += strideX; - iy += strideY; + return 0.0; } - return dot; + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, x, strideX, ix, y, strideY, iy ); } diff --git a/lib/node_modules/@stdlib/blas/base/dswap/lib/dswap.js b/lib/node_modules/@stdlib/blas/base/dswap/lib/dswap.js index 5b0183a8dc8..3254fd26640 100644 --- a/lib/node_modules/@stdlib/blas/base/dswap/lib/dswap.js +++ b/lib/node_modules/@stdlib/blas/base/dswap/lib/dswap.js @@ -18,9 +18,10 @@ 'use strict'; -// VARIABLES // +// MODULES // -var M = 3; +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); // MAIN // @@ -46,65 +47,14 @@ var M = 3; * // y => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] */ function dswap( N, x, strideX, y, strideY ) { - var tmp; var ix; var iy; - var m; - var i; - var j; if ( N <= 0 ) { return y; } - // Use unrolled loops if both strides are equal to `1`... - if ( strideX === 1 && strideY === 1 ) { - m = N % M; - - // If we have a remainder, run a clean-up loop... - if ( m > 0 ) { - for ( i = 0; i < m; i++ ) { - tmp = x[ i ]; - x[ i ] = y[ i ]; - y[ i ] = tmp; - } - } - if ( N < M ) { - return y; - } - for ( i = m; i < N; i += M ) { - tmp = x[ i ]; - x[ i ] = y[ i ]; - y[ i ] = tmp; - - j = i + 1; - tmp = x[ j ]; - x[ j ] = y[ j ]; - y[ j ] = tmp; - - j += 1; - tmp = x[ j ]; - x[ j ] = y[ j ]; - y[ j ] = tmp; - } - return y; - } - if ( strideX < 0 ) { - ix = (1-N) * strideX; - } else { - ix = 0; - } - if ( strideY < 0 ) { - iy = (1-N) * strideY; - } else { - iy = 0; - } - for ( i = 0; i < N; i++ ) { - tmp = x[ ix ]; - x[ ix ] = y[ iy ]; - y[ iy ] = tmp; - ix += strideX; - iy += strideY; - } - return y; + ix = stride2offset( N, strideX ); + iy = stride2offset( N, strideY ); + return ndarray( N, x, strideX, ix, y, strideY, iy ); }