|
| 1 | +/** |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2025 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 elements in input ndarrays and assign results to elements in an output ndarray. |
| 23 | +* |
| 24 | +* @module @stdlib/ndarray/base/binary |
| 25 | +* |
| 26 | +* @example |
| 27 | +* var Float64Array = require( '@stdlib/array/float64' ); |
| 28 | +* var ndarray = require( '@stdlib/ndarray/ctor' ); |
| 29 | +* var getData = require( '@stdlib/ndarray/data-buffer' ); |
| 30 | +* var binary = require( '@stdlib/ndarray/base/binary' ); |
| 31 | +* |
| 32 | +* function add( a, b ) { |
| 33 | +* return a + b; |
| 34 | +* } |
| 35 | +* |
| 36 | +* // Create data buffers: |
| 37 | +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 38 | +* var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 39 | +* var zbuf = new Float64Array( 6 ); |
| 40 | +* |
| 41 | +* // Define the shape of the input and output arrays: |
| 42 | +* var shape = [ 3, 1, 2 ]; |
| 43 | +* |
| 44 | +* // Define the array strides: |
| 45 | +* var sx = [ 2, 2, 1 ]; |
| 46 | +* var sy = [ 2, 2, 1 ]; |
| 47 | +* var sz = [ 2, 2, 1 ]; |
| 48 | +* |
| 49 | +* // Define the index offsets: |
| 50 | +* var ox = 0; |
| 51 | +* var oy = 0; |
| 52 | +* var oz = 0; |
| 53 | +* |
| 54 | +* // Create the input and output ndarrays: |
| 55 | +* var x = new ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' ); |
| 56 | +* var y = new ndarray( 'float64', ybuf, shape, sy, oy, 'row-major' ); |
| 57 | +* var z = new ndarray( 'float64', zbuf, shape, sz, oz, 'row-major' ); |
| 58 | +* |
| 59 | +* // Apply the binary function: |
| 60 | +* binary( [ x, y, z ], add ); |
| 61 | +* |
| 62 | +* console.log( getData( z ) ); |
| 63 | +* // => <Float64Array>[ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ] |
| 64 | +*/ |
| 65 | + |
| 66 | +// MODULES // |
| 67 | + |
| 68 | +var main = require( './main.js' ); |
| 69 | + |
| 70 | + |
| 71 | +// EXPORTS // |
| 72 | + |
| 73 | +module.exports = main; |
0 commit comments