Skip to content

Commit 26c29d5

Browse files
Merge branch 'bernoulli/entropy' of https://github.com/vivekmaurya001/stdlib into bernoulli/entropy
2 parents 149ce3c + 09b2c3f commit 26c29d5

File tree

61 files changed

+5256
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+5256
-15
lines changed

.github/workflows/scripts/create_sub_issue

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818

1919
# Script to create a sub-issue.
2020
#
21-
# Usage: ./create_sub_issue.sh <issue-title> <body-file> <parent-issue-number>
21+
# Usage: ./create_sub_issue.sh <issue-title> <body-file> <parent-issue-number> [<labels>]
2222
#
2323
# Arguments:
2424
#
2525
# issue-title Title for the new sub-issue.
2626
# body-file Path to the file containing the issue body.
2727
# parent-issue-number Number of the parent issue.
28+
# labels Optional comma-separated list of labels to apply to the new sub-issue.
2829
#
2930
# Environment variables:
3031
#
@@ -42,6 +43,7 @@ set -o pipefail
4243
issue_title="$1"
4344
body_file="$2"
4445
parent_issue_number="$3"
46+
labels="$4"
4547

4648
# Repository information:
4749
owner="stdlib-js"
@@ -61,6 +63,14 @@ if [ ! -f "$body_file" ]; then
6163
fi
6264
issue_body=$(cat "$body_file")
6365

66+
# Process labels into an array if provided:
67+
if [ -n "$labels" ]; then
68+
# Convert comma-separated string to JSON array...
69+
label_array="[$(echo "$labels" | sed 's/[[:space:]]*,[[:space:]]*/","/g' | sed 's/.*/"&"/')]"
70+
else
71+
label_array="[]"
72+
fi
73+
6474
# FUNCTIONS #
6575

6676
# Error handler.
@@ -95,7 +105,7 @@ EOF
95105
echo "$response" | jq -r '.data.repository.id'
96106
}
97107

98-
# Creates a child issue.
108+
# Creates a child issue with labels.
99109
#
100110
# $1 - repository node ID
101111
# $2 - issue body
@@ -108,11 +118,12 @@ create_child_issue() {
108118
-H "Content-Type: application/json" \
109119
--data @- << EOF
110120
{
111-
"query": "mutation CreateIssue(\$repositoryId: ID!, \$title: String!, \$body: String!) { createIssue(input: {repositoryId: \$repositoryId, title: \$title, body: \$body}) { issue { id number } } }",
121+
"query": "mutation CreateIssue(\$repositoryId: ID!, \$title: String!, \$body: String!, \$labelIds: [ID!]) { createIssue(input: {repositoryId: \$repositoryId, title: \$title, body: \$body, labelIds: \$labelIds}) { issue { id number } } }",
112122
"variables": {
113123
"repositoryId": "${repo_id}",
114124
"title": "${issue_title}",
115-
"body": $(echo "$issue_body" | jq -R -s '.')
125+
"body": $(echo "$issue_body" | jq -R -s '.'),
126+
"labelIds": ${label_array}
116127
}
117128
}
118129
EOF
@@ -140,6 +151,37 @@ EOF
140151
echo "$response" | jq -r '.data.repository.issue.id'
141152
}
142153

