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

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

-->

# dorgqr

> Generate an `M-by-N` real matrix `Q` with orthonormal columns, which is defined as the first `N` columns of a product of `K` elementary reflectors of order `M`.

<section class="intro">

The `dorgqr` routine generates the orthogonal matrix `Q` from the elementary reflectors returned by the QR factorization routine `dgeqrf`.

<!-- <equation class="equation" label="eq:Q" align="center" raw="Q = H(1) H(2) . . . H(k)" alt="Equation for Q."> -->

```math
Q = H(1) H(2) . . . H(k)
```

<!-- </equation> -->

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

#### dorgqr( order, M, N, K, A, LDA, TAU, WORK, LWORK )

Generates an `M-by-N` real matrix `Q` with orthonormal columns, which is defined as the first `N` columns of a product of `K` elementary reflectors of order `M`.

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

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

var A = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] );
var TAU = new Float64Array( [ 2.0, 2.0 ] );
var WORK = new Float64Array( 10 );

dorgqr( 'column-major', 3, 2, 2, A, 3, TAU, WORK, 10 );
// A => <Float64Array>[ -1.0, 0.0, 0.0, 0.0, -1.0, 0.0 ]
// WORK[ 0 ] => 2.0
```

The function has the following parameters:

- **order**: storage layout. Must be `'row-major'` or `'column-major'`.
- **M**: number of rows of `Q`.
- **N**: number of columns of `Q`. Must be less than or equal to `M`.
- **K**: number of elementary reflectors whose product defines the matrix `Q`. Must be less than or equal to `N`.
- **A**: input/output matrix of size `M×N` stored in linear memory as a [`Float64Array`][@stdlib/array/float64]. On entry, the i-th column of `A` must contain the reflector vector for `H(i)`, as returned by `dgeqrf`. On exit, `A` is overwritten by the `M-by-N` orthogonal matrix `Q`.
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). Must be at least `max(1,M)` when `order` is `'column-major'` and at least `max(1,N)` when `order` is `'row-major'`.
- **TAU**: scalar factors of the elementary reflectors as a [`Float64Array`][@stdlib/array/float64] of length `K`.
- **WORK**: workspace array as a [`Float64Array`][@stdlib/array/float64].
- **LWORK**: dimension of the array `WORK`. Must be at least `max(1,N)`, unless equal to `-1`, in which case a workspace query is performed and the optimal size of `WORK` is returned in `WORK[0]`.

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.0, 0.0, 0.0, 1.0, 0.0 ] );
var TAU0 = new Float64Array( [ 0.0, 2.0, 2.0 ] );
var WORK0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

// Create offset views...
var A = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var TAU = new Float64Array( TAU0.buffer, TAU0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var WORK = new Float64Array( WORK0.buffer, WORK0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

dorgqr( 'column-major', 3, 2, 2, A, 3, TAU, WORK, 10 );
// A0 => <Float64Array>[ 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0 ]
// WORK0[ 1 ] => 2.0
```

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

#### dorgqr.ndarray( M, N, K, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK, LWORK )

Generates an `M-by-N` real matrix `Q` with orthonormal columns using alternative indexing semantics.

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

var A = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] );
var TAU = new Float64Array( [ 2.0, 2.0 ] );
var WORK = new Float64Array( 10 );

dorgqr.ndarray( 3, 2, 2, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0, 10 );
// A => <Float64Array>[ -1.0, 0.0, 0.0, 0.0, -1.0, 0.0 ]
// WORK[ 0 ] => 2.0
```

The function has the following additional parameters:

- **strideA1**: stride length for the first dimension of `A`.
- **strideA2**: stride length for the second dimension of `A`.
- **offsetA**: starting index for `A`.
- **strideTAU**: stride length for `TAU`.
- **offsetTAU**: starting index for `TAU`.
- **strideWORK**: stride length for `WORK`.
- **offsetWORK**: starting index for `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.0, 0.0, 0.0, 1.0, 0.0 ] );
var TAU = new Float64Array( [ 0.0, 2.0, 2.0 ] );
var WORK = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

dorgqr.ndarray( 3, 2, 2, A, 1, 3, 1, TAU, 1, 1, WORK, 1, 1, 10 );
// A => <Float64Array>[ 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0 ]
// WORK[ 1 ] => 2.0
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- Both functions mutate the input arrays `A`, `TAU`, and `WORK`.

- Both functions return a status code indicating success (`0`) or failure.

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

</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 dorgqr = require( '@stdlib/lapack/base/dorgqr' );

// Define matrix dimensions:
var M = 6;
var N = 4;
var K = 4;
var shape = [ M, N ];
var order = 'row-major';
var strides = shape2strides( shape, order );

// Create the matrix A containing elementary reflector vectors from dgeqrf:
var A = new Float64Array( [
5.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 4.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 3.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 2.0, 0.0, 0.0
] );
console.log( ndarray2array( A, shape, strides, 0, order ) );

// Define the scalar factors and workspace array:
var TAU = new Float64Array( [ 2.0, 2.0, 2.0, 2.0 ] );
var WORK = new Float64Array( 20 );

// Generate the orthogonal matrix Q:
var info = dorgqr( order, M, N, K, A, strides[ 0 ], TAU, WORK, WORK.length );
console.log( ndarray2array( A, 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-dorgqr]: https://www.netlib.org/lapack/explore-html/d4/dfc/group__ungqr_ga9f4abcfe1543a5d6d90fcd4dd21f12f0.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