diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/README.md b/lib/node_modules/@stdlib/lapack/base/dlarfg/README.md new file mode 100644 index 000000000000..4542e3ddf5ff --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/README.md @@ -0,0 +1,302 @@ + + +# dlarfg + +> LAPACK routine to generate a real elementary reflector `H` of order `N` such that applying `H` to a vector `[alpha; X]` zeros out `X`. + +
+ +The `dlarfg` routine generates a **real elementary reflector** (also known as a Householder reflector) of order `N`, which can be used to zero out selected components of a vector. Specifically, it constructs a reflector matrix `H` such that: + + + + +```math +H \cdot \begin{bmatrix}\alpha \\ x \end{bmatrix} = \begin{bmatrix} \beta \\ 0 \end{bmatrix}, \quad \text{and} \quad H^T H = I +``` + + + + +Here: + +- `α` is a scalar. +- `X` is a real vector of length `N-1`. +- `β` is a scalar value. +- `H` is an orthogonal matrix known as a Householder reflector. + +The reflector `H` is constructed in the form: + + + +```math +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 `τ` and `V` are chosen so that applying `H` to the vector `[α; x]` results in a new vector `[β; 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 `τ = 0` and `H = I`, the identity matrix. +- Otherwise, `τ` satisfies `1 ≤ τ ≤ 2`, ensuring numerical stability in transformations. + +This elementary reflector is commonly used in algorithms for QR factorization and other orthogonal transformations. + +
+ + + +
+ +## Usage + +```javascript +var dlarfg = require( '@stdlib/lapack/base/dlarfg' ); +``` + +#### dlarfg( N, X, incx, out ) + +Generates a real elementary reflector `H` of order `N` such that applying `H` to a vector `[alpha; X]` zeros out `X`. + +```javascript +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, out ); +// X => [ ~0.19, ~0.28, ~0.37 ] +// out => [ ~-6.7, ~1.6 ] +``` + +The function has the following parameters: + +- **N**: number of rows/columns of the elementary reflector `H`. +- **X**: a [`Float64Array`][mdn-float64array] which is overwritten by the vector `V`. Should have `N - 1` indexed elements. +- **incx**: stride length of `X`. +- **out**: output [`Float64Array`][mdn-float64array]. The first element of `out` represents alpha and the second element of `out` represents `tau`. + +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' ); + +// Initial arrays... +var X0 = new Float64Array( [ 0.0, 2.0, 3.0, 4.0 ] ); +var out0 = new Float64Array( [ 0.0, 4.0, 0.0 ] ); + +// Create offset views... +var X1 = new Float64Array( X0.buffer, X0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var out1 = new Float64Array( out0.buffer, out0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +dlarfg( 4, X1, 1, out1 ); +// X0 => [ 0.0, ~0.19, ~0.28, ~0.37 ] +// out0 => [ 0.0, ~6.7, ~1.6 ] +``` + +#### dlarfg.ndarray( N, X, strideX, offsetX, out, strideOut, offsetOut ) + +Generates a real elementary reflector `H` of order `N` such that applying `H` to a vector `[alpha; X]` zeros out `X` using alternative indexing semantics. + +```javascript +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.ndarray( 4, X, 1, 0, out, 1, 0 ); +// X => [ ~0.19, ~0.28, ~0.37 ] +// out => [ ~-6.7, ~1.6 ] +``` + +The function has the following parameters: + +- **N**: number of rows/columns of the elementary reflector `H`. +- **X**: a [`Float64Array`][mdn-float64array] which is overwritten by the vector `V`. Should have `N - 1` indexed elements. +- **strideX**: stride length of `X`. +- **offsetX**: starting index of `X`. +- **out**: output [`Float64Array`][mdn-float64array]. The first element of `out` represents alpha and the second element of `out` represents `tau`. +- **strideOut**: stride length of `out`. +- **offsetOut**: starting index of `out`. + +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 X = new Float64Array( [ 0.0, 2.0, 3.0, 4.0 ] ); +var out = new Float64Array( [ 0.0, 4.0, 0.0 ] ); + +dlarfg.ndarray( 4, X, 1, 1, out, 1, 1 ); +// X => [ 0.0, ~0.19, ~0.28, ~0.37 ] +// out => [ 0.0, ~6.7, ~1.6 ] +``` + +
+ + + +
+ +## Notes + +- `dlarfg()` corresponds to the [LAPACK][lapack] routine [`dlarfg`][lapack-dlarfg]. + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dlarfg = require( '@stdlib/lapack/base/dlarfg' ); + +var N = 4; + +var X = uniform( N - 1, -10, 10, { + 'dtype': 'float64' +}); +console.log( 'X: ', X ); + +var alpha = 4.0; + +var out = new Float64Array( [ alpha, 0.0 ] ); + +dlarfg( N, X, 1, out ); + +console.log( 'V: ', X ); +console.log( 'beta: ', out[ 0 ] ); +console.log( 'tau: ', out[ 1 ] ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dlarfg/benchmark/benchmark.js new file mode 100644 index 000000000000..fccf79d1baae --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/benchmark/benchmark.js @@ -0,0 +1,103 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dlarfg = require( './../lib/dlarfg.js' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - number of elements along each dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var opts; + var out; + var X; + + opts = { + 'dtype': 'float64' + }; + + X = uniform( N-1, -10.0, 10.0, opts ); + out = uniform( 2, -10.0, 10.0, opts ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + dlarfg( N, X, 1, out ); + if ( isnan( X[ i%X.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( X[ i%X.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + N = pow( 10, i ); + f = createBenchmark( N ); + bench( pkg+':size='+(N), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dlarfg/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..70fbbc5b8851 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/benchmark/benchmark.ndarray.js @@ -0,0 +1,103 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var dlarfg = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} N - number of elements along each dimension +* @returns {Function} benchmark function +*/ +function createBenchmark( N ) { + var opts; + var out; + var X; + + opts = { + 'dtype': 'float64' + }; + + X = uniform( N-1, -10.0, 10.0, opts ); + out = uniform( 2, -10.0, 10.0, opts ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + dlarfg( N, X, 1, 0, out, 1, 0 ); + if ( isnan( X[ i%X.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( X[ i%X.length ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var min; + var max; + var N; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + N = pow( 10, i ); + f = createBenchmark( N ); + bench( pkg+':size='+(N), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/dlarfg/docs/repl.txt new file mode 100644 index 000000000000..9b497cfba405 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/docs/repl.txt @@ -0,0 +1,96 @@ + +{{alias}}( N, X, incx, out ) + 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 `H = I - tau * [1; V] * [1, V^T]`, + where `tau` is a scalar and `V` is a vector. The input vector is + `[alpha; X]`, where `alpha` is a scalar and `X` is a real `(n-1)`-element + vector. The result of applying `H` to `[alpha; X]` is `[beta; 0]`, with + `beta` being a scalar and the rest of the vector zeroed. If all elements of + `X` are zero, then `tau = 0` and `H` is the identity matrix. Otherwise, + `1 <= tau <= 2`. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + Parameters + ---------- + N: integer + Number of row/columns of the elementary reflector `H`. + + X: Float64Array + Input vector, overwritten by the vector `V` on exit, expects `N - 1` + indexed elements. + + incx: integer + Increment between successive values of `X`. + + out: Float64Array + Array to store `alpha` and `tau`, first indexed element stores `alpha` + and the second indexed element stores `tau`. + + Examples + -------- + > var X = new {{alias:@stdlib/array/float64}}( [ 2.0, 3.0, 4.0 ] ); + > var out = new {{alias:@stdlib/array/float64}}( [ 4.0, 0.0 ] ); + > {{alias}}( 4, X, 1, out ); + > X + [ ~0.19, ~0.28, ~0.37 ] + > out + [ ~-6.7, ~1.6 ] + + +{{alias}}.ndarray( N, X, strideX, offsetX, out, strideOut, offsetOut ) + 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 `H = I - tau * [1; V] * [1, V^T]`, + where `tau` is a scalar and `V` is a vector. The input vector is + `[alpha; X]`, where `alpha` is a scalar and `X` is a real `(n-1)`-element + vector. The result of applying `H` to `[alpha; X]` is `[beta; 0]`, with + `beta` being a scalar and the rest of the vector zeroed. If all elements of + `X` are zero, then `tau = 0` and `H` is the identity matrix. Otherwise, + `1 <= tau <= 2`. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + Parameters + ---------- + N: integer + Number of row/columns of the elementary reflector `H`. + + X: Float64Array + Input vector, overwritten by the vector `V` on exit, expects `N - 1` + indexed elements. + + strideX: integer + Stride length for `X`. + + offsetX: integer + Starting index for `X. + + out: Float64Array + Array to store `alpha` and `tau`, first indexed element stores `alpha` + and the second indexed element stores `tau`. + + strideOut: integer + Stride length for `out`. + + offsetOut: integer + Starting index for `out`. + + Examples + -------- + > var X = new {{alias:@stdlib/array/float64}}( [ 2.0, 3.0, 4.0 ] ); + > var out = new {{alias:@stdlib/array/float64}}( [ 4.0, 0.0 ] ); + > {{alias}}.ndarray( 4, X, 1, 0, out, 1, 0 ); + > X + [ ~0.19, ~0.28, ~0.37 ] + > out + [ ~-6.7, ~1.6 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/dlarfg/docs/types/index.d.ts new file mode 100644 index 000000000000..be15eb9ccbf3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/docs/types/index.d.ts @@ -0,0 +1,203 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 + +/** +* Interface describing `dlarfg`. +*/ +interface Routine { + /** + * 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` + * + * @param N - number of rows/columns of the elementary reflector `H` + * @param X - input vector + * @param incx - stride length for `X` + * @param out - output array + * + * @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, out ); + * // X => [ ~0.19, ~0.28, ~0.37 ] + * // out => [ ~-6.7, ~1.6 ] + */ + ( N: number, X: Float64Array, incx: number, out: Float64Array ): void; + + /** + * Generates a real elementary reflector `H` of order `N` such that applying `H` to a vector `[alpha; X]` zeros out `X` using alternative indexing semantics. + * + * `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` + * + * @param N - number of rows/columns of the elementary reflector `H` + * @param X - input vector + * @param strideX - stride length for `X` + * @param offsetX - starting index of `X` + * @param out - output array + * @param strideOut - stride length for `out` + * @param offsetOut - starting index of `out` + * + * @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 ] + */ + ndarray( N: number, X: Float64Array, strideX: number, offsetX: number, out: Float64Array, strideOut: number, offsetOut: number ): void; +} + +/** +* 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` +* +* @param N - number of rows/columns of the elementary reflector `H` +* @param X - input vector +* @param incx - stride length for `X` +* @param out - output array +* +* @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, out ); +* // X => [ ~0.19, ~0.28, ~0.37 ] +* // out => [ ~-6.7, ~1.6 ] +*/ +declare var dlarfg: Routine; + + +// EXPORTS // + +export = dlarfg; diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/dlarfg/docs/types/test.ts new file mode 100644 index 000000000000..2fff79e07f68 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/docs/types/test.ts @@ -0,0 +1,229 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +import dlarfg = require( './index' ); + + +// TESTS // + +// The function returns undefined... +{ + const X = new Float64Array( 3 ); + const out = new Float64Array( 2 ); + + dlarfg( 4, X, 1, out ); // $ExpectType void +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const X = new Float64Array( 3 ); + const out = new Float64Array( 2 ); + + dlarfg( '5', X, 1, out ); // $ExpectError + dlarfg( true, X, 1, out ); // $ExpectError + dlarfg( false, X, 1, out ); // $ExpectError + dlarfg( null, X, 1, out ); // $ExpectError + dlarfg( void 0, X, 1, out ); // $ExpectError + dlarfg( [], X, 1, out ); // $ExpectError + dlarfg( {}, X, 1, out ); // $ExpectError + dlarfg( ( x: number ): number => x, X, 1, out ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Float64Array... +{ + const out = new Float64Array( 2 ); + + dlarfg( 4, '5', 1, out ); // $ExpectError + dlarfg( 4, 5, 1, out ); // $ExpectError + dlarfg( 4, true, 1, out ); // $ExpectError + dlarfg( 4, false, 1, out ); // $ExpectError + dlarfg( 4, null, 1, out ); // $ExpectError + dlarfg( 4, void 0, 1, out ); // $ExpectError + dlarfg( 4, [], 1, out ); // $ExpectError + dlarfg( 4, {}, 1, out ); // $ExpectError + dlarfg( 4, ( x: number ): number => x, 1, out ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const X = new Float64Array( 3 ); + const out = new Float64Array( 2 ); + + dlarfg( 4, X, '1', out ); // $ExpectError + dlarfg( 4, X, true, out ); // $ExpectError + dlarfg( 4, X, false, out ); // $ExpectError + dlarfg( 4, X, null, out ); // $ExpectError + dlarfg( 4, X, void 0, out ); // $ExpectError + dlarfg( 4, X, [], out ); // $ExpectError + dlarfg( 4, X, {}, out ); // $ExpectError + dlarfg( 4, X, ( x: number ): number => x, out ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a Float64Array... +{ + const X = new Float64Array( 3 ); + + dlarfg( 4, X, 1, '5' ); // $ExpectError + dlarfg( 4, X, 1, 5 ); // $ExpectError + dlarfg( 4, X, 1, true ); // $ExpectError + dlarfg( 4, X, 1, false ); // $ExpectError + dlarfg( 4, X, 1, null ); // $ExpectError + dlarfg( 4, X, 1, void 0 ); // $ExpectError + dlarfg( 4, X, 1, [] ); // $ExpectError + dlarfg( 4, X, 1, {} ); // $ExpectError + dlarfg( 4, X, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const X = new Float64Array( 3 ); + const out = new Float64Array( 2 ); + + dlarfg(); // $ExpectError + dlarfg( 4 ); // $ExpectError + dlarfg( 4, X ); // $ExpectError + dlarfg( 4, X, 1 ); // $ExpectError + dlarfg( 4, X, 1, out, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns undefined... +{ + const X = new Float64Array( 3 ); + const out = new Float64Array( 2 ); + + dlarfg.ndarray( 4, X, 1, 0, out, 1, 0 ); // $ExpectType void +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const X = new Float64Array( 3 ); + const out = new Float64Array( 2 ); + + dlarfg.ndarray( '5', X, 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( true, X, 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( false, X, 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( null, X, 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( void 0, X, 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( [], X, 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( {}, X, 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( ( x: number ): number => x, X, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Float64Array... +{ + const out = new Float64Array( 2 ); + + dlarfg.ndarray( 4, '5', 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, 5, 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, true, 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, false, 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, null, 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, void 0, 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, [], 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, {}, 1, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, ( x: number ): number => x, 1, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const X = new Float64Array( 3 ); + const out = new Float64Array( 2 ); + + dlarfg.ndarray( 4, X, '1', 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, true, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, false, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, null, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, void 0, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, [], 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, {}, 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, ( x: number ): number => x, 0, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const X = new Float64Array( 3 ); + const out = new Float64Array( 2 ); + + dlarfg.ndarray( 4, X, 1, '0', out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, true, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, false, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, null, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, void 0, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, [], out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, {}, out, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, ( x: number ): number => x, out, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a Float64Array... +{ + const X = new Float64Array( 3 ); + + dlarfg.ndarray( 4, X, 1, 0, '5', 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, 5, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, true, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, false, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, null, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, void 0, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, [], 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, {}, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const X = new Float64Array( 3 ); + const out = new Float64Array( 2 ); + + dlarfg.ndarray( 4, X, 1, 0, out, '1', 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, true, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, false, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, null, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, void 0, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, [], 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, {}, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const X = new Float64Array( 3 ); + const out = new Float64Array( 2 ); + + dlarfg.ndarray( 4, X, 1, 0, out, 1, '0' ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, 1, true ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, 1, false ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, 1, null ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, 1, void 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, 1, [] ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, 1, {} ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const X = new Float64Array( 3 ); + const out = new Float64Array( 2 ); + + dlarfg.ndarray(); // $ExpectError + dlarfg.ndarray( 4 ); // $ExpectError + dlarfg.ndarray( 4, X ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, 1 ); // $ExpectError + dlarfg.ndarray( 4, X, 1, 0, out, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dlarfg/examples/index.js new file mode 100644 index 000000000000..bc6a258e1854 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/examples/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 uniform = require( '@stdlib/random/array/discrete-uniform' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dlarfg = require( './../lib' ); + +var N = 4; + +var X = uniform( N - 1, -10, 10, { + 'dtype': 'float64' +}); +console.log( 'X: ', X ); + +var alpha = 4.0; + +var out = new Float64Array( [ alpha, 0.0 ] ); + +dlarfg( N, X, 1, out ); + +console.log( 'V: ', X ); +console.log( 'beta: ', out[ 0 ] ); +console.log( 'tau: ', out[ 1 ] ); diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dlarfg/lib/base.js new file mode 100644 index 000000000000..da2c67ed7284 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/lib/base.js @@ -0,0 +1,142 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/dlarfg/lib/dlarfg.js b/lib/node_modules/@stdlib/lapack/base/dlarfg/lib/dlarfg.js new file mode 100644 index 000000000000..de6f7a95aaa0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/lib/dlarfg.js @@ -0,0 +1,91 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 base = require( './base.js' ); + + +// 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` +* +* @param {NonNegativeInteger} N - number of rows/columns of the elementary reflector `H` +* @param {Float64Array} X - input vector +* @param {integer} incx - stride length for `X` +* @param {Float64Array} out - output array +* @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, out ); +* // X => [ ~0.19, ~0.28, ~0.37 ] +* // out => [ ~-6.7, ~1.6 ] +*/ +function dlarfg( N, X, incx, out ) { + base( N, X, incx, 0, out, 1, 0 ); +} + + +// EXPORTS // + +module.exports = dlarfg; diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dlarfg/lib/index.js new file mode 100644 index 000000000000..fbcb7c94e991 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/lib/index.js @@ -0,0 +1,79 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 generate a real elementary reflector `H` of order `N` such that applying `H` to a vector `[alpha; X]` zeros out `X`. +* +* ## Notes +* +* - `H` is a Householder matrix with the form `H = I - tau * [1; V] * [1, V^T]`, where `tau` is a scalar and `V` is a vector. +* - the input vector is `[alpha; X]`, where `alpha` is a scalar and `X` is a real `(n-1)`-element vector. +* - the result of applying `H` to `[alpha; X]` is `[beta; 0]`, with `beta` being a scalar and the rest of the vector zeroed. +* - if all elements of `X` are zero, then `tau = 0` and `H` is the identity matrix. +* - otherwise, `1 <= tau <= 2` +* +* @module @stdlib/lapack/base/dlarfg +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dlarfg = require( '@stdlib/lapack/base/dlarfg' ); +* +* var X = new Float64Array( [ 2.0, 3.0, 4.0 ] ); +* var out = new Float64Array( [ 4.0, 0.0 ] ); +* +* dlarfg( 4, X, 1, out ); +* // X => [ ~0.19, ~0.28, ~0.37 ] +* // out => [ ~-6.7, ~1.6 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dlarfg = require( '@stdlib/lapack/base/dlarfg' ); + +* +* var X = new Float64Array( [ 2.0, 3.0, 4.0 ] ); +* var out = new Float64Array( [ 4.0, 0.0 ] ); +* +* dlarfg.ndarray( 4, X, 1, 0, out, 1, 0 ); +* // X => [ ~0.19, ~0.28, ~0.37 ] +* // out => [ ~-6.7, ~1.6 ] +*/ + +// 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 dlarfg; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dlarfg = main; +} else { + dlarfg = tmp; +} + + +// EXPORTS // + +module.exports = dlarfg; diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/lib/main.js b/lib/node_modules/@stdlib/lapack/base/dlarfg/lib/main.js new file mode 100644 index 000000000000..c7d8c0cc83fd --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 dlarfg = require( './dlarfg.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dlarfg, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dlarfg; diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dlarfg/lib/ndarray.js new file mode 100644 index 000000000000..dd77b892074f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/lib/ndarray.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 base = require( './base.js' ); + + +// MAIN // + +/** +* Generates a real elementary reflector `H` of order `N` such that applying `H` to a vector `[alpha; X]` zeros out `X` usinig alternative indexing semantics. +* +* `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` + +* +* @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 ) { + base( N, X, strideX, offsetX, out, strideOut, offsetOut ); +} + + +// EXPORTS // + +module.exports = dlarfg; diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/package.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/package.json new file mode 100644 index 000000000000..aa3aa3023976 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/lapack/base/dlarfg", + "version": "0.0.0", + "description": "LAPACK routine to generate a real elementary reflector `H` of order `N` such that applying `H` to a vector `[alpha; X]` zeros out `X`.", + "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", + "dlarfg", + "copy", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "matrix", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/large_strides/n_eq_one_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/large_strides/n_eq_one_test.json new file mode 100644 index 000000000000..1e5ec6ce4851 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/large_strides/n_eq_one_test.json @@ -0,0 +1,21 @@ +{ + "N": 1, + "X": [], + "strideX": 2, + "offsetX": 0, + "out": [ + 4.0, + 9999.0, + 0.0, + 9999.0 + ], + "strideOut": 2, + "offsetOut": 0, + "expectedX": [], + "expectedOut": [ + 4.0, + 9999.0, + 0.0, + 9999.0 + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/large_strides/n_gt_one_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/large_strides/n_gt_one_test.json new file mode 100644 index 000000000000..594af1d847a3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/large_strides/n_gt_one_test.json @@ -0,0 +1,35 @@ +{ + "N": 4, + "X": [ + 2, + 9999.0, + 3, + 9999.0, + 4, + 9999 + ], + "strideX": 2, + "offsetX": 0, + "out": [ + 4, + 9999.0, + 0, + 9999 + ], + "strideOut": 2, + "offsetOut": 0, + "expectedX": [ + 0.18677268499995647, + 9999.0, + 0.2801590274999347, + 9999.0, + 0.37354536999991295, + 9999 + ], + "expectedOut": [ + -6.7082039324993685, + 9999.0, + 1.596284793999944, + 9999 + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/large_strides/small_values_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/large_strides/small_values_test.json new file mode 100644 index 000000000000..42d2c19e28f7 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/large_strides/small_values_test.json @@ -0,0 +1,35 @@ +{ + "N": 4, + "X": [ + 2.2250738585e-313, + 9999.0, + 2.2250738585e-313, + 9999.0, + 2.2250738585e-313, + 9999.0 + ], + "strideX": 2, + "offsetX": 0, + "out": [ + 2.2250738585e-313, + 9999.0, + 0, + 9999.0 + ], + "strideOut": 2, + "offsetOut": 0, + "expectedX": [ + 0.33333333333333337, + 9999.0, + 0.33333333333333337, + 9999.0, + 0.33333333333333337, + 9999.0 + ], + "expectedOut": [ + -4.45014771704e-313, + 9999.0, + 1.5, + 9999.0 + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/large_strides/xnorm_eq_zerro_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/large_strides/xnorm_eq_zerro_test.json new file mode 100644 index 000000000000..358c40ae991e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/large_strides/xnorm_eq_zerro_test.json @@ -0,0 +1,35 @@ +{ + "N": 4, + "X": [ + 0.0, + 9999.0, + 0.0, + 9999.0, + 0.0, + 9999.0 + ], + "strideX": 2, + "offsetX": 0, + "out": [ + 4.0, + 9999.0, + 0.0, + 9999.0 + ], + "strideOut": 2, + "offsetOut": 0, + "expectedX": [ + 0.0, + 9999.0, + 0.0, + 9999.0, + 0.0, + 9999.0 + ], + "expectedOut": [ + 4.0, + 9999.0, + 0.0, + 9999.0 + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/n_eq_one_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/n_eq_one_test.json new file mode 100644 index 000000000000..f440195e8dec --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/n_eq_one_test.json @@ -0,0 +1,11 @@ +{ + "N": 1, + "X": [], + "strideX": 1, + "offsetX": 0, + "out": [ 4.0, 0.0 ], + "strideOut": 1, + "offsetOut": 0, + "expectedX": [], + "expectedOut": [ 4.0, 0.0 ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/n_gt_one_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/n_gt_one_test.json new file mode 100644 index 000000000000..2e97d2698f09 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/n_gt_one_test.json @@ -0,0 +1,11 @@ +{ + "N": 4, + "X": [ 2.0, 3.0, 4.0 ], + "strideX": 1, + "offsetX": 0, + "out": [ 4.0, 0.0 ], + "strideOut": 1, + "offsetOut": 0, + "expectedX": [ 0.18677268499995647, 0.28015902749993471, 0.37354536999991295 ], + "expectedOut": [ -6.7082039324993685, 1.5962847939999441 ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/negative_strides/n_eq_one_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/negative_strides/n_eq_one_test.json new file mode 100644 index 000000000000..fb498939e7b4 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/negative_strides/n_eq_one_test.json @@ -0,0 +1,20 @@ +{ + "N": 1, + "X": [], + "strideX": -1, + "offsetX": -1, + "out": [ + 0.0, + 4.0 + ], + "strideOut": -1, + "offsetOut": 1, + "expectedX": [], + "expectedOut": [ + 0.0, + 4.0 + ], + "offsetout": 1, + "offsetexpectedX": -1, + "offsetexpectedOut": 1 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/negative_strides/n_gt_one_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/negative_strides/n_gt_one_test.json new file mode 100644 index 000000000000..3722a2b452e1 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/negative_strides/n_gt_one_test.json @@ -0,0 +1,28 @@ +{ + "N": 4, + "X": [ + 4.0, + 3.0, + 2.0 + ], + "strideX": -1, + "offsetX": 2, + "out": [ + 0.0, + 4.0 + ], + "strideOut": -1, + "offsetOut": 1, + "expectedX": [ + 0.37354536999991295, + 0.2801590274999347, + 0.18677268499995647 + ], + "expectedOut": [ + 1.596284793999944, + -6.7082039324993685 + ], + "offsetout": 1, + "offsetexpectedX": 2, + "offsetexpectedOut": 1 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/negative_strides/small_values_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/negative_strides/small_values_test.json new file mode 100644 index 000000000000..6b27a74937ae --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/negative_strides/small_values_test.json @@ -0,0 +1,28 @@ +{ + "N": 4, + "X": [ + 2.2250738585e-313, + 2.2250738585e-313, + 2.2250738585e-313 + ], + "strideX": -1, + "offsetX": 2, + "out": [ + 0.0, + 2.2250738585e-313 + ], + "strideOut": -1, + "offsetOut": 1, + "expectedX": [ + 0.33333333333333337, + 0.33333333333333337, + 0.33333333333333337 + ], + "expectedOut": [ + 1.5, + -4.45014771704e-313 + ], + "offsetout": 1, + "offsetexpectedX": 2, + "offsetexpectedOut": 1 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/negative_strides/xnorm_eq_zerro_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/negative_strides/xnorm_eq_zerro_test.json new file mode 100644 index 000000000000..635c53311e7d --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/negative_strides/xnorm_eq_zerro_test.json @@ -0,0 +1,28 @@ +{ + "N": 4, + "X": [ + 0.0, + 0.0, + 0.0 + ], + "strideX": -1, + "offsetX": 2, + "out": [ + 0.0, + 4.0 + ], + "strideOut": -1, + "offsetOut": 1, + "expectedX": [ + 0.0, + 0.0, + 0.0 + ], + "expectedOut": [ + 0.0, + 4.0 + ], + "offsetout": 1, + "offsetexpectedX": 2, + "offsetexpectedOut": 1 +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/offsets/n_eq_one_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/offsets/n_eq_one_test.json new file mode 100644 index 000000000000..aea21703f1bb --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/offsets/n_eq_one_test.json @@ -0,0 +1,23 @@ +{ + "N": 1, + "X": [ + 9999.0 + ], + "strideX": 1, + "offsetX": 1, + "out": [ + 9999.0, + 4.0, + 0.0 + ], + "strideOut": 1, + "offsetOut": 1, + "expectedX": [ + 9999.0 + ], + "expectedOut": [ + 9999.0, + 4.0, + 0.0 + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/offsets/n_gt_one_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/offsets/n_gt_one_test.json new file mode 100644 index 000000000000..08ff089c9f07 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/offsets/n_gt_one_test.json @@ -0,0 +1,29 @@ +{ + "N": 4, + "X": [ + 9999.0, + 2.0, + 3.0, + 4.0 + ], + "strideX": 1, + "offsetX": 1, + "out": [ + 9999.0, + 4.0, + 0.0 + ], + "strideOut": 1, + "offsetOut": 1, + "expectedX": [ + 9999.0, + 0.18677268499995647, + 0.2801590274999347, + 0.37354536999991295 + ], + "expectedOut": [ + 9999.0, + -6.7082039324993685, + 1.596284793999944 + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/offsets/small_values_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/offsets/small_values_test.json new file mode 100644 index 000000000000..8c3c2fb4042c --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/offsets/small_values_test.json @@ -0,0 +1,29 @@ +{ + "N": 4, + "X": [ + 9999.0, + 2.2250738585e-313, + 2.2250738585e-313, + 2.2250738585e-313 + ], + "strideX": 1, + "offsetX": 1, + "out": [ + 9999.0, + 2.2250738585e-313, + 0 + ], + "strideOut": 1, + "offsetOut": 1, + "expectedX": [ + 9999.0, + 0.33333333333333337, + 0.33333333333333337, + 0.33333333333333337 + ], + "expectedOut": [ + 9999.0, + -4.45014771704e-313, + 1.5 + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/offsets/xnorm_eq_zerro_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/offsets/xnorm_eq_zerro_test.json new file mode 100644 index 000000000000..a4593dd60696 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/offsets/xnorm_eq_zerro_test.json @@ -0,0 +1,29 @@ +{ + "N": 4, + "X": [ + 9999.0, + 0.0, + 0.0, + 0 + ], + "strideX": 1, + "offsetX": 1, + "out": [ + 9999.0, + 4.0, + 0.0 + ], + "strideOut": 1, + "offsetOut": 1, + "expectedX": [ + 9999.0, + 0.0, + 0.0, + 0 + ], + "expectedOut": [ + 9999.0, + 4.0, + 0.0 + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/small_values_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/small_values_test.json new file mode 100644 index 000000000000..77bef0709a13 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/small_values_test.json @@ -0,0 +1,11 @@ +{ + "N": 4, + "X": [ 2.2250738585217783e-313, 2.2250738585217783e-313, 2.2250738585217783e-313 ], + "strideX": 1, + "offsetX": 0, + "out": [ 2.2250738585217783e-313, 0.0 ], + "strideOut": 1, + "offsetOut": 0, + "expectedX": [ 0.33333333333333337, 0.33333333333333337, 0.33333333333333337 ], + "expectedOut": [ -4.4501477170435566e-313, 1.5 ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/xnorm_eq_zerro_test.json b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/xnorm_eq_zerro_test.json new file mode 100644 index 000000000000..60eca89aeee7 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/fixtures/xnorm_eq_zerro_test.json @@ -0,0 +1,11 @@ +{ + "N": 4, + "X": [ 0.0, 0.0, 0.0 ], + "strideX": 1, + "offsetX": 0, + "out": [ 4.0, 0.0 ], + "strideOut": 1, + "offsetOut": 0, + "expectedX": [ 0.0, 0.0, 0.0 ], + "expectedOut": [ 4.0, 0.0 ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/test.dlarfg.js b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/test.dlarfg.js new file mode 100644 index 000000000000..dbf4566919e8 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/test.dlarfg.js @@ -0,0 +1,135 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 dlarfg = require( './../lib/dlarfg.js' ); + + +// FIXTURES // + +var N_GT_ONE_DATA = require( './fixtures/n_gt_one_test.json' ); +var N_EQ_ONE_DATA = require( './fixtures/n_eq_one_test.json' ); +var XNORM_EQ_ZERO_DATA = require( './fixtures/xnorm_eq_zerro_test.json' ); +var SMALL_VALUES_DATA = require( './fixtures/small_values_test.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlarfg, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 4', function test( t ) { + t.strictEqual( dlarfg.length, 4, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when N > 1', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = N_GT_ONE_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, out ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when N = 1', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = N_EQ_ONE_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, out ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when xnorm = 0', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = XNORM_EQ_ZERO_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, out ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output for small values', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = SMALL_VALUES_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, out ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/test.js b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/test.js new file mode 100644 index 000000000000..b7eccd0bc69f --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 dlarfg = 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 dlarfg, '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 dlarfg.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 dlarfg = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dlarfg, 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 dlarfg; + var main; + + main = require( './../lib/dlarfg.js' ); + + dlarfg = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dlarfg, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dlarfg/test/test.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/test.ndarray.js new file mode 100644 index 000000000000..1334568019f3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlarfg/test/test.ndarray.js @@ -0,0 +1,504 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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, id-length */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var dlarfg = require( './../lib/ndarray.js' ); + + +// FIXTURES // + +var N_GT_ONE_DATA = require( './fixtures/n_gt_one_test.json' ); +var N_EQ_ONE_DATA = require( './fixtures/n_eq_one_test.json' ); +var XNORM_EQ_ZERO_DATA = require( './fixtures/xnorm_eq_zerro_test.json' ); +var SMALL_VALUES_DATA = require( './fixtures/small_values_test.json' ); + +var OFFSET_N_GT_ONE_DATA = require( './fixtures/offsets/n_gt_one_test.json' ); +var OFFSET_N_EQ_ONE_DATA = require( './fixtures/offsets/n_eq_one_test.json' ); +var OFFSET_XNORM_EQ_ZERO_DATA = require( './fixtures/offsets/xnorm_eq_zerro_test.json' ); +var OFFSET_SMALL_VALUES_DATA = require( './fixtures/offsets/small_values_test.json' ); + +var NEG_STRIDE_N_GT_ONE_DATA = require( './fixtures/negative_strides/n_gt_one_test.json' ); +var NEG_STRIDE_N_EQ_ONE_DATA = require( './fixtures/negative_strides/n_eq_one_test.json' ); +var NEG_STRIDE_XNORM_EQ_ZERO_DATA = require( './fixtures/negative_strides/xnorm_eq_zerro_test.json' ); +var NEG_STRIDE_SMALL_VALUES_DATA = require( './fixtures/negative_strides/small_values_test.json' ); + +var LARGE_STRIDE_N_GT_ONE_DATA = require( './fixtures/large_strides/n_gt_one_test.json' ); +var LARGE_STRIDE_N_EQ_ONE_DATA = require( './fixtures/large_strides/n_eq_one_test.json' ); +var LARGE_STRIDE_XNORM_EQ_ZERO_DATA = require( './fixtures/large_strides/xnorm_eq_zerro_test.json' ); +var LARGE_STRIDE_SMALL_VALUES_DATA = require( './fixtures/large_strides/small_values_test.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlarfg, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( dlarfg.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when N > 1', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = N_GT_ONE_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when N = 1', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = N_EQ_ONE_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when xnorm = 0', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = XNORM_EQ_ZERO_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output for small values', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = SMALL_VALUES_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when N > 1 (offsets)', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = OFFSET_N_GT_ONE_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when N = 1 (offsets)', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = OFFSET_N_EQ_ONE_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when xnorm = 0 (offsets)', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = OFFSET_XNORM_EQ_ZERO_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output for small values (offsets)', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = OFFSET_SMALL_VALUES_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when N > 1 (large strides)', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = LARGE_STRIDE_N_GT_ONE_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when N = 1 (large strides)', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = LARGE_STRIDE_N_EQ_ONE_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when xnorm = 0 (large strides)', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = LARGE_STRIDE_XNORM_EQ_ZERO_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output for small values (large strides)', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = LARGE_STRIDE_SMALL_VALUES_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when N > 1 (negative strides)', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = NEG_STRIDE_N_GT_ONE_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when N = 1 (negative strides)', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = NEG_STRIDE_N_EQ_ONE_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when xnorm = 0 (negative strides)', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = NEG_STRIDE_XNORM_EQ_ZERO_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output for small values (negative strides)', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = NEG_STRIDE_SMALL_VALUES_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when N > 1', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = N_GT_ONE_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when N = 1', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = N_EQ_ONE_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output when xnorm = 0', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = XNORM_EQ_ZERO_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns expected output for small values', function test( t ) { + var expectedOut; + var expectedX; + var data; + var out; + var X; + + data = SMALL_VALUES_DATA; + + X = new Float64Array( data.X ); + out = new Float64Array( data.out ); + + expectedX = new Float64Array( data.expectedX ); + expectedOut = new Float64Array( data.expectedOut ); + + dlarfg( data.N, X, data.strideX, data.offsetX, out, data.strideOut, data.offsetOut ); + + t.deepEqual( X, expectedX, 'returns expected value' ); + t.deepEqual( out, expectedOut, 'returns expected value' ); + t.end(); +});