From 36c333a3cc5c642a3721a3e6f35093dac59a8fe4 Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Sun, 24 Nov 2024 11:09:31 +0000 Subject: [PATCH 1/7] feat: add array/base/broadcasted-ternary5d --- .../base/broadcasted-ternary5d/README.md | 141 ++++++++ .../benchmark/benchmark.js | 136 ++++++++ .../base/broadcasted-ternary5d/docs/repl.txt | 32 ++ .../docs/types/index.d.ts | 114 +++++++ .../broadcasted-ternary5d/docs/types/test.ts | 107 ++++++ .../broadcasted-ternary5d/examples/index.js | 47 +++ .../base/broadcasted-ternary5d/lib/index.js | 57 ++++ .../base/broadcasted-ternary5d/lib/main.js | 225 +++++++++++++ .../base/broadcasted-ternary5d/package.json | 67 ++++ .../base/broadcasted-ternary5d/test/test.js | 305 ++++++++++++++++++ 10 files changed, 1231 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md create mode 100644 lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/examples/index.js create mode 100644 lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js create mode 100644 lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js create mode 100644 lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/package.json create mode 100644 lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md new file mode 100644 index 00000000000..bfd5ef71059 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md @@ -0,0 +1,141 @@ + + +# bternary5d + +> Apply a ternary callback to elements in three [broadcasted][@stdlib/array/base/broadcast-array] nested input arrays and assign results to elements in a five-dimensional nested output array. + +
+ +
+ + + +
+ +## Usage + +```javascript +var bternary5d = require( '@stdlib/array/base/broadcasted-ternary5d' ); +``` + +#### bternary5d( arrays, shapes, fcn ) + +Applies a ternary callback to elements in three [broadcasted][@stdlib/array/base/broadcast-array] nested input arrays and assigns results to elements in a five-dimensional nested output array. + +```javascript +var add = require( '@stdlib/math/base/ops/add3' ); +var zeros5d = require( '@stdlib/array/base/zeros5d' ); + +var x = [ [ [ 1.0, 2.0 ] ] ]; +var y = [ [ [ 3.0 ], [ 4.0 ] ] ]; +var z = [ [ [ [4.0, 5.0] ], [ [4.0, 5.0] ] ] ]; +var out = zeros5d( [ 1, 1, 2, 2 ] ); + +var shapes = [ + [ 1, 1, 2 ], + [ 1, 2, 1 ], + [ 1, 2, 1, 2 ], + [ 1, 1, 2, 2, 2 ] +]; + +bternary5d( [ x, y, z, out ], shapes, add ); +// out => [[[[[8,10],[9,11]],[[8,10],[9,11]]]]] +``` + +The function accepts the following arguments: + +- **arrays**: array-like object containing three input nested arrays and one output nested array. +- **shapes**: array shapes. +- **fcn**: ternary function to apply. + +
+ + + +
+ +## Notes + +- The input and output array shapes must be broadcast [compatible][@stdlib/ndarray/base/broadcast-shapes]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filled5dBy = require( '@stdlib/array/base/filled5d-by' ); +var zeros5d = require( '@stdlib/array/base/zeros5d' ); +var add = require( '@stdlib/math/base/ops/add3' ); +var bternary5d = require( '@stdlib/array/base/broadcasted-ternary5d' ); + +var shapes = [ + [ 1, 1, 1, 1, 3 ], + [ 1, 1, 3, 1, 1 ], + [ 1, 1, 1, 3, 1 ], + [ 1, 1, 3, 3, 3 ] +]; + +var x = filled5dBy( shapes[ 0 ], discreteUniform( -100, 100 ) ); +console.log( x ); + +var y = filled5dBy( shapes[ 1 ], discreteUniform( -100, 100 ) ); +console.log( y ); + +var z = filled5dBy( shapes[ 2 ], discreteUniform( -100, 100 ) ); +console.log( z ); + +var out = zeros5d( shapes[ 3 ] ); +console.log( out ); + +bternary5d( [ x, y, z, out ], shapes, add ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js new file mode 100644 index 00000000000..a2b65eba270 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js @@ -0,0 +1,136 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/base/uniform' ).factory; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var add = require( '@stdlib/math/base/ops/add' ); +var filled5dBy = require( '@stdlib/array/base/filled5d-by' ); +var zeros5d = require( '@stdlib/array/base/zeros5d' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var pkg = require( './../package.json' ).name; +var bternary5d = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveIntegerArray} shape - output array shape +* @returns {Function} benchmark function +*/ +function createBenchmark(shape) { + var arrays; + var shapes; + var x; + var y; + var z; + var w; + + shapes = [ + [shape[0], 1, 1, 1, 1], + [1, 1, 1, 1, shape[1]], + [1, 1, shape[2], 1, 1], + shape + ]; + x = filled5dBy(shapes[0], uniform(-100.0, 100.0)); + y = filled5dBy(shapes[1], uniform(-100.0, 100.0)); + z = filled5dBy(shapes[2], uniform(-100.0, 100.0)); + w = zeros5d(shapes[3]); + + arrays = [x, y, z, w]; + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark(b) { + var i0; + var i1; + var i2; + var i3; + var i4; + var i; + + b.tic(); + for (i = 0; i < b.iterations; i++) { + bternary5d(arrays, shapes, add); + i4 = i % shapes[1][0]; + i3 = i % shapes[1][1]; + i2 = i % shapes[1][2]; + i1 = i % shapes[1][3]; + i0 = i % shapes[1][4]; + if (isnan(arrays[3][i4][i3][i2][i1][i0])) { + b.fail('should not return NaN'); + } + } + b.toc(); + + i4 = i % shapes[1][0]; + i3 = i % shapes[1][1]; + i2 = i % shapes[1][2]; + i1 = i % shapes[1][3]; + i0 = i % shapes[1][4]; + if (isnan(arrays[3][i4][i3][i2][i1][i0])) { + b.fail('should not return NaN'); + } + b.pass('benchmark finished'); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var sh; + var N; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for (i = min; i <= max; i++) { + N = floor(pow(pow(10, i), 1.0 / 5.0)); + sh = [N, N, N, N, N]; + f = createBenchmark(sh); + bench(pkg + '::equidimensional:size=' + numel(sh), f); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt new file mode 100644 index 00000000000..c3699c90d38 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt @@ -0,0 +1,32 @@ + +{{alias}}( arrays, shapes, fcn ) + Applies a ternary callback to elements in three broadcasted input arrays and + assigns results to elements in a five-dimensional nested output array. + + Parameters + ---------- + arrays: ArrayLikeObject + Array-like object containing three input nested arrays and one output + nested array. + + shapes: Array> + Array shapes. + + fcn: Function + Ternary callback. + + Examples + -------- + > function fcn( x, y, z ) { return x + y + z }; + > var x = [ [ [ 1.0 ] ] ]; + > var y = [ [ [ [ 2.0, 2.0 ] , [ 3.0, 3.0 ] ] ] ]; + > var z = [ [ [ [ [ 2.0 ] , [ 3.0 ] ] ] ] ]; + > var out = [ [ [ [ [ 0.0 ,0.0 ], [ 0.0 ,0.0 ] ] ] ] ]; + > var shapes =[[1, 1, 1], [1, 1, 2, 2], [1, 1, 1, 2, 1], [1, 1, 1, 2, 2]]; + > {{alias}}( [ x, y, z, out ], shapes, fcn ); + > out + [ [ [ [ [ 5.0 ,5.0 ], [ 7.0 ,7.0 ] ] ] ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/index.d.ts new file mode 100644 index 00000000000..d728c2d422d --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/index.d.ts @@ -0,0 +1,114 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Array1D, Array2D, Array3D, Array4D, Array5D } from '@stdlib/types/array'; +import { Shape1D, Shape2D, Shape3D, Shape4D, Shape5D } from '@stdlib/types/ndarray'; + +/** +* Ternary callback. +* +* @param v1 - element from first input array +* @param v2 - element from second input array +* @param v3 - element from third input array +* @returns result +*/ +type Ternary = ( v1: T, v2: U, v3: V ) => W; + +/** +* Input array. +*/ +type InputArray = Array1D | Array2D | Array3D | Array4D | Array5D; + +/** +* Input array shape. +*/ +type InputArrayShape = Shape1D | Shape2D | Shape3D | Shape4D | Shape5D; + +/** +* Output array. +*/ +type OutputArray = Array5D; + +/** +* Output array shape. +*/ +type OutputArrayShape = Shape5D; + +/** +* Input and output arrays. +*/ +type InOutArrays = [ + InputArray, + InputArray, + InputArray, + OutputArray +]; + +/** +* Input and output array shapes. +*/ +type InOutShapes = [ + InputArrayShape, + InputArrayShape, + InputArrayShape, + OutputArrayShape +]; + +/** +* Applies a ternary callback to elements in three broadcasted input arrays and assigns results to elements in a four-dimensional nested output array. +* +* ## Notes +* +* - The input array shapes must be broadcast compatible with the output array shape. +* +* @param arrays - array containing three input nested arrays and one output nested array +* @param shapes - array shapes +* @param fcn - ternary callback +* +* @example +* var ones5d = require( '@stdlib/array/base/ones5d' ); +* var zeros5d = require( '@stdlib/array/base/zeros5d' ); +* var add = require( '@stdlib/math/base/ops/add3' ); +* +* var shapes = [ +* [ 1, 2, 1, 1, 1], +* [ 2, 1, 1, 1, 1], +* [ 1, 1, 1, 1, 1], +* [ 2, 2, 1, 1, 1] +* ]; +* +* var x = ones5d( shapes[ 0 ] ); +* var y = ones5d( shapes[ 1 ] ); +* var z = ones5d( shapes[ 2 ] ); +* var out = zeros5d( shapes[ 3 ] ); +* +* bternary5d( [ x, y, z, out ], shapes, add ); +* +* console.log( out ); +* // =>[[[[[3]]],[[3]]],[[[[3]]],[[3]]]],[[[[3]]],[[3]]],[[[[3]]],[[3]]]] +*/ +declare function bternary5d( arrays: InOutArrays, shapes: InOutShapes, fcn: Ternary ): void; + + +// EXPORTS // + +export = bternary5d; diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/test.ts new file mode 100644 index 00000000000..d44c33c8108 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/test.ts @@ -0,0 +1,107 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import bternary5d = require( './index' ); + +/** +* Ternary function. +* +* @param x - input value +* @param y - input value +* @param z - input value +* @returns result +*/ +function fcn( x: number, y: number, z: number ): number { + return x + y + z; +} + + +// TESTS // + +// The function returns undefined... +{ + const x = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]; + const y = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]; + const z = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]; + const out = [ [ [ [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ] ] ]; + + const shapes: [ Array, Array, Array ] = [ [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ] ]; + + bternary5d( [ x, y, z, out ], shapes, fcn ); // $ExpectType void + bternary5d( [ x[0][0][0][0], y, z ], [ [ shapes[0][4] ], shapes[1], shapes[2] ], fcn ); // $ExpectType void +} + +// The compiler throws an error if the function is provided a first argument which is not an array of nested arrays... +{ + const shapes: [ Array, Array, Array ] = [ [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ] ]; + bternary5d( 'abc', shapes, fcn ); // $ExpectError + bternary5d( 3.14, shapes, fcn ); // $ExpectError + bternary5d( true, shapes, fcn ); // $ExpectError + bternary5d( false, shapes, fcn ); // $ExpectError + bternary5d( null, shapes, fcn ); // $ExpectError + bternary5d( [ '1' ], shapes, fcn ); // $ExpectError + bternary5d( {}, shapes, fcn ); // $ExpectError + bternary5d( ( x: number ): number => x, shapes, fcn ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not an array of arrays... +{ + const x = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]; + const y = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]; + const z = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]; + const out = [ [ [ [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ] ] ]; + + bternary5d( [x, y, z, out ], 'abc', fcn ); // $ExpectError + bternary5d( [x, y, z, out ], 3.14, fcn ); // $ExpectError + bternary5d( [x, y, z, out ], true, fcn ); // $ExpectError + bternary5d( [x, y, z, out ], false, fcn ); // $ExpectError + bternary5d( [x, y, z, out ], null, fcn ); // $ExpectError + bternary5d( [ x, y, z, out ], [ '1' ], fcn ); // $ExpectError + bternary5d( [ x, y, z, out ], {}, fcn ); // $ExpectError + bternary5d( [ x, y, z, out ], ( x: number ): number => x, fcn ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a valid callback... +{ + const x = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]; + const y = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]; + const z = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]; + const out = [ [ [ [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ] ] ]; + + const shapes: [ Array, Array, Array ] = [ [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ] ]; + bternary5d( [ x, y, z, out ], shapes, 'abc' ); // $ExpectError + bternary5d( [ x, y, z, out ], shapes, 3.14 ); // $ExpectError + bternary5d( [ x, y, z, out ], shapes, true ); // $ExpectError + bternary5d( [ x, y, z, out ], shapes, false ); // $ExpectError + bternary5d( [ x, y, z, out ], shapes, null ); // $ExpectError + bternary5d( [ x, y, z, out ], shapes, ['1'] ); // $ExpectError + bternary5d( [ x, y, z, out ], shapes, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]; + const y = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]; + const z = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ]; + const out = [ [ [ [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ] ] ]; + + const shapes: [ Array, Array, Array ] = [ [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ] ]; + bternary5d(); // $ExpectError + bternary5d( [ x, y, z, out ] ); // $ExpectError + bternary5d( [ x, y, z, out ], shapes, fcn, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/examples/index.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/examples/index.js new file mode 100644 index 00000000000..3dbe99bd15a --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/examples/index.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; +var filled5dBy = require( '@stdlib/array/base/filled5d-by' ); +var zeros5d = require( '@stdlib/array/base/zeros5d' ); +var add = require( '@stdlib/math/base/ops/add3' ); +var bternary5d = require( './../lib' ); + +var shapes = [ + [ 1, 1, 1, 1, 3 ], + [ 1, 1, 3, 1, 1 ], + [ 1, 1, 1, 3, 1 ], + [ 1, 1, 3, 3, 3 ] +]; + +var x = filled5dBy( shapes[ 0 ], discreteUniform( -100, 100 ) ); +console.log( x ); + +var y = filled5dBy( shapes[ 1 ], discreteUniform( -100, 100 ) ); +console.log( y ); + +var z = filled5dBy( shapes[ 2 ], discreteUniform( -100, 100 ) ); +console.log( z ); + +var out = zeros5d( shapes[ 3 ] ); +console.log( out ); + +bternary5d( [ x, y, z, out ], shapes, add ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js new file mode 100644 index 00000000000..aaddb9cbc7d --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Apply a ternary callback to elements in three broadcasted input arrays and assign results to elements in a five-dimensional nested output array. +* +* @module @stdlib/array/base/broadcasted-ternary5d +* +* @example +* var ones5d = require( '@stdlib/array/base/ones5d' ); +* var zeros5d = require( '@stdlib/array/base/zeros5d' ); +* var add = require( '@stdlib/math/base/ops/add3' ); +* var bternary5d = require( '@stdlib/array/base/broadcasted-ternary5d' ); +* var shapes = [ +* [ 1, 2, 1, 1, 1], +* [ 2, 1, 1, 1, 1], +* [ 1, 1, 1, 1, 1], +* [ 2, 2, 1, 1, 1] +* ]; +* +* var x = ones5d( shapes[ 0 ] ); +* var y = ones5d( shapes[ 1 ] ); +* var z = ones5d( shapes[ 2 ] ); +* var out = zeros5d( shapes[ 3 ] ); +* +* bternary4d( [ x, y, z, out ], shapes, add ); +* +* console.log( out ); +* // =>[[[[[3]]],[[3]]],[[[[3]]],[[3]]]],[[[[3]]],[[3]]],[[[[3]]],[[3]]]] + +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js new file mode 100644 index 00000000000..4cb6b655a39 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js @@ -0,0 +1,225 @@ +/* eslint-disable max-statements */ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var broadcastArray = require( '@stdlib/array/base/broadcast-array' ); + + +// MAIN // + +/** +* Applies a ternary callback to elements in three broadcasted input arrays and assigns results to elements in a five-dimensional nested output array. +* +* @param {ArrayLikeObject>} arrays - array-like object containing three input nested arrays and one output nested array +* @param {ArrayLikeObject} shapes - array shapes +* @param {Callback} fcn - ternary callback +* @returns {void} +* +* @example +* var ones5d = require( '@stdlib/array/base/ones5d' ); +* var zeros5d = require( '@stdlib/array/base/zeros5d' ); +* var add = require( '@stdlib/math/base/ops/add3' ); +* +* var shapes = [ +* [ 1, 2, 1, 1, 1], +* [ 2, 1, 1, 1, 1], +* [ 1, 1, 1, 1, 1], +* [ 2, 2, 1, 1, 1] +* ]; +* +* var x = ones5d( shapes[ 0 ] ); +* var y = ones5d( shapes[ 1 ] ); +* var z = ones5d( shapes[ 2 ] ); +* var out = zeros5d( shapes[ 3 ] ); +* +* bternary5d( [ x, y, z, out ], shapes, add ); +* +* console.log( out ); +* // =>[[[[[3]]],[[[3]]]],[[[[3]]],[[[3]]]]] +*/ +function bternary5d(arrays, shapes, fcn) { + var dx0; + var dx1; + var dx2; + var dx3; + var dx4; + var dy0; + var dy1; + var dy2; + var dy3; + var dy4; + var dz0; + var dz1; + var dz2; + var dz3; + var dz4; + var S0; + var S1; + var S2; + var S3; + var S4; + var i0; + var i1; + var i2; + var i3; + var i4; + var j0; + var j1; + var j2; + var j3; + var j4; + var k0; + var k1; + var k2; + var k3; + var k4; + var m0; + var m1; + var m2; + var m3; + var m4; + var x0; + var x1; + var x2; + var x3; + var y0; + var y1; + var y2; + var y3; + var z0; + var z1; + var z2; + var z3; + var sh; + var st; + var w0; + var w1; + var w2; + var w3; + var o; + var x; + var y; + var z; + var w; + + sh = shapes[3]; + S0 = sh[4]; + S1 = sh[3]; + S2 = sh[2]; + S3 = sh[1]; + S4 = sh[0]; + if (S0 <= 0 || S1 <= 0 || S2 <= 0 || S3 <= 0 || S4 <= 0) { + return; + } + o = broadcastArray(arrays[0], shapes[0], sh); + + x = o.data; + st = o.strides; + dx0 = st[4]; + dx1 = st[3]; + dx2 = st[2]; + dx3 = st[1]; + dx4 = st[0]; + + o = broadcastArray(arrays[1], shapes[1], sh); + y = o.data; + st = o.strides; + dy0 = st[4]; + dy1 = st[3]; + dy2 = st[2]; + dy3 = st[1]; + dy4 = st[0]; + + o = broadcastArray(arrays[2], shapes[2], sh); + z = o.data; + st = o.strides; + dz0 = st[4]; + dz1 = st[3]; + dz2 = st[2]; + dz3 = st[1]; + dz4 = st[0]; + + w = arrays[3]; + j4 = 0; + k4 = 0; + m4 = 0; + + for (i4 = 0; i4 < S4; i4++) { + j3 = 0; + k3 = 0; + m3 = 0; + x3 = x[j4]; + y3 = y[k4]; + z3 = z[m4]; + w3 = w[i4]; + for (i3 = 0; i3 < S3; i3++) { + j2 = 0; + k2 = 0; + m2 = 0; + x2 = x3[j3]; + y2 = y3[k3]; + z2 = z3[m3]; + w2 = w3[i3]; + for (i2 = 0; i2 < S2; i2++) { + j1 = 0; + k1 = 0; + m1 = 0; + x1 = x2[j2]; + y1 = y2[k2]; + z1 = z2[m2]; + w1 = w2[i2]; + for (i1 = 0; i1 < S1; i1++) { + j0 = 0; + k0 = 0; + m0 = 0; + x0 = x1[j1]; + y0 = y1[k1]; + z0 = z1[m1]; + w0 = w1[i1]; + for (i0 = 0; i0 < S0; i0++) { + w0[i0] = fcn(x0[j0], y0[k0], z0[m0]); + j0 += dx0; + k0 += dy0; + m0 += dz0; + } + j1 += dx1; + k1 += dy1; + m1 += dz1; + } + j2 += dx2; + k2 += dy2; + m2 += dz2; + } + j3 += dx3; + k3 += dy3; + m3 += dz3; + } + j4 += dx4; + k4 += dy4; + m4 += dz4; + } +} + + +// EXPORTS // + +module.exports = bternary5d; diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/package.json b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/package.json new file mode 100644 index 00000000000..718ed51583b --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/array/base/broadcasted-ternary5d", + "version": "0.0.0", + "description": "Apply a ternary callback to elements in three broadcasted input arrays and assign results to elements in a five-dimensional nested output array.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "base", + "array", + "multidimensional", + "ndarray", + "matrix", + "3d", + "binary", + "apply", + "foreach", + "map", + "transform", + "broadcast" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js new file mode 100644 index 00000000000..4c0bb9c2751 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js @@ -0,0 +1,305 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var add = require( '@stdlib/math/base/ops/add3' ); +var zeros5d = require( '@stdlib/array/base/zeros5d' ); +var bternary5d = require( './../lib' ); + + +// TESTS // + +tape('main export is a function', function test(t) { + t.ok(true, __filename); + t.strictEqual(typeof bternary5d, 'function', 'main export is a function'); + t.end(); +}); + +tape('the function applies a provided callback to broadcasted input arrays and assigns results to a nested output array', function test(t) { + var expected; + var shapes; + var x; + var y; + var z; + var w; + + shapes = [ + [1, 2, 1, 1, 1], + [2, 1, 1, 2], + [1, 1, 2, 1], + [2, 2, 2, 2, 2] + ]; + + x = [[[[[1.0]]], [[[2.0]]]]]; + y = [[[[3.0, 4.0]]], [[[4.0, 5.0]]]]; + z = [[[[6.0], [7.0]]]]; + w = zeros5d(shapes[3]); + + expected = [[ + [[[10.0, 11.0], [11.0, 12.0]], [[10.0, 11.0], [11.0, 12.0]]], + [[[12.0, 13.0], [13.0, 14.0]], [[12.0, 13.0], [13.0, 14.0]]]], + [[[[10.0, 11.0], [11.0, 12.0]], [[10.0, 11.0], [11.0, 12.0]]], + [[[12.0, 13.0], [13.0, 14.0]], [[12.0, 13.0], [13.0, 14.0]]]]]; + bternary5d([x, y, z, w], shapes, add); + t.deepEqual(w, expected, 'returns expected value'); + + shapes = [ + [1], + [2, 1, 1], + [2, 1, 2, 1, 1], + [2, 2, 2, 1, 1] + ]; + x = [1.0]; + y = [[[2.0]], [[3.0]]]; + z = [[[[[5.0]], [[6.0]]]], [[[[7.0]], [[8.0]]]]]; + w = zeros5d(shapes[3]); + + expected = [ + [[[[8.0]], [[10.0]]], [[[8.0]], [[10.0]]]], + [[[[10.0]], [[12.0]]], [[[10.0]], [[12.0]]]] + ]; + bternary5d([x, y, z, w], shapes, add); + t.deepEqual(w, expected, 'returns expected value'); + + // Same shapes: + shapes = [ + [2, 2, 2, 1, 1], + [2, 2, 2, 1, 1], + [2, 2, 2, 1, 1], + [2, 2, 2, 1, 1] + ]; + x = [ + [[[[1.0]], [[1.0]]], [[[1.0]], [[1.0]]]], + [[[[1.0]], [[1.0]]], [[[1.0]], [[1.0]]]] + ]; + y = x; + z = x; + w = zeros5d(shapes[3]); + + expected = [ + [[[[3.0]], [[3.0]]], [[[3.0]], [[3.0]]]], + [[[[3.0]], [[3.0]]], [[[3.0]], [[3.0]]]] + ]; + bternary5d([x, y, z, w], shapes, add); + t.deepEqual(w, expected, 'returns expected value'); + + t.end(); +}); + +tape('the function does not invoke a provided callback if provided an output shape having a first element equal to zero', function test(t) { + var expected; + var shapes; + var x; + var y; + var z; + var w; + + shapes = [ + [1, 1, 1, 2, 2], + [1, 1, 1, 2, 2], + [1, 1, 1, 2, 2], + [0, 2, 2, 2, 2] + ]; + x = [ + [ + [ + [ + [1.0, 2.0], + [3.0, 4.0] + ] + + ] + ] + ]; + y = x; + z = x; + w = zeros5d([2, 2, 2, 2, 2]); + + expected = zeros5d([2, 2, 2, 2, 2]); + bternary5d([x, y, z, w], shapes, clbk); + t.deepEqual(w, expected, 'returns expected value'); + + t.end(); + + function clbk() { + t.ok(false, 'should not invoke callback'); + } +}); + +tape('the function does not invoke a provided callback if provided an output shape having a second element equal to zero', function test(t) { + var expected; + var shapes; + var x; + var y; + var z; + var w; + + shapes = [ + [1, 1, 1, 2, 2], + [1, 1, 1, 2, 2], + [1, 1, 1, 2, 2], + [2, 0, 2, 2, 2] + ]; + x = [ + [ + [ + [ + [1.0, 2.0], + [3.0, 4.0] + ] + + ] + ] + ]; + y = x; + z = x; + w = zeros5d([2, 2, 2, 2, 2]); + + expected = zeros5d([2, 2, 2, 2, 2]); + bternary5d([x, y, z, w], shapes, clbk); + t.deepEqual(w, expected, 'returns expected value'); + + t.end(); + + function clbk() { + t.ok(false, 'should not invoke callback'); + } +}); + +tape('the function does not invoke a provided callback if provided an output shape having a third element equal to zero', function test(t) { + var expected; + var shapes; + var x; + var y; + var z; + var w; + + shapes = [ + [1, 1, 1, 2, 2], + [1, 1, 1, 2, 2], + [1, 1, 1, 2, 2], + [2, 2, 0, 2, 2] + ]; + x = [ + [ + [ + [ + [1.0, 2.0], + [3.0, 4.0] + ] + + ] + ] + ]; + y = x; + z = x; + w = zeros5d([2, 2, 2, 2, 2]); + + expected = zeros5d([2, 2, 2, 2, 2]); + bternary5d([x, y, z, w], shapes, clbk); + t.deepEqual(w, expected, 'returns expected value'); + + t.end(); + + function clbk() { + t.ok(false, 'should not invoke callback'); + } +}); + +tape('the function does not invoke a provided callback if provided an output shape having a forth element equal to zero', function test(t) { + var expected; + var shapes; + var x; + var y; + var z; + var w; + + shapes = [ + [1, 1, 1, 2, 2], + [1, 1, 1, 2, 2], + [1, 1, 1, 2, 2], + [2, 2, 2, 0, 2] + ]; + x = [ + [ + [ + [ + [1.0, 2.0], + [3.0, 4.0] + ] + + ] + ] + ]; + y = x; + z = x; + w = zeros5d([2, 2, 2, 2, 2]); + + expected = zeros5d([2, 2, 2, 2, 2]); + bternary5d([x, y, z, w], shapes, clbk); + t.deepEqual(w, expected, 'returns expected value'); + + t.end(); + + function clbk() { + t.ok(false, 'should not invoke callback'); + } +}); + +tape('the function does not invoke a provided callback if provided an output shape having a fifth element equal to zero', function test(t) { + var expected; + var shapes; + var x; + var y; + var z; + var w; + + shapes = [ + [1, 1, 1, 2, 2], + [1, 1, 1, 2, 2], + [1, 1, 1, 2, 2], + [2, 2, 2, 2, 0] + ]; + x = [ + [ + [ + [ + [1.0, 2.0], + [3.0, 4.0] + ] + + ] + ] + ]; + y = x; + z = x; + w = zeros5d([2, 2, 2, 2, 2]); + + expected = zeros5d([2, 2, 2, 2, 2]); + bternary5d([x, y, z, w], shapes, clbk); + t.deepEqual(w, expected, 'returns expected value'); + + t.end(); + + function clbk() { + t.ok(false, 'should not invoke callback'); + } +}); From 9854a280e54835eace1b71d3f9b3316bc8335b2b Mon Sep 17 00:00:00 2001 From: Vinit Pandit Date: Mon, 25 Nov 2024 07:00:48 +0000 Subject: [PATCH 2/7] fix: fix space between parens --- .../base/broadcasted-ternary5d/README.md | 2 +- .../benchmark/benchmark.js | 64 ++--- .../base/broadcasted-ternary5d/docs/repl.txt | 6 +- .../docs/types/index.d.ts | 12 +- .../base/broadcasted-ternary5d/lib/index.js | 13 +- .../base/broadcasted-ternary5d/lib/main.js | 110 ++++---- .../base/broadcasted-ternary5d/test/test.js | 254 ++++++++++-------- 7 files changed, 243 insertions(+), 218 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md index bfd5ef71059..9a0d397176c 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md @@ -57,7 +57,7 @@ var shapes = [ ]; bternary5d( [ x, y, z, out ], shapes, add ); -// out => [[[[[8,10],[9,11]],[[8,10],[9,11]]]]] +// out => [ [ [ [ [ 8, 10 ], [ 9, 11 ] ], [ [ 8, 10 ], [ 9, 11 ] ] ] ] ] ``` The function accepts the following arguments: diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js index a2b65eba270..1117deb8a7c 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js @@ -42,7 +42,7 @@ var bternary5d = require( './../lib' ); * @param {PositiveIntegerArray} shape - output array shape * @returns {Function} benchmark function */ -function createBenchmark(shape) { +function createBenchmark( shape ) { var arrays; var shapes; var x; @@ -51,17 +51,17 @@ function createBenchmark(shape) { var w; shapes = [ - [shape[0], 1, 1, 1, 1], - [1, 1, 1, 1, shape[1]], - [1, 1, shape[2], 1, 1], + [ shape[ 0 ], 1, 1, 1, 1 ], + [ 1, 1, 1, 1, shape[ 1 ] ], + [ 1, 1, shape[ 2 ], 1, 1 ], shape ]; - x = filled5dBy(shapes[0], uniform(-100.0, 100.0)); - y = filled5dBy(shapes[1], uniform(-100.0, 100.0)); - z = filled5dBy(shapes[2], uniform(-100.0, 100.0)); - w = zeros5d(shapes[3]); + x = filled5dBy( shapes[ 0 ], uniform( -100.0, 100.0 ) ); + y = filled5dBy( shapes[ 1 ], uniform( -100.0, 100.0 ) ); + z = filled5dBy( shapes[ 2 ], uniform( -100.0, 100.0 ) ); + w = zeros5d( shapes[ 3 ] ); - arrays = [x, y, z, w]; + arrays = [ x, y, z, w ]; return benchmark; @@ -71,7 +71,7 @@ function createBenchmark(shape) { * @private * @param {Benchmark} b - benchmark instance */ - function benchmark(b) { + function benchmark( b ) { var i0; var i1; var i2; @@ -80,28 +80,28 @@ function createBenchmark(shape) { var i; b.tic(); - for (i = 0; i < b.iterations; i++) { - bternary5d(arrays, shapes, add); - i4 = i % shapes[1][0]; - i3 = i % shapes[1][1]; - i2 = i % shapes[1][2]; - i1 = i % shapes[1][3]; - i0 = i % shapes[1][4]; - if (isnan(arrays[3][i4][i3][i2][i1][i0])) { - b.fail('should not return NaN'); + for ( i = 0; i < b.iterations; i++ ) { + bternary5d( arrays, shapes, add ); + i4 = i % shapes[ 1 ][ 0 ]; + i3 = i % shapes[ 1 ][ 1 ]; + i2 = i % shapes[ 1 ][ 2 ]; + i1 = i % shapes[ 1 ][ 3 ]; + i0 = i % shapes[ 1 ][ 4 ]; + if ( isnan( arrays[ 3 ][ i4 ][ i3 ][ i2 ][ i1 ][ i0 ] ) ) { + b.fail( 'should not return NaN' ); } } b.toc(); - i4 = i % shapes[1][0]; - i3 = i % shapes[1][1]; - i2 = i % shapes[1][2]; - i1 = i % shapes[1][3]; - i0 = i % shapes[1][4]; - if (isnan(arrays[3][i4][i3][i2][i1][i0])) { - b.fail('should not return NaN'); + i4 = i % shapes[ 1 ][ 0 ]; + i3 = i % shapes[ 1 ][ 1 ]; + i2 = i % shapes[ 1 ][ 2 ]; + i1 = i % shapes[1 ][ 3 ]; + i0 = i % shapes[ 1 ][ 4 ]; + if (isnan(arrays[ 3 ][ i4 ][ i3 ][ i2 ][ i1 ][ i0 ])) { + b.fail( 'should not return NaN' ); } - b.pass('benchmark finished'); + b.pass( 'benchmark finished' ); b.end(); } } @@ -125,11 +125,11 @@ function main() { min = 1; // 10^min max = 6; // 10^max - for (i = min; i <= max; i++) { - N = floor(pow(pow(10, i), 1.0 / 5.0)); - sh = [N, N, N, N, N]; - f = createBenchmark(sh); - bench(pkg + '::equidimensional:size=' + numel(sh), f); + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0 / 5.0 ) ); + sh = [ N, N, N, N, N ]; + f = createBenchmark( sh ); + bench( pkg + '::equidimensional:size=' + numel( sh ), f ); } } diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt index c3699c90d38..98a1a1958de 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt @@ -18,11 +18,11 @@ Examples -------- > function fcn( x, y, z ) { return x + y + z }; - > var x = [ [ [ 1.0 ] ] ]; - > var y = [ [ [ [ 2.0, 2.0 ] , [ 3.0, 3.0 ] ] ] ]; + > var x = [ 1.0 ]; + > var y = [ [ 2.0, 2.0 ] , [ 3.0, 3.0 ] ]; > var z = [ [ [ [ [ 2.0 ] , [ 3.0 ] ] ] ] ]; > var out = [ [ [ [ [ 0.0 ,0.0 ], [ 0.0 ,0.0 ] ] ] ] ]; - > var shapes =[[1, 1, 1], [1, 1, 2, 2], [1, 1, 1, 2, 1], [1, 1, 1, 2, 2]]; + > var shapes =[ [ 1 ], [ 2, 2 ], [ 1, 1, 1, 2, 1 ], [ 1, 1, 1, 2, 2 ] ]; > {{alias}}( [ x, y, z, out ], shapes, fcn ); > out [ [ [ [ [ 5.0 ,5.0 ], [ 7.0 ,7.0 ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/index.d.ts index d728c2d422d..c7d5a67ce38 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/index.d.ts @@ -88,12 +88,12 @@ type InOutShapes = [ * var ones5d = require( '@stdlib/array/base/ones5d' ); * var zeros5d = require( '@stdlib/array/base/zeros5d' ); * var add = require( '@stdlib/math/base/ops/add3' ); -* +* var bternary5d = require( '@stdlib/array/base/broadcasted-ternary5d' ); * var shapes = [ -* [ 1, 2, 1, 1, 1], -* [ 2, 1, 1, 1, 1], -* [ 1, 1, 1, 1, 1], -* [ 2, 2, 1, 1, 1] +* [ 1, 2, 1, 1, 1 ], +* [ 2, 1, 1, 1, 1 ], +* [ 1, 1, 1, 1, 1 ], +* [ 2, 2, 1, 1, 1 ] * ]; * * var x = ones5d( shapes[ 0 ] ); @@ -104,7 +104,7 @@ type InOutShapes = [ * bternary5d( [ x, y, z, out ], shapes, add ); * * console.log( out ); -* // =>[[[[[3]]],[[3]]],[[[[3]]],[[3]]]],[[[[3]]],[[3]]],[[[[3]]],[[3]]]] +* // =>[ [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ], [ [ [ 3 ] ], [ [ [ 3] ] ] ] ] */ declare function bternary5d( arrays: InOutArrays, shapes: InOutShapes, fcn: Ternary ): void; diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js index aaddb9cbc7d..6cfcae57ef4 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js @@ -29,10 +29,10 @@ * var add = require( '@stdlib/math/base/ops/add3' ); * var bternary5d = require( '@stdlib/array/base/broadcasted-ternary5d' ); * var shapes = [ -* [ 1, 2, 1, 1, 1], -* [ 2, 1, 1, 1, 1], -* [ 1, 1, 1, 1, 1], -* [ 2, 2, 1, 1, 1] +* [ 1, 2, 1, 1, 1 ], +* [ 2, 1, 1, 1, 1 ], +* [ 1, 1, 1, 1, 1 ], +* [ 2, 2, 1, 1, 1 ] * ]; * * var x = ones5d( shapes[ 0 ] ); @@ -40,11 +40,10 @@ * var z = ones5d( shapes[ 2 ] ); * var out = zeros5d( shapes[ 3 ] ); * -* bternary4d( [ x, y, z, out ], shapes, add ); +* bternary5d( [ x, y, z, out ], shapes, add ); * * console.log( out ); -* // =>[[[[[3]]],[[3]]],[[[[3]]],[[3]]]],[[[[3]]],[[3]]],[[[[3]]],[[3]]]] - +* // =>[ [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ], [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ] ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js index 4cb6b655a39..6c6552c710f 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js @@ -38,12 +38,12 @@ var broadcastArray = require( '@stdlib/array/base/broadcast-array' ); * var ones5d = require( '@stdlib/array/base/ones5d' ); * var zeros5d = require( '@stdlib/array/base/zeros5d' ); * var add = require( '@stdlib/math/base/ops/add3' ); -* + * var shapes = [ -* [ 1, 2, 1, 1, 1], -* [ 2, 1, 1, 1, 1], -* [ 1, 1, 1, 1, 1], -* [ 2, 2, 1, 1, 1] +* [ 1, 2, 1, 1, 1 ], +* [ 2, 1, 1, 1, 1 ], +* [ 1, 1, 1, 1, 1 ], +* [ 2, 2, 1, 1, 1 ] * ]; * * var x = ones5d( shapes[ 0 ] ); @@ -54,9 +54,9 @@ var broadcastArray = require( '@stdlib/array/base/broadcast-array' ); * bternary5d( [ x, y, z, out ], shapes, add ); * * console.log( out ); -* // =>[[[[[3]]],[[[3]]]],[[[[3]]],[[[3]]]]] +* // =>[ [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ], [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ] ] */ -function bternary5d(arrays, shapes, fcn) { +function bternary5d( arrays, shapes, fcn ) { var dx0; var dx1; var dx2; @@ -121,82 +121,82 @@ function bternary5d(arrays, shapes, fcn) { var z; var w; - sh = shapes[3]; - S0 = sh[4]; - S1 = sh[3]; - S2 = sh[2]; - S3 = sh[1]; - S4 = sh[0]; - if (S0 <= 0 || S1 <= 0 || S2 <= 0 || S3 <= 0 || S4 <= 0) { + sh = shapes[ 3 ]; + S0 = sh[ 4 ]; + S1 = sh[ 3 ]; + S2 = sh[ 2 ]; + S3 = sh[ 1 ]; + S4 = sh[ 0 ]; + if ( S0 <= 0 || S1 <= 0 || S2 <= 0 || S3 <= 0 || S4 <= 0 ) { return; } - o = broadcastArray(arrays[0], shapes[0], sh); + o = broadcastArray( arrays[ 0 ], shapes[ 0 ], sh ); x = o.data; st = o.strides; - dx0 = st[4]; - dx1 = st[3]; - dx2 = st[2]; - dx3 = st[1]; - dx4 = st[0]; + dx0 = st[ 4 ]; + dx1 = st[ 3 ]; + dx2 = st[ 2 ]; + dx3 = st[ 1 ]; + dx4 = st[ 0 ]; - o = broadcastArray(arrays[1], shapes[1], sh); + o = broadcastArray( arrays[ 1 ], shapes[ 1 ], sh ); y = o.data; st = o.strides; - dy0 = st[4]; - dy1 = st[3]; - dy2 = st[2]; - dy3 = st[1]; - dy4 = st[0]; + dy0 = st[ 4 ]; + dy1 = st[ 3 ]; + dy2 = st[ 2 ]; + dy3 = st[ 1 ]; + dy4 = st[ 0 ]; - o = broadcastArray(arrays[2], shapes[2], sh); + o = broadcastArray( arrays[ 2 ], shapes[ 2 ], sh ); z = o.data; st = o.strides; - dz0 = st[4]; - dz1 = st[3]; - dz2 = st[2]; - dz3 = st[1]; - dz4 = st[0]; + dz0 = st[ 4 ]; + dz1 = st[ 3 ]; + dz2 = st[ 2 ]; + dz3 = st[ 1 ]; + dz4 = st[ 0 ]; - w = arrays[3]; + w = arrays[ 3 ]; j4 = 0; k4 = 0; m4 = 0; - for (i4 = 0; i4 < S4; i4++) { + for ( i4 = 0; i4 < S4; i4++ ) { j3 = 0; k3 = 0; m3 = 0; - x3 = x[j4]; - y3 = y[k4]; - z3 = z[m4]; - w3 = w[i4]; - for (i3 = 0; i3 < S3; i3++) { + x3 = x[ j4 ]; + y3 = y[ k4 ]; + z3 = z[ m4 ]; + w3 = w[ i4 ]; + for ( i3 = 0; i3 < S3; i3++ ) { j2 = 0; k2 = 0; m2 = 0; - x2 = x3[j3]; - y2 = y3[k3]; - z2 = z3[m3]; - w2 = w3[i3]; - for (i2 = 0; i2 < S2; i2++) { + x2 = x3[ j3 ]; + y2 = y3[ k3 ]; + z2 = z3[ m3 ]; + w2 = w3[ i3 ]; + for ( i2 = 0; i2 < S2; i2++ ) { j1 = 0; k1 = 0; m1 = 0; - x1 = x2[j2]; - y1 = y2[k2]; - z1 = z2[m2]; - w1 = w2[i2]; - for (i1 = 0; i1 < S1; i1++) { + x1 = x2[ j2 ]; + y1 = y2[ k2 ]; + z1 = z2[ m2 ]; + w1 = w2[ i2 ]; + for ( i1 = 0; i1 < S1; i1++ ) { j0 = 0; k0 = 0; m0 = 0; - x0 = x1[j1]; - y0 = y1[k1]; - z0 = z1[m1]; - w0 = w1[i1]; - for (i0 = 0; i0 < S0; i0++) { - w0[i0] = fcn(x0[j0], y0[k0], z0[m0]); + x0 = x1[ j1 ]; + y0 = y1[ k1 ]; + z0 = z1[ m1 ]; + w0 = w1[ i1 ]; + for ( i0 = 0; i0 < S0; i0++ ) { + w0[ i0 ] = fcn( x0[ j0 ], y0[ k0 ], z0[ m0 ] ); j0 += dx0; k0 += dy0; m0 += dz0; diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js index 4c0bb9c2751..127c8060974 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js @@ -27,13 +27,13 @@ var bternary5d = require( './../lib' ); // TESTS // -tape('main export is a function', function test(t) { - t.ok(true, __filename); - t.strictEqual(typeof bternary5d, 'function', 'main export is a function'); +tape( 'main export is a function ', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof bternary5d, 'function', 'main export is a function' ); t.end(); -}); +} ); -tape('the function applies a provided callback to broadcasted input arrays and assigns results to a nested output array', function test(t) { +tape( 'the function applies a provided callback to broadcasted input arrays and assigns results to a nested output array ', function test( t ) { var expected; var shapes; var x; @@ -42,69 +42,100 @@ tape('the function applies a provided callback to broadcasted input arrays and a var w; shapes = [ - [1, 2, 1, 1, 1], - [2, 1, 1, 2], - [1, 1, 2, 1], - [2, 2, 2, 2, 2] + [ 1, 2, 1, 1, 1 ], + [ 2, 1, 1, 2 ], + [ 1, 1, 2, 1 ], + [ 2, 2, 2, 2, 2 ] ]; - x = [[[[[1.0]]], [[[2.0]]]]]; - y = [[[[3.0, 4.0]]], [[[4.0, 5.0]]]]; - z = [[[[6.0], [7.0]]]]; - w = zeros5d(shapes[3]); + x = [ [ [ [ [ 1.0 ] ] ], [ [ [ 2.0 ] ] ] ] ]; + y = [ [ [ [ 3.0, 4.0 ] ] ], [ [ [ 4.0, 5.0 ] ] ] ]; + z = [ [ [ [ 6.0 ], [ 7.0 ] ] ] ]; + w = zeros5d( shapes[ 3 ] ); - expected = [[ - [[[10.0, 11.0], [11.0, 12.0]], [[10.0, 11.0], [11.0, 12.0]]], - [[[12.0, 13.0], [13.0, 14.0]], [[12.0, 13.0], [13.0, 14.0]]]], - [[[[10.0, 11.0], [11.0, 12.0]], [[10.0, 11.0], [11.0, 12.0]]], - [[[12.0, 13.0], [13.0, 14.0]], [[12.0, 13.0], [13.0, 14.0]]]]]; - bternary5d([x, y, z, w], shapes, add); - t.deepEqual(w, expected, 'returns expected value'); + expected = [ + [ + [ + [ [ 10.0, 11.0 ], [ 11.0, 12.0 ] ], + [ [ 10.0, 11.0 ], [ 11.0, 12.0 ] ] + ], + [ + [ [ 12.0, 13.0 ], [ 13.0, 14.0 ] ], + [ [ 12.0, 13.0 ], [ 13.0, 14.0 ] ] + ] + ], + [ + [ + [ [ 10.0, 11.0 ], [ 11.0, 12.0 ] ], + [ [ 10.0, 11.0 ], [ 11.0, 12.0 ] ] + ], + [ + [ [ 12.0, 13.0 ], [ 13.0, 14.0 ] ], + [ [ 12.0, 13.0 ], [ 13.0, 14.0 ] ] + ] + ] + ]; + bternary5d( [ x, y, z, w ], shapes, add ); + t.deepEqual( w, expected, 'returns expected value' ); shapes = [ - [1], - [2, 1, 1], - [2, 1, 2, 1, 1], - [2, 2, 2, 1, 1] + [ 1 ], + [ 2, 1, 1 ], + [ 2, 1, 2, 1, 1 ], + [ 2, 2, 2, 1, 1 ] ]; - x = [1.0]; - y = [[[2.0]], [[3.0]]]; - z = [[[[[5.0]], [[6.0]]]], [[[[7.0]], [[8.0]]]]]; - w = zeros5d(shapes[3]); + x = [ 1.0 ]; + y = [ [ [ 2.0 ] ], [ [ 3.0 ] ] ]; + z = [ [ [ [ [ 5.0 ] ], [ [ 6.0 ] ] ] ], [ [ [ [ 7.0 ] ], [ [ 8.0 ] ] ] ] ]; + w = zeros5d( shapes[ 3 ] ); expected = [ - [[[[8.0]], [[10.0]]], [[[8.0]], [[10.0]]]], - [[[[10.0]], [[12.0]]], [[[10.0]], [[12.0]]]] + [ [ [ [ 8.0 ] ], [ [ 10.0 ] ] ], [ [ [ 8.0 ] ], [ [ 10.0 ] ] ] ], + [ [ [ [ 10.0 ] ], [ [ 12.0 ] ] ], [ [ [ 10.0 ] ], [ [ 12.0 ] ] ] ] ]; - bternary5d([x, y, z, w], shapes, add); - t.deepEqual(w, expected, 'returns expected value'); + bternary5d( [ x, y, z, w ], shapes, add ); + t.deepEqual( w, expected, 'returns expected value' ); // Same shapes: shapes = [ - [2, 2, 2, 1, 1], - [2, 2, 2, 1, 1], - [2, 2, 2, 1, 1], - [2, 2, 2, 1, 1] + [ 2, 2, 2, 1, 1 ], + [ 2, 2, 2, 1, 1 ], + [ 2, 2, 2, 1, 1 ], + [ 2, 2, 2, 1, 1 ] ]; x = [ - [[[[1.0]], [[1.0]]], [[[1.0]], [[1.0]]]], - [[[[1.0]], [[1.0]]], [[[1.0]], [[1.0]]]] + [ + [ [ [ 1.0 ] ], [ [ 1.0 ] ] ], + [ [ [ 1.0 ] ], [ [ 1.0 ] ] ] + ], + [ + [ [ [ 1.0 ] ], [ [ 1.0 ] ] ], + [ [ [ 1.0 ] ], [ [ 1.0 ] ] ] + ] ]; y = x; z = x; - w = zeros5d(shapes[3]); + w = zeros5d( shapes[ 3 ] ); expected = [ - [[[[3.0]], [[3.0]]], [[[3.0]], [[3.0]]]], - [[[[3.0]], [[3.0]]], [[[3.0]], [[3.0]]]] + [ + [ [ [ 3.0 ] ], [ [ 3.0 ] ] ], + [ [ [ 3.0 ] ], [ [ 3.0 ] ] ] + ], + [ + [ [ [ 3.0 ] ], [ [ 3.0 ] ] ], + [ [ [ 3.0 ] ], [ [ 3.0 ] ] ] + ] ]; - bternary5d([x, y, z, w], shapes, add); - t.deepEqual(w, expected, 'returns expected value'); + bternary5d( [ x, y, z, w ], shapes, add ); + t.deepEqual( w, expected, 'returns expected value' ); t.end(); -}); +} ); + +// ( And so on for the remaining parts of your code... ) -tape('the function does not invoke a provided callback if provided an output shape having a first element equal to zero', function test(t) { +tape( 'the function does not invoke a provided callback if provided an output shape having a first element equal to zero ', function test( t ) { var expected; var shapes; var x; @@ -113,38 +144,37 @@ tape('the function does not invoke a provided callback if provided an output sha var w; shapes = [ - [1, 1, 1, 2, 2], - [1, 1, 1, 2, 2], - [1, 1, 1, 2, 2], - [0, 2, 2, 2, 2] + [ 1, 1, 1, 2, 2 ], + [ 1, 1, 1, 2, 2 ], + [ 1, 1, 1, 2, 2 ], + [ 0, 2, 2, 2, 2 ] ]; x = [ [ [ [ - [1.0, 2.0], - [3.0, 4.0] + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] ] - ] ] ]; y = x; z = x; - w = zeros5d([2, 2, 2, 2, 2]); + w = zeros5d( [ 2, 2, 2, 2, 2 ] ); - expected = zeros5d([2, 2, 2, 2, 2]); - bternary5d([x, y, z, w], shapes, clbk); - t.deepEqual(w, expected, 'returns expected value'); + expected = zeros5d( [ 2, 2, 2, 2, 2 ] ); + bternary5d( [ x, y, z, w ], shapes, clbk ); + t.deepEqual( w, expected, 'returns expected value' ); t.end(); function clbk() { - t.ok(false, 'should not invoke callback'); + t.ok( false, 'should not invoke callback' ); } -}); +} ); -tape('the function does not invoke a provided callback if provided an output shape having a second element equal to zero', function test(t) { +tape( 'the function does not invoke a provided callback if provided an output shape having a second element equal to zero ', function test( t ) { var expected; var shapes; var x; @@ -153,38 +183,37 @@ tape('the function does not invoke a provided callback if provided an output sha var w; shapes = [ - [1, 1, 1, 2, 2], - [1, 1, 1, 2, 2], - [1, 1, 1, 2, 2], - [2, 0, 2, 2, 2] + [ 1, 1, 1, 2, 2 ], + [ 1, 1, 1, 2, 2 ], + [ 1, 1, 1, 2, 2 ], + [ 2, 0, 2, 2, 2 ] ]; x = [ [ [ [ - [1.0, 2.0], - [3.0, 4.0] + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] ] - ] ] ]; y = x; z = x; - w = zeros5d([2, 2, 2, 2, 2]); + w = zeros5d( [ 2, 2, 2, 2, 2 ] ); - expected = zeros5d([2, 2, 2, 2, 2]); - bternary5d([x, y, z, w], shapes, clbk); - t.deepEqual(w, expected, 'returns expected value'); + expected = zeros5d( [ 2, 2, 2, 2, 2 ] ); + bternary5d( [ x, y, z, w ], shapes, clbk ); + t.deepEqual( w, expected, 'returns expected value' ); t.end(); function clbk() { - t.ok(false, 'should not invoke callback'); + t.ok( false, 'should not invoke callback' ); } -}); +} ); -tape('the function does not invoke a provided callback if provided an output shape having a third element equal to zero', function test(t) { +tape( 'the function does not invoke a provided callback if provided an output shape having a third element equal to zero ', function test( t ) { var expected; var shapes; var x; @@ -193,38 +222,37 @@ tape('the function does not invoke a provided callback if provided an output sha var w; shapes = [ - [1, 1, 1, 2, 2], - [1, 1, 1, 2, 2], - [1, 1, 1, 2, 2], - [2, 2, 0, 2, 2] + [ 1, 1, 1, 2, 2 ], + [ 1, 1, 1, 2, 2 ], + [ 1, 1, 1, 2, 2 ], + [ 2, 2, 0, 2, 2 ] ]; x = [ [ [ [ - [1.0, 2.0], - [3.0, 4.0] + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] ] - ] ] ]; y = x; z = x; - w = zeros5d([2, 2, 2, 2, 2]); + w = zeros5d( [ 2, 2, 2, 2, 2 ] ); - expected = zeros5d([2, 2, 2, 2, 2]); - bternary5d([x, y, z, w], shapes, clbk); - t.deepEqual(w, expected, 'returns expected value'); + expected = zeros5d( [ 2, 2, 2, 2, 2 ] ); + bternary5d( [ x, y, z, w ], shapes, clbk ); + t.deepEqual( w, expected, 'returns expected value' ); t.end(); function clbk() { - t.ok(false, 'should not invoke callback'); + t.ok( false, 'should not invoke callback' ); } -}); +} ); -tape('the function does not invoke a provided callback if provided an output shape having a forth element equal to zero', function test(t) { +tape( 'the function does not invoke a provided callback if provided an output shape having a forth element equal to zero ', function test( t ) { var expected; var shapes; var x; @@ -233,38 +261,37 @@ tape('the function does not invoke a provided callback if provided an output sha var w; shapes = [ - [1, 1, 1, 2, 2], - [1, 1, 1, 2, 2], - [1, 1, 1, 2, 2], - [2, 2, 2, 0, 2] + [ 1, 1, 1, 2, 2 ], + [ 1, 1, 1, 2, 2 ], + [ 1, 1, 1, 2, 2 ], + [ 2, 2, 2, 0, 2 ] ]; x = [ [ [ [ - [1.0, 2.0], - [3.0, 4.0] + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] ] - ] ] ]; y = x; z = x; - w = zeros5d([2, 2, 2, 2, 2]); + w = zeros5d( [ 2, 2, 2, 2, 2 ] ); - expected = zeros5d([2, 2, 2, 2, 2]); - bternary5d([x, y, z, w], shapes, clbk); - t.deepEqual(w, expected, 'returns expected value'); + expected = zeros5d( [ 2, 2, 2, 2, 2 ] ); + bternary5d( [ x, y, z, w ], shapes, clbk ); + t.deepEqual( w, expected, 'returns expected value' ); t.end(); function clbk() { - t.ok(false, 'should not invoke callback'); + t.ok( false, 'should not invoke callback' ); } -}); +} ); -tape('the function does not invoke a provided callback if provided an output shape having a fifth element equal to zero', function test(t) { +tape( 'the function does not invoke a provided callback if provided an output shape having a fifth element equal to zero ', function test( t ) { var expected; var shapes; var x; @@ -273,33 +300,32 @@ tape('the function does not invoke a provided callback if provided an output sha var w; shapes = [ - [1, 1, 1, 2, 2], - [1, 1, 1, 2, 2], - [1, 1, 1, 2, 2], - [2, 2, 2, 2, 0] + [ 1, 1, 1, 2, 2 ], + [ 1, 1, 1, 2, 2 ], + [ 1, 1, 1, 2, 2 ], + [ 2, 2, 2, 2, 0 ] ]; x = [ [ [ [ - [1.0, 2.0], - [3.0, 4.0] + [ 1.0, 2.0 ], + [ 3.0, 4.0 ] ] - ] ] ]; y = x; z = x; - w = zeros5d([2, 2, 2, 2, 2]); + w = zeros5d( [ 2, 2, 2, 2, 2 ] ); - expected = zeros5d([2, 2, 2, 2, 2]); - bternary5d([x, y, z, w], shapes, clbk); - t.deepEqual(w, expected, 'returns expected value'); + expected = zeros5d( [ 2, 2, 2, 2, 2 ] ); + bternary5d( [ x, y, z, w ], shapes, clbk ); + t.deepEqual( w, expected, 'returns expected value' ); t.end(); function clbk() { - t.ok(false, 'should not invoke callback'); + t.ok( false, 'should not invoke callback' ); } -}); +} ); From 3cda0f38b3364693099b3e670f7f71a5b70de30c Mon Sep 17 00:00:00 2001 From: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:08:03 +0530 Subject: [PATCH 3/7] fix: fix spacing Signed-off-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> --- .../@stdlib/array/base/broadcasted-ternary5d/README.md | 2 +- .../array/base/broadcasted-ternary5d/benchmark/benchmark.js | 2 +- .../@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md index 9a0d397176c..feb7959bc88 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md @@ -46,7 +46,7 @@ var zeros5d = require( '@stdlib/array/base/zeros5d' ); var x = [ [ [ 1.0, 2.0 ] ] ]; var y = [ [ [ 3.0 ], [ 4.0 ] ] ]; -var z = [ [ [ [4.0, 5.0] ], [ [4.0, 5.0] ] ] ]; +var z = [ [ [ [ 4.0, 5.0 ] ], [ [ 4.0, 5.0 ] ] ] ]; var out = zeros5d( [ 1, 1, 2, 2 ] ); var shapes = [ diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js index 1117deb8a7c..a750ef5d4d1 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js @@ -98,7 +98,7 @@ function createBenchmark( shape ) { i2 = i % shapes[ 1 ][ 2 ]; i1 = i % shapes[1 ][ 3 ]; i0 = i % shapes[ 1 ][ 4 ]; - if (isnan(arrays[ 3 ][ i4 ][ i3 ][ i2 ][ i1 ][ i0 ])) { + if ( isnan(arrays[ 3 ][ i4 ][ i3 ][ i2 ][ i1 ][ i0 ] ) ) { b.fail( 'should not return NaN' ); } b.pass( 'benchmark finished' ); diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt index 98a1a1958de..53ff85da6a8 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt @@ -19,13 +19,13 @@ -------- > function fcn( x, y, z ) { return x + y + z }; > var x = [ 1.0 ]; - > var y = [ [ 2.0, 2.0 ] , [ 3.0, 3.0 ] ]; - > var z = [ [ [ [ [ 2.0 ] , [ 3.0 ] ] ] ] ]; + > var y = [ [ 2.0, 2.0 ], [ 3.0, 3.0 ] ]; + > var z = [ [ [ [ [ 2.0 ], [ 3.0 ] ] ] ] ]; > var out = [ [ [ [ [ 0.0 ,0.0 ], [ 0.0 ,0.0 ] ] ] ] ]; > var shapes =[ [ 1 ], [ 2, 2 ], [ 1, 1, 1, 2, 1 ], [ 1, 1, 1, 2, 2 ] ]; > {{alias}}( [ x, y, z, out ], shapes, fcn ); > out - [ [ [ [ [ 5.0 ,5.0 ], [ 7.0 ,7.0 ] ] ] ] ] + [ [ [ [ [ 5.0, 5.0 ], [ 7.0, 7.0 ] ] ] ] ] See Also -------- From 8386f9212313c7477211e0c8809883ad04727051 Mon Sep 17 00:00:00 2001 From: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:09:57 +0530 Subject: [PATCH 4/7] fix: fix spacing Signed-off-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> --- .../array/base/broadcasted-ternary5d/docs/types/test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/test.ts index d44c33c8108..83f845541a3 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/test.ts +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/test.ts @@ -43,7 +43,7 @@ function fcn( x: number, y: number, z: number ): number { const shapes: [ Array, Array, Array ] = [ [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ] ]; bternary5d( [ x, y, z, out ], shapes, fcn ); // $ExpectType void - bternary5d( [ x[0][0][0][0], y, z ], [ [ shapes[0][4] ], shapes[1], shapes[2] ], fcn ); // $ExpectType void + bternary5d( [ x[ 0 ][ 0 ][ 0 ][ 0 ], y, z ], [ [ shapes[ 0 ][ 4 ] ], shapes[ 1 ], shapes[ 2 ] ], fcn ); // $ExpectType void } // The compiler throws an error if the function is provided a first argument which is not an array of nested arrays... @@ -89,7 +89,7 @@ function fcn( x: number, y: number, z: number ): number { bternary5d( [ x, y, z, out ], shapes, true ); // $ExpectError bternary5d( [ x, y, z, out ], shapes, false ); // $ExpectError bternary5d( [ x, y, z, out ], shapes, null ); // $ExpectError - bternary5d( [ x, y, z, out ], shapes, ['1'] ); // $ExpectError + bternary5d( [ x, y, z, out ], shapes, [ '1' ] ); // $ExpectError bternary5d( [ x, y, z, out ], shapes, {} ); // $ExpectError } From 74a071745de8c334e3c6155610b74f4e5faacedd Mon Sep 17 00:00:00 2001 From: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Date: Tue, 26 Nov 2024 09:35:21 +0530 Subject: [PATCH 5/7] fix: clean up Co-authored-by: Athan Signed-off-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> --- .../array/base/broadcasted-ternary5d/benchmark/benchmark.js | 4 ++-- .../@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt | 2 +- .../array/base/broadcasted-ternary5d/docs/types/index.d.ts | 2 +- .../array/base/broadcasted-ternary5d/docs/types/test.ts | 3 +++ .../@stdlib/array/base/broadcasted-ternary5d/lib/index.js | 2 +- .../@stdlib/array/base/broadcasted-ternary5d/lib/main.js | 3 +-- .../@stdlib/array/base/broadcasted-ternary5d/package.json | 2 +- .../@stdlib/array/base/broadcasted-ternary5d/test/test.js | 1 - 8 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js index a750ef5d4d1..47db23a8dcd 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/benchmark/benchmark.js @@ -25,7 +25,7 @@ var uniform = require( '@stdlib/random/base/uniform' ).factory; var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pow = require( '@stdlib/math/base/special/pow' ); var floor = require( '@stdlib/math/base/special/floor' ); -var add = require( '@stdlib/math/base/ops/add' ); +var add = require( '@stdlib/math/base/ops/add3' ); var filled5dBy = require( '@stdlib/array/base/filled5d-by' ); var zeros5d = require( '@stdlib/array/base/zeros5d' ); var numel = require( '@stdlib/ndarray/base/numel' ); @@ -96,7 +96,7 @@ function createBenchmark( shape ) { i4 = i % shapes[ 1 ][ 0 ]; i3 = i % shapes[ 1 ][ 1 ]; i2 = i % shapes[ 1 ][ 2 ]; - i1 = i % shapes[1 ][ 3 ]; + i1 = i % shapes[ 1 ][ 3 ]; i0 = i % shapes[ 1 ][ 4 ]; if ( isnan(arrays[ 3 ][ i4 ][ i3 ][ i2 ][ i1 ][ i0 ] ) ) { b.fail( 'should not return NaN' ); diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt index 53ff85da6a8..64d831c7b6f 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/repl.txt @@ -22,7 +22,7 @@ > var y = [ [ 2.0, 2.0 ], [ 3.0, 3.0 ] ]; > var z = [ [ [ [ [ 2.0 ], [ 3.0 ] ] ] ] ]; > var out = [ [ [ [ [ 0.0 ,0.0 ], [ 0.0 ,0.0 ] ] ] ] ]; - > var shapes =[ [ 1 ], [ 2, 2 ], [ 1, 1, 1, 2, 1 ], [ 1, 1, 1, 2, 2 ] ]; + > var shapes = [ [ 1 ], [ 2, 2 ], [ 1, 1, 1, 2, 1 ], [ 1, 1, 1, 2, 2 ] ]; > {{alias}}( [ x, y, z, out ], shapes, fcn ); > out [ [ [ [ [ 5.0, 5.0 ], [ 7.0, 7.0 ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/index.d.ts index c7d5a67ce38..7852ffe67b1 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/index.d.ts @@ -104,7 +104,7 @@ type InOutShapes = [ * bternary5d( [ x, y, z, out ], shapes, add ); * * console.log( out ); -* // =>[ [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ], [ [ [ 3 ] ], [ [ [ 3] ] ] ] ] +* // => [ [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ], [ [ [ 3 ] ], [ [ [ 3] ] ] ] ] */ declare function bternary5d( arrays: InOutArrays, shapes: InOutShapes, fcn: Ternary ): void; diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/test.ts index 83f845541a3..214c4791c45 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/test.ts +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/docs/types/test.ts @@ -49,6 +49,7 @@ function fcn( x: number, y: number, z: number ): number { // The compiler throws an error if the function is provided a first argument which is not an array of nested arrays... { const shapes: [ Array, Array, Array ] = [ [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ] ]; + bternary5d( 'abc', shapes, fcn ); // $ExpectError bternary5d( 3.14, shapes, fcn ); // $ExpectError bternary5d( true, shapes, fcn ); // $ExpectError @@ -84,6 +85,7 @@ function fcn( x: number, y: number, z: number ): number { const out = [ [ [ [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ] ] ]; const shapes: [ Array, Array, Array ] = [ [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ] ]; + bternary5d( [ x, y, z, out ], shapes, 'abc' ); // $ExpectError bternary5d( [ x, y, z, out ], shapes, 3.14 ); // $ExpectError bternary5d( [ x, y, z, out ], shapes, true ); // $ExpectError @@ -101,6 +103,7 @@ function fcn( x: number, y: number, z: number ): number { const out = [ [ [ [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ] ] ]; const shapes: [ Array, Array, Array ] = [ [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ], [ 1, 1, 1, 2, 2 ] ]; + bternary5d(); // $ExpectError bternary5d( [ x, y, z, out ] ); // $ExpectError bternary5d( [ x, y, z, out ], shapes, fcn, {} ); // $ExpectError diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js index 6cfcae57ef4..f1516787acb 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js @@ -43,7 +43,7 @@ * bternary5d( [ x, y, z, out ], shapes, add ); * * console.log( out ); -* // =>[ [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ], [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ] ] +* // => [ [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ], [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ] ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js index 6c6552c710f..0acb3deffcc 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js @@ -54,7 +54,7 @@ var broadcastArray = require( '@stdlib/array/base/broadcast-array' ); * bternary5d( [ x, y, z, out ], shapes, add ); * * console.log( out ); -* // =>[ [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ], [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ] ] +* // => [ [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ], [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ] ] */ function bternary5d( arrays, shapes, fcn ) { var dx0; @@ -131,7 +131,6 @@ function bternary5d( arrays, shapes, fcn ) { return; } o = broadcastArray( arrays[ 0 ], shapes[ 0 ], sh ); - x = o.data; st = o.strides; dx0 = st[ 4 ]; diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/package.json b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/package.json index 718ed51583b..0e824c81419 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/package.json +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/package.json @@ -55,7 +55,7 @@ "multidimensional", "ndarray", "matrix", - "3d", + "5d", "binary", "apply", "foreach", diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js index 127c8060974..7c28f4f529e 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js @@ -133,7 +133,6 @@ tape( 'the function applies a provided callback to broadcasted input arrays and t.end(); } ); -// ( And so on for the remaining parts of your code... ) tape( 'the function does not invoke a provided callback if provided an output shape having a first element equal to zero ', function test( t ) { var expected; From 7eea62d148e4b24f130ee63e9715ceee48c78871 Mon Sep 17 00:00:00 2001 From: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Date: Tue, 26 Nov 2024 09:38:42 +0530 Subject: [PATCH 6/7] fix: adding decimals Signed-off-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> --- .../@stdlib/array/base/broadcasted-ternary5d/README.md | 2 +- .../@stdlib/array/base/broadcasted-ternary5d/lib/index.js | 2 +- .../@stdlib/array/base/broadcasted-ternary5d/lib/main.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md index feb7959bc88..e826e0f6193 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/README.md @@ -57,7 +57,7 @@ var shapes = [ ]; bternary5d( [ x, y, z, out ], shapes, add ); -// out => [ [ [ [ [ 8, 10 ], [ 9, 11 ] ], [ [ 8, 10 ], [ 9, 11 ] ] ] ] ] +// out => [ [ [ [ [ 8.0, 10.0 ], [ 9.0, 11.0 ] ], [ [ 8.0, 10.0 ], [ 9.0, 11.0 ] ] ] ] ] ``` The function accepts the following arguments: diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js index f1516787acb..83f4245dd7c 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/index.js @@ -43,7 +43,7 @@ * bternary5d( [ x, y, z, out ], shapes, add ); * * console.log( out ); -* // => [ [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ], [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ] ] +* // => [ [ [ [ [ 3.0 ] ] ], [ [ [ 3.0 ] ] ] ], [ [ [ [ 3.0 ] ] ], [ [ [ 3.0 ] ] ] ] ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js index 0acb3deffcc..0bb22b81175 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/lib/main.js @@ -54,7 +54,7 @@ var broadcastArray = require( '@stdlib/array/base/broadcast-array' ); * bternary5d( [ x, y, z, out ], shapes, add ); * * console.log( out ); -* // => [ [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ], [ [ [ [ 3 ] ] ], [ [ [ 3 ] ] ] ] ] +* // => [ [ [ [ [ 3.0 ] ] ], [ [ [ 3.0 ] ] ] ], [ [ [ [ 3.0 ] ] ], [ [ [ 3.0 ] ] ] ] ] */ function bternary5d( arrays, shapes, fcn ) { var dx0; From a6263982a93e3f99ff57a3e0ba166400904e3826 Mon Sep 17 00:00:00 2001 From: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> Date: Tue, 26 Nov 2024 09:44:52 +0530 Subject: [PATCH 7/7] fix: removing extra line Signed-off-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com> --- .../@stdlib/array/base/broadcasted-ternary5d/test/test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js index 7c28f4f529e..a82a7911a88 100644 --- a/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js +++ b/lib/node_modules/@stdlib/array/base/broadcasted-ternary5d/test/test.js @@ -133,7 +133,6 @@ tape( 'the function applies a provided callback to broadcasted input arrays and t.end(); } ); - tape( 'the function does not invoke a provided callback if provided an output shape having a first element equal to zero ', function test( t ) { var expected; var shapes;