Skip to content

Commit 4999761

Browse files
committed
Auto-generated commit
1 parent 2b0a902 commit 4999761

File tree

11 files changed

+953
-0
lines changed

11 files changed

+953
-0
lines changed

CHANGELOG.md

+24
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,28 @@
171171

172172
<!-- /.package -->
173173

174+
<section class="package" id="array-base-banded-filled2d-by-unreleased">
175+
176+
#### [@stdlib/array/base/banded/filled2d-by](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/banded/filled2d-by)
177+
178+
<details>
179+
180+
<section class="features">
181+
182+
##### Features
183+
184+
- [`6f20f70`](https://github.com/stdlib-js/stdlib/commit/6f20f707c3a94f5fb14b55144f52d2c1aa540c9f) - add `array/base/banded/filled2d-by`
185+
186+
</section>
187+
188+
<!-- /.features -->
189+
190+
</details>
191+
192+
</section>
193+
194+
<!-- /.package -->
195+
174196
<section class="package" id="array-base-broadcasted-quaternary3d-unreleased">
175197

176198
#### [@stdlib/array/base/broadcasted-quaternary3d](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/broadcasted-quaternary3d)
@@ -1195,6 +1217,8 @@ A total of 13 people contributed to this release. Thank you to the following con
11951217

11961218
<details>
11971219

1220+
- [`1bb5ea9`](https://github.com/stdlib-js/stdlib/commit/1bb5ea9e19c1d89b1cb7504d8e369b7fea02e94d) - **test:** add test cases _(by Athan Reines)_
1221+
- [`6f20f70`](https://github.com/stdlib-js/stdlib/commit/6f20f707c3a94f5fb14b55144f52d2c1aa540c9f) - **feat:** add `array/base/banded/filled2d-by` _(by Athan Reines)_
11981222
- [`8e00e52`](https://github.com/stdlib-js/stdlib/commit/8e00e52bed8c7b4fec42c468bd021815a417b988) - **bench:** parameterize `k` _(by Athan Reines)_
11991223
- [`41a2534`](https://github.com/stdlib-js/stdlib/commit/41a2534c6dd345a0dc73365826919ccbf1e9eca7) - **feat:** add `array/base/symmetric-banded/filled2d-by` _(by Athan Reines)_
12001224
- [`052b810`](https://github.com/stdlib-js/stdlib/commit/052b81032b766464a079bc88cc676e38dac0c35a) - **feat:** add `array/base/symmetric/filled2d-by` _(by Athan Reines)_

base/banded/filled2d-by/README.md

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# filled2dBy
22+
23+
> Create a filled two-dimensional banded nested array according to a provided callback function.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var filled2dBy = require( '@stdlib/array/base/banded/filled2d-by' );
41+
```
42+
43+
#### filled2dBy( shape, ku, kl, fill, clbk\[, thisArg] )
44+
45+
Returns a filled two-dimensional banded nested array according to a provided callback function.
46+
47+
```javascript
48+
function clbk( idx ) {
49+
return idx[ 0 ] + idx[ 1 ];
50+
}
51+
52+
var out = filled2dBy( [ 3, 3 ], 1, 1, 0, clbk );
53+
// returns [ [ 0, 1, 0 ], [ 1, 2, 3 ], [ 0, 3, 4 ] ]
54+
```
55+
56+
The function accepts the following arguments:
57+
58+
- **shape**: array shape.
59+
- **ku**: number of super-diagonals.
60+
- **kl**: number of sub-diagonals.
61+
- **fill**: fill value for elements outside the band.
62+
- **clbk**: callback function.
63+
- **thisArg**: callback function execution context (_optional_).
64+
65+
When invoked, a callback function is provided a single argument:
66+
67+
- **indices**: current array element indices.
68+
69+
To set the callback execution context, provide a `thisArg`.
70+
71+
<!-- eslint-disable no-invalid-this -->
72+
73+
```javascript
74+
function clbk() {
75+
this.count += 1;
76+
return 1;
77+
}
78+
79+
var ctx = {
80+
'count': 0
81+
};
82+
83+
var out = filled2dBy( [ 2, 2 ], 1, 0, 0, clbk, ctx );
84+
// returns [ [ 1, 1 ], [ 0, 1 ] ];
85+
86+
var cnt = ctx.count;
87+
// returns 3
88+
```
89+
90+
</section>
91+
92+
<!-- /.usage -->
93+
94+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
95+
96+
<section class="notes">
97+
98+
## Notes
99+
100+
- As the output array is banded, the callback function is only invoked for the elements residing within the band.
101+
102+
</section>
103+
104+
<!-- /.notes -->
105+
106+
<!-- Package usage examples. -->
107+
108+
<section class="examples">
109+
110+
## Examples
111+
112+
<!-- eslint no-undef: "error" -->
113+
114+
```javascript
115+
var constantFunction = require( '@stdlib/utils/constant-function' );
116+
var filled2dBy = require( '@stdlib/array/base/banded/filled2d-by' );
117+
118+
function clbk( indices ) {
119+
return indices[ 0 ] + indices[ 1 ];
120+
}
121+
122+
var out = filled2dBy( [ 4, 4 ], 1, 1, 0, clbk );
123+
// returns [ [ 0, 1, 0, 0 ], [ 1, 2, 3, 0 ], [ 0, 3, 4, 5 ], [ 0, 0, 5, 6 ] ]
124+
125+
out = filled2dBy( [ 3, 3 ], 1, 0, null, constantFunction( 'beep' ) );
126+
// returns [ [ 'beep', 'beep', null ], [ null, 'beep', 'beep' ], [ null, null, 'beep' ] ]
127+
```
128+
129+
</section>
130+
131+
<!-- /.examples -->
132+
133+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
134+
135+
<section class="references">
136+
137+
</section>
138+
139+
<!-- /.references -->
140+
141+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
142+
143+
<section class="related">
144+
145+
</section>
146+
147+
<!-- /.related -->
148+
149+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
150+
151+
<section class="links">
152+
153+
</section>
154+
155+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pow = require( '@stdlib/math/base/special/pow' );
25+
var floor = require( '@stdlib/math/base/special/floor' );
26+
var sqrt = require( '@stdlib/math/base/special/sqrt' );
27+
var isArrayArray = require( '@stdlib/assert/is-array-array' );
28+
var constantFunction = require( '@stdlib/utils/constant-function' );
29+
var pkg = require( './../package.json' ).name;
30+
var filled2dBy = require( './../lib' );
31+
32+
33+
// FUNCTIONS //
34+
35+
/**
36+
* Creates a benchmark function.
37+
*
38+
* @private
39+
* @param {PositiveInteger} N - array lengths
40+
* @param {NonNegativeInteger} ku - number of super-diagonals
41+
* @param {NonNegativeInteger} kl - number of sub-diagonals
42+
* @returns {Function} benchmark function
43+
*/
44+
function createBenchmark( N, ku, kl ) {
45+
return benchmark;
46+
47+
/**
48+
* Benchmark function.
49+
*
50+
* @private
51+
* @param {Benchmark} b - benchmark instance
52+
*/
53+
function benchmark( b ) {
54+
var out;
55+
var f;
56+
var i;
57+
58+
f = constantFunction( N );
59+
60+
b.tic();
61+
for ( i = 0; i < b.iterations; i++ ) {
62+
out = filled2dBy( [ N, N ], ku, kl, 0, f );
63+
if ( typeof out !== 'object' ) {
64+
b.fail( 'should return an array of arrays' );
65+
}
66+
}
67+
b.toc();
68+
if ( !isArrayArray( out ) ) {
69+
b.fail( 'should return an array of arrays' );
70+
}
71+
b.pass( 'benchmark finished' );
72+
b.end();
73+
}
74+
}
75+
76+
77+
// MAIN //
78+
79+
/**
80+
* Main execution sequence.
81+
*
82+
* @private
83+
*/
84+
function main() {
85+
var min;
86+
var max;
87+
var N;
88+
var f;
89+
var i;
90+
var k;
91+
92+
min = 1; // 10^min
93+
max = 6; // 10^max
94+
95+
k = 1;
96+
for ( i = min; i <= max; i++ ) {
97+
N = floor( sqrt( pow( 10, i ) ) );
98+
99+
f = createBenchmark( N, k );
100+
bench( pkg+':ku='+k+',kl='+k+',size='+(N*N), f );
101+
}
102+
}
103+
104+
main();

base/banded/filled2d-by/docs/repl.txt

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
{{alias}}( shape, ku, kl, fill, clbk[, thisArg] )
3+
Returns a filled two-dimensional banded nested array according to a provided
4+
callback function.
5+
6+
The callback function is provided one argument:
7+
8+
- indices: current array element indices.
9+
10+
As the output array is banded, the provided callback is only invoked for
11+
elements within the band.
12+
13+
Parameters
14+
----------
15+
shape: Array<integer>
16+
Array shape.
17+
18+
ku: integer
19+
Number of super-diagonals.
20+
21+
kl: integer
22+
Number of sub-diagonals.
23+
24+
fill: any
25+
Fill value for elements outside the band.
26+
27+
clbk: Function
28+
Callback function.
29+
30+
thisArg: any (optional)
31+
Callback execution context.
32+
33+
Returns
34+
-------
35+
out: Array
36+
Output array.
37+
38+
Examples
39+
--------
40+
> function clbk( idx ) { return idx[ 0 ] + idx[ 1 ]; };
41+
> var out = {{alias}}( [ 3, 3 ], 1, 1, 0, clbk )
42+
[ [ 0, 1, 0 ], [ 1, 2, 3 ], [ 0, 3, 4 ] ]
43+
44+
See Also
45+
--------
46+

0 commit comments

Comments
 (0)