Skip to content

Commit 12f78ee

Browse files
committed
Auto-generated commit
1 parent 816cef9 commit 12f78ee

File tree

11 files changed

+930
-0
lines changed

11 files changed

+930
-0
lines changed

CHANGELOG.md

+23
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,28 @@
193193

194194
<!-- /.package -->
195195

196+
<section class="package" id="array-base-banded-to-compact-unreleased">
197+
198+
#### [@stdlib/array/base/banded/to-compact](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/banded/to-compact)
199+
200+
<details>
201+
202+
<section class="features">
203+
204+
##### Features
205+
206+
- [`ef1d278`](https://github.com/stdlib-js/stdlib/commit/ef1d278f2a382993d2cc63f83458778593767708) - add `array/base/banded/to-compact`
207+
208+
</section>
209+
210+
<!-- /.features -->
211+
212+
</details>
213+
214+
</section>
215+
216+
<!-- /.package -->
217+
196218
<section class="package" id="array-base-broadcasted-quaternary3d-unreleased">
197219

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

12401262
<details>
12411263

1264+
- [`ef1d278`](https://github.com/stdlib-js/stdlib/commit/ef1d278f2a382993d2cc63f83458778593767708) - **feat:** add `array/base/banded/to-compact` _(by Athan Reines)_
12421265
- [`f9bb0d7`](https://github.com/stdlib-js/stdlib/commit/f9bb0d77a4ce5ad813c371f5d49d2cee7476b775) - **feat:** add `array/base/symmetric-banded/to-compact` _(by Athan Reines)_
12431266
- [`1bb5ea9`](https://github.com/stdlib-js/stdlib/commit/1bb5ea9e19c1d89b1cb7504d8e369b7fea02e94d) - **test:** add test cases _(by Athan Reines)_
12441267
- [`6f20f70`](https://github.com/stdlib-js/stdlib/commit/6f20f707c3a94f5fb14b55144f52d2c1aa540c9f) - **feat:** add `array/base/banded/filled2d-by` _(by Athan Reines)_

base/banded/to-compact/README.md

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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+
# toCompact
22+
23+
> Convert a two-dimensional banded nested array to compact banded storage.
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 toCompact = require( '@stdlib/array/base/banded/to-compact' );
41+
```
42+
43+
#### toCompact( arr, ku, kl, colexicographic )
44+
45+
Converts a two-dimensional banded nested array to compact banded storage.
46+
47+
```javascript
48+
var x = [ [ -1, 2, 0 ], [ 2, -2, 4 ], [ 0, 4, -3 ] ];
49+
50+
var out = toCompact( x, 1, 1, false );
51+
// returns [ [ 0, 2, 4 ], [ -1, -2, -3 ], [ 2, 4, 0 ] ]
52+
```
53+
54+
The function accepts the following arguments:
55+
56+
- **arr**: input two-dimensional nested array.
57+
- **ku**: number of super-diagonals.
58+
- **kl**: number of sub-diagonals.
59+
- **colexicographic**: boolean specifying whether to store diagonals in colexicographic access order.
60+
61+
</section>
62+
63+
<!-- /.usage -->
64+
65+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
66+
67+
<section class="notes">
68+
69+
</section>
70+
71+
<!-- /.notes -->
72+
73+
<!-- Package usage examples. -->
74+
75+
<section class="examples">
76+
77+
## Examples
78+
79+
<!-- eslint-disable no-multi-spaces -->
80+
81+
<!-- eslint no-undef: "error" -->
82+
83+
```javascript
84+
var toCompact = require( '@stdlib/array/base/banded/to-compact' );
85+
86+
// Define a banded matrix:
87+
var A = [
88+
[ 1, 2, 3, 0, 0 ],
89+
[ -2, 4, 5, 6, 0 ],
90+
[ -3, -5, 7, 8, 9 ],
91+
[ 0, -6, -8, 10, 11 ],
92+
[ 0, 0, -9, -11, 12 ]
93+
];
94+
95+
// Convert the matrix to lexicographic compact form:
96+
var AC = toCompact( A, 2, 2, false );
97+
/* e.g., returns =>
98+
[
99+
[ 0, 0, 3, 6, 9 ],
100+
[ 0, 2, 5, 8, 11 ],
101+
[ 1, 4, 7, 10, 12 ],
102+
[ -2, -5, -8, -11, 0 ],
103+
[ -3, -6, -9, 0, 0 ]
104+
]
105+
*/
106+
107+
AC = toCompact( A, 2, 1, false );
108+
/* e.g., returns =>
109+
[
110+
[ 0, 0, 3, 6, 9 ],
111+
[ 0, 2, 5, 8, 11 ],
112+
[ 1, 4, 7, 10, 12 ],
113+
[ -2, -5, -8, -11, 0 ]
114+
]
115+
*/
116+
117+
AC = toCompact( A, 1, 2, false );
118+
/* e.g., returns =>
119+
[
120+
[ 0, 2, 5, 8, 11 ],
121+
[ 1, 4, 7, 10, 12 ],
122+
[ -2, -5, -8, -11, 0 ],
123+
[ -3, -6, -9, 0, 0 ]
124+
]
125+
*/
126+
127+
// Convert the matrix to colexicographic compact form:
128+
AC = toCompact( A, 2, 2, true );
129+
/* e.g., returns =>
130+
[
131+
[ 0, 0, 1, -2, -3 ],
132+
[ 0, 2, 4, -5, -6 ],
133+
[ 3, 5, 7, -8, -9 ],
134+
[ 6, 8, 10, -11, 0 ],
135+
[ 9, 11, 12, 0, 0 ]
136+
]
137+
*/
138+
```
139+
140+
</section>
141+
142+
<!-- /.examples -->
143+
144+
<!-- 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. -->
145+
146+
<section class="references">
147+
148+
</section>
149+
150+
<!-- /.references -->
151+
152+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
153+
154+
<section class="related">
155+
156+
</section>
157+
158+
<!-- /.related -->
159+
160+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
161+
162+
<section class="links">
163+
164+
</section>
165+
166+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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 filled2dBy = require( './../../../../base/banded/filled2d-by' );
30+
var format = require( '@stdlib/string/format' );
31+
var pkg = require( './../package.json' ).name;
32+
var toCompact = require( './../lib' );
33+
34+
35+
// VARIABLES //
36+
37+
var orders = [
38+
true,
39+
false
40+
];
41+
42+
43+
// FUNCTIONS //
44+
45+
/**
46+
* Creates a benchmark function.
47+
*
48+
* @private
49+
* @param {PositiveInteger} N - array lengths
50+
* @param {boolean} colexicographic - boolean indicating whether to store diagonals in colexicographic access order
51+
* @param {NonNegativeInteger} k - number of super-/sub-diagonals
52+
* @returns {Function} benchmark function
53+
*/
54+
function createBenchmark( N, colexicographic, k ) {
55+
var x = filled2dBy( [ N, N ], k, k, 0, constantFunction( N ) );
56+
return benchmark;
57+
58+
/**
59+
* Benchmark function.
60+
*
61+
* @private
62+
* @param {Benchmark} b - benchmark instance
63+
*/
64+
function benchmark( b ) {
65+
var out;
66+
var i;
67+
68+
b.tic();
69+
for ( i = 0; i < b.iterations; i++ ) {
70+
out = toCompact( x, k, k, colexicographic );
71+
if ( typeof out !== 'object' ) {
72+
b.fail( 'should return an array of arrays' );
73+
}
74+
}
75+
b.toc();
76+
if ( !isArrayArray( out ) ) {
77+
b.fail( 'should return an array of arrays' );
78+
}
79+
b.pass( 'benchmark finished' );
80+
b.end();
81+
}
82+
}
83+
84+
85+
// MAIN //
86+
87+
/**
88+
* Main execution sequence.
89+
*
90+
* @private
91+
*/
92+
function main() {
93+
var min;
94+
var max;
95+
var N;
96+
var f;
97+
var i;
98+
var o;
99+
var k;
100+
101+
min = 1; // 10^min
102+
max = 6; // 10^max
103+
104+
k = 1;
105+
for ( o = 0; o < orders.length; o++ ) {
106+
for ( i = min; i <= max; i++ ) {
107+
N = floor( sqrt( pow( 10, i ) ) );
108+
109+
f = createBenchmark( N, orders[ o ], k );
110+
bench( format( '%s:colexicographic=%s,ku=%d,kl=%d,size=%d', pkg, orders[ o ], k, k, N*N ), f );
111+
}
112+
}
113+
}
114+
115+
main();

base/banded/to-compact/docs/repl.txt

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
{{alias}}( arr, ku, kl, colexicographic )
3+
Converts a two-dimensional banded nested array to compact banded storage.
4+
5+
Parameters
6+
----------
7+
arr: Array<Array>
8+
Input array.
9+
10+
ku: integer
11+
Number of super-diagonals.
12+
13+
kl: integer
14+
Number of sub-diagonals.
15+
16+
colexicographic: boolean
17+
Specifies whether to store diagonals in colexicographic access order.
18+
19+
Returns
20+
-------
21+
out: Array
22+
Output array.
23+
24+
Examples
25+
--------
26+
> var x = [ [ -1, 2, 0 ], [ 2, -3, 4 ], [ 0, 4, -5 ] ];
27+
> var out = {{alias}}( x, 1, 1, false )
28+
[ [ 0, 2, 4 ], [ -1, -3, -5 ], [ 2, 4, 0 ] ]
29+
30+
See Also
31+
--------
32+

0 commit comments

Comments
 (0)