ndarray.js (2852B)
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' ).ndarray; 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, meta.nin, meta.nout ); // eslint-disable-line max-len 33 34 35 // MAIN // 36 37 /** 38 * Computes the absolute value for each element in `x` and assigns the results to elements in `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 {NonNegativeInteger} offsetX - starting `x` index 44 * @param {Collection} y - destination array 45 * @param {integer} strideY - `y` stride length 46 * @param {NonNegativeInteger} offsetY - starting `y` index 47 * @throws {TypeError} first argument must be an integer 48 * @throws {TypeError} second argument must be an array-like object 49 * @throws {TypeError} third argument must be an integer 50 * @throws {TypeError} fourth argument must be a nonnegative integer 51 * @throws {TypeError} fifth argument must be an array-like object 52 * @throws {TypeError} sixth argument must be an integer 53 * @throws {TypeError} seventh argument must be a nonnegative integer 54 * @throws {Error} insufficient arguments 55 * @throws {Error} too many arguments 56 * @throws {RangeError} second argument has insufficient elements based on the associated stride and the number of indexed elements 57 * @throws {RangeError} fifth argument has insufficient elements based on the associated stride and the number of indexed elements 58 * @throws {TypeError} unable to resolve a strided array function supporting the provided array argument data types 59 * @returns {Collection} `y` 60 * 61 * @example 62 * var Float64Array = require( '@stdlib/array/float64' ); 63 * 64 * var x = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); 65 * var y = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); 66 * 67 * abs( x.length, x, 1, 0, y, 1, 0 ); 68 * // y => <Float64Array>[ 1.0, 2.0, 3.0, 4.0, 5.0 ] 69 */ 70 function abs( N, x, strideX, offsetX, y, strideY, offsetY ) { 71 return fcn( N, x, strideX, offsetX, y, strideY, offsetY ); 72 } 73 74 75 // EXPORTS // 76 77 module.exports = abs;