Skip to content

Commit 9000dcc

Browse files
committed
Auto-generated commit
1 parent 37c22f8 commit 9000dcc

13 files changed

Lines changed: 1067 additions & 5 deletions

File tree

base/binary5d/README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2023 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# binary5d
22+
23+
> Apply a binary callback to elements in five-dimensional nested input arrays and assign results to elements in a five-dimensional nested output array.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var binary5d = require( '@stdlib/array/base/binary5d' );
37+
```
38+
39+
#### binary5d( arrays, shape, fcn )
40+
41+
Applies a binary callback to elements in five-dimensional nested input arrays and assigns results to elements in a five-dimensional nested output array.
42+
43+
```javascript
44+
var add = require( '@stdlib/math/base/ops/add' );
45+
var zeros5d = require( '@stdlib/array/base/zeros5d' );
46+
47+
var x = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ];
48+
var z = zeros5d( [ 1, 1, 1, 2, 2 ] );
49+
50+
var shape = [ 1, 1, 1, 2, 2 ];
51+
52+
binary5d( [ x, x, z ], shape, add );
53+
// z => [ [ [ [ [ 2.0, 4.0 ], [ 6.0, 8.0 ] ] ] ] ]
54+
```
55+
56+
The function accepts the following arguments:
57+
58+
- **arrays**: array-like object containing two input nested arrays and one output nested array.
59+
- **shape**: array shape.
60+
- **fcn**: binary function to apply.
61+
62+
</section>
63+
64+
<!-- /.usage -->
65+
66+
<section class="notes">
67+
68+
## Notes
69+
70+
- The function assumes that the input and output arrays have the same shape.
71+
72+
</section>
73+
74+
<!-- /.notes -->
75+
76+
<section class="examples">
77+
78+
## Examples
79+
80+
<!-- eslint no-undef: "error" -->
81+
82+
```javascript
83+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
84+
var filled5dBy = require( '@stdlib/array/base/filled5d-by' );
85+
var zeros5d = require( '@stdlib/array/base/zeros5d' );
86+
var add = require( '@stdlib/math/base/ops/add' );
87+
var binary5d = require( '@stdlib/array/base/binary5d' );
88+
89+
var shape = [ 1, 2, 2, 3, 3 ];
90+
91+
var x = filled5dBy( shape, discreteUniform( -100, 100 ) );
92+
console.log( x );
93+
94+
var y = filled5dBy( shape, discreteUniform( -100, 100 ) );
95+
console.log( y );
96+
97+
var z = zeros5d( shape );
98+
console.log( z );
99+
100+
binary5d( [ x, y, z ], shape, add );
101+
console.log( z );
102+
```
103+
104+
</section>
105+
106+
<!-- /.examples -->
107+
108+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
109+
110+
<section class="related">
111+
112+
</section>
113+
114+
<!-- /.related -->
115+
116+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
117+
118+
<section class="links">
119+
120+
</section>
121+
122+
<!-- /.links -->
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/base/uniform' ).factory;
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var add = require( '@stdlib/math/base/ops/add' );
29+
var filled5dBy = require( './../../../base/filled5d-by' );
30+
var zeros5d = require( './../../../base/zeros5d' );
31+
var numel = require( '@stdlib/ndarray/base/numel' );
32+
var pkg = require( './../package.json' ).name;
33+
var binary5d = require( './../lib' );
34+
35+
36+
// FUNCTIONS //
37+
38+
/**
39+
* Creates a benchmark function.
40+
*
41+
* @private
42+
* @param {PositiveIntegerArray} shape - array shape
43+
* @returns {Function} benchmark function
44+
*/
45+
function createBenchmark( shape ) {
46+
var arrays;
47+
var x;
48+
var y;
49+
var z;
50+
51+
x = filled5dBy( shape, uniform( -100.0, 100.0 ) );
52+
y = filled5dBy( shape, uniform( -100.0, 100.0 ) );
53+
z = zeros5d( shape );
54+
55+
arrays = [ x, y, z ];
56+
57+
return benchmark;
58+
59+
/**
60+
* Benchmark function.
61+
*
62+
* @private
63+
* @param {Benchmark} b - benchmark instance
64+
*/
65+
function benchmark( b ) {
66+
var i0;
67+
var i1;
68+
var i2;
69+
var i3;
70+
var i4;
71+
var i;
72+
73+
b.tic();
74+
for ( i = 0; i < b.iterations; i++ ) {
75+
binary5d( arrays, shape, add );
76+
i4 = i % shape[ 0 ];
77+
i3 = i % shape[ 1 ];
78+
i2 = i % shape[ 2 ];
79+
i1 = i % shape[ 3 ];
80+
i0 = i % shape[ 4 ];
81+
if ( isnan( arrays[ 2 ][ i4 ][ i3 ][ i2 ][ i1 ][ i0 ] ) ) {
82+
b.fail( 'should not return NaN' );
83+
}
84+
}
85+
b.toc();
86+
87+
i4 = i % shape[ 0 ];
88+
i3 = i % shape[ 1 ];
89+
i2 = i % shape[ 2 ];
90+
i1 = i % shape[ 3 ];
91+
i0 = i % shape[ 4 ];
92+
if ( isnan( arrays[ 2 ][ i4 ][ i3 ][ i2 ][ i1 ][ i0 ] ) ) {
93+
b.fail( 'should not return NaN' );
94+
}
95+
b.pass( 'benchmark finished' );
96+
b.end();
97+
}
98+
}
99+
100+
101+
// MAIN //
102+
103+
/**
104+
* Main execution sequence.
105+
*
106+
* @private
107+
*/
108+
function main() {
109+
var min;
110+
var max;
111+
var sh;
112+
var N;
113+
var f;
114+
var i;
115+
116+
min = 1; // 10^min
117+
max = 6; // 10^max
118+
119+
for ( i = min; i <= max; i++ ) {
120+
N = floor( pow( pow( 10, i ), 1.0/5.0 ) );
121+
sh = [ N, N, N, N, N ];
122+
f = createBenchmark( sh );
123+
bench( pkg+'::equidimensional:size='+numel( sh ), f );
124+
}
125+
}
126+
127+
main();

base/binary5d/docs/repl.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
{{alias}}( arrays, shape, fcn )
3+
Applies a binary callback to elements in five-dimensional nested input
4+
arrays and assigns results to elements in a five-dimensional nested output
5+
array.
6+
7+
Parameters
8+
----------
9+
arrays: ArrayLikeObject
10+
Array-like object containing two input nested arrays and one output
11+
nested array.
12+
13+
shape: Array<integer>
14+
Array shape.
15+
16+
fcn: Function
17+
Binary callback.
18+
19+
Examples
20+
--------
21+
> var x = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ];
22+
> var y = [ [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ] ];
23+
> var z = [ [ [ [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] ] ] ];
24+
> var shape = [ 1, 1, 1, 2, 2 ];
25+
> {{alias}}( [ x, y, z ], shape, {{alias:@stdlib/math/base/ops/add}} );
26+
> z
27+
[ [ [ [ [ 2.0, 4.0 ], [ 6.0, 8.0 ] ] ] ] ]
28+
29+
See Also
30+
--------
31+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { Array5D } from '@stdlib/types/array';
24+
import { Shape5D } from '@stdlib/types/ndarray';
25+
26+
/**
27+
* Binary callback.
28+
*
29+
* @param value - input value
30+
* @returns result
31+
*/
32+
type Binary<T, U, V> = ( v1: T, v2: U ) => V;
33+
34+
/**
35+
* Applies a binary callback to elements in five-dimensional nested input arrays and assigns results to elements in a five-dimensional nested output array.
36+
*
37+
* ## Notes
38+
*
39+
* - The function assumes that the input and output arrays have the same shape.
40+
*
41+
* @param arrays - array containing two input nested arrays and one output nested array
42+
* @param shape - array shape
43+
* @param fcn - binary callback
44+
*
45+
* @example
46+
* var ones5d = require( `@stdlib/array/base/ones5d` );
47+
* var zeros5d = require( `@stdlib/array/base/zeros5d` );
48+
* var add = require( `@stdlib/math/base/ops/add` );
49+
*
50+
* var shape = [ 1, 1, 2, 2, 2 ];
51+
*
52+
* var x = ones5d( shape );
53+
* var y = ones5d( shape );
54+
* var z = zeros5d( shape );
55+
*
56+
* binary5d( [ x, y, z ], shape, add );
57+
*
58+
* console.log( z );
59+
* // => [ [ [ [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ], [ [ 2.0, 2.0 ], [ 2.0, 2.0 ] ] ] ] ]
60+
*/
61+
declare function binary5d<T = unknown, U = unknown, V = unknown>( arrays: [ Array5D<T>, Array5D<U>, Array5D<V> ], shape: Shape5D, fcn: Binary<T, U, V> ): void;
62+
63+
64+
// EXPORTS //
65+
66+
export = binary5d;

0 commit comments

Comments
 (0)