Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/node_modules/@stdlib/array/base/banded/to-compact/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ AC = toCompact( A, 1, 2, false );
AC = toCompact( A, 2, 2, true );
/* e.g., returns =>
[
[ 0, 0, 1, -2, -3 ],
[ 0, 2, 4, -5, -6 ],
[ 3, 5, 7, -8, -9 ],
[ 6, 8, 10, -11, 0 ],
[ 9, 11, 12, 0, 0 ]
[ 0, 0, 1, 2, 3 ],
[ 0, -2, 4, 5, 6 ],
[ -3, -5, 7, 8, 9 ],
[ -6, -8, 10, 11, 0 ],
[ -9, -11, 12, 0, 0 ]
]
*/
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@

/// <reference types="@stdlib/types"/>

import { Collection } from '@stdlib/types/array';

/**
* Two-dimensional nested array.
*/
type Array2D<T> = Array<Collection<T>>;
type Array2D<T> = Array<Array<T>>;

/**
* Converts a two-dimensional banded nested array to compact banded storage.
Expand Down Expand Up @@ -54,9 +52,9 @@ type Array2D<T> = Array<Collection<T>>;
* ];
*
* var out = toCompact( M, 1, 1, true );
* // returns [ [ 0, 11, 3 ], [ 2, 12, 5 ], [ 4, 13, 0 ] ]
* // returns [ [ 0, 11, 2 ], [ 3, 12, 4 ], [ 5, 13, 0 ] ]
*/
declare function toCompact<T = unknown>( arr: Array2D<T>, ku: number, kl: number, colexicographic: boolean ): Array2D<T>;
declare function toCompact<T>( arr: Array2D<T>, ku: number, kl: number, colexicographic: boolean ): Array2D<T>;


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ AC = toCompact( A, 2, 2, true );
console.log( AC );
/* e.g., =>
[
[ 0, 0, 1, -2, -3 ],
[ 0, 2, 4, -5, -6 ],
[ 3, 5, 7, -8, -9 ],
[ 6, 8, 10, -11, 0 ],
[ 9, 11, 12, 0, 0 ]
[ 0, 0, 1, 2, 3 ],
[ 0, -2, 4, 5, 6 ],
[ -3, -5, 7, 8, 9 ],
[ -6, -8, 10, 11, 0 ],
[ -9, -11, 12, 0, 0 ]
]
*/
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* ];
*
* var out = toCompact( M, 1, 1, true );
* // returns [ [ 0, 11, 3 ], [ 2, 12, 5 ], [ 4, 13, 0 ] ]
* // returns [ [ 0, 11, 2 ], [ 3, 12, 4 ], [ 5, 13, 0 ] ]
*/

// MODULES //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ var zeros2d = require( '@stdlib/array/base/zeros2d' );
* ];
*
* var out = toCompact( M, 1, 1, true );
* // returns [ [ 0, 11, 3 ], [ 2, 12, 5 ], [ 4, 13, 0 ] ]
* // returns [ [ 0, 11, 2 ], [ 3, 12, 4 ], [ 5, 13, 0 ] ]
*/
function toCompact( arr, ku, kl, colexicographic ) {
var out;
var to;
var M;
var N;
var i;
Expand All @@ -70,12 +69,11 @@ function toCompact( arr, ku, kl, colexicographic ) {

// Check whether to store diagonals along the columns...
if ( colexicographic ) {
out = zeros2d( [ N, ku+kl+1 ] );
for ( j = 0; j < N; j++ ) {
to = out[ j ];
k = ku - j;
for ( i = max( 0, j-ku ); i < min( M, j+kl+1 ); i++ ) {
to[ k+i ] = arr[ i ][ j ];
out = zeros2d( [ M, ku+kl+1 ] );
for ( j = 0; j < M; j++ ) {
k = kl - j;
for ( i = max( 0, j-kl ); i < min( N, j+ku+1 ); i++ ) {
out[ j ][ i+k ] = arr[ j ][ i ];
}
}
return out;
Expand Down
30 changes: 15 additions & 15 deletions lib/node_modules/@stdlib/array/base/banded/to-compact/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ tape( 'the function converts a banded nested array to compact banded storage ( c
];

expected = [
[ 0, 0, 1, -2, -3 ],
[ 0, 2, 4, -5, -6 ],
[ 3, 5, 7, -8, -9 ],
[ 6, 8, 10, -11, 0 ],
[ 9, 11, 12, 0, 0 ]
[ 0, 0, 1, 2, 3 ],
[ 0, -2, 4, 5, 6 ],
[ -3, -5, 7, 8, 9 ],
[ -6, -8, 10, 11, 0 ],
[ -9, -11, 12, 0, 0 ]
];
actual = toCompact( arr, 2, 2, true );
t.deepEqual( actual, expected, 'returns expected value' );
Expand All @@ -114,21 +114,21 @@ tape( 'the function converts a banded nested array to compact banded storage ( c
t.deepEqual( actual, expected, 'returns expected value' );

expected = [
[ 0, 1 ],
[ 2, 4 ],
[ 5, 7 ],
[ 8, 10 ],
[ 11, 12 ]
[ 1, 2 ],
[ 4, 5 ],
[ 7, 8 ],
[ 10, 11 ],
[ 12, 0 ]
];
actual = toCompact( arr, 1, 0, true );
t.deepEqual( actual, expected, 'returns expected value' );

expected = [
[ 1, -2, -3 ],
[ 4, -5, -6 ],
[ 7, -8, -9 ],
[ 10, -11, 0 ],
[ 12, 0, 0 ]
[ 0, 0, 1 ],
[ 0, -2, 4 ],
[ -3, -5, 7 ],
[ -6, -8, 10 ],
[ -9, -11, 12 ]
];
actual = toCompact( arr, 0, 2, true );
t.deepEqual( actual, expected, 'returns expected value' );
Expand Down
Loading