diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/README.md b/lib/node_modules/@stdlib/lapack/base/dlanst/README.md new file mode 100644 index 000000000000..e1deccf20667 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/README.md @@ -0,0 +1,268 @@ + + +# dlanst + +> Return the value of the one norm, or the Frobenius norm, or the infinity norm, or the element of largest absolute value of a real symmetric tridiagonal matrix. + +
+ +
+ + + +
+ +## Usage + +```javascript +var dlanst = require( '@stdlib/lapack/base/dlanst' ); +``` + +#### dlanst( norm, N, D, strideD, E, strideE ) + +Returns the value of the one norm, or the Frobenius norm, or the infinity norm, or the element of largest absolute value of a real symmetric tridiagonal matrix. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + +var out = dlanst( 'max', 4, D, 1, E, 1 ); +// returns 5.0 +``` + +The function has the following parameters: + +- **norm**: specifies the norm to compute. Must be one of the following: + - `'max'`: the element of largest absolute value. + - `'one-norm'`: the one norm of the matrix (maximum column sum). + - `'infinity-norm'`: the infinity norm of the matrix (maximum row sum). + - `'frobenius-norm'`: the Frobenius norm of the matrix (square root of the sum of squares). + +- **N**: order of the tridiagonal matrix `A`. + +- **D**: input [`Float64Array`][@stdlib/array/float64] containing the diagonal elements of `A`. + +- **strideD**: stride length for `D`. + +- **E**: input [`Float64Array`][@stdlib/array/float64] containing the sub-diagonal elements of `A`. + +- **strideE**: stride length for `E`. + +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, -2.0, 5.0, -1.0 ] ); +var E0 = new Float64Array( [ 0.0, 1.0, -3.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 + +// Compute the max norm: +var out = dlanst( 'max', 4, D1, 1, E1, 1 ); +// returns 5.0 +``` + +Note that for a symmetric tridiagonal matrix, the one norm and infinity norm are equal. + +#### dlanst.ndarray( norm, N, D, strideD, offsetD, E, strideE, offsetE ) + +Returns the value of the one norm, or the Frobenius norm, or the infinity norm, or the element of largest absolute value of a real symmetric tridiagonal matrix using alternative indexing semantics. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + +var out = dlanst.ndarray( 'max', 4, D, 1, 0, E, 1, 0 ); +// returns 5.0 +``` + +The function has the following additional parameters: + +- **offsetD**: starting index for `D`. +- **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, -2.0, 5.0, -1.0 ] ); +var E = new Float64Array( [ 0.0, 1.0, -3.0, 2.0 ] ); + +var out = dlanst.ndarray( 'one-norm', 4, D, 1, 1, E, 1, 1 ); +// returns 10.0 +``` + +
+ + + +
+ +## Notes + +- `dlanst()` corresponds to the [LAPACK][lapack] function [`dlanst`][lapack-dlanst]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var dlanst = require( '@stdlib/lapack/base/dlanst' ); + +var opts = { + 'dtype': 'float64' +}; +var D = discreteUniform( 5, -10, 10, opts ); +console.log( 'D:', D ); + +var E = discreteUniform( 4, -10, 10, opts ); +console.log( 'E:', E ); + +var maxNorm = dlanst( 'max', D.length, D, 1, E, 1 ); +console.log( 'Max norm:', maxNorm ); + +var oneNorm = dlanst( 'one-norm', D.length, D, 1, E, 1 ); +console.log( 'One norm:', oneNorm ); + +var infNorm = dlanst( 'infinity-norm', D.length, D, 1, E, 1 ); +console.log( 'Infinity norm:', infNorm ); + +var froNorm = dlanst( 'frobenius-norm', D.length, D, 1, E, 1 ); +console.log( 'Frobenius norm:', froNorm ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +TODO +``` + +#### TODO + +TODO. + +```c +TODO +``` + +TODO + +```c +TODO +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +TODO +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dlanst/benchmark/benchmark.js new file mode 100644 index 000000000000..5ba7b4bdbe5d --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/benchmark/benchmark.js @@ -0,0 +1,107 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dlanst = require( './../lib/dlanst.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, -100.0, 100.0, options ); + var E = uniform( len - 1, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var norms; + var out; + var i; + + norms = [ 'max', 'one-norm', 'infinity-norm', 'frobenius-norm' ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = dlanst( norms[ i%4 ], len, D, 1, E, 1 ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + 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( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dlanst/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..13ffb71905ac --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/benchmark/benchmark.ndarray.js @@ -0,0 +1,107 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var dlanst = 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, -100.0, 100.0, options ); + var E = uniform( len - 1, -100.0, 100.0, options ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var norms; + var out; + var i; + + norms = [ 'max', 'one-norm', 'infinity-norm', 'frobenius-norm' ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = dlanst( norms[ i%4 ], len, D, 1, 0, E, 1, 0 ); + if ( isnan( out ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( out ) ) { + 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( format( '%s::ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/dlanst/docs/repl.txt new file mode 100644 index 000000000000..84265b12bdc2 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/docs/repl.txt @@ -0,0 +1,93 @@ + +{{alias}}( norm, N, D, strideD, E, strideE ) + Returns the value of the one norm, or the Frobenius norm, or the infinity + norm, or the element of largest absolute value of a real symmetric + tridiagonal matrix. + + Indexing is relative to the first index. To introduce an offset, use typed + array views. + + Parameters + ---------- + norm: string + Specifies the norm to be returned. Must be one of 'max', 'one-norm', + 'infinity-norm', or 'frobenius-norm'. + + N: integer + Order of the matrix. + + D: Float64Array + Array containing the diagonal elements. + + strideD: integer + Stride length for `D`. + + E: Float64Array + Array containing the sub-diagonal elements. + + strideE: integer + Stride length for `E`. + + Returns + ------- + out: number + Norm value. + + Examples + -------- + > var D = new {{alias:@stdlib/array/float64}}( [ 4.0, -2.0, 5.0, -1.0 ] ); + > var E = new {{alias:@stdlib/array/float64}}( [ 1.0, -3.0, 2.0 ] ); + > {{alias}}( 'max', 4, D, 1, E, 1 ) + 5.0 + + +{{alias}}.ndarray( norm, N, D, sd, od, E, se, oe ) + Returns the value of the one norm, or the Frobenius norm, or the infinity + norm, or the element of largest absolute value of a real symmetric + tridiagonal matrix 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. + + Parameters + ---------- + norm: string + Specifies the norm to be returned. Must be one of 'max', 'one-norm', + 'infinity-norm', or 'frobenius-norm'. + + N: integer + Order of the matrix. + + D: Float64Array + Array containing the diagonal elements. + + sd: integer + Stride length for `D`. + + od: integer + Starting index for `D`. + + E: Float64Array + Array containing the sub-diagonal elements. + + se: integer + Stride length for `E`. + + oe: integer + Starting index for `E`. + + Returns + ------- + out: number + Norm value. + + Examples + -------- + > var D = new {{alias:@stdlib/array/float64}}( [ 0.0, 4.0, -2.0, 5.0, -1.0 ] ); + > var E = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, -3.0, 2.0 ] ); + > {{alias}}.ndarray( 'one-norm', 4, D, 1, 1, E, 1, 1 ) + 10.0 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/docs/types/index.d.ts b/lib/node_modules/@stdlib/lapack/base/dlanst/docs/types/index.d.ts new file mode 100644 index 000000000000..f23100d4c38b --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/docs/types/index.d.ts @@ -0,0 +1,108 @@ +/* +* @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 + +/// + +/** +* Interface describing `dlanst`. +*/ +interface Routine { + /** + * Returns the value of the one norm, or the Frobenius norm, or the infinity norm, or the element of largest absolute value of a real symmetric tridiagonal matrix. + * + * @param norm - specifies the norm to be returned (`'max'`, `'one-norm'`, `'infinity-norm'`, or `'frobenius-norm'`) + * @param N - order of the matrix + * @param D - array containing the diagonal elements + * @param strideD - stride length for `D` + * @param E - array containing the sub-diagonal elements + * @param strideE - stride length for `E` + * @returns norm value + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + * var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + * + * var out = dlanst( 'max', 4, D, 1, E, 1 ); + * // returns 5.0 + */ + ( norm: string, N: number, D: Float64Array, strideD: number, E: Float64Array, strideE: number ): number; + + /** + * Returns the value of the one norm, or the Frobenius norm, or the infinity norm, or the element of largest absolute value of a real symmetric tridiagonal matrix using alternative indexing semantics. + * + * @param norm - specifies the norm to be returned (`'max'`, `'one-norm'`, `'infinity-norm'`, or `'frobenius-norm'`) + * @param N - order of the matrix + * @param D - array containing the diagonal elements + * @param strideD - stride length for `D` + * @param offsetD - starting index for `D` + * @param E - array containing the sub-diagonal elements + * @param strideE - stride length for `E` + * @param offsetE - starting index for `E` + * @returns norm value + * + * @example + * var Float64Array = require( '@stdlib/array/float64' ); + * + * var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + * var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + * + * var out = dlanst.ndarray( 'max', 4, D, 1, 0, E, 1, 0 ); + * // returns 5.0 + */ + ndarray( norm: string, N: number, D: Float64Array, strideD: number, offsetD: number, E: Float64Array, strideE: number, offsetE: number ): number; +} + +/** +* Returns the value of the one norm, or the Frobenius norm, or the infinity norm, or the element of largest absolute value of a real symmetric tridiagonal matrix. +* +* @param norm - specifies the norm to be returned (`'max'`, `'one-norm'`, `'infinity-norm'`, or `'frobenius-norm'`) +* @param N - order of the matrix +* @param D - array containing the diagonal elements +* @param strideD - stride length for `D` +* @param E - array containing the sub-diagonal elements +* @param strideE - stride length for `E` +* @returns norm value +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +* var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); +* +* var out = dlanst( 'max', 4, D, 1, E, 1 ); +* // returns 5.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +* var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); +* +* var out = dlanst.ndarray( 'max', 4, D, 1, 0, E, 1, 0 ); +* // returns 5.0 +*/ +declare var dlanst: Routine; + + +// EXPORTS // + +export = dlanst; diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/docs/types/test.ts b/lib/node_modules/@stdlib/lapack/base/dlanst/docs/types/test.ts new file mode 100644 index 000000000000..6b217093ef56 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/docs/types/test.ts @@ -0,0 +1,278 @@ +/* +* @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 dlanst = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst( 'max', 4, D, 1, E, 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a first argument which is not a string... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst( 5, 4, D, 1, E, 1 ); // $ExpectError + dlanst( true, 4, D, 1, E, 1 ); // $ExpectError + dlanst( false, 4, D, 1, E, 1 ); // $ExpectError + dlanst( null, 4, D, 1, E, 1 ); // $ExpectError + dlanst( void 0, 4, D, 1, E, 1 ); // $ExpectError + dlanst( [], 4, D, 1, E, 1 ); // $ExpectError + dlanst( {}, 4, D, 1, E, 1 ); // $ExpectError + dlanst( ( x: number ): number => x, 4, D, 1, E, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst( 'max', '5', D, 1, E, 1 ); // $ExpectError + dlanst( 'max', true, D, 1, E, 1 ); // $ExpectError + dlanst( 'max', false, D, 1, E, 1 ); // $ExpectError + dlanst( 'max', null, D, 1, E, 1 ); // $ExpectError + dlanst( 'max', void 0, D, 1, E, 1 ); // $ExpectError + dlanst( 'max', [], D, 1, E, 1 ); // $ExpectError + dlanst( 'max', {}, D, 1, E, 1 ); // $ExpectError + dlanst( 'max', ( x: number ): number => x, D, 1, E, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a Float64Array... +{ + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst( 'max', 4, '5', 1, E, 1 ); // $ExpectError + dlanst( 'max', 4, 5, 1, E, 1 ); // $ExpectError + dlanst( 'max', 4, true, 1, E, 1 ); // $ExpectError + dlanst( 'max', 4, false, 1, E, 1 ); // $ExpectError + dlanst( 'max', 4, null, 1, E, 1 ); // $ExpectError + dlanst( 'max', 4, void 0, 1, E, 1 ); // $ExpectError + dlanst( 'max', 4, [], 1, E, 1 ); // $ExpectError + dlanst( 'max', 4, {}, 1, E, 1 ); // $ExpectError + dlanst( 'max', 4, ( x: number ): number => x, 1, E, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a number... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst( 'max', 4, D, '5', E, 1 ); // $ExpectError + dlanst( 'max', 4, D, true, E, 1 ); // $ExpectError + dlanst( 'max', 4, D, false, E, 1 ); // $ExpectError + dlanst( 'max', 4, D, null, E, 1 ); // $ExpectError + dlanst( 'max', 4, D, void 0, E, 1 ); // $ExpectError + dlanst( 'max', 4, D, [], E, 1 ); // $ExpectError + dlanst( 'max', 4, D, {}, E, 1 ); // $ExpectError + dlanst( 'max', 4, D, ( x: number ): number => x, E, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a Float64Array... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + + dlanst( 'max', 4, D, 1, '5', 1 ); // $ExpectError + dlanst( 'max', 4, D, 1, 5, 1 ); // $ExpectError + dlanst( 'max', 4, D, 1, true, 1 ); // $ExpectError + dlanst( 'max', 4, D, 1, false, 1 ); // $ExpectError + dlanst( 'max', 4, D, 1, null, 1 ); // $ExpectError + dlanst( 'max', 4, D, 1, void 0, 1 ); // $ExpectError + dlanst( 'max', 4, D, 1, [], 1 ); // $ExpectError + dlanst( 'max', 4, D, 1, {}, 1 ); // $ExpectError + dlanst( 'max', 4, D, 1, ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not a number... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst( 'max', 4, D, 1, E, '5' ); // $ExpectError + dlanst( 'max', 4, D, 1, E, true ); // $ExpectError + dlanst( 'max', 4, D, 1, E, false ); // $ExpectError + dlanst( 'max', 4, D, 1, E, null ); // $ExpectError + dlanst( 'max', 4, D, 1, E, void 0 ); // $ExpectError + dlanst( 'max', 4, D, 1, E, [] ); // $ExpectError + dlanst( 'max', 4, D, 1, E, {} ); // $ExpectError + dlanst( 'max', 4, D, 1, E, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst(); // $ExpectError + dlanst( 'max' ); // $ExpectError + dlanst( 'max', 4 ); // $ExpectError + dlanst( 'max', 4, D ); // $ExpectError + dlanst( 'max', 4, D, 1 ); // $ExpectError + dlanst( 'max', 4, D, 1, E ); // $ExpectError + dlanst( 'max', 4, D, 1, E, 1, 0 ); // $ExpectError +} + +// Attached to the main export is an `ndarray` method which returns a number... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst.ndarray( 'max', 4, D, 1, 0, E, 1, 0 ); // $ExpectType number +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a string... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst.ndarray( 5, 4, D, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( true, 4, D, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( false, 4, D, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( null, 4, D, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( void 0, 4, D, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( [], 4, D, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( {}, 4, D, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( ( x: number ): number => x, 4, D, 1, 0, E, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst.ndarray( 'max', '5', D, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', true, D, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', false, D, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', null, D, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', void 0, D, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', [], D, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', {}, D, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', ( x: number ): number => x, D, 1, 0, E, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float64Array... +{ + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst.ndarray( 'max', 4, '5', 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, 5, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, true, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, false, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, null, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, void 0, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, [], 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, {}, 1, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, ( x: number ): number => x, 1, 0, E, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst.ndarray( 'max', 4, D, '5', 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, true, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, false, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, null, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, void 0, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, [], 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, {}, 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, ( x: number ): number => x, 0, E, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst.ndarray( 'max', 4, D, 1, '5', E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, true, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, false, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, null, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, void 0, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, [], E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, {}, E, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, ( x: number ): number => x, E, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not a Float64Array... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + + dlanst.ndarray( 'max', 4, D, 1, 0, '5', 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, 5, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, true, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, false, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, null, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, void 0, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, [], 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, {}, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, ( x: number ): number => x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst.ndarray( 'max', 4, D, 1, 0, E, '5', 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, true, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, false, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, null, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, void 0, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, [], 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, {}, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst.ndarray( 'max', 4, D, 1, 0, E, 1, '5' ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, 1, true ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, 1, false ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, 1, null ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, 1, void 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, 1, [] ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, 1, {} ); // $ExpectError + dlanst.ndarray( 'max', 4, 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( [ 4.0, -2.0, 5.0, -1.0 ] ); + const E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + dlanst.ndarray(); // $ExpectError + dlanst.ndarray( 'max' ); // $ExpectError + dlanst.ndarray( 'max', 4 ); // $ExpectError + dlanst.ndarray( 'max', 4, D ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, 1 ); // $ExpectError + dlanst.ndarray( 'max', 4, D, 1, 0, E, 1, 0, 0 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/examples/index.js b/lib/node_modules/@stdlib/lapack/base/dlanst/examples/index.js new file mode 100644 index 000000000000..cafcfbc87028 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/examples/index.js @@ -0,0 +1,43 @@ +/** +* @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 dlanst = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; +var D = discreteUniform( 5, -10, 10, opts ); +console.log( 'D:', D ); + +var E = discreteUniform( 4, -10, 10, opts ); +console.log( 'E:', E ); + +var maxNorm = dlanst( 'max', D.length, D, 1, E, 1 ); +console.log( 'Max norm:', maxNorm ); + +var oneNorm = dlanst( 'one-norm', D.length, D, 1, E, 1 ); +console.log( 'One norm:', oneNorm ); + +var infNorm = dlanst( 'infinity-norm', D.length, D, 1, E, 1 ); +console.log( 'Infinity norm:', infNorm ); + +var froNorm = dlanst( 'frobenius-norm', D.length, D, 1, E, 1 ); +console.log( 'Frobenius norm:', froNorm ); diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/base.js new file mode 100644 index 000000000000..c187d0313453 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/base.js @@ -0,0 +1,137 @@ +/** +* @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 dlassq = require( '@stdlib/lapack/base/dlassq' ).ndarray; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var Float64Array = require( '@stdlib/array/float64' ); + + +// MAIN // + +/** +* Returns the value of the one norm, or the Frobenius norm, or the infinity norm, or the element of largest absolute value of a real symmetric tridiagonal matrix. +* +* @private +* @param {string} norm - specifies the norm to be returned +* @param {NonNegativeInteger} N - order of the matrix +* @param {Float64Array} D - array containing the diagonal elements (length N) +* @param {integer} strideD - stride length for `D` +* @param {NonNegativeInteger} offsetD - starting index for `D` +* @param {Float64Array} E - array containing the sub-diagonal elements (length N-1) +* @param {integer} strideE - stride length for `E` +* @param {NonNegativeInteger} offsetE - starting index for `E` +* @returns {number} norm value +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +* var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); +* +* var out = dlanst( 'max', 4, D, 1, 0, E, 1, 0 ); +* // returns 5.0 +*/ +function dlanst( norm, N, D, strideD, offsetD, E, strideE, offsetE ) { + var anorm; + var scale; + var out; + var sum; + var id; + var ie; + var i; + + if ( N <= 0 ) { + return 0.0; + } + if ( norm === 'max' ) { + // Find max(abs(A(i,j)))... + id = offsetD + ( ( N - 1 ) * strideD ); + anorm = abs( D[ id ] ); + id = offsetD; + ie = offsetE; + for ( i = 0; i < N - 1; i++ ) { + sum = abs( D[ id ] ); + if ( anorm < sum || isnan( sum ) ) { + anorm = sum; + } + sum = abs( E[ ie ] ); + if ( anorm < sum || isnan( sum ) ) { + anorm = sum; + } + id += strideD; + ie += strideE; + } + return anorm; + } + if ( norm === 'one-norm' || norm === 'infinity-norm' ) { + // Find norm1(A) which equals normI(A) for symmetric tridiagonal matrices... + if ( N === 1 ) { + return abs( D[ offsetD ] ); + } + anorm = abs( D[ offsetD ] ) + abs( E[ offsetE ] ); + id = offsetD + ( ( N - 1 ) * strideD ); + ie = offsetE + ( ( N - 2 ) * strideE ); + sum = abs( E[ ie ] ) + abs( D[ id ] ); + if ( anorm < sum || isnan( sum ) ) { + anorm = sum; + } + id = offsetD + strideD; + ie = offsetE; + for ( i = 1; i < N - 1; i++ ) { + sum = abs( D[ id ] ) + abs( E[ ie ] ) + abs( E[ ie + strideE ] ); + if ( anorm < sum || isnan( sum ) ) { + anorm = sum; + } + id += strideD; + ie += strideE; + } + return anorm; + } + if ( norm === 'frobenius-norm' ) { + // Find normF(A)... + scale = 0.0; + sum = 1.0; + out = new Float64Array( 2 ); + if ( N > 1 ) { + out[ 0 ] = scale; + out[ 1 ] = sum; + dlassq( N - 1, E, strideE, offsetE, scale, sum, out, 1, 0 ); + scale = out[ 0 ]; + sum = out[ 1 ]; + sum = 2.0 * sum; + } + out[ 0 ] = scale; + out[ 1 ] = sum; + dlassq( N, D, strideD, offsetD, scale, sum, out, 1, 0 ); + scale = out[ 0 ]; + sum = out[ 1 ]; + return scale * sqrt( sum ); + } + return 0.0; +} + + +// EXPORTS // + +module.exports = dlanst; diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/lib/dlanst.js b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/dlanst.js new file mode 100644 index 000000000000..417709c2fac0 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/dlanst.js @@ -0,0 +1,95 @@ +/** +* @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 stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var format = require( '@stdlib/string/format' ); +var isMatrixNorm = require( './is_norm.js' ); +var base = require( './base.js' ); + + +// MAIN // + +/** +* Returns the value of the one norm, or the Frobenius norm, or the infinity norm, or the element of largest absolute value of a real symmetric tridiagonal matrix. +* +* @param {string} norm - specifies the norm to be returned +* @param {NonNegativeInteger} N - order of the matrix +* @param {Float64Array} D - array containing the diagonal elements +* @param {integer} strideD - stride length for `D` +* @param {Float64Array} E - array containing the sub-diagonal elements +* @param {integer} strideE - stride length for `E` +* @throws {TypeError} first argument must be a valid norm +* @returns {number} norm value +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +* var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); +* +* var out = dlanst( 'max', 4, D, 1, E, 1 ); +* // returns 5.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +* var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); +* +* var out = dlanst( 'one-norm', 4, D, 1, E, 1 ); +* // returns 10.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +* var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); +* +* var out = dlanst( 'infinity-norm', 4, D, 1, E, 1 ); +* // returns 10.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +* var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); +* +* var out = dlanst( 'frobenius-norm', 4, D, 1, E, 1 ); +* // returns ~8.6023 +*/ +function dlanst( norm, N, D, strideD, E, strideE ) { + var od; + var oe; + + if ( !isMatrixNorm( norm ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid norm. Value: `%s`.', norm ) ); + } + + od = stride2offset( N, strideD ); + oe = stride2offset( N - 1, strideE ); + return base( norm, N, D, strideD, od, E, strideE, oe ); +} + + +// EXPORTS // + +module.exports = dlanst; diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/lib/index.js b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/index.js new file mode 100644 index 000000000000..e8279ac3b7b1 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/index.js @@ -0,0 +1,80 @@ +/** +* @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 return the value of the one norm, or the Frobenius norm, or the infinity norm, or the element of largest absolute value of a real symmetric tridiagonal matrix. +* +* @module @stdlib/lapack/base/dlanst +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dlanst = require( '@stdlib/lapack/base/dlanst' ); +* +* var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +* var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); +* +* var out = dlanst( 'max', 4, D, 1, E, 1 ); +* // returns 5.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dlanst = require( '@stdlib/lapack/base/dlanst' ); +* +* var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +* var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); +* +* var out = dlanst( 'one-norm', 4, D, 1, E, 1 ); +* // returns 10.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var dlanst = require( '@stdlib/lapack/base/dlanst' ); +* +* var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +* var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); +* +* var out = dlanst.ndarray( 'frobenius-norm', 4, D, 1, 0, E, 1, 0 ); +* // returns ~8.6023 +*/ + +// 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 dlanst; +var tmp = tryRequire( join( __dirname, './native.js' ) ); +if ( isError( tmp ) ) { + dlanst = main; +} else { + dlanst = tmp; +} + + +// EXPORTS // + +module.exports = dlanst; + +// exports: { "ndarray": "dlanst.ndarray" } diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/lib/is_norm.js b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/is_norm.js new file mode 100644 index 000000000000..f899d461d593 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/is_norm.js @@ -0,0 +1,56 @@ +/** +* @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 contains = require( '@stdlib/array/base/assert/contains' ).factory; + + +// VARIABLES // + +var NORMS = [ 'max', 'one-norm', 'infinity-norm', 'frobenius-norm' ]; +var isNorm = contains( NORMS ); + + +// MAIN // + +/** +* Tests whether a value is a valid matrix norm. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating whether a value is a valid matrix norm +* +* @example +* var bool = isMatrixNorm( 'max' ); +* // returns true +* +* @example +* var bool = isMatrixNorm( 'foo' ); +* // returns false +*/ +function isMatrixNorm( value ) { + return isNorm( value ); +} + + +// EXPORTS // + +module.exports = isMatrixNorm; diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/lib/main.js b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/main.js new file mode 100644 index 000000000000..79f58e666401 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/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 dlanst = require( './dlanst.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( dlanst, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = dlanst; diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/ndarray.js new file mode 100644 index 000000000000..87d98ff97e2a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/ndarray.js @@ -0,0 +1,84 @@ +/** +* @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 base = require( './base.js' ); + + +// MAIN // + +/** +* Returns the value of the one norm, or the Frobenius norm, or the infinity norm, or the element of largest absolute value of a real symmetric tridiagonal matrix using alternative indexing semantics. +* +* @param {string} norm - specifies the norm to be returned +* @param {NonNegativeInteger} N - order of the matrix +* @param {Float64Array} D - array containing the diagonal elements +* @param {integer} strideD - stride length for `D` +* @param {NonNegativeInteger} offsetD - starting index for `D` +* @param {Float64Array} E - array containing the sub-diagonal elements +* @param {integer} strideE - stride length for `E` +* @param {NonNegativeInteger} offsetE - starting index for `E` +* @returns {number} norm value +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +* var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); +* +* var out = dlanst( 'max', 4, D, 1, 0, E, 1, 0 ); +* // returns 5.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +* var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); +* +* var out = dlanst( 'one-norm', 4, D, 1, 0, E, 1, 0 ); +* // returns 10.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +* var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); +* +* var out = dlanst( 'infinity-norm', 4, D, 1, 0, E, 1, 0 ); +* // returns 10.0 +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); +* var E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); +* +* var out = dlanst( 'frobenius-norm', 4, D, 1, 0, E, 1, 0 ); +* // returns ~8.6023 +*/ +function dlanst( norm, N, D, strideD, offsetD, E, strideE, offsetE ) { + return base( norm, N, D, strideD, offsetD, E, strideE, offsetE ); +} + + +// EXPORTS // + +module.exports = dlanst; diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/package.json b/lib/node_modules/@stdlib/lapack/base/dlanst/package.json new file mode 100644 index 000000000000..0bc6393f4c75 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/lapack/base/dlanst", + "version": "0.0.0", + "description": "Return the value of the one norm, or the Frobenius norm, or the infinity norm, or the element of largest absolute value of a real symmetric tridiagonal matrix.", + "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", + "dlanst", + "norm", + "tridiagonal", + "symmetric", + "matrix", + "linear", + "algebra", + "subroutines", + "array", + "ndarray", + "float64", + "double", + "float64array" + ] +} diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/test/test.dlanst.js b/lib/node_modules/@stdlib/lapack/base/dlanst/test/test.dlanst.js new file mode 100644 index 000000000000..bc3a5c775b8a --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/test/test.dlanst.js @@ -0,0 +1,359 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var Float64Array = require( '@stdlib/array/float64' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var dlanst = require( './../lib/dlanst.js' ); + + +// FUNCTIONS // + +/** +* Tests for approximate equality. +* +* @private +* @param {Object} t - test object +* @param {number} actual - actual value +* @param {number} expected - expected value +* @param {number} maxULP - units in the last place +*/ +function isApprox( t, actual, expected, maxULP ) { + t.strictEqual( isAlmostSameValue( actual, expected, maxULP ), true, 'returns expected value. actual: ' + actual + '. expected: ' + expected + '.' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlanst, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( dlanst.length, 6, '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 = [ + 'foo', + 'bar', + 'invalid', + 123, + true, + null, + void 0, + {} + ]; + + D = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + E = new Float64Array( [ 1.0, 2.0 ] ); + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + dlanst( value, 3, D, 1, E, 1 ); + }; + } +}); + +tape( 'the function returns 0 when N is 0', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( 0 ); + E = new Float64Array( 0 ); + + out = dlanst( 'max', 0, D, 1, E, 1 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + out = dlanst( 'one-norm', 0, D, 1, E, 1 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + out = dlanst( 'infinity-norm', 0, D, 1, E, 1 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + out = dlanst( 'frobenius-norm', 0, D, 1, E, 1 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns 0 when N is negative', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 1.0, 2.0 ] ); + E = new Float64Array( [ 1.0 ] ); + + out = dlanst( 'max', -1, D, 1, E, 1 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the max norm (N=1)', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ -7.0 ] ); + E = new Float64Array( 0 ); + + out = dlanst( 'max', 1, D, 1, E, 1 ); + t.strictEqual( out, 7.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the max norm', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + out = dlanst( 'max', 4, D, 1, E, 1 ); + t.strictEqual( out, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the max norm (max in sub-diagonal)', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + E = new Float64Array( [ -10.0, 4.0 ] ); + + out = dlanst( 'max', 3, D, 1, E, 1 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the max norm with NaN propagation', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 1.0, NaN, 3.0 ] ); + E = new Float64Array( [ 2.0, 4.0 ] ); + + out = dlanst( 'max', 3, D, 1, E, 1 ); + t.strictEqual( out !== out, true, 'returns NaN' ); + + D = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + E = new Float64Array( [ NaN, 4.0 ] ); + + out = dlanst( 'max', 3, D, 1, E, 1 ); + t.strictEqual( out !== out, true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function computes the one-norm (N=1)', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ -7.0 ] ); + E = new Float64Array( 0 ); + + out = dlanst( 'one-norm', 1, D, 1, E, 1 ); + t.strictEqual( out, 7.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the one-norm', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + out = dlanst( 'one-norm', 4, D, 1, E, 1 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the one-norm (2x2 matrix)', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 3.0, 2.0 ] ); + E = new Float64Array( [ -5.0 ] ); + + out = dlanst( 'one-norm', 2, D, 1, E, 1 ); + t.strictEqual( out, 8.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the one-norm with NaN propagation', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 1.0, NaN, 3.0 ] ); + E = new Float64Array( [ 2.0, 4.0 ] ); + + out = dlanst( 'one-norm', 3, D, 1, E, 1 ); + t.strictEqual( out !== out, true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function computes the infinity-norm (equal to one-norm for symmetric tridiagonal)', function test( t ) { + var out; + var D; + var E; + + // For a symmetric tridiagonal matrix, the infinity norm equals the one norm + D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + out = dlanst( 'infinity-norm', 4, D, 1, E, 1 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Frobenius norm (N=1)', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ -7.0 ] ); + E = new Float64Array( 0 ); + + out = dlanst( 'frobenius-norm', 1, D, 1, E, 1 ); + t.strictEqual( out, 7.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Frobenius norm', function test( t ) { + var expected; + var out; + var D; + var E; + + D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + expected = sqrt( 74.0 ); + + out = dlanst( 'frobenius-norm', 4, D, 1, E, 1 ); + isApprox( t, out, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function computes the Frobenius norm (2x2 matrix)', function test( t ) { + var expected; + var out; + var D; + var E; + + D = new Float64Array( [ 3.0, 2.0 ] ); + E = new Float64Array( [ -5.0 ] ); + + expected = sqrt( 63.0 ); + + out = dlanst( 'frobenius-norm', 2, D, 1, E, 1 ); + isApprox( t, out, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function computes the Frobenius norm (identity-like tridiagonal)', function test( t ) { + var expected; + var out; + var D; + var E; + + D = new Float64Array( [ 1.0, 1.0, 1.0 ] ); + E = new Float64Array( [ 0.0, 0.0 ] ); + + expected = sqrt( 3.0 ); + + out = dlanst( 'frobenius-norm', 3, D, 1, E, 1 ); + isApprox( t, out, expected, 2.0 ); + + t.end(); +}); + +tape( 'the function supports negative strides', function test( t ) { + var out; + var D; + var E; + + // When strideD = -1, elements are traversed in reverse + D = new Float64Array( [ -1.0, 5.0, -2.0, 4.0 ] ); // reversed order + E = new Float64Array( [ 2.0, -3.0, 1.0 ] ); // reversed order + + out = dlanst( 'max', 4, D, -1, E, -1 ); + t.strictEqual( out, 5.0, 'returns expected value' ); + + out = dlanst( 'one-norm', 4, D, -1, E, -1 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function handles all equal diagonal elements', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 5.0, 5.0, 5.0 ] ); + E = new Float64Array( [ 0.0, 0.0 ] ); + + out = dlanst( 'max', 3, D, 1, E, 1 ); + t.strictEqual( out, 5.0, 'returns expected value' ); + + out = dlanst( 'one-norm', 3, D, 1, E, 1 ); + t.strictEqual( out, 5.0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/test/test.js b/lib/node_modules/@stdlib/lapack/base/dlanst/test/test.js new file mode 100644 index 000000000000..477dc0e334a4 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/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 dlanst = 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 dlanst, '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 dlanst.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 dlanst = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dlanst, 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 dlanst; + var main; + + main = require( './../lib/main.js' ); + + dlanst = proxyquire( './../lib', { + '@stdlib/utils/try-require': tryRequire + }); + + t.strictEqual( dlanst, main, 'returns expected value' ); + t.end(); + + function tryRequire() { + return new Error( 'Cannot find module' ); + } +}); diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/test/test.ndarray.js b/lib/node_modules/@stdlib/lapack/base/dlanst/test/test.ndarray.js new file mode 100644 index 000000000000..3db393aacd34 --- /dev/null +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/test/test.ndarray.js @@ -0,0 +1,331 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var dlanst = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Tests for approximate equality. +* +* @private +* @param {Object} t - test object +* @param {number} actual - actual value +* @param {number} expected - expected value +* @param {number} maxULP - units in the last place +*/ +function isApprox( t, actual, expected, maxULP ) { + t.strictEqual( isAlmostSameValue( actual, expected, maxULP ), true, 'returns expected value. actual: ' + actual + '. expected: ' + expected + '.' ); +} + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof dlanst, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 6', function test( t ) { + t.strictEqual( dlanst.length, 6, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method has an arity of 8', function test( t ) { + t.strictEqual( dlanst.ndarray.length, 8, 'returns expected value' ); + t.end(); +}); + +tape( 'the `ndarray` method computes the max norm', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + out = dlanst.ndarray( 'max', 4, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 5.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method computes the one-norm', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + out = dlanst.ndarray( 'one-norm', 4, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method computes the infinity-norm', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + out = dlanst.ndarray( 'infinity-norm', 4, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method computes the Frobenius norm', function test( t ) { + var expected; + var out; + var D; + var E; + + D = new Float64Array( [ 4.0, -2.0, 5.0, -1.0 ] ); + E = new Float64Array( [ 1.0, -3.0, 2.0 ] ); + + expected = sqrt( 74.0 ); + + out = dlanst.ndarray( 'frobenius-norm', 4, D, 1, 0, E, 1, 0 ); + isApprox( t, out, expected, 2.0 ); + + t.end(); +}); + +tape( 'the `ndarray` method returns 0 when N is 0', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( 0 ); + E = new Float64Array( 0 ); + + out = dlanst.ndarray( 'max', 0, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + out = dlanst.ndarray( 'one-norm', 0, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + out = dlanst.ndarray( 'frobenius-norm', 0, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports providing offsets', function test( t ) { + var out; + var D; + var E; + + // D contains a leading zero element + D = new Float64Array( [ 0.0, 4.0, -2.0, 5.0, -1.0 ] ); + E = new Float64Array( [ 0.0, 1.0, -3.0, 2.0 ] ); + + out = dlanst.ndarray( 'max', 4, D, 1, 1, E, 1, 1 ); + t.strictEqual( out, 5.0, 'returns expected value' ); + + out = dlanst.ndarray( 'one-norm', 4, D, 1, 1, E, 1, 1 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports negative strides', function test( t ) { + var out; + var D; + var E; + + // Reversed arrays with negative strides + D = new Float64Array( [ -1.0, 5.0, -2.0, 4.0 ] ); + E = new Float64Array( [ 2.0, -3.0, 1.0 ] ); + + out = dlanst.ndarray( 'max', 4, D, -1, 3, E, -1, 2 ); + t.strictEqual( out, 5.0, 'returns expected value' ); + + out = dlanst.ndarray( 'one-norm', 4, D, -1, 3, E, -1, 2 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports large strides', function test( t ) { + var out; + var D; + var E; + + // D has stride 2: elements at indices 0, 2, 4, 6 + D = new Float64Array( [ 4.0, 999.0, -2.0, 999.0, 5.0, 999.0, -1.0 ] ); + + // E has stride 2: elements at indices 0, 2, 4 + E = new Float64Array( [ 1.0, 999.0, -3.0, 999.0, 2.0 ] ); + + out = dlanst.ndarray( 'max', 4, D, 2, 0, E, 2, 0 ); + t.strictEqual( out, 5.0, 'returns expected value' ); + + out = dlanst.ndarray( 'one-norm', 4, D, 2, 0, E, 2, 0 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method supports combined offsets and strides', function test( t ) { + var expected; + var out; + var D; + var E; + + // D at offset 1, stride 2: indices 1, 3, 5, 7 + D = new Float64Array( [ 999.0, 4.0, 999.0, -2.0, 999.0, 5.0, 999.0, -1.0 ] ); + + // E at offset 1, stride 2: indices 1, 3, 5 + E = new Float64Array( [ 999.0, 1.0, 999.0, -3.0, 999.0, 2.0 ] ); + + out = dlanst.ndarray( 'max', 4, D, 2, 1, E, 2, 1 ); + t.strictEqual( out, 5.0, 'returns expected value' ); + + out = dlanst.ndarray( 'one-norm', 4, D, 2, 1, E, 2, 1 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + expected = sqrt( 74.0 ); + out = dlanst.ndarray( 'frobenius-norm', 4, D, 2, 1, E, 2, 1 ); + isApprox( t, out, expected, 2.0 ); + + t.end(); +}); + +tape( 'the `ndarray` method computes the max norm (N=1)', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ -7.0 ] ); + E = new Float64Array( 0 ); + + out = dlanst.ndarray( 'max', 1, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 7.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method computes the Frobenius norm (N=1)', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ -7.0 ] ); + E = new Float64Array( 0 ); + + out = dlanst.ndarray( 'frobenius-norm', 1, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 7.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method propagates NaN in max norm', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 1.0, NaN, 3.0 ] ); + E = new Float64Array( [ 2.0, 4.0 ] ); + + out = dlanst.ndarray( 'max', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( out !== out, true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the `ndarray` method propagates NaN in one-norm', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 1.0, NaN, 3.0 ] ); + E = new Float64Array( [ 2.0, 4.0 ] ); + + out = dlanst.ndarray( 'one-norm', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( out !== out, true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the `ndarray` method handles all-zero matrices', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 0.0, 0.0, 0.0 ] ); + E = new Float64Array( [ 0.0, 0.0 ] ); + + out = dlanst.ndarray( 'max', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + out = dlanst.ndarray( 'one-norm', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + out = dlanst.ndarray( 'frobenius-norm', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the `ndarray` method computes the Frobenius norm (larger matrix)', function test( t ) { + var expected; + var out; + var D; + var E; + + D = new Float64Array( [ 2.0, -1.0, 3.0, 4.0, -2.0 ] ); + E = new Float64Array( [ 1.0, -2.0, 1.0, 3.0 ] ); + + expected = 8.0; + + out = dlanst.ndarray( 'frobenius-norm', 5, D, 1, 0, E, 1, 0 ); + isApprox( t, out, expected, 2.0 ); + + t.end(); +}); + +tape( 'the `ndarray` method returns 0.0 if provided an invalid norm', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + E = new Float64Array( [ 1.0, 2.0 ] ); + + out = dlanst.ndarray( 'foo', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + t.end(); +});