|
| 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 | +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; |
| 22 | +var filledarray = require( '@stdlib/array/filled' ); |
| 23 | +var filledarrayBy = require( '@stdlib/array/filled-by' ); |
| 24 | +var add = require( '@stdlib/number/float64/base/add' ); |
| 25 | +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); |
| 26 | +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); |
| 27 | +var binary = require( './../lib' ); |
| 28 | + |
| 29 | +var N = 10; |
| 30 | +var x = { |
| 31 | + 'dtype': 'generic', |
| 32 | + 'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ), |
| 33 | + 'shape': [ 5, 2 ], |
| 34 | + 'strides': [ 2, 1 ], |
| 35 | + 'offset': 0, |
| 36 | + 'order': 'row-major' |
| 37 | +}; |
| 38 | +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); |
| 39 | + |
| 40 | +var y = { |
| 41 | + 'dtype': 'generic', |
| 42 | + 'data': filledarrayBy( N, 'generic', discreteUniform( -100, 100 ) ), |
| 43 | + 'shape': x.shape.slice(), |
| 44 | + 'strides': shape2strides( x.shape, 'column-major' ), |
| 45 | + 'offset': 0, |
| 46 | + 'order': 'column-major' |
| 47 | +}; |
| 48 | +console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) ); |
| 49 | + |
| 50 | +var z = { |
| 51 | + 'dtype': 'generic', |
| 52 | + 'data': filledarray( 0, N, 'generic' ), |
| 53 | + 'shape': x.shape.slice(), |
| 54 | + 'strides': shape2strides( x.shape, 'column-major' ), |
| 55 | + 'offset': 0, |
| 56 | + 'order': 'column-major' |
| 57 | +}; |
| 58 | + |
| 59 | +binary( [ x, y, z ], add ); |
| 60 | +console.log( ndarray2array( z.data, z.shape, z.strides, z.offset, z.order ) ); |
0 commit comments