time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

main.js (2932B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2020 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 // MAIN //
     22 
     23 /**
     24 * Applies a quinary callback to strided input array elements and assigns results to elements in a strided output array.
     25 *
     26 * @param {ArrayLikeObject<Collection>} arrays - array-like object containing five input arrays and one output array
     27 * @param {NonNegativeIntegerArray} shape - array-like object containing a single element, the number of indexed elements
     28 * @param {IntegerArray} strides - array-like object containing the stride lengths for the input and output arrays
     29 * @param {Callback} fcn - quinary callback
     30 * @returns {void}
     31 *
     32 * @example
     33 * var Float64Array = require( '@stdlib/array/float64' );
     34 *
     35 * function add( x, y, z, w, u ) {
     36 *     return x + y + z + w + u;
     37 * }
     38 *
     39 * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
     40 * var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
     41 * var z = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
     42 * var w = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
     43 * var u = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
     44 * var v = new Float64Array( x.length );
     45 *
     46 * var shape = [ x.length ];
     47 * var strides = [ 1, 1, 1, 1, 1, 1 ];
     48 *
     49 * quinary( [ x, y, z, w, u, v ], shape, strides, add );
     50 *
     51 * console.log( v );
     52 * // => <Float64Array>[ 5.0, 10.0, 15.0, 20.0, 25.0 ]
     53 */
     54 function quinary( arrays, shape, strides, fcn ) {
     55 	var sx;
     56 	var sy;
     57 	var sz;
     58 	var sw;
     59 	var su;
     60 	var sv;
     61 	var ix;
     62 	var iy;
     63 	var iz;
     64 	var iw;
     65 	var iu;
     66 	var iv;
     67 	var x;
     68 	var y;
     69 	var z;
     70 	var w;
     71 	var u;
     72 	var v;
     73 	var N;
     74 	var i;
     75 
     76 	N = shape[ 0 ];
     77 	if ( N <= 0 ) {
     78 		return;
     79 	}
     80 	sx = strides[ 0 ];
     81 	sy = strides[ 1 ];
     82 	sz = strides[ 2 ];
     83 	sw = strides[ 3 ];
     84 	su = strides[ 4 ];
     85 	sv = strides[ 5 ];
     86 	if ( sx < 0 ) {
     87 		ix = (1-N) * sx;
     88 	} else {
     89 		ix = 0;
     90 	}
     91 	if ( sy < 0 ) {
     92 		iy = (1-N) * sy;
     93 	} else {
     94 		iy = 0;
     95 	}
     96 	if ( sz < 0 ) {
     97 		iz = (1-N) * sz;
     98 	} else {
     99 		iz = 0;
    100 	}
    101 	if ( sw < 0 ) {
    102 		iw = (1-N) * sw;
    103 	} else {
    104 		iw = 0;
    105 	}
    106 	if ( su < 0 ) {
    107 		iu = (1-N) * su;
    108 	} else {
    109 		iu = 0;
    110 	}
    111 	if ( sv < 0 ) {
    112 		iv = (1-N) * sv;
    113 	} else {
    114 		iv = 0;
    115 	}
    116 	x = arrays[ 0 ];
    117 	y = arrays[ 1 ];
    118 	z = arrays[ 2 ];
    119 	w = arrays[ 3 ];
    120 	u = arrays[ 4 ];
    121 	v = arrays[ 5 ];
    122 	for ( i = 0; i < N; i++ ) {
    123 		v[ iv ] = fcn( x[ ix ], y[ iy ], z[ iz ], w[ iw ], u[ iu ] );
    124 		ix += sx;
    125 		iy += sy;
    126 		iz += sz;
    127 		iw += sw;
    128 		iu += su;
    129 		iv += sv;
    130 	}
    131 }
    132 
    133 
    134 // EXPORTS //
    135 
    136 module.exports = quinary;