Skip to content

feat: add lapack/base/dgebal #6989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 43 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
191fc91
feat: add base implementation
aayush0325 May 12, 2025
08cc97d
feat: add main export
aayush0325 May 12, 2025
3a12298
test: add initial tests
aayush0325 May 12, 2025
080ed50
test: add P job test
aayush0325 May 12, 2025
02f5d2d
test: add test for S job
aayush0325 May 12, 2025
0b4af09
test: add test for job = B
aayush0325 May 12, 2025
aeaff94
test: add ndarray tests
aayush0325 May 12, 2025
03a6986
chore: cleanup
aayush0325 May 12, 2025
5f956b0
test: add tests for empty submatrix
aayush0325 May 13, 2025
4ab0380
test: add more tests
aayush0325 May 13, 2025
8192ae8
test: add test for norm = 0
aayush0325 May 13, 2025
f70eec0
test: add test for small values
aayush0325 May 13, 2025
c9ded98
refactor: update job names
aayush0325 May 13, 2025
2c45388
test: add tests with weird values
aayush0325 May 13, 2025
6d755ca
test: add ndarray tests
aayush0325 May 13, 2025
91366cd
test: add some tests
aayush0325 May 14, 2025
ecf4a87
test: more negative stride tests
aayush0325 May 14, 2025
91d0ec8
test: add tests for negative strides
aayush0325 May 14, 2025
7631cba
chore: clean up
aayush0325 May 14, 2025
7030f4d
test: add offset tests
aayush0325 May 15, 2025
f6fcf1d
test: add tests for mixed strides
aayush0325 May 15, 2025
f6054c2
test: add tests for large strides
aayush0325 May 15, 2025
099194a
docs: add examples
aayush0325 May 15, 2025
2ca9245
bench: add benchmarks and cleanup
aayush0325 May 16, 2025
a69fa0b
fix: out should be an int32array because it contains indices
aayush0325 May 16, 2025
2ac5b9c
chore: remove decimals from int32arrays
aayush0325 May 16, 2025
ee1d3a1
chore: cleanupp
aayush0325 May 16, 2025
eb38b48
docs: update docs
aayush0325 May 16, 2025
b516efd
docs: add ts declaration file
aayush0325 May 16, 2025
3f05266
test: add ts test file
aayush0325 May 16, 2025
c86cd76
docs: add repl.txt
aayush0325 May 16, 2025
51b8662
docs: add readme
aayush0325 May 17, 2025
115d185
chore: linting error
aayush0325 May 17, 2025
944cc60
chore: linting error
aayush0325 May 17, 2025
bd0084f
chore: move variables to a separate section
aayush0325 May 18, 2025
09f01ca
chore: update error message
aayush0325 May 21, 2025
50a4de1
chore: update error mesages
aayush0325 May 21, 2025
0c607b9
chore: resolve conflicts
aayush0325 May 22, 2025
021712f
refactor: pointer arithmetics
aayush0325 May 22, 2025
89c3b1c
refactor: pointer arithmetic
aayush0325 May 22, 2025
5f0fdaa
refactor: pointer arithmetic
aayush0325 May 22, 2025
d50308b
refactor: pointer arithmetic
aayush0325 May 22, 2025
ff55902
refactor: pointer arithmetic
aayush0325 May 22, 2025
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
314 changes: 314 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dgebal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
<!--

@license Apache-2.0

Copyright (c) 2025 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.

-->

# dgebal

> Balances a general real matrix `A`.

<section class="usage">

## Usage

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

#### dgebal( order, job, N, A, LDA, out, scale )

Balances a general real matrix `A`.

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

var A = new Float64Array( [ 1.0, 100.0, 0.0, 2.0, 200.0, 0.0, 0.0, 0.0, 3.0 ] );
var out = new Int32Array( 2 );
var scale = new Float64Array( 3 );

/*
A = [
[ 1.0, 100.0, 0.0 ],
[ 2.0, 200.0, 0.0 ],
[ 0.0, 0.0, 3.0 ],
]
*/

dgebal( 'row-major', 'both', 3, A, 3, out, scale );
// A => <Float64Array>[ 1.0, 12.5, 0.0, 16.0, 200.0, 0.0, 0.0, 0.0, 3.0 ]
// out => <Int32Array>[ 0, 1 ]
// scale => <Float64Array>[ 8.0, 1.0, 2.0 ]
```

The function has the following parameters:

- **order**: storage layout.
- **job**: indicates the operations to be performed. The `job` parameter can be one of the following. `none` (do nothing), `permute` (permute only), `scale` (scale only) and `both` (both permute and scale).
- **N**: number of row/columns in `A`.
- **A**: input [`Float64Array`][mdn-float64array].
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
- **out**: stores the first and last row/column of the balanced submatrix as a [`Int32Array`][mdn-int32array].
- **scale**: scale factors are stored in the `scale` array as a [`Float64Array`][mdn-float64array]. Where the indices `0` to `out[ 0 ] - 1` and `out[ 1 ] + 1` to `N-1` contain the index of the interchanged row/column (zero based), and the indices `out[ 0 ]` to `out[ 1 ]` contains the scaling factor applied.

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' );
var Int32Array = require( '@stdlib/array/int32' );

// Initial arrays...
var A0 = new Float64Array( [ 0.0, 1.0, 100.0, 0.0, 2.0, 200.0, 0.0, 0.0, 0.0, 3.0 ] );
var out0 = new Int32Array( 3 );
var scale0 = new Float64Array( 4 );

// Create offset views...
var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var out1 = new Int32Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var scale1 = new Float64Array( scale0.buffer, scale0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

/*
A = [
[ 1.0, 100.0, 0.0 ],
[ 2.0, 200.0, 0.0 ],
[ 0.0, 0.0, 3.0 ],
]
*/

dgebal( 'row-major', 'both', 3, A1, 3, out1, scale1 );
// A0 => <Float64Array>[ 0.0, 1.0, 12.5, 0.0, 16.0, 200.0, 0.0, 0.0, 0.0, 3.0 ]
// out0 => <Int32Array>[ 0, 0, 1 ]
// scale0 => <Float64Array>[ 0.0, 8.0, 1.0, 2.0 ]
```

