time-to-botec

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

ndarray.js (1954B)


      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' ).ndarray;
     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 {NonNegativeInteger} offsetX - starting `x` index
     36 * @param {Collection} y - destination array/collection
     37 * @param {integer} strideY - `y` stride length
     38 * @param {NonNegativeInteger} offsetY - starting `y` index
     39 * @param {Callback} clbk - callback
     40 * @param {*} [thisArg] - callback execution context
     41 * @returns {Collection} `y`
     42 *
     43 * @example
     44 * function accessor( v ) {
     45 *     return v * 2.0;
     46 * }
     47 *
     48 * var x = [ 1.0, -2.0, 3.0, -4.0, 5.0 ];
     49 * var y = [ 0.0, 0.0, 0.0, 0.0, 0.0 ];
     50 *
     51 * absBy( x.length, x, 1, 0, y, 1, 0, accessor );
     52 *
     53 * console.log( y );
     54 * // => [ 2.0, 4.0, 6.0, 8.0, 10.0 ]
     55 */
     56 function absBy( N, x, strideX, offsetX, y, strideY, offsetY, clbk, thisArg ) {
     57 	return mapBy( N, x, strideX, offsetX, y, strideY, offsetY, abs, clbk, thisArg ); // eslint-disable-line max-len
     58 }
     59 
     60 
     61 // EXPORTS //
     62 
     63 module.exports = absBy;