-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add lapack/base/dlarf
#12331
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
iampratik13
wants to merge
7
commits into
stdlib-js:develop
Choose a base branch
from
iampratik13:lapack/dlarf
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.
Open
feat: add lapack/base/dlarf
#12331
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cd153f6
feat: add lapack/base/dlarf
iampratik13 96f21e7
Merge branch 'develop' into lapack/dlarf
anandkaranubc ab9f119
docs: fix typo
anandkaranubc b38927f
docs: fix misleading wording
anandkaranubc 043f930
fix: add column-major LDC validation
anandkaranubc 433d6ce
chore: add early return to avoid BLAS calls
anandkaranubc 1693198
chore: use correct variable names
anandkaranubc 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,337 @@ | ||
| <!-- | ||
|
|
||
| @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. | ||
|
|
||
| --> | ||
|
|
||
| # dlarf | ||
|
|
||
| > Apply a real elementary reflector `H = I - tau * v * v^T` to a real M by N matrix `C`. | ||
|
|
||
| <section class="intro"> | ||
|
|
||
| A **Householder transformation** (or an **elementary reflector**) is a linear transformation that describes a reflection about a plane or a hyperplane containing the origin. | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.intro --> | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| var dlarf = require( '@stdlib/lapack/base/dlarf' ); | ||
| ``` | ||
|
|
||
| #### dlarf( order, side, M, N, V, strideV, tau, C, LDC, work ) | ||
|
|
||
| Applies a real elementary reflector `H = I - tau * v * v^T` to a real M by N matrix `C`. | ||
|
|
||
| <!-- eslint-disable max-len --> | ||
|
|
||
| ```javascript | ||
| var Float64Array = require( '@stdlib/array/float64' ); | ||
|
|
||
| var C = new Float64Array( [ 1.0, 5.0, 9.0, 2.0, 6.0, 10.0, 3.0, 7.0, 11.0, 4.0, 8.0, 12.0 ] ); | ||
| var V = new Float64Array( [ 0.5, 0.5, 0.5, 0.5 ] ); | ||
| var work = new Float64Array( 3 ); | ||
|
|
||
| var out = dlarf( 'row-major', 'left', 4, 3, V, 1, 1.0, C, 3, work ); | ||
| // returns <Float64Array>[ -1.5, -1.5, -1.5, -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 1.5, 1.5, 1.5 ] | ||
| ``` | ||
|
|
||
| The function has the following parameters: | ||
|
|
||
| - **order**: storage layout. | ||
| - **side**: specifies the side of multiplication with `C`. | ||
| - **M**: number of rows in `C`. | ||
| - **N**: number of columns in `C`. | ||
| - **V**: the vector `v` as a [`Float64Array`][mdn-float64array]. | ||
| - **strideV**: stride length for `V`. If `strideV` is negative, the elements of `V` are accessed in reverse order. | ||
| - **tau**: scalar constant. | ||
| - **C**: input matrix stored in linear memory as a [`Float64Array`][mdn-float64array]. | ||
| - **LDC**: stride of the first dimension of `C` (a.k.a., leading dimension of the matrix `C`). Must be at least `max(1,N)` when `order` is `'row-major'` and at least `max(1,M)` when `order` is `'column-major'`. | ||
| - **work**: workspace [`Float64Array`][mdn-float64array]. | ||
|
|
||
| When `side` is `'left'`, | ||
|
|
||
| - `work` should have `N` indexed elements. | ||
| - `V` should have `1 + (M-1) * abs(strideV)` indexed elements. | ||
| - `C` is overwritten by `H * C`. | ||
|
|
||
| When `side` is `'right'`, | ||
|
|
||
| - `work` should have `M` indexed elements. | ||
| - `V` should have `1 + (N-1) * abs(strideV)` indexed elements. | ||
| - `C` is overwritten by `C * H`. | ||
|
|
||
| The sign of the increment parameter `strideV` determines the order in which elements of `V` are accessed. For example, to access elements in reverse order, | ||
|
|
||
| <!-- eslint-disable max-len --> | ||
|
|
||
| ```javascript | ||
| var Float64Array = require( '@stdlib/array/float64' ); | ||
|
|
||
| var C = new Float64Array( [ 1.0, 5.0, 9.0, 2.0, 6.0, 10.0, 3.0, 7.0, 11.0, 4.0, 8.0, 12.0 ] ); | ||
| var V = new Float64Array( [ 0.5, 0.4, 0.3, 0.2 ] ); | ||
| var work = new Float64Array( 3 ); | ||
|
|
||
| var out = dlarf( 'row-major', 'left', 4, 3, V, -1, 1.0, C, 3, work ); | ||
| // returns <Float64Array>[ 0.2, ~3.08, ~5.96, 0.8, ~3.12, ~5.44, 1.4, ~3.16, ~4.92, 2.0, 3.2, 4.4 ] | ||
| ``` | ||
|
|
||
| To perform strided access over `V`, provide an `abs(strideV)` value greater than one. For example, to access every other element in `V`, | ||
|
|
||
| <!-- eslint-disable max-len --> | ||
|
|
||
| ```javascript | ||
| var Float64Array = require( '@stdlib/array/float64' ); | ||
|
|
||
| var C = new Float64Array( [ 1.0, 5.0, 9.0, 2.0, 6.0, 10.0, 3.0, 7.0, 11.0, 4.0, 8.0, 12.0 ] ); | ||
| var V = new Float64Array( [ 0.5, 999, 0.5, 999, 0.5, 999, 0.5 ] ); | ||
| var work = new Float64Array( 3 ); | ||
|
|
||
| var out = dlarf( 'row-major', 'left', 4, 3, V, 2, 1.0, C, 3, work ); | ||
| // returns <Float64Array>[ -1.5, -1.5, -1.5, -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 1.5, 1.5, 1.5 ] | ||
| ``` | ||
|
|
||
| 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 arrays... | ||
| var C0 = new Float64Array( [ 0.0, 1.0, 5.0, 9.0, 2.0, 6.0, 10.0, 3.0, 7.0, 11.0, 4.0, 8.0, 12.0 ] ); | ||
| var V0 = new Float64Array( [ 0.0, 0.5, 0.5, 0.5, 0.5 ] ); | ||
| var work0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); | ||
|
|
||
| // Create offset views... | ||
| var C1 = new Float64Array( C0.buffer, C0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||
| var V1 = new Float64Array( V0.buffer, V0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||
| var work1 = new Float64Array( work0.buffer, work0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||
|
|
||
| var out = dlarf( 'row-major', 'left', 4, 3, V1, 1, 1.0, C1, 3, work1 ); | ||
| // C0 => <Float64Array>[ 0.0, -1.5, -1.5, -1.5, -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 1.5, 1.5, 1.5 ] | ||
| ``` | ||
|
|
||
| #### dlarf.ndarray( side, M, N, V, sv, ov, tau, C, sc1, sc2, oc, work, sw, ow ) | ||
|
|
||
| Applies a real elementary reflector `H = I - tau * v * v^T` to a real M by N matrix `C` using alternative indexing semantics. | ||
|
|
||
| <!-- eslint-disable max-len --> | ||
|
|
||
| ```javascript | ||
| var Float64Array = require( '@stdlib/array/float64' ); | ||
|
|
||
| var C = new Float64Array( [ 1.0, 5.0, 9.0, 2.0, 6.0, 10.0, 3.0, 7.0, 11.0, 4.0, 8.0, 12.0 ] ); | ||
| var V = new Float64Array( [ 0.5, 0.5, 0.5, 0.5 ] ); | ||
| var work = new Float64Array( 3 ); | ||
|
|
||
| var out = dlarf.ndarray( 'left', 4, 3, V, 1, 0, 1.0, C, 3, 1, 0, work, 1, 0 ); | ||
| // returns <Float64Array>[ -1.5, -1.5, -1.5, -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 1.5, 1.5, 1.5 ] | ||
| ``` | ||
|
|
||
| The function has the following parameters: | ||
|
|
||
| - **side**: specifies the side of multiplication with `C`. | ||
| - **M**: number of rows in `C`. | ||
| - **N**: number of columns in `C`. | ||
| - **V**: the vector `v` as a [`Float64Array`][mdn-float64array]. | ||
| - **sv**: stride length for `V`. | ||
| - **ov**: starting index for `V`. | ||
| - **tau**: scalar constant. | ||
| - **C**: input matrix as a [`Float64Array`][mdn-float64array]. | ||
| - **sc1**: stride of the first dimension of `C`. | ||
| - **sc2**: stride of the second dimension of `C`. | ||
| - **oc**: starting index for `C`. | ||
| - **work**: workspace array as a [`Float64Array`][mdn-float64array]. | ||
| - **sw**: stride length for `work`. | ||
| - **ow**: starting index for `work`. | ||
|
|
||
| When `side` is `'left'`, | ||
|
|
||
| - `work` should have `N` indexed elements. | ||
| - `V` should have `1 + (M-1) * abs(sv)` indexed elements. | ||
| - `C` is overwritten by `H * C`. | ||
|
|
||
| When `side` is `'right'`, | ||
|
|
||
| - `work` should have `M` indexed elements. | ||
| - `V` should have `1 + (N-1) * abs(sv)` indexed elements. | ||
| - `C` is overwritten by `C * H`. | ||
|
|
||
| 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 C = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 1.0, 5.0, 9.0, 2.0, 6.0, 10.0, 3.0, 7.0, 11.0, 4.0, 8.0, 12.0 ] ); | ||
| var V = new Float64Array( [ 0.0, 0.0, 0.5, 0.5, 0.5, 0.5 ] ); | ||
| var work = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); | ||
|
|
||
| var out = dlarf.ndarray( 'left', 4, 3, V, 1, 2, 1.0, C, 3, 1, 4, work, 1, 0 ); | ||
| // C => <Float64Array>[ 0.0, 0.0, 0.0, 0.0, -1.5, -1.5, -1.5, -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 1.5, 1.5, 1.5 ] | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <section class="notes"> | ||
|
|
||
| ## Notes | ||
|
|
||
| - `dlarf()` corresponds to the [LAPACK][LAPACK] function [`dlarf`][lapack-dlarf]. | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ## Examples | ||
|
|
||
| <!-- eslint no-undef: "error" --> | ||
|
|
||
| <!-- eslint-disable max-len --> | ||
|
|
||
| ```javascript | ||
| var Float64Array = require( '@stdlib/array/float64' ); | ||
| var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); | ||
| var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); | ||
| var dlarf = require( '@stdlib/lapack/base/dlarf' ); | ||
|
|
||
| // Specify matrix meta data: | ||
| var shape = [ 4, 3 ]; | ||
| var order = 'row-major'; | ||
| var strides = shape2strides( shape, order ); | ||
|
|
||
| // Create a matrix stored in linear memory: | ||
| var C = new Float64Array( [ 1.0, 5.0, 9.0, 2.0, 6.0, 10.0, 3.0, 7.0, 11.0, 4.0, 8.0, 12.0 ] ); | ||
| console.log( ndarray2array( C, shape, strides, 0, order ) ); | ||
|
|
||
| // Define the vector `v` and a workspace array: | ||
| var V = new Float64Array( [ 0.5, 0.5, 0.5, 0.5 ] ); | ||
| var work = new Float64Array( 3 ); | ||
|
|
||
| // Apply the elementary reflector: | ||
| dlarf( order, 'left', shape[ 0 ], shape[ 1 ], V, 1, 1.0, C, strides[ 0 ], work ); | ||
| console.log( ndarray2array( C, shape, strides, 0, 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-dlarf]: https://netlib.org/lapack/explore-html/d2/d97/group__larf_gade3d1409d3046a8b5b39bb500456b349.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.
They are not "additional"