154+
# Fetches label IDs for given label names.
155+
fetch_label_ids() {
156+
if [ -z "$labels" ]; then
157+
echo "[]"
158+
return
159+
fi
160+
161+
local label_names="${labels//,/\",\"}"
162+
local response
163+
response=$(curl -s -X POST 'https://api.github.com/graphql' \
164+
-H "Authorization: bearer ${github_token}" \
165+
-H "Content-Type: application/json" \
166+
--data @- << EOF
167+
{
168+
"query": "query(\$owner: String!, \$repo: String!) { repository(owner: \$owner, name: \$repo) { labels(first: 100) { nodes { id name } } } }",
169+
"variables": {
170+
"owner": "${owner}",
171+
"repo": "${repo}"
172+
}
173+
}
174+
EOF
175+
)
176+
177+
# Extract and filter label IDs that match our requested labels...
178+
echo "$response" | jq --arg names "${label_names}" '
179+
.data.repository.labels.nodes |
180+
map(select(.name as $n | [$names] | contains([$n]))) |
181+
map(.id)
182+
'
183+
}
184+
143185
# Creates a sub-issue relationship.
144186
#
145187
# $1 - parent issue ID
@@ -175,6 +217,14 @@ main() {
175217
exit 1
176218
fi
177219

220+
if [ -n "$labels" ]; then
221+
echo "Fetching label IDs..."
222+
label_array=$(fetch_label_ids)
223+
if [ "$label_array" = "[]" ]; then
224+
echo -e "Warning: No valid labels found for the provided label names."
225+
fi
226+
fi
227+
178228
echo "Creating child issue..."
179229
child_issue_response=$(create_child_issue "$repo_id" "$issue_body")
180230

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 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+
# bternary5d
22+
23+
> 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.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var bternary5d = require( '@stdlib/array/base/broadcasted-ternary5d' );
37+
```
38+
39+
#### bternary5d( arrays, shapes, fcn )
40+
41+
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.
42+
43+
```javascript
44+
var add = require( '@stdlib/math/base/ops/add3' );
45+
var zeros5d = require( '@stdlib/array/base/zeros5d' );
46+
47+
var x = [ [ [ 1.0, 2.0 ] ] ];
48+
var y = [ [ [ 3.0 ], [ 4.0 ] ] ];
49+
var z = [ [ [ [ 4.0, 5.0 ] ], [ [ 4.0, 5.0 ] ] ] ];
50+
var out = zeros5d( [ 1, 1, 2, 2 ] );
51+
52+
var shapes = [
53+
[ 1, 1, 2 ],
54+
[ 1, 2, 1 ],
55+
[ 1, 2, 1, 2 ],
56+
[ 1, 1, 2, 2, 2 ]
57+
];
58+
59+
bternary5d( [ x, y, z, out ], shapes, add );
60+
// out => [ [ [ [ [ 8.0, 10.0 ], [ 9.0, 11.0 ] ], [ [ 8.0, 10.0 ], [ 9.0, 11.0 ] ] ] ] ]
61+
```
62+
63+
The function accepts the following arguments:
64+
65+
- **arrays**: array-like object containing three input nested arrays and one output nested array.
66+
- **shapes**: array shapes.
67+
- **fcn**: ternary function to apply.
68+
69+
</section>
70+
71+
<!-- /.usage -->
72+
73+
<section class="notes">
74+
75+
## Notes
76+
77+
- The input and output array shapes must be broadcast [compatible][@stdlib/ndarray/base/broadcast-shapes].
78+
79+
</section>
80+
81+
<!-- /.notes -->
82+
83+
<section class="examples">
84+
85+
## Examples
86+
87+
<!-- eslint no-undef: "error" -->
88+
89+
```javascript
90+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
91+
var filled5dBy = require( '@stdlib/array/base/filled5d-by' );
92+
var zeros5d = require( '@stdlib/array/base/zeros5d' );
93+
var add = require( '@stdlib/math/base/ops/add3' );
94+
var bternary5d = require( '@stdlib/array/base/broadcasted-ternary5d' );
95+
96+
var shapes = [
97+
[ 1, 1, 1, 1, 3 ],
98+
[ 1, 1, 3, 1, 1 ],
99+
[ 1, 1, 1, 3, 1 ],
100+
[ 1, 1, 3, 3, 3 ]
101+
];
102+
103+
var x = filled5dBy( shapes[ 0 ], discreteUniform( -100, 100 ) );
104+
console.log( x );
105+
106+
var y = filled5dBy( shapes[ 1 ], discreteUniform( -100, 100 ) );
107+
console.log( y );
108+
109+
var z = filled5dBy( shapes[ 2 ], discreteUniform( -100, 100 ) );
110+
console.log( z );
111+
112+
var out = zeros5d( shapes[ 3 ] );
113+
console.log( out );
114+
115+
bternary5d( [ x, y, z, out ], shapes, add );
116+
console.log( out );
117+
```
118+
119+
</section>
120+
121+
<!-- /.examples -->
122+
123+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
124+
125+
<section class="related">
126+
127+
</section>
128+
129+
<!-- /.related -->
130+
131+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
132+
133+
<section class="links">
134+
135+
[@stdlib/array/base/broadcast-array]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/broadcast-array
136+
137+
[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes
138+
139+
</section>
140+
141+
<!-- /.links -->
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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/add3' );
29+
var filled5dBy = require( '@stdlib/array/base/filled5d-by' );
30+
var zeros5d = require( '@stdlib/array/base/zeros5d' );
31+
var numel = require( '@stdlib/ndarray/base/numel' );
32+
var pkg = require( './../package.json' ).name;
33+
var bternary5d = require( './../lib' );
34+
35+
36+
// FUNCTIONS //
37+
38+
/**
39+
* Creates a benchmark function.
40+
*
41+
* @private
42+
* @param {PositiveIntegerArray} shape - output array shape
43+
* @returns {Function} benchmark function
44+
*/
45+
function createBenchmark( shape ) {
46+
var arrays;
47+
var shapes;
48+
var x;
49+
var y;
50+
var z;
51+
var w;
52+
53+
shapes = [
54+
[ shape[ 0 ], 1, 1, 1, 1 ],
55+
[ 1, 1, 1, 1, shape[ 1 ] ],
56+
[ 1, 1, shape[ 2 ], 1, 1 ],
57+
shape
58+
];
59+
x = filled5dBy( shapes[ 0 ], uniform( -100.0, 100.0 ) );
60+
y = filled5dBy( shapes[ 1 ], uniform( -100.0, 100.0 ) );
61+
z = filled5dBy( shapes[ 2 ], uniform( -100.0, 100.0 ) );
62+
w = zeros5d( shapes[ 3 ] );
63+
64+
arrays = [ x, y, z, w ];
65+
66+
return benchmark;
67+
68+
/**
69+
* Benchmark function.
70+
*
71+
* @private
72+
* @param {Benchmark} b - benchmark instance
73+
*/
74+
function benchmark( b ) {
75+
var i0;
76+
var i1;
77+
var i2;
78+
var i3;
79+
var i4;
80+
var i;
81+
82+
b.tic();
83+
for ( i = 0; i < b.iterations; i++ ) {
84+
bternary5d( arrays, shapes, add );
85+
i4 = i % shapes[ 1 ][ 0 ];
86+
i3 = i % shapes[ 1 ][ 1 ];
87+
i2 = i % shapes[ 1 ][ 2 ];
88+
i1 = i % shapes[ 1 ][ 3 ];
89+
i0 = i % shapes[ 1 ][ 4 ];
90+
if ( isnan( arrays[ 3 ][ i4 ][ i3 ][ i2 ][ i1 ][ i0 ] ) ) {
91+
b.fail( 'should not return NaN' );
92+
}
93+
}
94+
b.toc();
95+
96+
i4 = i % shapes[ 1 ][ 0 ];
97+
i3 = i % shapes[ 1 ][ 1 ];
98+
i2 = i % shapes[ 1 ][ 2 ];
99+
i1 = i % shapes[ 1 ][ 3 ];
100+
i0 = i % shapes[ 1 ][ 4 ];
101+
if ( isnan(arrays[ 3 ][ i4 ][ i3 ][ i2 ][ i1 ][ i0 ] ) ) {
102+
b.fail( 'should not return NaN' );
103+
}
104+
b.pass( 'benchmark finished' );
105+
b.end();
106+
}
107+
}
108+
109+
110+
// MAIN //
111+
112+
/**
113+
* Main execution sequence.
114+
*
115+
* @private
116+
*/
117+
function main() {
118+
var min;
119+
var max;
120+
var sh;
121+
var N;
122+
var f;
123+
var i;
124+
125+
min = 1; // 10^min
126+
max = 6; // 10^max
127+
128+
for ( i = min; i <= max; i++ ) {
129+
N = floor( pow( pow( 10, i ), 1.0 / 5.0 ) );
130+
sh = [ N, N, N, N, N ];
131+
f = createBenchmark( sh );
132+
bench( pkg + '::equidimensional:size=' + numel( sh ), f );
133+
}
134+
}
135+
136+
main();

0 commit comments

Comments
 (0)