time-to-botec

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

rsqrt.js (2556B)


      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 dispatch = require( '@stdlib/strided/dispatch' );
     24 var unary = require( '@stdlib/strided/base/unary' );
     25 var types = require( './types.json' );
     26 var meta = require( './meta.json' );
     27 var data = require( './data.js' );
     28 
     29 
     30 // VARIABLES //
     31 
     32 var fcn = dispatch( unary, types, data, meta.nargs, meta.nin, meta.nout );
     33 
     34 
     35 // MAIN //
     36 
     37 /**
     38 * Computes the reciprocal square root for each element in a strided array `x` and assigns the results to elements in a strided array `y`.
     39 *
     40 * @param {integer} N - number of indexed elements
     41 * @param {Collection} x - input array
     42 * @param {integer} strideX - `x` stride length
     43 * @param {Collection} y - destination array
     44 * @param {integer} strideY - `y` stride length
     45 * @throws {TypeError} first argument must be an integer
     46 * @throws {TypeError} second argument must be an array-like object
     47 * @throws {TypeError} third argument must be an integer
     48 * @throws {TypeError} fourth argument must be an array-like object
     49 * @throws {TypeError} fifth argument must be an integer
     50 * @throws {Error} insufficient arguments
     51 * @throws {Error} too many arguments
     52 * @throws {RangeError} second argument has insufficient elements based on the associated stride and the number of indexed elements
     53 * @throws {RangeError} fourth argument has insufficient elements based on the associated stride and the number of indexed elements
     54 * @throws {TypeError} unable to resolve a strided array function supporting the provided array argument data types
     55 * @returns {Collection} `y`
     56 *
     57 * @example
     58 * var Float64Array = require( '@stdlib/array/float64' );
     59 *
     60 * var x = new Float64Array( [ 0.0, 4.0, 9.0, 12.0, 24.0 ] );
     61 * var y = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
     62 *
     63 * rsqrt( x.length, x, 1, y, 1 );
     64 * // y => <Float64Array>[ Infinity, 0.5, ~0.333, ~0.289, ~0.204 ]
     65 */
     66 function rsqrt( N, x, strideX, y, strideY ) {
     67 	return fcn( N, x, strideX, y, strideY );
     68 }
     69 
     70 
     71 // EXPORTS //
     72 
     73 module.exports = rsqrt;