#### dgebal.ndarray( uplo, M, N, A, sa1, sa2, oa, B, sb1, sb2, ob )

Balances a general real matrix `A` using alternative indexing semantics.

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

var A = new Float64Array( [ 1.0, 100.0, 0.0, 2.0, 200.0, 0.0, 0.0, 0.0, 3.0 ] );
var out = new Int32Array( 2 );
var scale = new Float64Array( 3 );

/*
A = [
[ 1.0, 100.0, 0.0 ],
[ 2.0, 200.0, 0.0 ],
[ 0.0, 0.0, 3.0 ],
]
*/

dgebal.ndarray( 'both', 3, A, 3, 1, 0, out, 1, 0, scale, 1, 0 );
// A => <Float64Array>[ 1.0, 12.5, 0.0, 16.0, 200.0, 0.0, 0.0, 0.0, 3.0 ]
// out => <Int32Array>[ 0, 1 ]
// scale => <Float64Array>[ 8.0, 1.0, 2.0 ]
```

The function has the following parameters:

- **job**: indicates the operations to be performed. The `job` parameter can be one of the following. `none` (do nothing), `permute` (permute only), `scale` (scale only) and `both` (both permute and scale).
- **N**: number of row/columns in `A`.
- **A**: input [`Float64Array`][mdn-float64array].
- **strideA1**: stride of the first dimension of `A`.
- **strideA2**: stride of the second dimension of `A`.
- **offsetA**: starting index for `A`.
- **out**: stores the first and last row/column of the balanced submatrix as a [`Int32Array`][mdn-int32array].
- **strideOut**: stride length of `out`.
- **offsetOut**: starting index for `out`.
- **scale**: scale factors are stored in the `scale` array as a [`Float64Array`][mdn-float64array]. Where the indices `0` to `out[ 0 ] - 1` and `out[ 1 ] + 1` to `N-1` contain the index of the interchanged row/column (zero based), and the indices `out[ 0 ]` to `out[ 1 ]` contains the scaling factor applied.
- **strideScale**: stride length for `scale`.
- **offsetScale**: starting index for `scale`.

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,

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

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

var A = new Float64Array( [ 0.0, 1.0, 100.0, 0.0, 2.0, 200.0, 0.0, 0.0, 0.0, 3.0 ] );
var out = new Int32Array( 3 );
var scale = new Float64Array( 4 );

/*
A = [
[ 1.0, 100.0, 0.0 ],
[ 2.0, 200.0, 0.0 ],
[ 0.0, 0.0, 3.0 ],
]
*/

dgebal.ndarray( 'both', 3, A, 3, 1, 1, out, 1, 1, scale, 1, 1 );
// A => <Float64Array>[ 0.0, 1.0, 12.5, 0.0, 16.0, 200.0, 0.0, 0.0, 0.0, 3.0 ]
// out => <Int32Array>[ 0, 0, 1 ]
// scale => <Float64Array>[ 0.0, 8.0, 1.0, 2.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- `dgebal()` corresponds to the [LAPACK][lapack] routine [`dgebal`][lapack-dgebal].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var Int32Array = require( '@stdlib/array/int32' );
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
var dgebal = require( '@stdlib/lapack/base/dgebal' );

// Specify matrix meta data:
var shape = [ 3, 3 ];
var strides = [ 3, 1 ];
var offset = 0;
var order = 'row-major';

// Create a matrix stored in linear memory:
var A = new Float64Array( [ 1.0, 100.0, 0.0, 2.0, 200.0, 0.0, 0.0, 0.0, 3.0 ] );
console.log( ndarray2array( A, shape, strides, offset, order ) );

// Define arrays to store the scaling factors
var out = new Int32Array( 2 );
var scale = new Float64Array( 3 );

// Permute and scale the matrix:
dgebal( order, 'both', shape[ 0 ], A, strides[ 0 ], out, scale );

console.log( ndarray2array( A, shape, strides, offset, order ) );
console.log( out );
console.log( scale );
```

</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-dgebal]: https://www.netlib.org/lapack/explore-html-3.6.1/dd/d9a/group__double_g_ecomputational_ga411292dd693c20ff9c27650fb7bddf85.html

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

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

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

</section>

<!-- /.links -->
Loading