diff --git a/lib/node_modules/@stdlib/lapack/base/dpttrf/README.md b/lib/node_modules/@stdlib/lapack/base/dpttrf/README.md new file mode 100644 index 000000000000..7f3bf7a5d132 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/README.md @@ -0,0 +1,256 @@ + + +# dpttrf + +> Compute the `L * D * L^T` factorization of a real symmetric positive definite tridiagonal matrix `A`. + +
+ +## Usage + +```javascript +var dpttrf = require( '@stdlib/lapack/base/dpttrf' ); +``` + +#### dpttrf( N, D, E ) + +Computes the `L * D * L^T` factorization of a real symmetric positive definite tridiagonal matrix `A`. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var D = new Float64Array( [ 4.0, 5.0, 6.0 ] ); +var E = new Float64Array( [ 1.0, 2.0 ] ); + +dpttrf( 3, D, E ); +// D => [ 4, 4.75, ~5.15789 ] +// E => [ 0.25, ~0.4210 ] +``` + +The function has the following parameters: + +- **N**: order of matrix `A`. +- **D**: the `N` diagonal elements of `A` as a [`Float64Array`][mdn-float64array]. +- **E**: the N-1 subdiagonal elements of `A` as a [`Float64Array`][mdn-float64array]. + +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 D0 = new Float64Array( [ 0.0, 4.0, 5.0, 6.0 ] ); +var E0 = new Float64Array( [ 0.0, 1.0, 2.0 ] ); + +// Create offset views... +var D1 = new Float64Array( D0.buffer, D0.BYTES_PER_ELEMENT*1 ); // start at 2nd element +var E1 = new Float64Array( E0.buffer, E0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +dpttrf( 3, D1, E1 ); +// D0 => [ 0.0, 4.0, 4.75, ~5.15789 ] +// E0 => [ 0.0, 0.25, ~0.4210 ] +``` + +#### dpttrf.ndarray( N, D, strideD, offsetD, E, strideE, offsetE ) + +Computes the `L * D * L^T` factorization of a real symmetric positive definite tridiagonal matrix `A` using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var D = new Float64Array( [ 4.0, 5.0, 6.0 ] ); +var E = new Float64Array( [ 1.0, 2.0 ] ); + +dpttrf.ndarray( 3, D, 1, 0, E, 1, 0 ); +// D => [ 4, 4.75, ~5.15789 ] +// E => [ 0.25, ~0.4210 ] +``` + +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 Float64Array = require( '@stdlib/array/float64' ); + +var D = new Float64Array( [ 0.0, 4.0, 5.0, 6.0 ] ); +var E = new Float64Array( [ 0.0, 1.0, 2.0 ] ); + +dpttrf.ndarray( 3, D, 1, 1, E, 1, 1 ); +// D => [ 0.0, 4.0, 4.75, ~5.15789 ] +// E => [ 0.0, 0.25, ~0.4210 ] +``` + +
+ + + +
+ +## 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. + +- `dpttrf()` corresponds to the [LAPACK][LAPACK] routine [`dpttrf`][lapack-dpttrf]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dpttrf = require( '@stdlib/lapack/base/dpttrf' ); + +var opts = { + 'dtype': 'float64' +}; +var D = discreteUniform( 5, 1, 5, opts ); +console.log( D ); + +var E = discreteUniform( D.length-1, 1, 5, opts ); +console.log( E ); + +// Perform the `L * D * L^T` factorization: +var info = dpttrf( 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/dpttrf/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dpttrf/benchmark/benchmark.js new file mode 100644 index 000000000000..90011e025b7a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/benchmark/benchmark.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 dpttrf = require( './../lib/dpttrf.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var D = uniform( len, 0.0, 100.0, options ); + var E = uniform( len, 0.0, 100.0, options ); + return benchmark; + + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = dpttrf( len, D, E ); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( 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/dpttrf/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dpttrf/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..1bbdc5232ed4 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/benchmark/benchmark.ndarray.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 dpttrf = require( './../lib/ndarray.js' ); + + +// VARIABLES // + +var options = { + 'dtype': 'float64' +}; + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var D = uniform( len, 0.0, 100.0, options ); + var E = uniform( len, 0.0, 100.0, options ); + return benchmark; + + function benchmark( b ) { + var d; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + d = dpttrf( len, D, 1, 0, E, 1, 0 ); + if ( isnan( d ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( 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/dpttrf/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/dpttrf/docs/repl.txt new file mode 100644 index 000000000000..ab24124b8e9a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/docs/repl.txt @@ -0,0 +1,131 @@ + +{{alias}}( N, D, E ) + Computes the `L * D * L^T` factorization of a real symmetric 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: Float64Array + 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^T` factorization of `A`. + + E: Float64Array + 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^T` factorization of `A`. `E` can also be + regarded as the superdiagonal of the unit bidiagonal factor `U` from the + `U^T * 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/float64}}( [ 4.0, 5.0, 6.0 ] ); + > var E = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0 ] ); + > {{alias}}( 3, D, E ) + 0 + > D + [ 4, 4.75, ~5.15789 ] + > E + [ 0.25, ~0.42105 ] + + // Using typed array views: + > var D0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 4.0, 5.0, 6.0 ] ); + > var E0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0 ] ); + > D = new Float64Array( D0.buffer, D0.BYTES_PER_ELEMENT*1 ); + > E = new Float64Array( E0.buffer, E0.BYTES_PER_ELEMENT*1 ); + > {{alias}}( 3, D, E ) + 0 + > D0 + [ 0.0, 4.0, 4.75, ~5.15789 ] + > E0 + [ 0.0, 0.25, ~0.42105 ] + + +{{alias}}.ndarray( N, D, strideD, offsetD, E, strideE, offsetE ) + Computes the `L * D * L^T` factorization of a real symmetric 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: Float64Array + 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^T` factorization of `A`. + + strideD: integer + Stride length for `D`. + + offsetD: integer + Starting index for `D`. + + E: Float64Array + 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^T` factorization of `A`. `E` can also be + regarded as the superdiagonal of the unit bidiagonal factor `U` from the + `U^T * 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/float64}}( [ 0.0, 4.0, 5.0, 6.0 ] ); + > var E = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 2.0 ] ); + > {{alias}}.ndarray( 3, D, 1, 1, E, 1, 1 ) + 0 + > D + [ 0.0, 4.0, 4.75, ~5.15789 ] + > E + [ 0.0, 0.25, ~0.42105 ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/lapack/base/dpttrf/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/dpttrf/docs/types/index.d.ts new file mode 100644 index 000000000000..7ef13b643d5e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/docs/types/index.d.ts @@ -0,0 +1,116 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Status code. +* +* ## Notes +* +* The status code indicates the following conditions: +* +* - if equal to zero, then the 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 `dpttrf`. +*/ +interface Routine { + /** + * Computes the `L * D * L^T` factorization of a real symmetric 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 Float64Array = require( '@stdlib/array/float64' ); + * + * var D = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + * var E = new Float64Array( [ 1.0, 2.0 ] ); + * + * dpttrf( 3, D, E ); + * // D => [ 4, 4.75, ~5.15789 ] + * // E => [ 0.25, ~0.4210 ] + */ + ( N: number, D: Float64Array, E: Float64Array ): StatusCode; + + /** + * Computes the `L * D * L^T` factorization of a real symmetric 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 Float64Array = require( '@stdlib/array/float64' ); + * + * var D = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + * var E = new Float64Array( [ 1.0, 2.0 ] ); + * + * dpttrf.ndarray( 3, D, 1, 0, E, 1, 0 ); + * // D => [ 4, 4.75, ~5.15789 ] + * // E => [ 0.25, ~0.4210 ] + */ + ndarray( N: number, D: Float64Array, strideD: number, offsetD: number, E: Float64Array, strideE: number, offsetE: number ): StatusCode; +} + +/** +* Computes the `L * D * L^T` factorization of a real symmetric 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 Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, 5.0, 6.0 ] ); +* var E = new Float64Array( [ 1.0, 2.0 ] ); +* +* dpttrf( 3, D, E ); +* // D => [ 4, 4.75, ~5.15789 ] +* // E => [ 0.25, ~0.4210 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, 5.0, 6.0 ] ); +* var E = new Float64Array( [ 1.0, 2.0 ] ); +* +* dpttrf.ndarray( 3, D, 1, 0, E, 1, 0 ); +* // D => [ 4, 4.75, ~5.15789 ] +* // E => [ 0.25, ~0.4210 ] +*/ +declare var dpttrf: Routine; + + +// EXPORTS // + +export = dpttrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dpttrf/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/dpttrf/docs/types/test.ts new file mode 100644 index 000000000000..36b410c96b9a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/docs/types/test.ts @@ -0,0 +1,215 @@ + +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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 dpttrf = require( './index' ); + + +// TESTS // + +// The function returns a Float64Array... +{ + const D = new Float64Array( 3 ); + const E = new Float64Array( 2 ); + + dpttrf( 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 Float64Array( 3 ); + const E = new Float64Array( 2 ); + + dpttrf( '5', D, E ); // $ExpectError + dpttrf( true, D, E ); // $ExpectError + dpttrf( false, D, E ); // $ExpectError + dpttrf( null, D, E ); // $ExpectError + dpttrf( void 0, D, E ); // $ExpectError + dpttrf( [], D, E ); // $ExpectError + dpttrf( {}, D, E ); // $ExpectError + dpttrf( ( x: number ): number => x, D, E ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a Float64Array... +{ + const E = new Float64Array( 2 ); + + dpttrf( 3, '5', E ); // $ExpectError + dpttrf( 3, 5, E ); // $ExpectError + dpttrf( 3, true, E ); // $ExpectError + dpttrf( 3, false, E ); // $ExpectError + dpttrf( 3, null, E ); // $ExpectError + dpttrf( 3, void 0, E ); // $ExpectError + dpttrf( 3, [], E ); // $ExpectError + dpttrf( 3, {}, E ); // $ExpectError + dpttrf( 3, ( x: number ): number => x, E ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Float64Array... +{ + const D = new Float64Array( 3 ); + + dpttrf( 3, D, '5' ); // $ExpectError + dpttrf( 3, D, 5 ); // $ExpectError + dpttrf( 3, D, true ); // $ExpectError + dpttrf( 3, D, false ); // $ExpectError + dpttrf( 3, D, null ); // $ExpectError + dpttrf( 3, D, void 0 ); // $ExpectError + dpttrf( 3, D, [] ); // $ExpectError + dpttrf( 3, D, {} ); // $ExpectError + dpttrf( 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 Float64Array( 3 ); + const E = new Float64Array( 2 ); + + dpttrf(); // $ExpectError + dpttrf( 3 ); // $ExpectError + dpttrf( 3, D ); // $ExpectError + dpttrf( 3, D, E, 10 ); // $ExpectError +} + +// Attached to main export is an `ndarray` method which returns a Float64Array... +{ + const D = new Float64Array( 3 ); + const E = new Float64Array( 2 ); + + dpttrf.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 Float64Array( 3 ); + const E = new Float64Array( 2 ); + + dpttrf.ndarray( '5', D, 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( true, D, 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( false, D, 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( null, D, 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( void 0, D, 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( [], D, 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( {}, D, 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.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 Float64Array... +{ + const E = new Float64Array( 2 ); + + dpttrf.ndarray( 3, '5', 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, 5, 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, true, 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, false, 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, null, 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, void 0, 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, [], 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, {}, 1, 0, E, 1, 0 ); // $ExpectError + dpttrf.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 Float64Array( 3 ); + const E = new Float64Array( 2 ); + + dpttrf.ndarray( 3, D, '5', 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, true, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, false, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, null, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, void 0, 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, [], 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, {}, 0, E, 1, 0 ); // $ExpectError + dpttrf.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 Float64Array( 3 ); + const E = new Float64Array( 2 ); + + dpttrf.ndarray( 3, D, 1, '5', E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, true, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, false, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, null, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, void 0, E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, [], E, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, {}, E, 1, 0 ); // $ExpectError + dpttrf.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 Float64Array... +{ + const D = new Float64Array( 3 ); + + dpttrf.ndarray( 3, D, 1, 0, '5', 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, 5, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, true, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, false, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, null, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, void 0, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, [], 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, {}, 1, 0 ); // $ExpectError + dpttrf.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 Float64Array( 3 ); + const E = new Float64Array( 2 ); + + dpttrf.ndarray( 3, D, 1, 0, E, '5', 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E, true, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E, false, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E, null, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E, void 0, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E, [], 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E, {}, 0 ); // $ExpectError + dpttrf.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 Float64Array( 3 ); + const E = new Float64Array( 2 ); + + dpttrf.ndarray( 3, D, 1, 0, E, 1, '5' ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E, 1, true ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E, 1, false ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E, 1, null ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E, 1, void 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E, 1, [] ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E, 1, {} ); // $ExpectError + dpttrf.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 Float64Array( 3 ); + const E = new Float64Array( 2 ); + + dpttrf.ndarray(); // $ExpectError + dpttrf.ndarray( 3 ); // $ExpectError + dpttrf.ndarray( 3, D ); // $ExpectError + dpttrf.ndarray( 3, D, 1 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E, 1 ); // $ExpectError + dpttrf.ndarray( 3, D, 1, 0, E, 1, 0, 10 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/dpttrf/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dpttrf/examples/index.js new file mode 100644 index 000000000000..dd435aff0ec7 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/examples/index.js @@ -0,0 +1,37 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 dpttrf = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; +var D = discreteUniform( 5, 1, 5, opts ); +console.log( D ); + +var E = discreteUniform( D.length-1, 1, 5, opts ); +console.log( E ); + +// Perform the `L * D * L^T` factorization: +var info = dpttrf( D.length, D, E ); +console.log( D ); +console.log( E ); +console.log( info ); diff --git a/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/base.js new file mode 100644 index 000000000000..e2b35f02b8f7 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/base.js @@ -0,0 +1,83 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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'; + +// MAIN // + +/** +* Computes the `L * D * L^T` factorization of a real symmetric positive definite tridiagonal matrix `A`. +* +* @private +* @param {NonNegativeInteger} N - order of matrix `A` +* @param {Float64Array} D - the `N` diagonal elements of `A` +* @param {integer} strideD - stride length for `D` +* @param {NonNegativeInteger} offsetD - starting index of `D` +* @param {Float64Array} 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 Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, 5.0, 6.0 ] ); +* var E = new Float64Array( [ 1.0, 2.0 ] ); +* +* dpttrf( 3, D, 1, 0, E, 1, 0 ); +* // D => [ 4, 4.75, ~5.15789 ] +* // E => [ 0.25, ~0.4210 ] +*/ +function dpttrf( N, D, strideD, offsetD, E, strideE, offsetE ) { + var id; + var ie; + var v; + var i; + + if ( N === 0 ) { + return 0; + } + ie = offsetE; + id = offsetD; + + // Compute the `L * D * L^T` 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]... + v = E[ ie ]; + E[ ie ] = v / D[ id ]; + + id += strideD; + D[ id ] -= E[ ie ] * v; + + ie += strideE; + } + // Check `D[k]` for positive definiteness... + if ( D[ id ] <= 0.0 ) { + return N; + } + return 0; +} + + +// EXPORTS // + +module.exports = dpttrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/dpttrf.js b/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/dpttrf.js new file mode 100644 index 000000000000..3fe9ec5a395c --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/dpttrf.js @@ -0,0 +1,58 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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^T` factorization of a real symmetric positive definite tridiagonal matrix `A`. +* +* @param {NonNegativeInteger} N - order of matrix `A` +* @param {Float64Array} D - the `N` diagonal elements of `A` +* @param {Float64Array} E - the `N-1` subdiagonal elements of `A` +* @throws {RangeError} first argument must be a nonnegative integer +* @returns {integer} status code +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, 5.0, 6.0 ] ); +* var E = new Float64Array( [ 1.0, 2.0 ] ); +* +* dpttrf( 3, D, E ); +* // D => [ 4, 4.75, ~5.15789 ] +* // E => [ 0.25, ~0.4210 ] +*/ +function dpttrf( 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 = dpttrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/index.js new file mode 100644 index 000000000000..559cb9dc72ee --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/index.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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^T` factorization of a real symmetric positive definite tridiagonal matrix `A`. +* +* @module @stdlib/lapack/base/dpttrf +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dpttrf = require( '@stdlib/lapack/base/dpttrf' ); +* +* var D = new Float64Array( [ 4.0, 5.0, 6.0 ] ); +* var E = new Float64Array( [ 1.0, 2.0 ] ); +* +* dpttrf( 3, D, E ); +* // D => [ 4, 4.75, ~5.15789 ] +* // E => [ 0.25, ~0.4210 ] +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dpttrf = require( '@stdlib/lapack/base/dpttrf' ); +* +* var D = new Float64Array( [ 4.0, 5.0, 6.0 ] ); +* var E = new Float64Array( [ 1.0, 2.0 ] ); +* +* dpttrf.ndarray( 3, D, 1, 0, E, 1, 0 ); +* // D => [ 4, 4.75, ~5.15789 ] +* // E => [ 0.25, ~0.4210 ] +*/ + +// 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 dpttrf; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dpttrf = main; +} else { + dpttrf = tmp; +} + + +// EXPORTS // + +module.exports = dpttrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/main.js b/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/main.js new file mode 100644 index 000000000000..379eea00a54e --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/main.js @@ -0,0 +1,35 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 dpttrf = require( './dpttrf.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dpttrf, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dpttrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/ndarray.js new file mode 100644 index 000000000000..1e6b25b49819 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/lib/ndarray.js @@ -0,0 +1,62 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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^T` factorization of a real symmetric positive definite tridiagonal matrix `A` using alternative indexing semantics. +* +* @param {NonNegativeInteger} N - order of matrix `A` +* @param {Float64Array} D - the `N` diagonal elements of `A` +* @param {integer} strideD - stride length for `D` +* @param {NonNegativeInteger} offsetD - starting index of `D` +* @param {Float64Array} 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 Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, 5.0, 6.0 ] ); +* var E = new Float64Array( [ 1.0, 2.0 ] ); +* +* dpttrf( 3, D, 1, 0, E, 1, 0 ); +* // D => [ 4, 4.75, ~5.15789 ] +* // E => [ 0.25, ~0.4210 ] +*/ +function dpttrf( 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 = dpttrf; diff --git a/lib/node_modules/@stdlib/lapack/base/dpttrf/package.json b/lib/node_modules/@stdlib/lapack/base/dpttrf/package.json new file mode 100644 index 000000000000..08756d23d552 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/lapack/base/dpttrf", + "version": "0.0.0", + "description": "Compute the `L * D * L^T` factorization of a real symmetric 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", + "dpttrf", + "cholesky", + "factorization", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dpttrf/test/test.dpttrf.js b/lib/node_modules/@stdlib/lapack/base/dpttrf/test/test.dpttrf.js new file mode 100644 index 000000000000..28cb569d9ce6 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/test/test.dpttrf.js @@ -0,0 +1,191 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Float64Array = require( '@stdlib/array/float64' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var dpttrf = require( './../lib/dpttrf.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 dpttrf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 3', function test( t ) { + t.strictEqual( dpttrf.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 Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + E = new Float64Array( [ 1.0, 2.0, 3.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() { + dpttrf( value, D, E ); + }; + } +}); + +tape( 'the function computes the `L * D * L^T` factorization of a real symmetric positive definite tridiagonal matrix `A`', function test( t ) { + var expectedD; + var expectedE; + var info; + var D; + var E; + var N; + + N = 3; + + D = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + E = new Float64Array( [ 1.0, 2.0 ] ); + + expectedD = new Float64Array( [ 4.0, 4.75, 5.157894736842105 ] ); + expectedE = new Float64Array( [ 0.25, 0.42105263157894735 ] ); + + info = dpttrf( N, D, E ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 2.0 ); + isApprox( t, E, expectedE, 2.0 ); + + N = 7; + + D = new Float64Array( [ 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + E = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0] ); + + expectedD = new Float64Array( [ 4.0, 4.75, 5.157894736842105, 5.255102040816327, 4.955339805825243, 3.954937304075235, 0.89745368076885157 ] ); + expectedE = new Float64Array( [ 0.25, 0.42105263157894735, 0.58163265306122447, 0.76116504854368927, 1.0090125391849529, 1.5170910532051916 ] ); + + info = dpttrf( N, D, E ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 2.0 ); + isApprox( t, E, expectedE, 2.0 ); + + 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 Float64Array( [ 0.0, 5.0, 6.0 ] ); + E = new Float64Array( [ 1.0, 2.0 ] ); + + info = dpttrf( N, D, E ); + t.strictEqual( info, 1, 'returns expected value' ); + + D = new Float64Array( [ 4.0, 0.0, 6.0 ] ); + E = new Float64Array( [ 1.0, 2.0 ] ); + + info = dpttrf( N, D, E ); + t.strictEqual( info, 2, 'returns expected value' ); + + D = new Float64Array( [ 4.0, 5.0, 0.0 ] ); + E = new Float64Array( [ 1.0, 2.0 ] ); + + info = dpttrf( 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 Float64Array( [ 4.0, 5.0, 6.0 ] ); + E = new Float64Array( [ 1.0, 2.0 ] ); + + expectedD = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + expectedE = new Float64Array( [ 1.0, 2.0 ] ); + + info = dpttrf( N, D, E ); + t.strictEqual( info, 0, 'returns expected value' ); + t.deepEqual( D, expectedD, 'returns expected value' ); + t.deepEqual( E, expectedE, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dpttrf/test/test.js b/lib/node_modules/@stdlib/lapack/base/dpttrf/test/test.js new file mode 100644 index 000000000000..3c86332ae22d --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/test/test.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 dpttrf = 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 dpttrf, '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 dpttrf.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 dpttrf = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dpttrf, 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 dpttrf; + var main; + + main = require( './../lib/dpttrf.js' ); + + dpttrf = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dpttrf, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dpttrf/test/test.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dpttrf/test/test.ndarray.js new file mode 100644 index 000000000000..a7ff392364f1 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dpttrf/test/test.ndarray.js @@ -0,0 +1,287 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 Float64Array = require( '@stdlib/array/float64' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var dpttrf = 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 dpttrf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( dpttrf.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 Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + E = new Float64Array( [ 1.0, 2.0, 3.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() { + dpttrf( value, D, 1, 0, E, 1, 0 ); + }; + } +}); + +tape( 'the function computes the `L * D * L^T` factorization of a real symmetric positive definite tridiagonal matrix `A`', function test( t ) { + var expectedD; + var expectedE; + var info; + var D; + var E; + var N; + + N = 3; + + D = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + E = new Float64Array( [ 1.0, 2.0 ] ); + + expectedD = new Float64Array( [ 4.0, 4.75, 5.157894736842105 ] ); + expectedE = new Float64Array( [ 0.25, 0.42105263157894735 ] ); + + info = dpttrf( N, D, 1, 0, E, 1, 0 ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 2.0 ); + isApprox( t, E, expectedE, 2.0 ); + + N = 7; + + D = new Float64Array( [ 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ); + E = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0] ); + + expectedD = new Float64Array( [ 4.0, 4.75, 5.157894736842105, 5.255102040816327, 4.955339805825243, 3.954937304075235, 0.89745368076885157 ] ); + expectedE = new Float64Array( [ 0.25, 0.42105263157894735, 0.58163265306122447, 0.76116504854368927, 1.0090125391849529, 1.5170910532051916 ] ); + + info = dpttrf( N, D, 1, 0, E, 1, 0 ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 2.0 ); + isApprox( t, E, expectedE, 2.0 ); + + 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 Float64Array( [ 0.0, 0.0, 4.0, 5.0, 6.0 ] ); + E = new Float64Array( [ 0.0, 0.0, 0.0, 1.0, 2.0 ] ); + + expectedD = new Float64Array( [ 0.0, 0.0, 4.0, 4.75, 5.157894736842105 ] ); + expectedE = new Float64Array( [ 0.0, 0.0, 0.0, 0.25, 0.42105263157894735 ] ); + + info = dpttrf( N, D, 1, 2, E, 1, 3 ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 2.0 ); + isApprox( t, E, expectedE, 2.0 ); + + 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 Float64Array( [ 0.0, 0.0, 4.0, 0.0, 0.0, 5.0, 0.0, 0.0, 6.0 ] ); + E = new Float64Array( [ 0.0, 0.0, 0.0, 1.0, 0.0, 2.0 ] ); + + expectedD = new Float64Array( [ 0.0, 0.0, 4.0, 0.0, 0.0, 4.75, 0.0, 0.0, 5.157894736842105 ] ); + expectedE = new Float64Array( [ 0.0, 0.0, 0.0, 0.25, 0.0, 0.42105263157894735 ] ); + + info = dpttrf( N, D, 3, 2, E, 2, 3 ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 2.0 ); + isApprox( t, E, expectedE, 2.0 ); + + 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 Float64Array( [ 6.0, 0.0, 0.0, 5.0, 0.0, 0.0, 4.0 ] ); + E = new Float64Array( [ 0.0, 0.0, 0.0, 1.0, 0.0, 2.0 ] ); + + expectedD = new Float64Array( [ 5.157894736842105, 0.0, 0.0, 4.75, 0.0, 0.0, 4.0 ] ); + expectedE = new Float64Array( [ 0.0, 0.0, 0.0, 0.25, 0.0, 0.42105263157894735 ] ); + + info = dpttrf( N, D, -3, 6, E, 2, 3 ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 2.0 ); + isApprox( t, E, expectedE, 2.0 ); + + 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 Float64Array( [ 6.0, 0.0, 0.0, 5.0, 0.0, 0.0, 4.0 ] ); + E = new Float64Array( [ 0.0, 0.0, 0.0, 2.0, 0.0, 1.0 ] ); + + expectedD = new Float64Array( [ 5.157894736842105, 0.0, 0.0, 4.75, 0.0, 0.0, 4.0 ] ); + expectedE = new Float64Array( [ 0.0, 0.0, 0.0, 0.42105263157894735, 0.0, 0.25 ] ); + + info = dpttrf( N, D, -3, 6, E, -2, 5 ); + t.strictEqual( info, 0, 'returns expected value' ); + isApprox( t, D, expectedD, 2.0 ); + isApprox( t, E, expectedE, 2.0 ); + + 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 Float64Array( [ 0.0, 5.0, 6.0 ] ); + E = new Float64Array( [ 1.0, 2.0 ] ); + + info = dpttrf( N, D, 1, 0, E, 1, 0 ); + t.strictEqual( info, 1, 'returns expected value' ); + + D = new Float64Array( [ 4.0, 0.0, 6.0 ] ); + E = new Float64Array( [ 1.0, 2.0 ] ); + + info = dpttrf( N, D, 1, 0, E, 1, 0 ); + t.strictEqual( info, 2, 'returns expected value' ); + + D = new Float64Array( [ 4.0, 5.0, 0.0 ] ); + E = new Float64Array( [ 1.0, 2.0 ] ); + + info = dpttrf( 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 Float64Array( [ 4.0, 5.0, 6.0 ] ); + E = new Float64Array( [ 1.0, 2.0 ] ); + + expectedD = new Float64Array( [ 4.0, 5.0, 6.0 ] ); + expectedE = new Float64Array( [ 1.0, 2.0 ] ); + + info = dpttrf( N, D, 1, 0, E, 1, 0 ); + t.strictEqual( info, 0, 'returns expected value' ); + t.deepEqual( D, expectedD, 'returns expected value' ); + t.deepEqual( E, expectedE, 'returns expected value' ); + + t.end(); +});