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
341 changes: 341 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dgbequ/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,341 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# dgbequ

> Compute row and column scale factors intended to equilibrate an M-by-N band matrix `A` and reduce its condition number.

<section class="intro">

The band matrix `A`, having `KL` subdiagonals and `KU` superdiagonals, is stored in a band array `AB` having `KL+KU+1` rows and `N` columns, such that the element `A(i,j)` is stored in row `KU+i-j` and column `j` of `AB` (zero-based), for `max(0,j-KU) <= i <= min(M-1,j+KL)`. For example, for a 4-by-4 matrix with `KL = 1` and `KU = 2`,

```text
A = [ AB = [
[ a00, a01, a02, 0 ], [ *, *, a02, a13 ],
[ a10, a11, a12, a13 ], => [ *, a01, a12, a23 ],
[ 0, a21, a22, a23 ], [ a00, a11, a22, a33 ],
[ 0, 0, a32, a33 ] [ a10, a21, a32, * ]
] ]
```

where `*` denotes an element which is not referenced. In column-major order, element `(b,j)` of `AB` is `AB[b+j*LDAB]`; in row-major order, it is `AB[b*LDAB+j]`.

The computed scale factors `R` and `C` are chosen such that each element of the scaled matrix `B(i,j) = R(i)*A(i,j)*C(j)` has an absolute value of at most one, and each row and column of `B` has at least one element with an absolute value of one (barring underflow and overflow).

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var dgbequ = require( '@stdlib/lapack/base/dgbequ' );
```

#### dgbequ( order, M, N, KL, KU, AB, LDAB, R, C, out )

Computes row and column scale factors intended to equilibrate an M-by-N band matrix `A` and reduce its condition number.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

/*
A = [
[ 1.0, 2.0, 0.0 ],
[ 3.0, 4.0, 5.0 ],
[ 0.0, 6.0, 8.0 ]
]
*/

// Store the band of `A` (KL = 1, KU = 1) as a column-major band array:
var AB = new Float64Array( [ 0.0, 1.0, 3.0, 2.0, 4.0, 6.0, 5.0, 8.0, 0.0 ] );
var R = new Float64Array( 3 );
var C = new Float64Array( 3 );
var out = new Float64Array( 3 );

var info = dgbequ( 'column-major', 3, 3, 1, 1, AB, 3, R, C, out );
// returns 0

console.log( R );
// => <Float64Array>[ 0.5, 0.2, 0.125 ]

console.log( C );
// => <Float64Array>[ ~1.67, 1.0, 1.0 ]

console.log( out );
// => <Float64Array>[ 0.25, ~0.6, 8.0 ]
```

The function has the following parameters:

- **order**: storage layout of the band array `AB` (either `'row-major'` or `'column-major'`).
- **M**: number of rows in `A`.
- **N**: number of columns in `A`.
- **KL**: number of subdiagonals within the band of `A`.
- **KU**: number of superdiagonals within the band of `A`.
- **AB**: band array as a [`Float64Array`][mdn-float64array], having `KL+KU+1` rows and `N` columns.
- **LDAB**: leading dimension of the band array `AB`. Must be greater than or equal to `KL+KU+1` when `order` is `'column-major'` and greater than or equal to `max(1,N)` when `order` is `'row-major'`.
- **R**: output vector for the row scale factors as a [`Float64Array`][mdn-float64array] having `M` indexed elements.
- **C**: output vector for the column scale factors as a [`Float64Array`][mdn-float64array] having `N` indexed elements.
- **out**: three element output [`Float64Array`][mdn-float64array] whose elements are set to `[ ROWCND, COLCND, AMAX ]`.

The elements of `out` are

- **ROWCND**: ratio of the smallest `R[i]` to the largest `R[i]`.
- **COLCND**: ratio of the smallest `C[j]` to the largest `C[j]`.
- **AMAX**: absolute value of the largest element of `A`.

The function returns a status code. If `0`, the scale factors were successfully computed. If `> 0` and `<= M`, the `info`-th row of `A` is exactly zero; if `> M`, the `(info-M)`-th column of `A` is exactly zero. The status code uses one-based indexing to match the LAPACK convention, so the corresponding zero-based JavaScript index is `info-1` for a zero row and `info-M-1` for a zero column.

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

<!-- eslint-disable stdlib/capitalized-comments, max-len -->

```javascript
var Float64Array = require( '@stdlib/array/float64' );

// Initial array...
var AB0 = new Float64Array( [ 0.0, 0.0, 1.0, 3.0, 2.0, 4.0, 6.0, 5.0, 8.0, 0.0 ] );

// Create an offset view...
var AB = new Float64Array( AB0.buffer, AB0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

var R = new Float64Array( 3 );
var C = new Float64Array( 3 );
var out = new Float64Array( 3 );

var info = dgbequ( 'column-major', 3, 3, 1, 1, AB, 3, R, C, out );
// returns 0

console.log( out );
// => <Float64Array>[ 0.25, ~0.6, 8.0 ]
```

