Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update implementations for blas/base Level 1 routines #2517

Merged
merged 2 commits into from
Jul 6, 2024
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
47 changes: 6 additions & 41 deletions lib/node_modules/@stdlib/blas/base/daxpy/lib/daxpy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

'use strict';

// VARIABLES //
// MODULES //

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


// MAIN //
Expand Down Expand Up @@ -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 );
}


Expand Down
49 changes: 7 additions & 42 deletions lib/node_modules/@stdlib/blas/base/ddot/lib/ddot.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

'use strict';

// VARIABLES //
// MODULES //

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


// MAIN //
Expand All @@ -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 );
}


Expand Down
39 changes: 9 additions & 30 deletions lib/node_modules/@stdlib/blas/base/drot/lib/drot.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

'use strict';

// MODULES //

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


// MAIN //

/**
Expand All @@ -43,42 +49,15 @@
* // y => <Float64Array>[ ~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 );
}


Expand Down
104 changes: 9 additions & 95 deletions lib/node_modules/@stdlib/blas/base/drotm/lib/drotm.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

'use strict';

// MODULES //

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


// MAIN //

/**
Expand All @@ -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 );
}


Expand Down
49 changes: 7 additions & 42 deletions lib/node_modules/@stdlib/blas/base/dsdot/lib/dsdot.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

'use strict';

// VARIABLES //
// MODULES //

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


// MAIN //
Expand All @@ -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 );
}


Expand Down
Loading
Loading