From 7964b17f8b3902a2e0dcac6abb0d3ba863e6f81f Mon Sep 17 00:00:00 2001 From: Prajjwal Bajpai Date: Sun, 14 Jun 2026 00:06:29 +0530 Subject: [PATCH] feat: add `lapack/base/dgeqr2` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/lapack/base/dgeqr2/README.md | 345 ++++++++++++++++ .../lapack/base/dgeqr2/benchmark/benchmark.js | 118 ++++++ .../dgeqr2/benchmark/benchmark.ndarray.js | 132 ++++++ .../@stdlib/lapack/base/dgeqr2/docs/repl.txt | 182 +++++++++ .../lapack/base/dgeqr2/docs/types/index.d.ts | 151 +++++++ .../lapack/base/dgeqr2/docs/types/test.ts | 382 ++++++++++++++++++ .../lapack/base/dgeqr2/examples/index.js | 59 +++ .../@stdlib/lapack/base/dgeqr2/lib/base.js | 99 +++++ .../@stdlib/lapack/base/dgeqr2/lib/dgeqr2.js | 88 ++++ .../@stdlib/lapack/base/dgeqr2/lib/dlarfg.js | 142 +++++++ .../@stdlib/lapack/base/dgeqr2/lib/index.js | 63 +++ .../@stdlib/lapack/base/dgeqr2/lib/main.js | 35 ++ .../@stdlib/lapack/base/dgeqr2/lib/ndarray.js | 71 ++++ .../@stdlib/lapack/base/dgeqr2/package.json | 69 ++++ .../base/dgeqr2/test/fixtures/col_maj.json | 49 +++ .../base/dgeqr2/test/fixtures/row_maj.json | 49 +++ .../lapack/base/dgeqr2/test/test.dgeqr2.js | 166 ++++++++ .../@stdlib/lapack/base/dgeqr2/test/test.js | 82 ++++ 18 files changed, 2282 insertions(+) create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/README.md create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/examples/index.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/base.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/dgeqr2.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/dlarfg.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/index.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/main.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/package.json create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/test/fixtures/col_maj.json create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/test/fixtures/row_maj.json create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/test/test.dgeqr2.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dgeqr2/test/test.js diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/README.md b/lib/node_modules/@stdlib/lapack/base/dgeqr2/README.md new file mode 100644 index 000000000000..9c27ab805232 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/README.md @@ -0,0 +1,345 @@ + + +# dgeqr2 + +> Computes a QR factorization of a general rectangular matrix using an unblocked algorithm. + +
+ +dgeqr2 computes an LQ factorization of a real m-by-n matrix A: + + + +```math +A = Q * \left[ +\begin{array}{c} +R \\ +0 +\end{array} +\right] +``` + + + +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 + + + +```math +Q = H(1) H(2) . . . H(K) +``` + + + +where `K` = `min(M,N)`. + +Each H(i) has the form + + + +```math +H(i) = I - TAU_i V_i V_i^T +``` + + + +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)` + +
+ + + +
+ +## 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 => [ ~-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 => [ ~1.097, ~1.084, 0.0 ] +// work => [ ~-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. + + + +```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 => [ 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 => [ 0.0, ~1.097, ~1.084, 0.0 ] +// work0 => [ 0.0, ~-1.894, ~-2.842, ~17.046, 0.0 ] +``` + + + +#### 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 => [ ~-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 => [ ~1.097, ~1.084, 0.0 ] +// work => [ ~-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 => [ 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 => [ 0.0, ~1.097, ~1.084, 0.0 ] +// work0 => [ 0.0, ~-1.894, ~-2.842, ~17.046, 0.0 ] +``` + +
+ + + +
+ +## 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]. + +
+ + + +
+ +## Examples + + + +```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 ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dgeqr2/benchmark/benchmark.js new file mode 100644 index 000000000000..4f8d51ab6040 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/benchmark/benchmark.js @@ -0,0 +1,118 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dgeqr2 = require( './../lib/dgeqr2.js' ); + + +// VARIABLES // + +var LAYOUTS = [ + 'row-major', + 'column-major' +]; +var opts = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {string} order - storage layout +* @param {PositiveInteger} N - matrix dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( order, N ) { + var work = new Float64Array( N ); + var TAU = new Float64Array( N ); + var A = discreteUniform( N*N, 1.0, 10.0, opts ); + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + var z; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = dgeqr2( order, N, N, A, N, TAU, work ); + if ( z !== 0 ) { + b.fail( 'should return 0' ); + } + } + b.toc(); + + if ( z !== 0 ) { + b.fail( 'should return 0' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var ord; + var N; + var f; + var i; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < LAYOUTS.length; k++ ) { + ord = LAYOUTS[ k ]; + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( ord, N ); + bench( format( '%s::square_matrix:order=%s,size=%d', pkg, ord, N*N ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dgeqr2/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..1dc26bb40a4b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/benchmark/benchmark.ndarray.js @@ -0,0 +1,132 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var Float64Array = require( '@stdlib/array/float64' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dgeqr2 = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var LAYOUTS = [ + 'row-major', + 'column-major' +]; +var opts = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {string} order - storage layout +* @param {PositiveInteger} N - matrix dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( order, N ) { + var work; + var TAU; + var sa1; + var sa2; + var A; + + work = new Float64Array( N ); + TAU = new Float64Array( N ); + A = discreteUniform( N*N, 1.0, 10.0, opts ); + if ( isColumnMajor( order ) ) { + sa1 = 1; + sa2 = N; + } else { // order === 'row-major' + sa1 = N; + sa2 = 1; + } + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + var z; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + z = dgeqr2( N, N, A, sa1, sa2, 0, TAU, 1, 0, work, 1, 0 ); + if ( z !== 0 ) { + b.fail( 'should return 0' ); + } + } + b.toc(); + + if ( z !== 0 ) { + b.fail( 'should return 0' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var ord; + var N; + var f; + var i; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < LAYOUTS.length; k++ ) { + ord = LAYOUTS[ k ]; + for ( i = min; i <= max; i++ ) { + N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); + f = createBenchmark( ord, N ); + bench( format( '%s::square_matrix:ndarray:order=%s,size=%d', pkg, ord, N*N ), f ); + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/dgeqr2/docs/repl.txt new file mode 100644 index 000000000000..20d43e423aad --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/docs/repl.txt @@ -0,0 +1,182 @@ + +{{alias}}( order, M, N, A, LDA, TAU, WORK ) + Computes an computes a QR factorization of a real `M-by-N` matrix `A`. + + On exit, the elements on and above the diagonal of A contain the min(M,N) + by `N` upper trapezoidal matrix R (R is upper triangular if M >= N) matrix + `R`. The elements below the diagonal, with the array `TAU`, represent the + orthogonal matrix `Q` as a product of elementary reflectors. + + Parameters + ---------- + order: string + Storage layout order. + + M: NonNegativeInteger + Number of rows in `A`. + + N: NonNegativeInteger + Number of columns in `A`. + + A: Float64Array + Input/output matrix. + + LDA: PositiveInteger + Stride of the first dimension of `A` (i.e., the leading dimension of + the matrix `A`). + + TAU: Float64Array + Output array of scalar factors. Should have `min(M,N)` indexed + elements. + + WORK: Float64Array + Workspace array. Should have at least `M` indexed elements. + + Returns + ------- + status: integer + Status code. The status code indicates the following conditions: + + - if equal to zero, then the computation was successful. + - if less than zero, then the `-i`th argument had an illegal value. + + Examples + -------- + > 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( 'column-major', 3, 4, A, 3, TAU, work ) + 0 + > A[ 0 ] + ~-10.344 + > A[ 1 ] + ~0.441 + > A[ 2 ] + ~0.793 + > A[ 3 ] + ~-11.794 + > A[ 4 ] + ~0.947 + > A[ 5 ] + ~0.919 + > A[ 6 ] + ~-13.244 + > A[ 7 ] + ~1.894 + > A[ 8 ] + ~0.0 + > A[ 9 ] + ~-14.694 + > A[ 10 ] + ~2.842 + > A[ 11 ] + ~0.0 + > TAU + [ ~1.097, ~1.084, 0.0 ] + > work + [ ~-1.894, ~-2.842, ~17.046, 0.0 ] + + +{{alias}}.ndarray( M, N, A, sA1, sA2, oA, TAU, sT, oT, WORK, sWORK, oWORK ) + Computes an computes a QR factorization of a real `M-by-N` matrix `A` + using alternative indexing semantics. + + On exit, the elements on and above the diagonal of A contain the min(M,N) + by `N` upper trapezoidal matrix R (R is upper triangular if M >= N) matrix + `R`. The elements below the diagonal, with the array `TAU`, represent the + orthogonal matrix `Q` as a product of elementary reflectors. + + Parameters + ---------- + M: NonNegativeInteger + Number of rows in `A`. + + N: NonNegativeInteger + Number of columns in `A`. + + A: Float64Array + Input/output matrix. On entry, the matrix `A`. On exit, the elements on + and below the diagonal of `A` contain the lower trapezoidal matrix `L`, + and the elements above the diagonal contain information used to + represent `Q`. + + sA1: integer + Stride length for the first dimension of `A`. + + sA2: integer + Stride length for the second dimension of `A`. + + oA: NonNegativeInteger + Starting index for `A`. + + TAU: Float64Array + Output array of scalar factors. Should have `min(M,N)` indexed + elements. + + sT: integer + Stride length for `TAU`. + + oT: NonNegativeInteger + Starting index for `TAU`. + + WORK: Float64Array + Workspace array. Should have at least `M` indexed elements. + + sWORK: integer + Stride length for `WORK`. + + oWORK: NonNegativeInteger + Starting index for `WORK`. + + Returns + ------- + status: integer + Status code. The status code indicates the following conditions: + + - if equal to zero, then the computation was successful. + - if less than zero, then the `-i`th argument had an illegal value. + + Examples + -------- + > 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 ) + 0 + > A[ 0 ] + ~-10.344 + > A[ 1 ] + ~0.441 + > A[ 2 ] + ~0.793 + > A[ 3 ] + ~-11.794 + > A[ 4 ] + ~0.947 + > A[ 5 ] + ~0.919 + > A[ 6 ] + ~-13.244 + > A[ 7 ] + ~1.894 + > A[ 8 ] + ~0.0 + > A[ 9 ] + ~-14.694 + > A[ 10 ] + ~2.842 + > A[ 11 ] + ~0.0 + > TAU + [ ~1.097, ~1.084, 0.0 ] + > work + [ ~-1.894, ~-2.842, ~17.046, 0.0 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/dgeqr2/docs/types/index.d.ts new file mode 100644 index 000000000000..2a1193ebd0c0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/docs/types/index.d.ts @@ -0,0 +1,151 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +/** +* Status code. +* +* ## Notes +* +* The status code indicates the following conditions: +* +* - if equal to zero, then the computation was successful. +* - if less than zero, then the `-i`th argument had an illegal value. +*/ +type StatusCode = number; + +/** +* Interface describing `dgeqr2`. +*/ +interface Routine { + /** + * Computes an computes a QR factorization of a real `M-by-N` matrix `A`. + * + * ## Notes + * + * - On exit, the elements on and above the diagonal of A contain the min(M,N) by `N` upper trapezoidal matrix R (R is upper triangular if M >= N) matrix `R`. + * - The elements below the diagonal, with the array `TAU`, represent the orthogonal matrix `Q` as a product of elementary reflectors. + * + * @param order - storage layout + * @param M - number of rows in `A` + * @param N - number of columns in `A` + * @param A - input/output matrix + * @param LDA - stride of the first dimension of `A` (i.e., leading dimension of `A`) + * @param TAU - output array of scalar factors (length min(M,N)) + * @param WORK - workspace array (length >= M) + * @returns status code + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * 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 => [ ~-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 => [ ~1.097, ~1.084, 0.0 ] + * // work => [ ~-1.894, ~-2.842, ~17.046, 0.0 ] + */ + ( order: string, M: number, N: number, A: Float64Array, LDA: number, TAU: Float64Array, WORK: Float64Array ): StatusCode; + + /** + * Computes an computes a QR factorization of a real `M-by-N` matrix `A` using alternative indexing semantics. + * + * ## Notes + * + * - On exit, the elements on and above the diagonal of A contain the min(M,N) by `N` upper trapezoidal matrix R (R is upper triangular if M >= N) matrix `R`. + * - The elements below the diagonal, with the array `TAU`, represent the orthogonal matrix `Q` as a product of elementary reflectors. + * + * @param M - number of rows in `A` + * @param N - number of columns in `A` + * @param A - input/output matrix + * @param strideA1 - stride of the first dimension of `A` + * @param strideA2 - stride of the second dimension of `A` + * @param offsetA - starting index for `A` + * @param TAU - output array of scalar factors (length min(M,N)) + * @param strideTAU - stride for `TAU` + * @param offsetTAU - starting index for `TAU` + * @param WORK - workspace array (length >= M) + * @param strideWORK - stride for `WORK` + * @param offsetWORK - starting index for `WORK` + * @returns status code + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * 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.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, work, 1, 0 ); + * // A => [ ~-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 => [ ~1.097, ~1.084, 0.0 ] + * // work => [ ~-1.894, ~-2.842, ~17.046, 0.0 ] + */ + ndarray( M: number, N: number, A: Float64Array, strideA1: number, strideA2: number, offsetA: number, TAU: Float64Array, strideTAU: number, offsetTAU: number, WORK: Float64Array, strideWORK: number, offsetWORK: number ): StatusCode; +} + +/** +* Computes an computes a QR factorization of a real `M-by-N` matrix `A`. +* +* ## Notes +* +* - On exit, the elements on and above the diagonal of A contain the min(M,N) by `N` upper trapezoidal matrix R (R is upper triangular if M >= N) matrix `R`. +* - The elements below the diagonal, with the array `TAU`, represent the orthogonal matrix `Q` as a product of elementary reflectors. +* +* @param order - storage layout +* @param M - number of rows in `A` +* @param N - number of columns in `A` +* @param A - input/output matrix +* @param LDA - stride of the first dimension of `A` (i.e., leading dimension of `A`) +* @param TAU - output array of scalar factors (length min(M,N)) +* @param WORK - workspace array (length >= M) +* @returns status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* 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( 'column-major', 3, 4, A, 3, TAU, work ); +* // A => [ ~-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 => [ ~1.097, ~1.084, 0.0 ] +* // work => [ ~-1.894, ~-2.842, ~17.046, 0.0 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* 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 => [ ~-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 => [ ~1.097, ~1.084, 0.0 ] +* // work => [ ~-1.894, ~-2.842, ~17.046, 0.0 ] +*/ +declare var dgeqr2: Routine; + + +// EXPORTS // + +export = dgeqr2; diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/dgeqr2/docs/types/test.ts new file mode 100644 index 000000000000..c3cfa864fd5f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/docs/types/test.ts @@ -0,0 +1,382 @@ +/* +* @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. +*/ + +// TypeScript Version: 4.1 + +import dgeqr2 = require( './index' ); + +// TESTS // + +// The function returns a number... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2( 'column-major', 3, 4, A, 3, TAU, WORK ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a string... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2( 5, 3, 4, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( true, 3, 4, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( false, 3, 4, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( null, 3, 4, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( undefined, 3, 4, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( [], 3, 4, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( {}, 3, 4, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( ( x: number ): number => x, 3, 4, A, 3, TAU, WORK ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2( 'column-major', '5', 4, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', true, 4, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', false, 4, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', null, 4, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', undefined, 4, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', [], 4, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', {}, 4, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', ( x: number ): number => x, 4, A, 3, TAU, WORK ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2( 'column-major', 3, '5', A, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, true, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, false, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, null, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, undefined, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, [], A, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, {}, A, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, ( x: number ): number => x, A, 3, TAU, WORK ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a Float64Array... +{ + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2( 'column-major', 3, 4, '5', 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, 5, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, true, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, false, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, null, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, undefined, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, [], 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, {}, 3, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, ( x: number ): number => x, 3, TAU, WORK ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2( 'column-major', 3, 4, A, '5', TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, true, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, false, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, null, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, undefined, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, [], TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, {}, TAU, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, ( x: number ): number => x, TAU, WORK ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a Float64Array... +{ + var A = new Float64Array( 12 ); + var WORK = new Float64Array( 4 ); + + dgeqr2( 'column-major', 3, 4, A, 3, '5', WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, 5, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, true, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, false, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, null, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, undefined, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, [], WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, {}, WORK ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, ( x: number ): number => x, WORK ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a Float64Array... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + + dgeqr2( 'column-major', 3, 4, A, 3, TAU, '5' ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, TAU, 5 ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, TAU, true ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, TAU, false ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, TAU, null ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, TAU, undefined ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, TAU, [] ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, TAU, {} ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, TAU, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided unsupported number of arguments... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2(); // $ExpectError + dgeqr2( 'column-major' ); // $ExpectError + dgeqr2( 'column-major', 3 ); // $ExpectError + dgeqr2( 'column-major', 3, 4 ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3 ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, TAU ); // $ExpectError + dgeqr2( 'column-major', 3, 4, A, 3, TAU, WORK, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + var A = new Float64Array( 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 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2.ndarray( '5', 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( true, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( false, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( null, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( undefined, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( [], 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( {}, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( ( x: number ): number => x, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2.ndarray( 3, '5', A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, true, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, false, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, null, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, undefined, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, [], A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, {}, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, ( x: number ): number => x, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Float64Array... +{ + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2.ndarray( 3, 4, '5', 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, 5, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, true, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, false, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, null, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, undefined, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, [], 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, {}, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, ( x: number ): number => x, 1, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2.ndarray( 3, 4, A, '5', 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, true, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, false, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, null, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, undefined, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, [], 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, {}, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, ( x: number ): number => x, 3, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a number... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2.ndarray( 3, 4, A, 1, '5', 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, true, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, false, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, null, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, undefined, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, [], 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, {}, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, ( x: number ): number => x, 0, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2.ndarray( 3, 4, A, 1, 3, '5', TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, true, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, false, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, null, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, undefined, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, [], TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, {}, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, ( x: number ): number => x, TAU, 1, 0, WORK, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a Float64Array... +{ + var A = new Float64Array( 12 ); + var WORK = new Float64Array( 4 ); + + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, '5', 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, 5, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, true, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, false, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, null, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, undefined, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, [], 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, {}, 1, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, ( x: number ): number => x, 1, 0, WORK, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eighth argument which is not a number... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, '5', 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, true, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, false, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, null, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, undefined, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, [], 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, {}, 0, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, ( x: number ): number => x, 0, WORK, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a ninth argument which is not a number... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, '5', WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, true, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, false, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, null, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, undefined, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, [], WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, {}, WORK, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, ( x: number ): number => x, WORK, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a tenth argument which is not a Float64Array... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, '5', 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, 5, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, true, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, false, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, null, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, undefined, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, [], 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, {}, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an eleventh argument which is not a number... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, '5', 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, true, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, false, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, null, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, undefined, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, [], 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, {}, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a twelfth argument which is not a number... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, '5' ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, true ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, false ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, null ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, undefined ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, [] ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, {} ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + var A = new Float64Array( 12 ); + var TAU = new Float64Array( 3 ); + var WORK = new Float64Array( 4 ); + + dgeqr2.ndarray(); // $ExpectError + dgeqr2.ndarray( 3 ); // $ExpectError + dgeqr2.ndarray( 3, 4 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1 ); // $ExpectError + dgeqr2.ndarray( 3, 4, A, 1, 3, 0, TAU, 1, 0, WORK, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dgeqr2/examples/index.js new file mode 100644 index 000000000000..c4f04ee131c3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/examples/index.js @@ -0,0 +1,59 @@ +/** +* @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. +*/ + +'use strict'; + +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var dgeqr2 = require( './../lib' ); + +// 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 ); diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/base.js new file mode 100644 index 000000000000..6cc46926cd09 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/base.js @@ -0,0 +1,99 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var dlarf1f = require( '@stdlib/lapack/base/dlarf1f' ).ndarray; +var Float64Array = require( '@stdlib/array/float64' ); +var min = require( '@stdlib/math/base/special/min' ); +var dlarfg = require( './dlarfg.js' ); + + +// MAIN // + +/** +* Compute a QR factorization of a general rectangular matrix using an unblocked algorithm. +* +* ## Notes +* +* - On exit, the elements on and above the diagonal of A contain the min(M,N) by `N` upper trapezoidal matrix R (R is upper triangular if M >= N) matrix `R`. +* - The elements below the diagonal, with the array `TAU`, represent the orthogonal matrix `Q` as a product of elementary reflectors. +* +* @private +* @param {NonNegativeInteger} M - number of rows in `A` +* @param {NonNegativeInteger} N - number of columns in `A` +* @param {Float64Array} A - input/output matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for `A` +* @param {Float64Array} TAU - output array of scalar factors (length min(M,N)) +* @param {integer} strideTAU - stride for TAU +* @param {NonNegativeInteger} offsetTAU - starting index for TAU +* @param {Float64Array} WORK - workspace array (length >= M) +* @param {integer} strideWORK - stride for WORK +* @param {NonNegativeInteger} offsetWORK - starting index for WORK +* @returns {integer} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* 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( 3, 4, A, 1, 3, 0, TAU, 1, 0, work, 1, 0 ); +* // A => [ ~-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 => [ ~1.097, ~1.084, 0.0 ] +* // work => [ ~-1.894, ~-2.842, ~17.046, 0.0 ] +*/ +function dgeqr2( M, N, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK ) { // eslint-disable-line stdlib/jsdoc-doctest-decimal-point, max-len, max-params + var taui; + var aii; + var out; + var K; + var i; + + K = min( M, N ); + out = new Float64Array( 2 ); + + aii = offsetA; // Index of A(i,i) + taui = offsetTAU; // Index of TAU(i) + + for ( i = 0; i < K; i++ ) { + // Generate elementary reflector H(i) to annihilate A(i+1:m,i) + out[ 0 ] = A[ aii ]; + dlarfg( M - i, A, strideA1, aii + ( min( 1, M - 1 - i ) * strideA1 ), out, 1, 0 ); + A[ aii ] = out[ 0 ]; + TAU[ taui ] = out[ 1 ]; + + if ( i < N - 1 ) { + // Apply H(i) to A(i:m,i+1:n) from the left + dlarf1f( 'left', M - i, N - i - 1, A, strideA1, aii, TAU[ taui ], A, strideA1, strideA2, aii + strideA2, WORK, strideWORK, offsetWORK ); + } + aii += strideA1 + strideA2; + taui += strideTAU; + } + return 0; +} + + +// EXPORTS // + +module.exports = dgeqr2; diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/dgeqr2.js b/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/dgeqr2.js new file mode 100644 index 000000000000..d8bc69960f55 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/dgeqr2.js @@ -0,0 +1,88 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var isLayout = require( '@stdlib/blas/base/assert/is-layout' ); +var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' ); +var max = require( '@stdlib/math/base/special/max' ); +var format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Computes an computes a QR factorization of a real `M-by-N` matrix `A`. +* +* ## Notes +* +* - On exit, the elements on and above the diagonal of A contain the min(M,N) by `N` upper trapezoidal matrix R (R is upper triangular if M >= N) matrix `R`. +* - The elements below the diagonal, with the array `TAU`, represent the orthogonal matrix `Q` as a product of elementary reflectors. +* +* @param {string} order - storage layout +* @param {NonNegativeInteger} M - number of rows in `A` +* @param {NonNegativeInteger} N - number of columns in `A` +* @param {Float64Array} A - input/output matrix +* @param {PositiveInteger} LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`) +* @param {Float64Array} TAU - output array of scalar factors (length min(M,N)) +* @param {Float64Array} WORK - workspace array (length >= M) +* @throws {TypeError} first argument must be a valid order +* @throws {RangeError} fifth argument must be greater than or equal to max(1,`M`) +* @returns {integer} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* 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( 'column-major', 3, 4, A, 3, TAU, work ); +* // A => [ ~-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 => [ ~1.097, ~1.084, 0.0 ] +* // work => [ ~-1.894, ~-2.842, ~17.046, 0.0 ] +*/ +function dgeqr2( order, M, N, A, LDA, TAU, WORK ) { // eslint-disable-line stdlib/jsdoc-doctest-decimal-point + var sa1; + var sa2; + + if ( !isLayout( order ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) ); + } + if ( isColumnMajor( order ) ) { + if ( LDA < max( 1, M ) ) { + throw new RangeError( format( 'invalid argument. Fifth argument must be greater than or equal to max(1,`M`). Value: `%d`.', LDA ) ); + } + } + if ( isColumnMajor( order ) ) { + sa1 = 1; + sa2 = LDA; + } else { // order === 'row-major' + sa1 = LDA; + sa2 = 1; + } + return base( M, N, A, sa1, sa2, 0, TAU, 1, 0, WORK, 1, 0 ); +} + + +// EXPORTS // + +module.exports = dgeqr2; diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/dlarfg.js b/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/dlarfg.js new file mode 100644 index 000000000000..04ab125dc7e7 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/dlarfg.js @@ -0,0 +1,142 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var dnrm2 = require( '@stdlib/blas/base/dnrm2' ).ndarray; +var sign = require( '@stdlib/math/base/special/copysign' ); +var dlamch = require( '@stdlib/lapack/base/dlamch' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var dscal = require( '@stdlib/blas/base/dscal' ).ndarray; +var dlapy2 = require( '@stdlib/lapack/base/dlapy2' ); + + +// MAIN // + +/** +* Generates a real elementary reflector `H` of order `N` such that applying `H` to a vector `[alpha; X]` zeros out `X`. +* +* `H` is a Householder matrix with the form: +* +* ```tex +* H \cdot \begin{bmatrix} \alpha \\ x \end{bmatrix} = \begin{bmatrix} \beta \\ 0 \end{bmatrix}, \quad \text{and} \quad H^T H = I +* ``` +* +* where: +* +* - `tau` is a scalar +* - `X` is a vector of length `N-1` +* - `beta` is a scalar value +* - `H` is an orthogonal matrix known as a Householder reflector. +* +* The reflector `H` is constructed in the form: +* +* ```tex +* H = I - \tau \begin{bmatrix}1 \\ v \end{bmatrix} \begin{bmatrix}1 & v^T \end{bmatrix} +* ``` +* +* where: +* +* - `tau` is a real scalar +* - `V` is a real vector of length `N-1` that defines the Householder vector +* - The vector `[1; V]` is the Householder direction. +* +* The values of `tau` and `V` are chosen so that applying `H` to the vector `[alpha; X]` results in a new vector `[beta; 0]`, i.e., only the first component remains nonzero. The reflector matrix `H` is symmetric and orthogonal, satisfying `H^T = H` and `H^T H = I` +* +* ## Special cases +* +* - If all elements of `X` are zero, then `tau = 0` and `H = I`, the identity matrix. +* - Otherwise, `tau` satisfies `1 ≤ tau ≤ 2`, ensuring numerical stability in transformations. +* +* ## Notes +* +* - `X` should have `N-1` indexed elements +* - The output array contains the following two elements: `alpha` and `tau` +* +* @private +* @param {NonNegativeInteger} N - number of rows/columns of the elementary reflector `H` +* @param {Float64Array} X - input vector +* @param {integer} strideX - stride length for `X` +* @param {NonNegativeInteger} offsetX - starting index of `X` +* @param {Float64Array} out - output array +* @param {integer} strideOut - stride length for `out` +* @param {NonNegativeInteger} offsetOut - starting index of `out` +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var X = new Float64Array( [ 2.0, 3.0, 4.0 ] ); +* var out = new Float64Array( [ 4.0, 0.0 ] ); +* +* dlarfg( 4, X, 1, 0, out, 1, 0 ); +* // X => [ ~0.19, ~0.28, ~0.37 ] +* // out => [ ~-6.7, ~1.6 ] +*/ +function dlarfg( N, X, strideX, offsetX, out, strideOut, offsetOut ) { + var safemin; + var rsafmin; + var xnorm; + var alpha; + var beta; + var tau; + var knt; + var i; + + if ( N <= 1 ) { + out[ offsetOut + strideOut ] = 0.0; + return; + } + + xnorm = dnrm2( N - 1, X, strideX, offsetX ); + alpha = out[ offsetOut ]; + + if ( xnorm === 0.0 ) { + out[ strideOut + offsetOut ] = 0.0; + } else { + beta = -1.0 * sign( dlapy2( alpha, xnorm ), alpha ); + safemin = dlamch( 'safemin' ) / dlamch( 'epsilon' ); + knt = 0; + if ( abs( beta ) < safemin ) { + rsafmin = 1.0 / safemin; + while ( abs( beta ) < safemin && knt < 20 ) { + knt += 1; + dscal( N-1, rsafmin, X, strideX, offsetX ); + beta *= rsafmin; + alpha *= rsafmin; + } + xnorm = dnrm2( N - 1, X, strideX, offsetX ); + beta = -1.0 * sign( dlapy2( alpha, xnorm ), alpha ); + } + tau = ( beta - alpha ) / beta; + dscal( N-1, 1.0 / ( alpha - beta ), X, strideX, offsetX ); + for ( i = 0; i < knt; i++ ) { + beta *= safemin; + } + + out[ offsetOut ] = beta; + out[ strideOut + offsetOut ] = tau; + } +} + + +// EXPORTS // + +module.exports = dlarfg; diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/index.js new file mode 100644 index 000000000000..cc7b332256f2 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/index.js @@ -0,0 +1,63 @@ +/** +* @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. +*/ + +'use strict'; + +/** +* LAPACK routine to compute an computes a QR factorization of a real `M-by-N` matrix `A`. +* +* @module @stdlib/lapack/base/dgeqr2 +* +* @example +* 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 ); +* +* var out = dgeqr2( 'column-major', 3, 4, A, 3, TAU, work ); +* // A => [ ~-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 => [ ~1.097, ~1.084, 0.0 ] +* // work => [ ~-1.894, ~-2.842, ~17.046, 0.0 ] +*/ + +// MODULES // + +var join = require( 'path' ).join; +var tryRequire = require( '@stdlib/utils/try-require' ); +var isError = require( '@stdlib/assert/is-error' ); +var main = require( './main.js' ); + + +// MAIN // + +var dgeqr2; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dgeqr2 = main; +} else { + dgeqr2 = tmp; +} + + +// EXPORTS // + +module.exports = dgeqr2; + +// exports: { "ndarray": "dgeqr2.ndarray" } diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/main.js b/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/main.js new file mode 100644 index 000000000000..7fcca931b090 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/main.js @@ -0,0 +1,35 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var dgeqr2 = require( './dgeqr2.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dgeqr2, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dgeqr2; diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/ndarray.js new file mode 100644 index 000000000000..5e15ff5f65cd --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/lib/ndarray.js @@ -0,0 +1,71 @@ +/** +* @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. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +// MODULES // + +var base = require( './base.js' ); + + +// MAIN // + +/** +* Computes an computes a QR factorization of a real `M-by-N` matrix `A` using alternative indexing semantics. +* +* ## Notes +* +* - On exit, the elements on and above the diagonal of A contain the min(M,N) by `N` upper trapezoidal matrix R (R is upper triangular if M >= N) matrix `R`. +* - The elements below the diagonal, with the array `TAU`, represent the orthogonal matrix `Q` as a product of elementary reflectors. +* +* @param {NonNegativeInteger} M - number of rows in `A` +* @param {NonNegativeInteger} N - number of columns in `A` +* @param {Float64Array} A - input/output matrix +* @param {integer} strideA1 - stride of the first dimension of `A` +* @param {integer} strideA2 - stride of the second dimension of `A` +* @param {NonNegativeInteger} offsetA - starting index for A`` +* @param {Float64Array} TAU - output array of scalar factors (length min(M,N)) +* @param {integer} strideTAU - stride for TAU +* @param {NonNegativeInteger} offsetTAU - starting index for TAU +* @param {Float64Array} WORK - workspace array (length >= M) +* @param {integer} strideWORK - stride for WORK +* @param {NonNegativeInteger} offsetWORK - starting index for WORK +* @returns {integer} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* 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( 3, 4, A, 1, 3, 0, TAU, 1, 0, work, 1, 0 ); +* // A => [ ~-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 => [ ~1.097, ~1.084, 0.0 ] +* // work => [ ~-1.894, ~-2.842, ~17.046, 0.0 ] +*/ +function dgeqr2( M, N, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK ) { // eslint-disable-line stdlib/jsdoc-doctest-decimal-point, max-params + return base( M, N, A, strideA1, strideA2, offsetA, TAU, strideTAU, offsetTAU, WORK, strideWORK, offsetWORK ); +} + + +// EXPORTS // + +module.exports = dgeqr2; diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/package.json b/lib/node_modules/@stdlib/lapack/base/dgeqr2/package.json new file mode 100644 index 000000000000..fb053454632a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/lapack/base/dgeqr2", + "version": "0.0.0", + "description": "LAPACK routine to compute an computes a QR factorization of a real `M-by-N` matrix `A`.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "lapack", + "dgelq2", + "reflector", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "matrix", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/test/fixtures/col_maj.json b/lib/node_modules/@stdlib/lapack/base/dgeqr2/test/fixtures/col_maj.json new file mode 100644 index 000000000000..3b4711ab68de --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/test/fixtures/col_maj.json @@ -0,0 +1,49 @@ +{ + "order": "column-major", + + "M": 3, + "N": 4, + + "A": [ 1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12 ], + "strideA1": 1, + "strideA2": 3, + "offsetA": 0, + "LDA": 3, + "A_mat": [ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12] + ], + + "TAU": [ 0, 0, 0 ], + "strideTAU": 1, + "offsetTAU": 0, + + "WORK": [ 0, 0, 0, 0 ], + "strideWORK": 1, + "offsetWORK": 0, + + "A_out": [ + -10.34408043278860311887, + 0.44075851098059426469, + 0.79336531976506974306, + -11.79418516635709224261, + 0.94720444555662541841, + 0.91891723513735434903, + -13.24428989992558669542, + 1.89440889111325461158, + 0.0000000000000015543122344752192, + -14.69439463349408470094, + 2.84161333666988724644, + 0.000000000000004440892098500626 + ], + "A_out_mat": [ + [ -10.3440804327886031, -11.7941851663570922, -13.2442898999255867, -14.6943946334940847 ], + [ 0.4407585109805943, 0.9472044455566254, 1.8944088911132546, 2.8416133366698872 ], + [ 0.7933653197650697, 0.9189172351373543, 0.0000000000000016, 0.0000000000000044 ] + ], + + "TAU_out": [ 1.0966736489045663, 1.0843582549564548, 0.0000000000000000 ], + + "WORK_out": [ -1.8944088911132555, -2.8416133366698908, 17.0464519250255933, 0.0000000000000000 ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/test/fixtures/row_maj.json b/lib/node_modules/@stdlib/lapack/base/dgeqr2/test/fixtures/row_maj.json new file mode 100644 index 000000000000..622f8d3b64ca --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/test/fixtures/row_maj.json @@ -0,0 +1,49 @@ +{ + "order": "row-major", + + "M": 3, + "N": 4, + + "A": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], + "strideA1": 4, + "strideA2": 1, + "offsetA": 0, + "LDA": 4, + "A_mat": [ + [1, 2, 3, 4], + [5, 6, 7, 8], + [9, 10, 11, 12] + ], + + "TAU": [ 0, 0, 0 ], + "strideTAU": 1, + "offsetTAU": 0, + + "WORK": [ 0, 0, 0, 0 ], + "strideWORK": 1, + "offsetWORK": 0, + + "A_out": [ + -10.3440804327886031, + -11.7941851663570922, + -13.2442898999255867, + -14.6943946334940847, + 0.4407585109805943, + 0.9472044455566254, + 1.8944088911132546, + 2.8416133366698872, + 0.7933653197650697, + 0.9189172351373543, + 0.0000000000000016, + 0.0000000000000044 + ], + "A_out_mat": [ + [ -10.3440804327886031, -11.7941851663570922, -13.2442898999255867, -14.6943946334940847 ], + [ 0.4407585109805943, 0.9472044455566254, 1.8944088911132546, 2.8416133366698872 ], + [ 0.7933653197650697, 0.9189172351373543, 0.0000000000000016, 0.0000000000000044 ] + ], + + "TAU_out": [ 1.0966736489045663, 1.0843582549564548, 0.0000000000000000 ], + + "WORK_out": [ -1.8944088911132555, -2.8416133366698908, 17.0464519250255933, 0.0000000000000000 ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/test/test.dgeqr2.js b/lib/node_modules/@stdlib/lapack/base/dgeqr2/test/test.dgeqr2.js new file mode 100644 index 000000000000..2e0919c90865 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/test/test.dgeqr2.js @@ -0,0 +1,166 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isAlmostEqual = require( '@stdlib/assert/is-almost-equal-float64array' ); +var dgeqr2 = require( './../lib/dgeqr2.js' ); + + +// FIXTURES // + +var COL_MAJ = require( './fixtures/col_maj.json' ); +var ROW_MAJ = require( './fixtures/row_maj.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dgeqr2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( dgeqr2.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not a valid order', function test( t ) { + var values; + var work; + var TAU; + var A; + var i; + + A = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12 ] ); + TAU = new Float64Array( 3 ); + work = new Float64Array( 3 ); + + values = [ + 'foo', + 'bar', + 'beep', + 'boop', + -5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgeqr2( value, 3, 4, A, 3, TAU, work ); + }; + } +}); + +tape( 'the function throws an error if provided a fifth argument which is not a valid LDA value', function test( t ) { + var values; + var work; + var TAU; + var A; + var i; + + A = new Float64Array( [ 1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12 ] ); + TAU = new Float64Array( 3 ); + work = new Float64Array( 3 ); + + values = [ + 2, + 1, + 0 + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dgeqr2( 'column-major', 3, 4, A, value, TAU, work ); + }; + } +}); + +tape( 'the function computes an computes a QR factorization of a real `M-by-N` matrix `A` (col-major)', function test( t ) { + var expectedWork; + var expectedTau; + var expectedA; + var data; + var work; + var tau; + var A; + + data = COL_MAJ; + + A = new Float64Array( data.A ); + tau = new Float64Array( data.TAU ); + work = new Float64Array( data.WORK ); + + expectedA = new Float64Array( data.A_out ); + expectedTau = new Float64Array( data.TAU_out ); + expectedWork = new Float64Array( data.WORK_out ); + + dgeqr2( data.order, data.M, data.N, A, data.LDA, tau, work ); + t.strictEqual( isAlmostEqual( A, expectedA, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( tau, expectedTau, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( work, expectedWork, 1 ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function computes an computes a QR factorization of a real `M-by-N` matrix `A` (row-major)', function test( t ) { + var expectedWork; + var expectedTau; + var expectedA; + var data; + var work; + var tau; + var A; + + data = ROW_MAJ; + + A = new Float64Array( data.A ); + tau = new Float64Array( data.TAU ); + work = new Float64Array( data.WORK ); + + expectedA = new Float64Array( data.A_out ); + expectedTau = new Float64Array( data.TAU_out ); + expectedWork = new Float64Array( data.WORK_out ); + + dgeqr2( data.order, data.M, data.N, A, data.LDA, tau, work ); + t.strictEqual( isAlmostEqual( A, expectedA, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( tau, expectedTau, 1 ), true, 'returns expected value' ); + t.strictEqual( isAlmostEqual( work, expectedWork, 1 ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dgeqr2/test/test.js b/lib/node_modules/@stdlib/lapack/base/dgeqr2/test/test.js new file mode 100644 index 000000000000..23ed57a6698b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dgeqr2/test/test.js @@ -0,0 +1,82 @@ +/** +* @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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var proxyquire = require( 'proxyquire' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var dgeqr2 = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dgeqr2, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof dgeqr2.ndarray, 'function', 'method is a function' ); + t.end(); +}); + +tape( 'if a native implementation is available, the main export is the native implementation', opts, function test( t ) { + var dgeqr2 = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dgeqr2, mock, 'returns expected value' ); + t.end(); + + function tryRequire() { + return mock; + } + + function mock() { + // Mock... + } +}); + +tape( 'if a native implementation is not available, the main export is a JavaScript implementation', opts, function test( t ) { + var dgeqr2; + var main; + + main = require( './../lib/dgeqr2.js' ); + + dgeqr2 = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dgeqr2, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +});