diff --git a/lib/node_modules/@stdlib/strided/base/ternary/lib/main.js b/lib/node_modules/@stdlib/strided/base/ternary/lib/main.js index e23849bcdae1..ce4008f9e641 100644 --- a/lib/node_modules/@stdlib/strided/base/ternary/lib/main.js +++ b/lib/node_modules/@stdlib/strided/base/ternary/lib/main.js @@ -18,6 +18,12 @@ 'use strict'; +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + // MAIN // /** @@ -47,60 +53,17 @@ * // => [ 3.0, 6.0, 9.0, 12.0, 15.0 ] */ function ternary( arrays, shape, strides, fcn ) { - var sx; - var sy; - var sz; - var sw; - var ix; - var iy; - var iz; - var iw; - var x; - var y; - var z; - var w; + 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 ]; - 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; - } - x = arrays[ 0 ]; - y = arrays[ 1 ]; - z = arrays[ 2 ]; - w = arrays[ 3 ]; - for ( i = 0; i < N; i++ ) { - w[ iw ] = fcn( x[ ix ], y[ iy ], z[ iz ] ); - ix += sx; - iy += sy; - iz += sz; - iw += sw; - } + offsets = [ + stride2offset( N, strides[ 0 ] ), + stride2offset( N, strides[ 1 ] ), + stride2offset( N, strides[ 2 ] ), + stride2offset( N, strides[ 3 ] ) + ]; + return ndarray( arrays, shape, strides, offsets, fcn ); }