time-to-botec

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

ramp.native.js (2735B)


      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 // MODULES //
     22 
     23 var isTypedArrayLike = require( '@stdlib/assert/is-typed-array-like' );
     24 var addon = require( './../src/addon.node' );
     25 var js = require( './ramp.js' );
     26 
     27 
     28 // MAIN //
     29 
     30 /**
     31 * Evaluates the ramp function for each element in a strided array `x` and assigns the results to elements in a strided array `y`.
     32 *
     33 * @param {integer} N - number of indexed elements
     34 * @param {Collection} x - input array
     35 * @param {integer} strideX - `x` stride length
     36 * @param {Collection} y - destination array
     37 * @param {integer} strideY - `y` stride length
     38 * @throws {TypeError} first argument must be an integer
     39 * @throws {TypeError} second argument must be an array-like object
     40 * @throws {TypeError} third argument must be an integer
     41 * @throws {TypeError} fourth argument must be an array-like object
     42 * @throws {TypeError} fifth argument must be an integer
     43 * @throws {Error} insufficient arguments
     44 * @throws {Error} too many arguments
     45 * @throws {RangeError} second argument has insufficient elements based on the associated stride and the number of indexed elements
     46 * @throws {RangeError} fourth argument has insufficient elements based on the associated stride and the number of indexed elements
     47 * @throws {TypeError} unable to resolve a strided array function supporting the provided array argument data types
     48 * @returns {Collection} `y`
     49 *
     50 * @example
     51 * var Float64Array = require( '@stdlib/array/float64' );
     52 *
     53 * var x = new Float64Array( [ 1.1, 2.5, -3.5, 4.0, -5.9 ] );
     54 * var y = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
     55 *
     56 * ramp( x.length, x, 1, y, 1 );
     57 * // y => <Float64Array>[ 1.1, 2.5, 0.0, 4.0, 0.0 ]
     58 */
     59 function ramp( N, x, strideX, y, strideY ) {
     60 	// WARNING: we assume that, if we're provided something resembling a typed array, we're provided a typed array; however, this can lead to potential unintended errors as the native add-on cannot work with non-typed array objects (e.g., generic arrays)...
     61 	if ( !isTypedArrayLike( x ) || !isTypedArrayLike( y ) ) {
     62 		return js( N, x, strideX, y, strideY );
     63 	}
     64 	addon( N, x, strideX, y, strideY );
     65 	return y;
     66 }
     67 
     68 
     69 // EXPORTS //
     70 
     71 module.exports = ramp;