Skip to content

Commit

Permalink
refactor: reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Jul 6, 2024
1 parent bb1d8a0 commit 3656b32
Showing 1 changed file with 16 additions and 73 deletions.
89 changes: 16 additions & 73 deletions lib/node_modules/@stdlib/strided/base/quinary/lib/main.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 Down Expand Up @@ -49,82 +55,19 @@
* // => <Float64Array>[ 5.0, 10.0, 15.0, 20.0, 25.0 ]
*/
function quinary( arrays, shape, strides, fcn ) {
var sx;
var sy;
var sz;
var sw;
var su;
var sv;
var ix;
var iy;
var iz;
var iw;
var iu;
var iv;
var x;
var y;
var z;
var w;
var u;
var v;
var offsets;
var N;
var i;

N = shape[ 0 ];
if ( N <= 0 ) {
return;
}
sx = strides[ 0 ];
sy = strides[ 1 ];
sz = strides[ 2 ];
sw = strides[ 3 ];
su = strides[ 4 ];
sv = strides[ 5 ];
if ( sx < 0 ) {
ix = (1-N) * sx;
} else {
ix = 0;
}
if ( sy < 0 ) {
iy = (1-N) * sy;
} else {
iy = 0;
}
if ( sz < 0 ) {
iz = (1-N) * sz;
} else {
iz = 0;
}
if ( sw < 0 ) {
iw = (1-N) * sw;
} else {
iw = 0;
}
if ( su < 0 ) {
iu = (1-N) * su;
} else {
iu = 0;
}
if ( sv < 0 ) {
iv = (1-N) * sv;
} else {
iv = 0;
}
x = arrays[ 0 ];
y = arrays[ 1 ];
z = arrays[ 2 ];
w = arrays[ 3 ];
u = arrays[ 4 ];
v = arrays[ 5 ];
for ( i = 0; i < N; i++ ) {
v[ iv ] = fcn( x[ ix ], y[ iy ], z[ iz ], w[ iw ], u[ iu ] );
ix += sx;
iy += sy;
iz += sz;
iw += sw;
iu += su;
iv += sv;
}
offsets = [
stride2offset( N, strides[ 0 ] ),
stride2offset( N, strides[ 1 ] ),
stride2offset( N, strides[ 2 ] ),
stride2offset( N, strides[ 3 ] ),
stride2offset( N, strides[ 4 ] ),
stride2offset( N, strides[ 5 ] )
];
return ndarray( arrays, shape, strides, offsets, fcn );
}


Expand Down

0 comments on commit 3656b32

Please sign in to comment.