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

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

-->

# dgeqr2

> Computes a QR factorization of a general rectangular matrix using an unblocked algorithm.

<section class="intro">

dgeqr2 computes an LQ factorization of a real m-by-n matrix A:

<!-- <equation class="equation" label="eq:qr_decomposition" align="center" raw="A = Q * \left[\begin{array}{c}R \\0\end{array}\right]" alt="Equation for QR factorization."> -->

```math
A = Q * \left[
\begin{array}{c}
R \\
0
\end{array}
\right]
```

<!-- </equation> -->

Where:

- `Q` is an `M-by-M` orthogonal matrix.
- `R` is an upper-triangular `N-by-N` matrix.
- `0` is a `(m-n)-by-n` zero matrix, if `M > N`.

On exit, the elements on and above the diagonal of the array contain the min(M,N) by N upper trapezoidal matrix R (R is upper triangular if M >= N). The elements below the diagonal, with the array TAU represent the orthogonal matrix Q as a product of elementary reflectors.

The matrix Q is represented as a product of elementary reflectors

<!-- <equation class="equation" label="eq:Q" align="center" raw="Q = H(1) H(2) . . . H(K)" alt="product of elementary reflector."> -->

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

<!-- </equation> -->

where `K` = `min(M,N)`.

Each H(i) has the form

<!-- <equation class="equation" label="eq:householder_reflector" align="center" raw="H(i) = I - tau_i v_i v_i^T" alt="Householder reflector."> -->

```math
H(i) = I - TAU_i V_i V_i^T
```

<!-- </equation> -->

Where `TAU` is a real scalar, and `V` is a real vector with `V(1:i-1)` = 0 and `V(i)` = 1 and `V(i+1:n)` is stored on exit in `A(i+1:m,i)`

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

#### dgeqr2( order, M, N, A, LDA, TAU, WORK )

Compute a QR factorization of a general rectangular matrix using an unblocked algorithm.

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

var A = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12 ] );
var TAU = new Float64Array( 3 );
var work = new Float64Array( 3 );

dgeqr2( 'column-major', 3, 4, A, 3, TAU, work );
// A => <Float64Array>[ ~-10.344, ~0.441, ~0.793, ~-11.794, ~0.947, ~0.919, ~-13.244, ~1.894, ~0.0, ~-14.694, ~2.842, ~0.0 ]
// TAU => <Float64Array>[ ~1.097, ~1.084, 0.0 ]
// work => <Float64Array>[ ~-1.894, ~-2.842, ~17.046, 0.0 ]
```

The function has the following parameters:

- **order**: storage layout.
- **M**: number of rows in `A`.
- **N**: number of columns in `A`.
- **A**: input/output matrix as a [`Float64Array`][@stdlib/array/float64]. Should have `M*N` indexed elements. On exit, the elements on and below the diagonal of `A` contain the lower trapezoidal matrix `L`, and the elements above the diagonal, together with `TAU`, represent the orthogonal matrix `Q`.
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
- **TAU**: output array of scalar factors as a [`Float64Array`][@stdlib/array/float64]. Should have `min(M,N)` indexed elements.
- **WORK**: workspace array as a [`Float64Array`][@stdlib/array/float64]. Should have at least `M` indexed elements.

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

// Initial arrays...
var A0 = 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 TAU0 = new Float64Array( 4 );
var work0 = new Float64Array( 5 );

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

dgeqr2( 'column-major', 3, 4, A, 3, TAU, work );
// A0 => <Float64Array>[ 0.0, ~-10.344, ~0.441, ~0.793, ~-11.794, ~0.947, ~0.919, ~-13.244, ~1.894, ~0.0, ~-14.694, ~2.842, ~0.0 ]
// TAU0 => <Float64Array>[ 0.0, ~1.097, ~1.084, 0.0 ]
// work0 => <Float64Array>[ 0.0, ~-1.894, ~-2.842, ~17.046, 0.0 ]
```

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

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

Compute a QR factorization of a general rectangular matrix using an unblocked algorithm using alternative indexing semantics.

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

var A = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12 ] );
var TAU = new Float64Array( 3 );
var work = new Float64Array( 4 );

dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, work, 1, 0 );
// A => <Float64Array>[ ~-10.344, ~0.441, ~0.793, ~-11.794, ~0.947, ~0.919, ~-13.244, ~1.894, ~0.0, ~-14.694, ~2.842, ~0.0 ]
// TAU => <Float64Array>[ ~1.097, ~1.084, 0.0 ]
// work => <Float64Array>[ ~-1.894, ~-2.842, ~17.046, 0.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,

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

var A0 = 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 TAU0 = new Float64Array( 4 );
var work0 = new Float64Array( 5 );
dgeqr2.ndarray( 3, 4, A0, 1, 3, 1, TAU0, 1, 1, work0, 1, 1 );
// A0 => <Float64Array>[ 0.0, ~-10.344, ~0.441, ~0.793, ~-11.794, ~0.947, ~0.919, ~-13.244, ~1.894, ~0.0, ~-14.694, ~2.842, ~0.0 ]
// TAU0 => <Float64Array>[ 0.0, ~1.097, ~1.084, 0.0 ]
// work0 => <Float64Array>[ 0.0, ~-1.894, ~-2.842, ~17.046, 0.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 or failure. The status code indicates the following conditions:
- `0`: computation was successful.
- `<0`: the `-i`th argument had an illegal value.
- `dgeqr2()` corresponds to the [LAPACK][lapack] routine [`dgeqr2`][lapack-dgeqr2].

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

// Specify matrix meta data:
var shape = [ 3, 4 ];
var order = 'row-major';
var strides = shape2strides( shape, order );

// Create a matrix stored in linear memory:
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); // eslint-disable-line max-len

console.log( 'A (unmodified):', ndarray2array( A, shape, strides, 0, order ) );

// Output arrays:
var TAU = new Float64Array( 3 );
var work = new Float64Array( shape[ 1 ] );

// Compute the LQ factorization in-place:
var info = dgeqr2( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ], TAU, work );

console.log( 'Status Code:', info );
console.log( 'A (L + reflectors):', ndarray2array( A, shape, strides, 0, order ) );
console.log( 'TAU:', TAU );
console.log( 'WORK:', work );

// Re-initialize arrays for the ndarray interface:
A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
TAU = new Float64Array( 3 );
work = new Float64Array( 3 );

// Compute the LQ factorization again using the ndarray interface:
info = dgeqr2.ndarray( shape[ 0 ], shape[ 1 ], A, strides[ 0 ], strides[ 1 ], 0, TAU, 1, 0, work, 1, 0 );

console.log( 'Status Code:', info );
console.log( 'A (L + reflectors):', ndarray2array( A, shape, strides, 0, order ) );
console.log( 'TAU:', TAU );
console.log( 'WORK:', work );
```

</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-dgeqr2]: https://www.netlib.org/lapack/explore-html/d6/da5/group__geqr2_ga0ff91490bc2e246cabb8fe02f3f1da97.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