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