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

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

-->

# dormqr

> Apply an orthogonal matrix `Q`, formed from Householder reflectors returned by `DGEQRF`, to overwrite matrix `C` by multiplying from the left or right with `Q` or `Q^T`.

<section class="intro">

`dormqr` applies the real orthogonal matrix `Q` from the QR factorization of a general matrix `A = Q * R` to another general matrix `C`. The matrix `Q` is represented as a product of elementary reflectors

```math
Q = H(k) \cdots H(2) H(1)
```

as returned by `DGEQRF`. `Q` is of order `M` if `SIDE = 'left'` and of order `N` if `SIDE = 'right'`.

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

#### dormqr( order, side, trans, M, N, K, A, LDA, TAU, C, LDC, WORK, LWORK )

Applies an orthogonal matrix `Q`, formed from Householder reflectors returned by `DGEQRF`, to overwrite matrix `C` by multiplying from the left or right with `Q` or `Q^T`.

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

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

var A = new Float64Array( [ 1, 0, 0 ] );
var TAU = new Float64Array( [ 2 ] );
var C = new Float64Array( [ 1, 3, 5, 2, 4, 6 ] );
var WORK = new Float64Array( 64 );

var info = dormqr( 'row-major', 'left', 'no-transpose', 2, 3, 1, A, 2, TAU, C, 3, WORK, 64 );
// returns 0
// C => <Float64Array>[ -1, -3, -5, 2, 4, 6 ]
// WORK[ 0 ] => 4256
```

The function has the following parameters:

- **order**: storage layout. Must be either `'row-major'` or `'column-major'`.
- **side**: specifies the side of multiplication with `C`. Use `'left'` to form `Q * C` or `Q^T * C`, and `'right'` to form `C * Q` or `C * Q^T`.
- **trans**: transpose operation. Use `'no-transpose'` for `Q` and `'transpose'` for `Q^T`.
- **M**: number of rows of `C`.
- **N**: number of columns of `C`.
- **K**: number of elementary reflectors. Must be smaller than the order of `Q`.
- **A**: reflector vectors from `DGEQRF` as a [`Float64Array`][@stdlib/array/float64].
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
- **TAU**: scalar factors of elementary reflectors as a [`Float64Array`][@stdlib/array/float64].
- **C**: input/output matrix stored in linear memory as a [`Float64Array`][@stdlib/array/float64].
- **LDC**: stride of the first dimension of `C` (a.k.a., leading dimension of the matrix `C`).
- **WORK**: workspace array as a [`Float64Array`][@stdlib/array/float64].
- **LWORK**: dimension of the array `WORK`.

When `side` is `'left'`:

- `WORK` must have length `LWORK >= max(1, N)`.
- `LDA` must be greater than or equal to `max(1, M)` for column-major layout and `max(1, K)` for row-major layout.

When `side` is `'right'`:

- `WORK` must have length `LWORK >= max(1, M)`.
- `LDA` must be greater than or equal to `max(1, N)` for column-major layout and `max(1, K)` for row-major layout.

If `LWORK` is equal to `-1`, the function returns a workspace query and only the first element of `WORK` is modified with the optimal workspace size.

The function overwrites `C` with:

- `Q * C` if `SIDE = 'left'` and `TRANS = 'no-transpose'`
- `Q^T * C` if `SIDE = 'left'` and `TRANS = 'transpose'`
- `C * Q` if `SIDE = 'right'` and `TRANS = 'no-transpose'`
- `C * Q^T` if `SIDE = 'right'` and `TRANS = 'transpose'`

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 A0 = new Float64Array( [ 0.0, 1, 0, 0 ] );
var TAU0 = new Float64Array( [ 0.0, 2 ] );
var C0 = new Float64Array( [ 0.0, 1, 3, 5, 2, 4, 6 ] );
var WORK0 = new Float64Array( 65 );

// Create offset views...
var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var TAU1 = new Float64Array( TAU0.buffer, TAU0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var C1 = new Float64Array( C0.buffer, C0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var WORK1 = new Float64Array( WORK0.buffer, WORK0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

dormqr( 'row-major', 'left', 'no-transpose', 2, 3, 1, A1, 2, TAU1, C1, 3, WORK1, 64 );
// C0 => <Float64Array>[ 0.0, -1, -3, -5, 2, 4, 6 ]
```

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

