index.js (2034B)
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 /** 22 * Apply a unary callback to elements in a strided input array and assign results to elements in a strided output array. 23 * 24 * @module @stdlib/strided/base/unary 25 * 26 * @example 27 * var Float64Array = require( '@stdlib/array/float64' ); 28 * var unary = require( '@stdlib/strided/base/unary' ); 29 * 30 * function scale( x ) { 31 * return x * 10.0; 32 * } 33 * 34 * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); 35 * var y = new Float64Array( x.length ); 36 * 37 * var shape = [ x.length ]; 38 * var strides = [ 1, 1 ]; 39 * 40 * unary( [ x, y ], shape, strides, scale ); 41 * 42 * console.log( y ); 43 * // => <Float64Array>[ 10.0, 20.0, 30.0, 40.0, 50.0 ] 44 * 45 * @example 46 * var Float64Array = require( '@stdlib/array/float64' ); 47 * var unary = require( '@stdlib/strided/base/unary' ); 48 * 49 * function scale( x ) { 50 * return x * 10.0; 51 * } 52 * 53 * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); 54 * var y = new Float64Array( x.length ); 55 * 56 * var shape = [ x.length ]; 57 * var strides = [ 1, 1 ]; 58 * var offsets = [ 0, 0 ]; 59 * 60 * unary.ndarray( [ x, y ], shape, strides, offsets, scale ); 61 * 62 * console.log( y ); 63 * // => <Float64Array>[ 10.0, 20.0, 30.0, 40.0, 50.0 ] 64 */ 65 66 // MODULES // 67 68 var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); 69 var unary = require( './main.js' ); 70 var ndarray = require( './ndarray.js' ); 71 72 73 // MAIN // 74 75 setReadOnly( unary, 'ndarray', ndarray ); 76 77 78 // EXPORTS // 79 80 module.exports = unary;