diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/README.md b/lib/node_modules/@stdlib/lapack/base/cpttrf/README.md new file mode 100644 index 000000000000..f15c4897dd1d --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/README.md @@ -0,0 +1,276 @@ + + +# cpttrf + +> Compute the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A`. + +
+ +## Usage + +```javascript +var cpttrf = require( '@stdlib/lapack/base/cpttrf' ); +``` + +#### cpttrf( N, D, E ) + +Computes the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A`. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); + +var D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); +var E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + +cpttrf( 3, D, E ); +// D => [ 4, 4.75, ~5.15789 ] + +var viewE = reinterpret( E, 0 ); +// viewE => [ 0.25, 0.0, ~0.421053, 0.0 ] +``` + +The function has the following parameters: + +- **N**: order of matrix `A`. +- **D**: the `N` diagonal elements of `A` as a [`Float32Array`][mdn-float32array]. +- **E**: the N-1 subdiagonal elements of `A` as a [`Complex64Array`][@stdlib/array/complex64]. + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + + + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); + +// Initial arrays... +var D0 = new Float32Array( [ 0.0, 4.0, 5.0, 6.0 ] ); +var E0 = new Complex64Array( [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0 ] ); + +// Create offset views... +var D1 = new Float32Array( D0.buffer, D0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var E1 = new Complex64Array( E0.buffer, E0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +cpttrf( 3, D1, E1 ); +// D0 => [ 0.0, 4.0, 4.75, ~5.15789 ] + +var viewE = reinterpret( E0, 0 ); +// viewE => [ 0.0, 0.0, 0.25, 0.0, ~0.421053, 0.0 ] +``` + +#### cpttrf.ndarray( N, D, strideD, offsetD, E, strideE, offsetE ) + +Computes the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A` using alternative indexing semantics. + +```javascript +var Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); + +var D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); +var E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + +cpttrf.ndarray( 3, D, 1, 0, E, 1, 0 ); +// D => [ 4, 4.75, ~5.15789 ] + +var viewE = reinterpret( E, 0 ); +// viewE => [ 0.25, 0.0, ~0.421053, 0.0 ] +``` + +The function has the following additional parameters: + +- **strideD**: stride length for `D`. +- **offsetD**: starting index for `D`. +- **strideE**: stride length for `E`. +- **offsetE**: starting index for `E`. + +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 Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); + +var D = new Float32Array( [ 0.0, 4.0, 5.0, 6.0 ] ); +var E = new Complex64Array( [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0 ] ); + +cpttrf.ndarray( 3, D, 1, 1, E, 1, 1 ); +// D => [ 0.0, 4.0, 4.75, ~5.15789 ] + +var viewE = reinterpret( E, 0 ); +// viewE => [ 0.0, 0.0, 0.25, 0.0, ~0.421053, 0.0 ] +``` + +
+ + + +
+ +## Notes + +- Both functions mutate the input arrays `D` and `E`. + +- Both functions return a status code indicating success or failure. A status code indicates the following conditions: + + - `0`: factorization was successful. + - `<0`: the k-th argument had an illegal value, where `-k` equals the status code value. + - `0 < k < N`: the leading principal minor of order `k` is not positive and factorization could not be completed, where `k` equals the status code value. + - `N`: the leading principal minor of order `N` is not positive, and factorization was completed. + +- `cpttrf()` corresponds to the [LAPACK][LAPACK] routine [`cpttrf`][lapack-cpttrf]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var cpttrf = require( '@stdlib/lapack/base/cpttrf' ); + +var opts = { + 'dtype': 'float32' +}; +var D = discreteUniform( 5, 1, 5, opts ); +console.log( D ); + +var N = D.length - 1; +var E = new Complex64Array( discreteUniform( 2*N, 0, 2, opts ) ); +console.log( E ); + +// Perform the `L * D * L^H` factorization: +var info = cpttrf( D.length, D, E ); +console.log( D ); +console.log( E ); +console.log( info ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/cpttrf/benchmark/benchmark.js new file mode 100644 index 000000000000..d3d6568aa614 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/benchmark/benchmark.js @@ -0,0 +1,109 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var cpttrf = require( './../lib/cpttrf.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var ebuf; + var D; + var E; + + D = uniform( len, 0.0, 100.0, options ); + ebuf = uniform( 2*(len-1), 0.0, 100.0, options ); + E = new Complex64Array( ebuf ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = cpttrf( len, D, E ); + if ( isnanf( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( d ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/cpttrf/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..745381a567cf --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/benchmark/benchmark.ndarray.js @@ -0,0 +1,109 @@ +/** +* @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 uniform = require( '@stdlib/random/array/uniform' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var cpttrf = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float32' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var ebuf; + var D; + var E; + + D = uniform( len, 0.0, 100.0, options ); + ebuf = uniform( 2*(len-1), 0.0, 100.0, options ); + E = new Complex64Array( ebuf ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = cpttrf( len, D, 1, 0, E, 1, 0 ); + if ( isnanf( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnanf( d ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':ndarray:len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/cpttrf/docs/repl.txt new file mode 100644 index 000000000000..5e39983b406d --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/docs/repl.txt @@ -0,0 +1,131 @@ + +{{alias}}( N, D, E ) + Computes the `L * D * L^H` factorization of a complex Hermitian positive + definite tridiagonal matrix `A`. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + The function mutates both `D` and `E`. + + Parameters + ---------- + N: integer + Order of matrix `A`. + + D: Float32Array + The `N` diagonal elements of `A`. Upon successful factorization, `D` + will contain the `N` diagonal elements of the diagonal matrix `D` from + the `L * D * L^H` factorization of `A`. + + E: Complex64Array + The `N-1` subdiagonal elements of `A`. Upon successful factorization, + `E` will contain the `N-1` subdiagonal elements of the unit bidiagonal + factor `L` from the `L * D * L^H` factorization of `A`. `E` can also be + regarded as the superdiagonal of the unit bidiagonal factor `U` from the + `U^H * D * U` factorization of `A`. + + Returns + ------- + info: integer + Status code. The status code indicates the following conditions: + + - if equal to zero, then the factorization was successful. + - if less than zero, then the k-th argument had an illegal value, + where `k = -info`. + - if greater than zero, then the leading principal minor of order `k` + is not positive, where `k = info`. If `k < N`, then the + factorization could not be completed. If `k = N`, then the + factorization was completed, but `D(N) <= 0`, meaning that the + matrix `A` is not positive definite. + + Examples + -------- + > var D = new {{alias:@stdlib/array/float32}}( [ 4.0, 5.0, 6.0 ] ); + > var E = new {{alias:@stdlib/array/complex64}}( [ 1.0, 0.0, 2.0, 0.0 ] ); + > {{alias}}( 3, D, E ) + 0 + > D + [ 4, 4.75, ~5.15789 ] + > E + + + // Using typed array views: + > var D0 = new {{alias:@stdlib/array/float32}}( [ 0.0, 4.0, 5.0, 6.0 ] ); + > var E0 = new {{alias:@stdlib/array/complex64}}( [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0 ] ); + > D = new {{alias:@stdlib/array/float32}}( D0.buffer, D0.BYTES_PER_ELEMENT*1 ); + > E = new {{alias:@stdlib/array/complex64}}( E0.buffer, E0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, D, E ) + 0 + > D0 + [ 0.0, 4.0, 4.75, ~5.15789 ] + > E0 + + + +{{alias}}.ndarray( N, D, strideD, offsetD, E, strideE, offsetE ) + Computes the `L * D * L^H` factorization of a complex Hermitian positive + definite tridiagonal matrix `A` using alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameters support indexing semantics based on starting + indices. + + The function mutates both `D` and `E`. + + Parameters + ---------- + N: integer + Order of matrix `A`. + + D: Float32Array + The `N` diagonal elements of `A`. Upon successful factorization, `D` + will contain the `N` diagonal elements of the diagonal matrix `D` from + the `L * D * L^H` factorization of `A`. + + strideD: integer + Stride length for `D`. + + offsetD: integer + Starting index for `D`. + + E: Complex64Array + The `N-1` subdiagonal elements of `A`. Upon successful factorization, + `E` will contain the `N-1` subdiagonal elements of the unit bidiagonal + factor `L` from the `L * D * L^H` factorization of `A`. `E` can also be + regarded as the superdiagonal of the unit bidiagonal factor `U` from the + `U^H * D * U` factorization of `A`. + + strideE: integer + Stride length for `E`. + + offsetE: integer + Starting index for `E`. + + Returns + ------- + info: integer + Status code. The status code indicates the following conditions: + + - if equal to zero, then the factorization was successful. + - if less than zero, then the k-th argument had an illegal value, + where `k = -info`. + - if greater than zero, then the leading principal minor of order `k` + is not positive, where `k = info`. If `k < N`, then the + factorization could not be completed. If `k = N`, then the + factorization was completed, but `D(N) <= 0`, meaning that the + matrix `A` is not positive definite. + + Examples + -------- + > var D = new {{alias:@stdlib/array/float32}}( [ 0.0, 4.0, 5.0, 6.0 ] ); + > var E = new {{alias:@stdlib/array/complex64}}( [ 0.0, 0.0, 1.0, 0.0, 2.0, 0.0 ] ); + > {{alias}}.ndarray( 3, D, 1, 1, E, 1, 1 ) + 0 + > D + [ 0.0, 4.0, 4.75, ~5.15789 ] + > E + + + See Also + -------- diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/cpttrf/docs/types/index.d.ts new file mode 100644 index 000000000000..ede06ceb5796 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/docs/types/index.d.ts @@ -0,0 +1,120 @@ +/* +* @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 { Complex64Array } from '@stdlib/types/array'; + +/** +* Status code. +* +* ## Notes +* +* The status code indicates the following conditions: +* +* - if equal to zero, then the factorization was successful. +* - if less than zero, then the k-th argument had an illegal value, where `k = -StatusCode`. +* - if greater than zero, then the leading principal minor of order `k` is not positive, where `k = StatusCode`. If `k < N`, then the factorization could not be completed. If `k = N`, then the factorization was completed, but `D(N) <= 0`, meaning that the matrix `A` is not positive definite. +*/ +type StatusCode = number; + +/** +* Interface describing `cpttrf`. +*/ +interface Routine { + /** + * Computes the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A`. + * + * @param N - order of matrix `A` + * @param D - the `N` diagonal elements of `A` + * @param E - the `N-1` subdiagonal elements of `A` + * @returns status code + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * var D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); + * var E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + * + * cpttrf( 3, D, E ); + * // D => [ 4, 4.75, ~5.15789 ] + */ + ( N: number, D: Float32Array, E: Complex64Array ): StatusCode; + + /** + * Computes the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A` using alternative indexing semantics. + * + * @param N - order of matrix `A` + * @param D - the `N` diagonal elements of `A` + * @param strideD - stride length for `D` + * @param offsetD - starting index of `D` + * @param E - the `N-1` subdiagonal elements of `A` + * @param strideE - stride length for `E` + * @param offsetE - starting index of `E` + * @returns status code + * + * @example + * var Float32Array = require( '@stdlib/array/float32' ); + * var Complex64Array = require( '@stdlib/array/complex64' ); + * + * var D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); + * var E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + * + * cpttrf.ndarray( 3, D, 1, 0, E, 1, 0 ); + * // D => [ 4, 4.75, ~5.15789 ] + */ + ndarray( N: number, D: Float32Array, strideD: number, offsetD: number, E: Complex64Array, strideE: number, offsetE: number ): StatusCode; +} + +/** +* Computes the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A`. +* +* @param N - order of matrix `A` +* @param D - the `N` diagonal elements of `A` +* @param E - the `N-1` subdiagonal elements of `A` +* @returns status code +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); +* var E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); +* +* cpttrf( 3, D, E ); +* // D => [ 4, 4.75, ~5.15789 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); +* var E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); +* +* cpttrf.ndarray( 3, D, 1, 0, E, 1, 0 ); +* // D => [ 4, 4.75, ~5.15789 ] +*/ +declare var cpttrf: Routine; + + +// EXPORTS // + +export = cpttrf; diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/cpttrf/docs/types/test.ts new file mode 100644 index 000000000000..da03f6deb9f4 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/docs/types/test.ts @@ -0,0 +1,215 @@ + +/* +* @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. +*/ + +import cpttrf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const D = new Float32Array( 3 ); + const E = new Complex64Array( 2 ); + + cpttrf( 3, D, E ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const D = new Float32Array( 3 ); + const E = new Complex64Array( 2 ); + + cpttrf( '5', D, E ); // $ExpectError + cpttrf( true, D, E ); // $ExpectError + cpttrf( false, D, E ); // $ExpectError + cpttrf( null, D, E ); // $ExpectError + cpttrf( void 0, D, E ); // $ExpectError + cpttrf( [], D, E ); // $ExpectError + cpttrf( {}, D, E ); // $ExpectError + cpttrf( ( x: number ): number => x, D, E ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Float32Array... +{ + const E = new Complex64Array( 2 ); + + cpttrf( 3, '5', E ); // $ExpectError + cpttrf( 3, 5, E ); // $ExpectError + cpttrf( 3, true, E ); // $ExpectError + cpttrf( 3, false, E ); // $ExpectError + cpttrf( 3, null, E ); // $ExpectError + cpttrf( 3, void 0, E ); // $ExpectError + cpttrf( 3, [], E ); // $ExpectError + cpttrf( 3, {}, E ); // $ExpectError + cpttrf( 3, ( x: number ): number => x, E ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Complex64Array... +{ + const D = new Float32Array( 3 ); + + cpttrf( 3, D, '5' ); // $ExpectError + cpttrf( 3, D, 5 ); // $ExpectError + cpttrf( 3, D, true ); // $ExpectError + cpttrf( 3, D, false ); // $ExpectError + cpttrf( 3, D, null ); // $ExpectError + cpttrf( 3, D, void 0 ); // $ExpectError + cpttrf( 3, D, [] ); // $ExpectError + cpttrf( 3, D, {} ); // $ExpectError + cpttrf( 3, D, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const D = new Float32Array( 3 ); + const E = new Complex64Array( 2 ); + + cpttrf(); // $ExpectError + cpttrf( 3 ); // $ExpectError + cpttrf( 3, D ); // $ExpectError + cpttrf( 3, D, E, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a number... +{ + const D = new Float32Array( 3 ); + const E = new Complex64Array( 2 ); + + cpttrf.ndarray( 3, D, 1, 0, E, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const D = new Float32Array( 3 ); + const E = new Complex64Array( 2 ); + + cpttrf.ndarray( '5', D, 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( true, D, 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( false, D, 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( null, D, 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( void 0, D, 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( [], D, 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( {}, D, 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( ( x: number ): number => x, D, 1, 0, E, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Float32Array... +{ + const E = new Complex64Array( 2 ); + + cpttrf.ndarray( 3, '5', 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, 5, 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, true, 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, false, 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, null, 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, void 0, 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, [], 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, {}, 1, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, ( x: number ): number => x, 1, 0, E, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a number... +{ + const D = new Float32Array( 3 ); + const E = new Complex64Array( 2 ); + + cpttrf.ndarray( 3, D, '5', 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, true, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, false, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, null, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, void 0, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, [], 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, {}, 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, ( x: number ): number => x, 0, E, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const D = new Float32Array( 3 ); + const E = new Complex64Array( 2 ); + + cpttrf.ndarray( 3, D, 1, '5', E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, true, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, false, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, null, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, void 0, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, [], E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, {}, E, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, ( x: number ): number => x, E, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a Complex64Array... +{ + const D = new Float32Array( 3 ); + + cpttrf.ndarray( 3, D, 1, 0, '5', 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, 5, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, true, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, false, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, null, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, void 0, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, [], 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, {}, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 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 D = new Float32Array( 3 ); + const E = new Complex64Array( 2 ); + + cpttrf.ndarray( 3, D, 1, 0, E, '5', 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, true, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, false, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, null, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, void 0, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, [], 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, {}, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, ( 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 D = new Float32Array( 3 ); + const E = new Complex64Array( 2 ); + + cpttrf.ndarray( 3, D, 1, 0, E, 1, '5' ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, 1, true ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, 1, false ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, 1, null ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, 1, void 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, 1, [] ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, 1, {} ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments... +{ + const D = new Float32Array( 3 ); + const E = new Complex64Array( 2 ); + + cpttrf.ndarray(); // $ExpectError + cpttrf.ndarray( 3 ); // $ExpectError + cpttrf.ndarray( 3, D ); // $ExpectError + cpttrf.ndarray( 3, D, 1 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, 1 ); // $ExpectError + cpttrf.ndarray( 3, D, 1, 0, E, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/examples/index.js b/lib/node_modules/@stdlib/lapack/base/cpttrf/examples/index.js new file mode 100644 index 000000000000..3705a5292463 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/examples/index.js @@ -0,0 +1,39 @@ +/** +* @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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var cpttrf = require( './../lib' ); + +var opts = { + 'dtype': 'float32' +}; +var D = discreteUniform( 5, 1, 5, opts ); +console.log( D ); + +var N = D.length - 1; +var E = new Complex64Array( discreteUniform( 2*N, 0, 2, opts ) ); +console.log( E ); + +// Perform the `L * D * L^H` factorization: +var info = cpttrf( D.length, D, E ); +console.log( D ); +console.log( E ); +console.log( info ); diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/lib/base.js b/lib/node_modules/@stdlib/lapack/base/cpttrf/lib/base.js new file mode 100644 index 000000000000..826729944cb6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/lib/base.js @@ -0,0 +1,106 @@ +/** +* @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 reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' ); +var f32 = require( '@stdlib/number/float64/base/to-float32' ); + + +// MAIN // + +/** +* Computes the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A`. +* +* @private +* @param {NonNegativeInteger} N - order of matrix `A` +* @param {Float32Array} D - the `N` diagonal elements of `A` +* @param {integer} strideD - stride length for `D` +* @param {NonNegativeInteger} offsetD - starting index of `D` +* @param {Complex64Array} E - the `N-1` subdiagonal elements of `A` +* @param {integer} strideE - stride length for `E` +* @param {NonNegativeInteger} offsetE - starting index of `E` +* @returns {integer} status code +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); +* var E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); +* +* cpttrf( 3, D, 1, 0, E, 1, 0 ); +* // D => [ 4, 4.75, ~5.15789 ] +*/ +function cpttrf( N, D, strideD, offsetD, E, strideE, offsetE ) { + var viewE; + var eir; + var eii; + var id; + var ie; + var f; + var g; + var i; + + if ( N === 0 ) { + return 0; + } + // Reinterpret complex array as float32 array: + viewE = reinterpret( E, 0 ); + + ie = offsetE * 2; + id = offsetD; + + // Compute the `L * D * L^H` factorization of `A`... + for ( i = 0; i < N-1; i++ ) { + // If `D[k] <= 0`, then the matrix is not positive definite... + if ( D[ id ] <= 0.0 ) { + return i+1; + } + // Solve for E[k] and D[k+1]... + // Extract real and imaginary parts of E[k]: + eir = viewE[ ie ]; + eii = viewE[ ie + 1 ]; + + // Compute F and G: + f = f32( eir / D[ id ] ); + g = f32( eii / D[ id ] ); + + // Store the result back in E[k]: + viewE[ ie ] = f; + viewE[ ie + 1 ] = g; + + // Update D[k+1]: D[k+1] = D[k+1] - F*EIR - G*EII + id += strideD; + D[ id ] = f32( D[ id ] - f32( f32( f * eir ) + f32( g * eii ) ) ); + + ie += strideE * 2; + } + // Check `D[k]` for positive definiteness... + if ( D[ id ] <= 0.0 ) { + return N; + } + return 0; +} + + +// EXPORTS // + +module.exports = cpttrf; diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/lib/cpttrf.js b/lib/node_modules/@stdlib/lapack/base/cpttrf/lib/cpttrf.js new file mode 100644 index 000000000000..9f16c29c4133 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/lib/cpttrf.js @@ -0,0 +1,58 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Computes the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A`. +* +* @param {NonNegativeInteger} N - order of matrix `A` +* @param {Float32Array} D - the `N` diagonal elements of `A` +* @param {Complex64Array} E - the `N-1` subdiagonal elements of `A` +* @throws {RangeError} first argument must be a nonnegative integer +* @returns {integer} status code +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); +* var E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); +* +* cpttrf( 3, D, E ); +* // D => [ 4, 4.75, ~5.15789 ] +*/ +function cpttrf( N, D, E ) { + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + return base( N, D, 1, 0, E, 1, 0 ); +} + + +// EXPORTS // + +module.exports = cpttrf; diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/lib/index.js b/lib/node_modules/@stdlib/lapack/base/cpttrf/lib/index.js new file mode 100644 index 000000000000..3b26375e4cf9 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/lib/index.js @@ -0,0 +1,70 @@ +/** +* @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 the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A`. +* +* @module @stdlib/lapack/base/cpttrf +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var cpttrf = require( '@stdlib/lapack/base/cpttrf' ); +* +* var D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); +* var E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); +* +* cpttrf( 3, D, E ); +* // D => [ 4, 4.75, ~5.15789 ] +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var cpttrf = require( '@stdlib/lapack/base/cpttrf' ); +* +* var D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); +* var E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); +* +* cpttrf.ndarray( 3, D, 1, 0, E, 1, 0 ); +* // D => [ 4, 4.75, ~5.15789 ] +*/ + +// 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 cpttrf; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + cpttrf = main; +} else { + cpttrf = tmp; +} + + +// EXPORTS // + +module.exports = cpttrf; diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/lib/main.js b/lib/node_modules/@stdlib/lapack/base/cpttrf/lib/main.js new file mode 100644 index 000000000000..1d6b98a29168 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/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 cpttrf = require( './cpttrf.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( cpttrf, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = cpttrf; diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/cpttrf/lib/ndarray.js new file mode 100644 index 000000000000..651c4be29a23 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/lib/ndarray.js @@ -0,0 +1,62 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Computes the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A` using alternative indexing semantics. +* +* @param {NonNegativeInteger} N - order of matrix `A` +* @param {Float32Array} D - the `N` diagonal elements of `A` +* @param {integer} strideD - stride length for `D` +* @param {NonNegativeInteger} offsetD - starting index of `D` +* @param {Complex64Array} E - the `N-1` subdiagonal elements of `A` +* @param {integer} strideE - stride length for `E` +* @param {NonNegativeInteger} offsetE - starting index of `E` +* @throws {RangeError} first argument must be a nonnegative integer +* @returns {integer} status code +* +* @example +* var Float32Array = require( '@stdlib/array/float32' ); +* var Complex64Array = require( '@stdlib/array/complex64' ); +* +* var D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); +* var E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); +* +* cpttrf( 3, D, 1, 0, E, 1, 0 ); +* // D => [ 4, 4.75, ~5.15789 ] +*/ +function cpttrf( N, D, strideD, offsetD, E, strideE, offsetE ) { + if ( N < 0 ) { + throw new RangeError( format( 'invalid argument. First argument must be a nonnegative integer. Value: `%d`.', N ) ); + } + return base( N, D, strideD, offsetD, E, strideE, offsetE ); +} + + +// EXPORTS // + +module.exports = cpttrf; diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/package.json b/lib/node_modules/@stdlib/lapack/base/cpttrf/package.json new file mode 100644 index 000000000000..700d91f6a5c3 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/lapack/base/cpttrf", + "version": "0.0.0", + "description": "Compute the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal 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", + "cpttrf", + "cholesky", + "factorization", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "float32", + "single", + "complex", + "complex64", + "float32array", + "complex64array", + "hermitian" + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/test/test.cpttrf.js b/lib/node_modules/@stdlib/lapack/base/cpttrf/test/test.cpttrf.js new file mode 100644 index 000000000000..a04e7ccf0c7c --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/test/test.cpttrf.js @@ -0,0 +1,193 @@ +/** +* @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 tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var cpttrf = require( './../lib/cpttrf.js' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cpttrf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( cpttrf.length, 3, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var D; + var E; + var i; + + values = [ + -1, + -2, + -3, + -4, + -5 + ]; + + D = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 3.0, 0.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() { + cpttrf( value, D, E ); + }; + } +}); + +tape( 'the function computes the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A`', function test( t ) { + var expectedD; + var expectedE; + var info; + var D; + var E; + var N; + + N = 3; + + D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); + E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + expectedD = new Float32Array( [ 4.0, 4.75, 5.157894736842105 ] ); + expectedE = new Complex64Array( [ 0.25, 0.0, 0.42105263157894735, 0.0 ] ); + + info = cpttrf( N, D, E ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 10.0 ); + t.ok( isSameComplex64Array( E, expectedE ), 'returns expected value' ); + + N = 7; + + D = new Float32Array( [ 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 3.0, 0.0, 4.0, 0.0, 5.0, 0.0, 6.0, 0.0 ] ); + + expectedD = new Float32Array( [ 4.0, 4.75, 5.157894736842105, 5.255102040816327, 4.955339805825243, 3.9549379348754883, 0.8974552154541016 ] ); + expectedE = new Complex64Array( [ 0.25, 0.0, 0.42105263157894735, 0.0, 0.58163265306122447, 0.0, 0.76116504854368927, 0.0, 1.0090124607086182, 0.0, 1.5170907974243164, 0.0 ] ); + + info = cpttrf( N, D, E ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 15.0 ); + t.ok( isSameComplex64Array( E, expectedE ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a non-zero status code when a diagonal element is less than or equal to zero', function test( t ) { + var info; + var D; + var E; + var N; + + N = 3; + + D = new Float32Array( [ 0.0, 5.0, 6.0 ] ); + E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + info = cpttrf( N, D, E ); + t.strictEqual( info, 1, 'returns expected value' ); + + D = new Float32Array( [ 4.0, 0.0, 6.0 ] ); + E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + info = cpttrf( N, D, E ); + t.strictEqual( info, 2, 'returns expected value' ); + + D = new Float32Array( [ 4.0, 5.0, 0.0 ] ); + E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + info = cpttrf( N, D, E ); + t.strictEqual( info, 3, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function leaves the input arrays unchanged when `N` is equal to zero', function test( t ) { + var expectedD; + var expectedE; + var info; + var D; + var E; + var N; + + N = 0; + + D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); + E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + expectedD = new Float32Array( [ 4.0, 5.0, 6.0 ] ); + expectedE = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + info = cpttrf( N, D, E ); + t.strictEqual( info, 0, 'returns expected value' ); + t.deepEqual( D, expectedD, 'returns expected value' ); + t.ok( isSameComplex64Array( E, expectedE ), 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/test/test.js b/lib/node_modules/@stdlib/lapack/base/cpttrf/test/test.js new file mode 100644 index 000000000000..77c48e0d7f60 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/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 cpttrf = 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 cpttrf, '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 cpttrf.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 cpttrf = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( cpttrf, 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 cpttrf; + var main; + + main = require( './../lib/cpttrf.js' ); + + cpttrf = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( cpttrf, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/lapack/base/cpttrf/test/test.ndarray.js b/lib/node_modules/@stdlib/lapack/base/cpttrf/test/test.ndarray.js new file mode 100644 index 000000000000..7d8cf0ed56fe --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/cpttrf/test/test.ndarray.js @@ -0,0 +1,289 @@ +/** +* @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 tape = require( 'tape' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var isSameComplex64Array = require( '@stdlib/assert/is-same-complex64array' ); +var EPS = require( '@stdlib/constants/float32/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var cpttrf = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Tests for element-wise approximate equality. +* +* @private +* @param {Object} t - test object +* @param {Collection} actual - actual values +* @param {Collection} expected - expected values +* @param {number} rtol - relative tolerance +*/ +function isApprox( t, actual, expected, rtol ) { + var delta; + var tol; + var i; + + t.strictEqual( actual.length, expected.length, 'returns expected value' ); + for ( i = 0; i < expected.length; i++ ) { + if ( actual[ i ] === expected[ i ] ) { + t.strictEqual( actual[ i ], expected[ i ], 'returns expected value' ); + } else { + delta = abs( actual[ i ] - expected[ i ] ); + tol = rtol * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. actual: '+actual[ i ]+'. expected: '+expected[ i ]+'. delta: '+delta+'. tol: '+tol+'.' ); + } + } +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cpttrf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( cpttrf.length, 7, 'returns expected value' ); + t.end(); +}); + +tape( 'the function throws an error if provided an invalid first argument', function test( t ) { + var values; + var D; + var E; + var i; + + values = [ + -1, + -2, + -3, + -4, + -5 + ]; + + D = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 3.0, 0.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() { + cpttrf( value, D, 1, 0, E, 1, 0 ); + }; + } +}); + +tape( 'the function computes the `L * D * L^H` factorization of a complex Hermitian positive definite tridiagonal matrix `A`', function test( t ) { + var expectedD; + var expectedE; + var info; + var D; + var E; + var N; + + N = 3; + + D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); + E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + expectedD = new Float32Array( [ 4.0, 4.75, 5.157894736842105 ] ); + expectedE = new Complex64Array( [ 0.25, 0.0, 0.42105263157894735, 0.0 ] ); + + info = cpttrf( N, D, 1, 0, E, 1, 0 ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 2.0 ); + t.ok( isSameComplex64Array( E, expectedE ), 'returns expected value' ); + + N = 7; + + D = new Float32Array( [ 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0, 3.0, 0.0, 4.0, 0.0, 5.0, 0.0, 6.0, 0.0 ] ); + + expectedD = new Float32Array( [ 4.0, 4.75, 5.157894736842105, 5.255102040816327, 4.955339805825243, 3.9549379348754883, 0.8974552154541016 ] ); + expectedE = new Complex64Array( [ 0.25, 0.0, 0.42105263157894735, 0.0, 0.58163265306122447, 0.0, 0.76116504854368927, 0.0, 1.0090124607086182, 0.0, 1.5170907974243164, 0.0 ] ); + + info = cpttrf( N, D, 1, 0, E, 1, 0 ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 15.0 ); + t.ok( isSameComplex64Array( E, expectedE ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing index offsets', function test( t ) { + var expectedD; + var expectedE; + var info; + var D; + var E; + var N; + + N = 3; + + D = new Float32Array( [ 0.0, 0.0, 4.0, 5.0, 6.0 ] ); + E = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 2.0, 0.0 ] ); + + expectedD = new Float32Array( [ 0.0, 0.0, 4.0, 4.75, 5.157894736842105 ] ); + expectedE = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.25, 0.0, 0.42105263157894735, 0.0 ] ); + + info = cpttrf( N, D, 1, 2, E, 1, 3 ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 10.0 ); + t.ok( isSameComplex64Array( E, expectedE ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing positive strides', function test( t ) { + var expectedD; + var expectedE; + var info; + var D; + var E; + var N; + + N = 3; + + D = new Float32Array( [ 0.0, 0.0, 4.0, 0.0, 0.0, 5.0, 0.0, 0.0, 6.0 ] ); + E = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 2.0, 0.0 ] ); + + expectedD = new Float32Array( [ 0.0, 0.0, 4.0, 0.0, 0.0, 4.75, 0.0, 0.0, 5.157894736842105 ] ); + expectedE = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 0.0, 0.42105263157894735, 0.0 ] ); + + info = cpttrf( N, D, 3, 2, E, 2, 3 ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 10.0 ); + t.ok( isSameComplex64Array( E, expectedE ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing mixed sign strides', function test( t ) { + var expectedD; + var expectedE; + var info; + var D; + var E; + var N; + + N = 3; + + D = new Float32Array( [ 6.0, 0.0, 0.0, 5.0, 0.0, 0.0, 4.0 ] ); + E = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 2.0, 0.0 ] ); + + expectedD = new Float32Array( [ 5.157894736842105, 0.0, 0.0, 4.75, 0.0, 0.0, 4.0 ] ); + expectedE = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 0.0, 0.42105263157894735, 0.0 ] ); + + info = cpttrf( N, D, -3, 6, E, 2, 3 ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 10.0 ); + t.ok( isSameComplex64Array( E, expectedE ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing negative strides', function test( t ) { + var expectedD; + var expectedE; + var info; + var D; + var E; + var N; + + N = 3; + + D = new Float32Array( [ 6.0, 0.0, 0.0, 5.0, 0.0, 0.0, 4.0 ] ); + E = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] ); + + expectedD = new Float32Array( [ 5.157894736842105, 0.0, 0.0, 4.75, 0.0, 0.0, 4.0 ] ); + expectedE = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.42105263157894735, 0.0, 0.0, 0.0, 0.25, 0.0 ] ); + + info = cpttrf( N, D, -3, 6, E, -2, 5 ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 10.0 ); + t.ok( isSameComplex64Array( E, expectedE ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a non-zero status code when a diagonal element is less than or equal to zero', function test( t ) { + var info; + var D; + var E; + var N; + + N = 3; + + D = new Float32Array( [ 0.0, 5.0, 6.0 ] ); + E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + info = cpttrf( N, D, 1, 0, E, 1, 0 ); + t.strictEqual( info, 1, 'returns expected value' ); + + D = new Float32Array( [ 4.0, 0.0, 6.0 ] ); + E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + info = cpttrf( N, D, 1, 0, E, 1, 0 ); + t.strictEqual( info, 2, 'returns expected value' ); + + D = new Float32Array( [ 4.0, 5.0, 0.0 ] ); + E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + info = cpttrf( N, D, 1, 0, E, 1, 0 ); + t.strictEqual( info, 3, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function leaves the input arrays unchanged when `N` is equal to zero', function test( t ) { + var expectedD; + var expectedE; + var info; + var D; + var E; + var N; + + N = 0; + + D = new Float32Array( [ 4.0, 5.0, 6.0 ] ); + E = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + expectedD = new Float32Array( [ 4.0, 5.0, 6.0 ] ); + expectedE = new Complex64Array( [ 1.0, 0.0, 2.0, 0.0 ] ); + + info = cpttrf( N, D, 1, 0, E, 1, 0 ); + t.strictEqual( info, 0, 'returns expected value' ); + t.deepEqual( D, expectedD, 'returns expected value' ); + t.ok( isSameComplex64Array( E, expectedE ), 'returns expected value' ); + + t.end(); +});