#### dormqr.ndarray( side, trans, M, N, K, A, sa1, sa2, oa, TAU, st, ot, C, sc1, sc2, oc, WORK, sw, ow, LWORK )

Applies an orthogonal matrix `Q`, formed from Householder reflectors returned by `DGEQRF`, to overwrite matrix `C` by multiplying from the left or right with `Q` or `Q^T` using alternative indexing semantics.

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

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

var A = new Float64Array( [ 1, 0, 0 ] );
var TAU = new Float64Array( [ 2 ] );
var C = new Float64Array( [ 1, 3, 5, 2, 4, 6 ] );
var WORK = new Float64Array( 64 );

var info = dormqr.ndarray( 'left', 'no-transpose', 2, 3, 1, A, 2, 1, 0, TAU, 1, 0, C, 3, 1, 0, WORK, 1, 0, 64 );
// returns 0
// C => <Float64Array>[ -1, -3, -5, 2, 4, 6 ]
```

The function has the following additional parameters:

- **side**: specifies the side of multiplication with `C`.
- **trans**: transpose operation.
- **M**: number of rows of `C`.
- **N**: number of columns of `C`.
- **K**: number of elementary reflectors.
- **A**: reflector vectors from `DGEQRF` as a [`Float64Array`][@stdlib/array/float64].
- **sa1**: stride of the first dimension of `A`.
- **sa2**: stride of the second dimension of `A`.
- **oa**: starting index for `A`.
- **TAU**: scalar factors of elementary reflectors as a [`Float64Array`][@stdlib/array/float64].
- **st**: stride length for `TAU`.
- **ot**: starting index for `TAU`.
- **C**: input/output matrix as a [`Float64Array`][@stdlib/array/float64].
- **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`][@stdlib/array/float64].
- **sw**: stride length for `WORK`.
- **ow**: starting index for `WORK`.
- **LWORK**: dimension of the array `WORK`.

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 A = new Float64Array( [ 0.0, 1, 0, 0 ] );
var TAU = new Float64Array( [ 0.0, 2 ] );
var C = new Float64Array( [ 0.0, 1, 3, 5, 2, 4, 6 ] );
var WORK = new Float64Array( 65 );

var info = dormqr.ndarray( 'left', 'no-transpose', 2, 3, 1, A, 2, 1, 1, TAU, 1, 1, C, 3, 1, 1, WORK, 1, 1, 64 );
// C => <Float64Array>[ 0.0, -1, -3, -5, 2, 4, 6 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

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

</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 shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
var dormqr = require( '@stdlib/lapack/base/dormqr' );

// Define a matrix C stored in column-major order:
var shape = [ 2, 3 ];
var order = 'column-major';
var strides = shape2strides( shape, order );

var C = new Float64Array( [ 1.0, 2.0, 4.0, 5.0, 3.0, 6.0 ] );
console.log( ndarray2array( C, shape, strides, 0, order ) );

// Define the reflector vector A and scalar factors:
var A = new Float64Array( [ 1.0, 0.0 ] );
var TAU = new Float64Array( [ 2.0 ] );
var WORK = new Float64Array( 3 );

// Apply the orthogonal matrix Q from the left (no transpose):
var info = dormqr( order, 'left', 'no-transpose', shape[ 0 ], shape[ 1 ], 1, A, 2, TAU, C, strides[ 1 ], WORK, WORK.length );
console.log( ndarray2array( C, shape, strides, 0, order ) );
console.log( info );
```

</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-dormqr]: https://www.netlib.org/lapack/explore-html/d7/d50/group__unmqr_ga768bd221f959be1b3d15bd177bb5c1b3.html

[@stdlib/array/float64]: https://stdlib.io/docs/api/latest/@stdlib/array/float64

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

</section>

<!-- /.links -->
Loading
Loading