Skip to content

feat: add lapack/base/dgebak #7035

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 27 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7a9f642
feat: add base implementation
aayush0325 May 18, 2025
1261ce4
docs: update jsdoc
aayush0325 May 18, 2025
f0304f8
feat: add ndarray and main functions
aayush0325 May 19, 2025
0f9b07f
feat: complete writing main implementation
aayush0325 May 19, 2025
61c4181
feat: rearrange params
aayush0325 May 19, 2025
d525027
test: add initial tests
aayush0325 May 19, 2025
78fd823
test: add tests for scaling
aayush0325 May 20, 2025
9154bd4
test: add tests for permutation
aayush0325 May 20, 2025
da376a7
test: add test for job = both
aayush0325 May 20, 2025
6531fd9
docs: add matrix representations in tests
aayush0325 May 20, 2025
f47e281
test: add basic ndarray and offset tests
aayush0325 May 20, 2025
0da4e78
chore: cleanup
aayush0325 May 20, 2025
7d92997
test: add tests for negative strides
aayush0325 May 20, 2025
d946d73
test: add tests for mixed strides
aayush0325 May 21, 2025
342bb22
test: add tests for large strides
aayush0325 May 21, 2025
49591cb
test: add test for LDV
aayush0325 May 21, 2025
ba95a7b
docs: add examples
aayush0325 May 21, 2025
fd18879
bench: add benchmarks
aayush0325 May 21, 2025
fc78f96
docs: add ts files
aayush0325 May 21, 2025
e1d65b2
docs: add readme
aayush0325 May 21, 2025
7392aa6
docs: add repl.txt
aayush0325 May 21, 2025
aed3649
refactor: remove the swaps to a different function
aayush0325 May 21, 2025
e82dc31
refactor: make the base implementation cleaner
aayush0325 May 22, 2025
3a90873
refactor: use inbuilt functions to check for jobs and size
aayush0325 May 22, 2025
ea41ad9
refactor: make base implementation cleaner
aayush0325 May 22, 2025
2009012
chore: use decimals
aayush0325 May 22, 2025
f3082fe
chore: cleanup
aayush0325 May 23, 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
285 changes: 285 additions & 0 deletions lib/node_modules/@stdlib/lapack/base/dgebak/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
<!--

@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.

-->

# dgebak

> LAPACK routine to form the right or left eigenvectors of a real general matrix by backward transformation on the computed eigenvectors of the balanced matrix output by `dgebal`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: link to dgebal once merged.


<section class="usage">

## Usage

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

#### dgebak( order, job, side, N, M, ilo, ihi, scale, V, LDC )

Forms the right or left eigenvectors of a real general matrix by backward transformation on the computed eigenvectors of the balanced matrix output by `dgebal`.

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

var scale = new Float64Array( [ 0.5, 2.0, 1.0 ] );
var V = new Float64Array( [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] );

/*
V = [
[ 1.0, 4.0 ],
[ 2.0, 5.0 ],
[ 3.0, 6.0 ]
]
*/

var out = dgebak( 'row-major', 'scale', 'right', 3, 2, 0, 2, scale, V, 2 );
// returns <Float64Array>[ 0.5, 2.0, 4.0, 10.0, 3.0, 6.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).
- **side**: specifies the side of the eigenvectors in `V` (`right` or `left`).
- **N**: number of rows in `V`.
- **M**: number of columns in `V`.
- **ilo**: index of the leftmost element in the submatrix computed by `dgebal` (zero-based).
- **ihi**: index of the rightmost element in the submatrix computed by `dgebal` (zero-based).
- **scale**: contains the details of the permutations and scaling factors applied when balancing `V`, computed by `dgebal` as a [`Float64Array`][mdn-float64array].
- **V**: input matrix stored in linear memory as a [`Float64Array`][mdn-float64array].
- **LDV**: stride of the first dimension of `V` (a.k.a., leading dimension of the matrix `V`).


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 -->

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

// Initial arrays...
var scale0 = new Float64Array( [ 0.0, 0.5, 2.0, 1.0 ] );
var V0 = new Float64Array( [ 0.0, 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] );

// Create offset views...
var scale1 = new Float64Array( scale0.buffer, scale0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var V1 = new Float64Array( V0.buffer, V0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

/*
V = [
[ 1.0, 4.0 ],
[ 2.0, 5.0 ],
[ 3.0, 6.0 ]
]
*/

var out = dgebak( 'row-major', 'scale', 'right', 3, 2, 0, 2, scale1, V1, 2 );
// V0 => <Float64Array>[ 0.0, 0.5, 2.0, 4.0, 10.0, 3.0, 6.0 ]
```

#### dgebak.ndarray( job, side, N, M, ilo, ihi, scale, ss, os, V, sv1, sv2, ov )

Forms the right or left eigenvectors of a real general matrix by backward transformation on the computed eigenvectors of the balanced matrix output by `dgebal` using alternative indexing semantics.

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

var scale = new Float64Array( [ 0.5, 2.0, 1.0 ] );
var V = new Float64Array( [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] );

/*
V = [
[ 1.0, 4.0 ],
[ 2.0, 5.0 ],
[ 3.0, 6.0 ]
]
*/

var out = dgebak.ndarray( 'scale', 'right', 3, 2, 0, 2, scale, 1, 0, V, 2, 1, 0 );
// returns <Float64Array>[ 0.5, 2.0, 4.0, 10.0, 3.0, 6.0 ]
```

The function has the following additional parameters:

- **ss**: stride of `scale`.
- **os**: starting index of `scale`.
- **sv1**: stride of the first dimension of `V`.
- **sv2**: stride of the second dimension of `V`.
- **ov**: starting index of `V`.

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 scale = new Float64Array( [ 0.0, 0.5, 2.0, 1.0 ] );
var V = new Float64Array( [ 0.0, 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] );

/*
V = [
[ 1.0, 4.0 ],
[ 2.0, 5.0 ],
[ 3.0, 6.0 ]
]
*/

var out = dgebak.ndarray( 'scale', 'right', 3, 2, 0, 2, scale, 1, 1, V, 2, 1, 1 );
// returns <Float64Array>[ 0.0, 0.5, 2.0, 4.0, 10.0, 3.0, 6.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- `dgebak()` corresponds to the [LAPACK][LAPACK] function [`dgebak`][lapack-dgebak].

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

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

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

// Create a matrix stored in linear memory:
var V = new Float64Array( [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] );
console.log( ndarray2array( V, shape, strides, offset, order ) );

var scale = new Float64Array( [ 0.5, 2.0, 1.0 ] );

var out = dgebak( order, 'scale', 'right', shape[ 0 ], shape[ 1 ], 0, 2, scale, V, strides[ 0 ] );
console.log( ndarray2array( out, shape, strides, offset, order ) );
```

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

[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