time-to-botec

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

main.js (1755B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2021 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 // MODULES //
     22 
     23 var mapBy = require( '@stdlib/strided/base/map-by' );
     24 var abs = require( './../../../../base/special/abs' );
     25 
     26 
     27 // MAIN //
     28 
     29 /**
     30 * Computes the absolute value of each element retrieved from a strided input array `x` via a callback function and assigns each result to an element in a strided output array `y`.
     31 *
     32 * @param {NonNegativeInteger} N - number of indexed elements
     33 * @param {Collection} x - input array/collection
     34 * @param {integer} strideX - `x` stride length
     35 * @param {Collection} y - destination array/collection
     36 * @param {integer} strideY - `y` stride length
     37 * @param {Callback} clbk - callback
     38 * @param {*} [thisArg] - callback execution context
     39 * @returns {Collection} `y`
     40 *
     41 * @example
     42 * function accessor( v ) {
     43 *     return v * 2.0;
     44 * }
     45 *
     46 * var x = [ 1.0, -2.0, 3.0, -4.0, 5.0 ];
     47 * var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ];
     48 *
     49 * absBy( x.length, x, 1, y, 1, accessor );
     50 *
     51 * console.log( y );
     52 * // => [ 2.0, 4.0, 6.0, 8.0, 10.0 ]
     53 */
     54 function absBy( N, x, strideX, y, strideY, clbk, thisArg ) {
     55 	return mapBy( N, x, strideX, y, strideY, abs, clbk, thisArg );
     56 }
     57 
     58 
     59 // EXPORTS //
     60 
     61 module.exports = absBy;