-
-
Notifications
You must be signed in to change notification settings - Fork 823
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
aayush0325
wants to merge
27
commits into
stdlib-js:develop
Choose a base branch
from
aayush0325:lapack-dgebak
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,917
−0
Open
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 1261ce4
docs: update jsdoc
aayush0325 f0304f8
feat: add ndarray and main functions
aayush0325 0f9b07f
feat: complete writing main implementation
aayush0325 61c4181
feat: rearrange params
aayush0325 d525027
test: add initial tests
aayush0325 78fd823
test: add tests for scaling
aayush0325 9154bd4
test: add tests for permutation
aayush0325 da376a7
test: add test for job = both
aayush0325 6531fd9
docs: add matrix representations in tests
aayush0325 f47e281
test: add basic ndarray and offset tests
aayush0325 0da4e78
chore: cleanup
aayush0325 7d92997
test: add tests for negative strides
aayush0325 d946d73
test: add tests for mixed strides
aayush0325 342bb22
test: add tests for large strides
aayush0325 49591cb
test: add test for LDV
aayush0325 ba95a7b
docs: add examples
aayush0325 fd18879
bench: add benchmarks
aayush0325 fc78f96
docs: add ts files
aayush0325 e1d65b2
docs: add readme
aayush0325 7392aa6
docs: add repl.txt
aayush0325 aed3649
refactor: remove the swaps to a different function
aayush0325 e82dc31
refactor: make the base implementation cleaner
aayush0325 3a90873
refactor: use inbuilt functions to check for jobs and size
aayush0325 ea41ad9
refactor: make base implementation cleaner
aayush0325 2009012
chore: use decimals
aayush0325 f3082fe
chore: cleanup
aayush0325 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. | ||
|
||
<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`). | ||
|
||
|
||
aayush0325 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 --> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.