<!-- lint disable maximum-heading-length -->

#### dgbequ.ndarray( M, N, KL, KU, AB, sab1, sab2, oab, R, sr, or, C, sc, oc, out, so, oo )

Computes row and column scale factors intended to equilibrate an M-by-N band matrix `A` and reduce its condition number using alternative indexing semantics.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var AB = new Float64Array( [ 0.0, 1.0, 3.0, 2.0, 4.0, 6.0, 5.0, 8.0, 0.0 ] );
var R = new Float64Array( 3 );
var C = new Float64Array( 3 );
var out = new Float64Array( 3 );

var info = dgbequ.ndarray( 3, 3, 1, 1, AB, 1, 3, 0, R, 1, 0, C, 1, 0, out, 1, 0 );
// returns 0

console.log( out );
// => <Float64Array>[ 0.25, ~0.6, 8.0 ]
```

The function has the following additional parameters:

- **sab1**: stride of the first dimension of `AB` (i.e., between band rows).
- **sab2**: stride of the second dimension of `AB` (i.e., between columns).
- **oab**: starting index for `AB`.
- **sr**: stride length for `R`.
- **or**: starting index for `R`.
- **sc**: stride length for `C`.
- **oc**: starting index for `C`.
- **so**: stride length for `out`.
- **oo**: starting index for `out`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example,

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var AB = new Float64Array( [ 0.0, 0.0, 1.0, 3.0, 2.0, 4.0, 6.0, 5.0, 8.0, 0.0 ] );
var R = new Float64Array( 3 );
var C = new Float64Array( 3 );
var out = new Float64Array( 3 );

var info = dgbequ.ndarray( 3, 3, 1, 1, AB, 1, 3, 1, R, 1, 0, C, 1, 0, out, 1, 0 );
// returns 0

console.log( R );
// => <Float64Array>[ 0.5, 0.2, 0.125 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- Both functions mutate the output arrays `R`, `C`, and `out`. The band array `AB` is not modified.
- If the status code is `0`, `R`, `C`, and all three elements of `out` contain valid values. If the status code is greater than `M`, `R`, `ROWCND`, and `AMAX` contain valid values, but `C` and `COLCND` do not. If the status code is greater than `0` and less than or equal to `M`, only `AMAX` contains a valid value. Elements which do not contain valid values are left unmodified, matching the LAPACK reference implementation.
- When the status code is greater than `0` and less than or equal to `M`, the routine exits before scaling, and `R` holds the maximum absolute value of each row, prior to inversion. When the status code is greater than `M`, `C` holds the maximum absolute value of each column, as scaled by `R` and prior to inversion.
- Row and column maxima are clamped to the interval `[smlnum, bignum]` before being inverted, where `smlnum` is the smallest normal double-precision number and `bignum` is its reciprocal. Accordingly, scale factors neither overflow to infinity nor underflow to zero, and `ROWCND` may exceed `1` when every row maximum is subnormal.
- Only the elements of `AB` within the band are referenced. `KL` and `KU` may exceed the matrix dimensions.
- `dgbequ()` corresponds to the [LAPACK][lapack] routine [`dgbequ`][lapack-dgbequ].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint-disable max-len -->

<!-- eslint no-undef: "error" -->

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var dgbequ = require( '@stdlib/lapack/base/dgbequ' );

/*
Tridiagonal matrix (KL = 1, KU = 1) whose rows differ greatly in scale:

A = [
[ 2.0, 1.0, 0.0, 0.0 ],
[ 10.0, 40.0, 20.0, 0.0 ],
[ 0.0, 100.0, 400.0, 300.0 ],
[ 0.0, 0.0, 3000.0, 4000.0 ]
]
*/

// Store the band of `A` as a column-major band array:
var AB = new Float64Array( [ 0.0, 2.0, 10.0, 1.0, 40.0, 100.0, 20.0, 400.0, 3000.0, 300.0, 4000.0, 0.0 ] );
var R = new Float64Array( 4 );
var C = new Float64Array( 4 );
var out = new Float64Array( 3 );

var info = dgbequ( 'column-major', 4, 4, 1, 1, AB, 3, R, C, out );
console.log( info );
// => 0

console.log( R );
// => <Float64Array>[ 0.5, 0.025, 0.0025, 0.00025 ]

console.log( C );
// => <Float64Array>[ 1.0, 1.0, 1.0, 1.0 ]

console.log( out );
// => <Float64Array>[ 0.0005, 1.0, 4000.0 ]
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
TODO
```

#### TODO

TODO.

```c
TODO
```

TODO

```c
TODO
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
TODO
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[lapack]: https://www.netlib.org/lapack/explore-html/

[lapack-dgbequ]: https://github.com/Reference-LAPACK/lapack/blob/master/SRC/dgbequ.f

[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

</section>

<!-- /.links -->
Loading