From 9e65b9e1d2b09343c96f35b63e3e0f2483b5b0ed Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Fri, 19 Jun 2026 01:21:32 +0530 Subject: [PATCH 1/3] feat: add lapack/base/dlanst --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/lapack/base/dlanst/README.md | 268 +++++++++++++ .../lapack/base/dlanst/benchmark/benchmark.js | 107 ++++++ .../dlanst/benchmark/benchmark.ndarray.js | 107 ++++++ .../@stdlib/lapack/base/dlanst/docs/repl.txt | 93 +++++ .../lapack/base/dlanst/docs/types/index.d.ts | 108 ++++++ .../lapack/base/dlanst/docs/types/test.ts | 278 ++++++++++++++ .../lapack/base/dlanst/examples/index.js | 43 +++ .../@stdlib/lapack/base/dlanst/lib/base.js | 137 +++++++ .../@stdlib/lapack/base/dlanst/lib/dlanst.js | 95 +++++ .../@stdlib/lapack/base/dlanst/lib/index.js | 80 ++++ .../@stdlib/lapack/base/dlanst/lib/is_norm.js | 56 +++ .../@stdlib/lapack/base/dlanst/lib/main.js | 35 ++ .../@stdlib/lapack/base/dlanst/lib/ndarray.js | 84 ++++ .../@stdlib/lapack/base/dlanst/package.json | 71 ++++ .../lapack/base/dlanst/test/test.dlanst.js | 359 ++++++++++++++++++ .../@stdlib/lapack/base/dlanst/test/test.js | 82 ++++ .../lapack/base/dlanst/test/test.ndarray.js | 331 ++++++++++++++++ 17 files changed, 2334 insertions(+) create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/README.md create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/examples/index.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/lib/base.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/lib/dlanst.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/lib/index.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/lib/is_norm.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/lib/main.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/package.json create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/test/test.dlanst.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/test/test.js create mode 100644 lib/node_modules/@stdlib/lapack/base/dlanst/test/test.ndarray.js 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(); +}); From bf3cf7394029f18955e8420e405f9ebd88562af9 Mon Sep 17 00:00:00 2001 From: iampratik13 Date: Fri, 24 Jul 2026 22:58:20 +0530 Subject: [PATCH 2/3] chore: suggested changes --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/lapack/base/dlanst/lib/base.js | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/base.js index c187d0313453..78b6065a44e5 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlanst/lib/base.js +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/base.js @@ -27,6 +27,11 @@ var sqrt = require( '@stdlib/math/base/special/sqrt' ); var Float64Array = require( '@stdlib/array/float64' ); +// VARIABLES // + +var work = new Float64Array( 2 ); + + // MAIN // /** @@ -55,7 +60,6 @@ var Float64Array = require( '@stdlib/array/float64' ); function dlanst( norm, N, D, strideD, offsetD, E, strideE, offsetE ) { var anorm; var scale; - var out; var sum; var id; var ie; @@ -99,7 +103,7 @@ function dlanst( norm, N, D, strideD, offsetD, E, strideE, offsetE ) { id = offsetD + strideD; ie = offsetE; for ( i = 1; i < N - 1; i++ ) { - sum = abs( D[ id ] ) + abs( E[ ie ] ) + abs( E[ ie + strideE ] ); + sum = abs( D[ id ] ) + abs( E[ ie + strideE ] ) + abs( E[ ie ] ); if ( anorm < sum || isnan( sum ) ) { anorm = sum; } @@ -112,20 +116,19 @@ function dlanst( norm, N, D, strideD, offsetD, E, strideE, offsetE ) { // 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 ]; + work[ 0 ] = scale; + work[ 1 ] = sum; + dlassq( N - 1, E, strideE, offsetE, scale, sum, work, 1, 0 ); + scale = work[ 0 ]; + sum = work[ 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 ]; + work[ 0 ] = scale; + work[ 1 ] = sum; + dlassq( N, D, strideD, offsetD, scale, sum, work, 1, 0 ); + scale = work[ 0 ]; + sum = work[ 1 ]; return scale * sqrt( sum ); } return 0.0; From eb9c54826b0ed7e4a72f673d67ffe8960d64c26b Mon Sep 17 00:00:00 2001 From: Karan Anand Date: Sat, 1 Aug 2026 12:25:14 -0700 Subject: [PATCH 3/3] chore: code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/lapack/base/dlanst/README.md | 7 +- .../lapack/base/dlanst/benchmark/benchmark.js | 27 +- .../dlanst/benchmark/benchmark.ndarray.js | 27 +- .../@stdlib/lapack/base/dlanst/docs/repl.txt | 8 +- .../lapack/base/dlanst/docs/types/index.d.ts | 10 + .../@stdlib/lapack/base/dlanst/lib/base.js | 37 +-- .../@stdlib/lapack/base/dlanst/lib/dlanst.js | 5 + .../@stdlib/lapack/base/dlanst/lib/ndarray.js | 11 + .../lapack/base/dlanst/test/test.dlanst.js | 234 ++++++++++++-- .../@stdlib/lapack/base/dlanst/test/test.js | 2 +- .../lapack/base/dlanst/test/test.ndarray.js | 289 +++++++++++++----- 11 files changed, 520 insertions(+), 137 deletions(-) diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/README.md b/lib/node_modules/@stdlib/lapack/base/dlanst/README.md index e1deccf20667..3c96b94d0525 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlanst/README.md +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/README.md @@ -60,11 +60,11 @@ The function has the following parameters: - **N**: order of the tridiagonal matrix `A`. -- **D**: input [`Float64Array`][@stdlib/array/float64] containing the diagonal elements of `A`. +- **D**: input [`Float64Array`][@stdlib/array/float64] containing the `N` diagonal elements of `A`. - **strideD**: stride length for `D`. -- **E**: input [`Float64Array`][@stdlib/array/float64] containing the sub-diagonal elements of `A`. +- **E**: input [`Float64Array`][@stdlib/array/float64] containing the `N-1` sub-diagonal elements of `A`. - **strideE**: stride length for `E`. @@ -131,6 +131,9 @@ var out = dlanst.ndarray( 'one-norm', 4, D, 1, 1, E, 1, 1 ); ## Notes +- `D` should have `N` indexed elements. +- `E` should have `N-1` indexed elements. +- Both functions throw an error if provided an unrecognized `norm`. - `dlanst()` corresponds to the [LAPACK][lapack] function [`dlanst`][lapack-dlanst]. diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/benchmark/benchmark.js b/lib/node_modules/@stdlib/lapack/base/dlanst/benchmark/benchmark.js index 5ba7b4bdbe5d..51a5ee062f29 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlanst/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/benchmark/benchmark.js @@ -31,6 +31,12 @@ var dlanst = require( './../lib/dlanst.js' ); // VARIABLES // +var NORMS = [ + 'max', + 'one-norm', + 'infinity-norm', + 'frobenius-norm' +]; var options = { 'dtype': 'float64' }; @@ -42,10 +48,11 @@ var options = { * Creates a benchmark function. * * @private +* @param {string} norm - specifies the norm to be returned * @param {PositiveInteger} len - array length * @returns {Function} benchmark function */ -function createBenchmark( len ) { +function createBenchmark( norm, len ) { var D = uniform( len, -100.0, 100.0, options ); var E = uniform( len - 1, -100.0, 100.0, options ); return benchmark; @@ -57,15 +64,12 @@ function createBenchmark( len ) { * @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 ); + out = dlanst( norm, len, D, 1, E, 1 ); if ( isnan( out ) ) { b.fail( 'should not return NaN' ); } @@ -88,19 +92,24 @@ function createBenchmark( len ) { * @private */ function main() { + var norm; var len; var min; var max; var f; var i; + var j; 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 ); + for ( j = 0; j < NORMS.length; j++ ) { + norm = NORMS[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( norm, len ); + bench( format( '%s:norm=%s,len=%d', pkg, norm, len ), f ); + } } } 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 index 13ffb71905ac..292243f3ead6 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlanst/benchmark/benchmark.ndarray.js +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/benchmark/benchmark.ndarray.js @@ -31,6 +31,12 @@ var dlanst = require( './../lib/ndarray.js' ); // VARIABLES // +var NORMS = [ + 'max', + 'one-norm', + 'infinity-norm', + 'frobenius-norm' +]; var options = { 'dtype': 'float64' }; @@ -42,10 +48,11 @@ var options = { * Creates a benchmark function. * * @private +* @param {string} norm - specifies the norm to be returned * @param {PositiveInteger} len - array length * @returns {Function} benchmark function */ -function createBenchmark( len ) { +function createBenchmark( norm, len ) { var D = uniform( len, -100.0, 100.0, options ); var E = uniform( len - 1, -100.0, 100.0, options ); return benchmark; @@ -57,15 +64,12 @@ function createBenchmark( len ) { * @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 ); + out = dlanst( norm, len, D, 1, 0, E, 1, 0 ); if ( isnan( out ) ) { b.fail( 'should not return NaN' ); } @@ -88,19 +92,24 @@ function createBenchmark( len ) { * @private */ function main() { + var norm; var len; var min; var max; var f; var i; + var j; 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 ); + for ( j = 0; j < NORMS.length; j++ ) { + norm = NORMS[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( norm, len ); + bench( format( '%s::ndarray:norm=%s,len=%d', pkg, norm, len ), f ); + } } } diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/docs/repl.txt b/lib/node_modules/@stdlib/lapack/base/dlanst/docs/repl.txt index 84265b12bdc2..34b324c240c4 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlanst/docs/repl.txt +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/docs/repl.txt @@ -17,13 +17,13 @@ Order of the matrix. D: Float64Array - Array containing the diagonal elements. + Array containing the `N` diagonal elements. strideD: integer Stride length for `D`. E: Float64Array - Array containing the sub-diagonal elements. + Array containing the `N-1` sub-diagonal elements. strideE: integer Stride length for `E`. @@ -60,7 +60,7 @@ Order of the matrix. D: Float64Array - Array containing the diagonal elements. + Array containing the `N` diagonal elements. sd: integer Stride length for `D`. @@ -69,7 +69,7 @@ Starting index for `D`. E: Float64Array - Array containing the sub-diagonal elements. + Array containing the `N-1` sub-diagonal elements. se: integer Stride length for `E`. 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 index f23100d4c38b..48414b36d48b 100644 --- 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 @@ -27,6 +27,11 @@ 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. * + * ## Notes + * + * - `D` should have `N` indexed elements. + * - `E` should have `N-1` indexed elements. + * * @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 @@ -49,6 +54,11 @@ 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 using alternative indexing semantics. * + * ## Notes + * + * - `D` should have `N` indexed elements. + * - `E` should have `N-1` indexed elements. + * * @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 diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/lib/base.js b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/base.js index 78b6065a44e5..f8e185c492fc 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlanst/lib/base.js +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/base.js @@ -37,13 +37,18 @@ var work = new Float64Array( 2 ); /** * 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. * +* ## Notes +* +* - `D` should have `N` indexed elements. +* - `E` should have `N-1` indexed elements. +* * @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 {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 (length N-1) +* @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 @@ -112,26 +117,22 @@ function dlanst( norm, N, D, strideD, offsetD, E, strideE, offsetE ) { } return anorm; } - if ( norm === 'frobenius-norm' ) { - // Find normF(A)... - scale = 0.0; - sum = 1.0; - if ( N > 1 ) { - work[ 0 ] = scale; - work[ 1 ] = sum; - dlassq( N - 1, E, strideE, offsetE, scale, sum, work, 1, 0 ); - scale = work[ 0 ]; - sum = work[ 1 ]; - sum = 2.0 * sum; - } + // Find normF(A)... + scale = 0.0; + sum = 1.0; + if ( N > 1 ) { + // Seed the workspace with the current scale and sum, as `dlassq` returns the workspace unmodified whenever either value is NaN... work[ 0 ] = scale; work[ 1 ] = sum; - dlassq( N, D, strideD, offsetD, scale, sum, work, 1, 0 ); + dlassq( N - 1, E, strideE, offsetE, scale, sum, work, 1, 0 ); scale = work[ 0 ]; - sum = work[ 1 ]; - return scale * sqrt( sum ); + sum = 2.0 * work[ 1 ]; } - return 0.0; + // Seed the workspace (see above)... + work[ 0 ] = scale; + work[ 1 ] = sum; + dlassq( N, D, strideD, offsetD, scale, sum, work, 1, 0 ); + return work[ 0 ] * sqrt( work[ 1 ] ); } diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/lib/dlanst.js b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/dlanst.js index 417709c2fac0..0d0625dbdec2 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlanst/lib/dlanst.js +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/dlanst.js @@ -31,6 +31,11 @@ var base = require( './base.js' ); /** * 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. * +* ## Notes +* +* - `D` should have `N` indexed elements. +* - `E` should have `N-1` indexed elements. +* * @param {string} norm - specifies the norm to be returned * @param {NonNegativeInteger} N - order of the matrix * @param {Float64Array} D - array containing the diagonal elements diff --git a/lib/node_modules/@stdlib/lapack/base/dlanst/lib/ndarray.js b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/ndarray.js index 87d98ff97e2a..635dd76dbdee 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlanst/lib/ndarray.js +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/lib/ndarray.js @@ -20,6 +20,8 @@ // MODULES // +var format = require( '@stdlib/string/format' ); +var isMatrixNorm = require( './is_norm.js' ); var base = require( './base.js' ); @@ -28,6 +30,11 @@ var base = require( './base.js' ); /** * 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. * +* ## Notes +* +* - `D` should have `N` indexed elements. +* - `E` should have `N-1` indexed elements. +* * @param {string} norm - specifies the norm to be returned * @param {NonNegativeInteger} N - order of the matrix * @param {Float64Array} D - array containing the diagonal elements @@ -36,6 +43,7 @@ var base = require( './base.js' ); * @param {Float64Array} E - array containing the sub-diagonal elements * @param {integer} strideE - stride length for `E` * @param {NonNegativeInteger} offsetE - starting index for `E` +* @throws {TypeError} first argument must be a valid norm * @returns {number} norm value * * @example @@ -75,6 +83,9 @@ var base = require( './base.js' ); * // returns ~8.6023 */ function dlanst( norm, N, D, strideD, offsetD, E, strideE, offsetE ) { + if ( !isMatrixNorm( norm ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a valid norm. Value: `%s`.', norm ) ); + } return base( norm, N, D, strideD, offsetD, E, strideE, offsetE ); } 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 index bc3a5c775b8a..16e2444bdf42 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlanst/test/test.dlanst.js +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/test/test.dlanst.js @@ -22,27 +22,12 @@ var tape = require( 'tape' ); var Float64Array = require( '@stdlib/array/float64' ); -var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); 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 ) { @@ -66,6 +51,9 @@ tape( 'the function throws an error if provided an invalid first argument', func 'foo', 'bar', 'invalid', + '1', + 'M', + 'F', 123, true, null, @@ -122,6 +110,15 @@ tape( 'the function returns 0 when N is negative', function test( t ) { out = dlanst( 'max', -1, D, 1, E, 1 ); t.strictEqual( out, 0.0, 'returns expected value' ); + out = dlanst( 'one-norm', -1, D, 1, E, 1 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + out = dlanst( 'infinity-norm', -1, D, 1, E, 1 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + out = dlanst( 'frobenius-norm', -1, D, 1, E, 1 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + t.end(); }); @@ -153,6 +150,20 @@ tape( 'the function computes the max norm', function test( t ) { t.end(); }); +tape( 'the function computes the max norm (max is the last diagonal element)', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 1.0, 2.0, 3.0, -9.0 ] ); + E = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + + out = dlanst( 'max', 4, D, 1, E, 1 ); + t.strictEqual( out, 9.0, 'returns expected value' ); + + t.end(); +}); + tape( 'the function computes the max norm (max in sub-diagonal)', function test( t ) { var out; var D; @@ -176,13 +187,13 @@ tape( 'the function computes the max norm with NaN propagation', function test( E = new Float64Array( [ 2.0, 4.0 ] ); out = dlanst( 'max', 3, D, 1, E, 1 ); - t.strictEqual( out !== out, true, 'returns NaN' ); + t.strictEqual( isnan( out ), true, 'returns expected value' ); 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.strictEqual( isnan( out ), true, 'returns expected value' ); t.end(); }); @@ -215,6 +226,34 @@ tape( 'the function computes the one-norm', function test( t ) { t.end(); }); +tape( 'the function computes the one-norm (max is the first row)', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 10.0, 1.0, 1.0 ] ); + E = new Float64Array( [ 5.0, 1.0 ] ); + + out = dlanst( 'one-norm', 3, D, 1, E, 1 ); + t.strictEqual( out, 15.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the one-norm (max is the last row)', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 1.0, 2.0, 3.0, 40.0 ] ); + E = new Float64Array( [ 1.0, 1.0, 5.0 ] ); + + out = dlanst( 'one-norm', 4, D, 1, E, 1 ); + t.strictEqual( out, 45.0, 'returns expected value' ); + + t.end(); +}); + tape( 'the function computes the one-norm (2x2 matrix)', function test( t ) { var out; var D; @@ -238,7 +277,7 @@ tape( 'the function computes the one-norm with NaN propagation', function test( E = new Float64Array( [ 2.0, 4.0 ] ); out = dlanst( 'one-norm', 3, D, 1, E, 1 ); - t.strictEqual( out !== out, true, 'returns NaN' ); + t.strictEqual( isnan( out ), true, 'returns expected value' ); t.end(); }); @@ -258,6 +297,83 @@ tape( 'the function computes the infinity-norm (equal to one-norm for symmetric t.end(); }); +tape( 'the function computes the infinity-norm (N=1)', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ -7.0 ] ); + E = new Float64Array( 0 ); + + out = dlanst( 'infinity-norm', 1, D, 1, E, 1 ); + t.strictEqual( out, 7.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the infinity-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( 'infinity-norm', 3, D, 1, E, 1 ); + t.strictEqual( isnan( out ), true, 'returns expected value' ); + + D = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + E = new Float64Array( [ NaN, 4.0 ] ); + + out = dlanst( 'infinity-norm', 3, D, 1, E, 1 ); + t.strictEqual( isnan( out ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Frobenius 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( 'frobenius-norm', 3, D, 1, E, 1 ); + t.strictEqual( isnan( out ), true, 'returns expected value' ); + + D = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + E = new Float64Array( [ NaN, 4.0 ] ); + + out = dlanst( 'frobenius-norm', 3, D, 1, E, 1 ); + t.strictEqual( isnan( out ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports infinite values', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 1.0, PINF, 3.0 ] ); + E = new Float64Array( [ 2.0, 4.0 ] ); + + out = dlanst( 'max', 3, D, 1, E, 1 ); + t.strictEqual( out, PINF, 'returns expected value' ); + + out = dlanst( 'one-norm', 3, D, 1, E, 1 ); + t.strictEqual( out, PINF, 'returns expected value' ); + + out = dlanst( 'infinity-norm', 3, D, 1, E, 1 ); + t.strictEqual( out, PINF, 'returns expected value' ); + + out = dlanst( 'frobenius-norm', 3, D, 1, E, 1 ); + t.strictEqual( out, PINF, 'returns expected value' ); + + t.end(); +}); + tape( 'the function computes the Frobenius norm (N=1)', function test( t ) { var out; var D; @@ -284,7 +400,7 @@ tape( 'the function computes the Frobenius norm', function test( t ) { expected = sqrt( 74.0 ); out = dlanst( 'frobenius-norm', 4, D, 1, E, 1 ); - isApprox( t, out, expected, 2.0 ); + t.strictEqual( out, expected, 'returns expected value' ); t.end(); }); @@ -301,7 +417,7 @@ tape( 'the function computes the Frobenius norm (2x2 matrix)', function test( t expected = sqrt( 63.0 ); out = dlanst( 'frobenius-norm', 2, D, 1, E, 1 ); - isApprox( t, out, expected, 2.0 ); + t.strictEqual( out, expected, 'returns expected value' ); t.end(); }); @@ -318,12 +434,49 @@ tape( 'the function computes the Frobenius norm (identity-like tridiagonal)', fu expected = sqrt( 3.0 ); out = dlanst( 'frobenius-norm', 3, D, 1, E, 1 ); - isApprox( t, out, expected, 2.0 ); + t.strictEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Frobenius norm without intermediate overflow', function test( t ) { + var expected; + var out; + var D; + var E; + + D = new Float64Array( [ 1.0e300, -1.0e300, 1.0e300 ] ); + E = new Float64Array( [ 1.0e300, -1.0e300 ] ); + + // sqrt( 3*(1e300)^2 + 2*2*(1e300)^2 ) = sqrt(7)*1e300: + expected = sqrt( 7.0 ) * 1.0e300; + + out = dlanst( 'frobenius-norm', 3, D, 1, E, 1 ); + t.strictEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Frobenius norm without intermediate underflow', function test( t ) { + var expected; + var out; + var D; + var E; + + D = new Float64Array( [ 1.0e-300, -1.0e-300, 1.0e-300 ] ); + E = new Float64Array( [ 1.0e-300, -1.0e-300 ] ); + + // sqrt( 3*(1e-300)^2 + 2*2*(1e-300)^2 ) = sqrt(7)*1e-300: + expected = sqrt( 7.0 ) * 1.0e-300; + + out = dlanst( 'frobenius-norm', 3, D, 1, E, 1 ); + t.strictEqual( out, expected, 'returns expected value' ); t.end(); }); tape( 'the function supports negative strides', function test( t ) { + var expected; var out; var D; var E; @@ -338,6 +491,41 @@ tape( 'the function supports negative strides', function test( t ) { out = dlanst( 'one-norm', 4, D, -1, E, -1 ); t.strictEqual( out, 10.0, 'returns expected value' ); + out = dlanst( 'infinity-norm', 4, D, -1, E, -1 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + expected = sqrt( 74.0 ); + out = dlanst( 'frobenius-norm', 4, D, -1, E, -1 ); + t.strictEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports non-unit strides', function test( t ) { + var expected; + 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( 'max', 4, D, 2, E, 2 ); + t.strictEqual( out, 5.0, 'returns expected value' ); + + out = dlanst( 'one-norm', 4, D, 2, E, 2 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + out = dlanst( 'infinity-norm', 4, D, 2, E, 2 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + expected = sqrt( 74.0 ); + out = dlanst( 'frobenius-norm', 4, D, 2, E, 2 ); + t.strictEqual( out, expected, '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 index 477dc0e334a4..12e2dc7596d2 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlanst/test/test.js +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/test/test.js @@ -67,7 +67,7 @@ tape( 'if a native implementation is not available, the main export is a JavaScr var dlanst; var main; - main = require( './../lib/main.js' ); + main = require( './../lib/dlanst.js' ); dlanst = proxyquire( './../lib', { '@stdlib/utils/try-require': tryRequire 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 index 3db393aacd34..92d8278b6290 100644 --- a/lib/node_modules/@stdlib/lapack/base/dlanst/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/lapack/base/dlanst/test/test.ndarray.js @@ -24,25 +24,10 @@ var tape = require( 'tape' ); var Float64Array = require( '@stdlib/array/float64' ); -var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); 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 + '.' ); -} +var PINF = require( '@stdlib/constants/float64/pinf' ); +var dlanst = require( './../lib/ndarray.js' ); // TESTS // @@ -53,17 +38,47 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function has an arity of 6', function test( t ) { - t.strictEqual( dlanst.length, 6, 'returns expected value' ); +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( dlanst.length, 8, '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' ); +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', + '1', + 'M', + 'F', + 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, 0, E, 1, 0 ); + }; + } }); -tape( 'the `ndarray` method computes the max norm', function test( t ) { +tape( 'the function computes the max norm', function test( t ) { var out; var D; var E; @@ -71,13 +86,13 @@ tape( 'the `ndarray` method computes the max norm', function test( t ) { 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 ); + out = dlanst( '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 ) { +tape( 'the function computes the one-norm', function test( t ) { var out; var D; var E; @@ -85,13 +100,13 @@ tape( 'the `ndarray` method computes the one-norm', function test( t ) { 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 ); + out = dlanst( '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 ) { +tape( 'the function computes the infinity-norm', function test( t ) { var out; var D; var E; @@ -99,13 +114,13 @@ tape( 'the `ndarray` method computes the infinity-norm', function test( t ) { 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 ); + out = dlanst( '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 ) { +tape( 'the function computes the Frobenius norm', function test( t ) { var expected; var out; var D; @@ -116,13 +131,13 @@ tape( 'the `ndarray` method computes the Frobenius norm', function test( t ) { expected = sqrt( 74.0 ); - out = dlanst.ndarray( 'frobenius-norm', 4, D, 1, 0, E, 1, 0 ); - isApprox( t, out, expected, 2.0 ); + out = dlanst( 'frobenius-norm', 4, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, expected, 'returns expected value' ); t.end(); }); -tape( 'the `ndarray` method returns 0 when N is 0', function test( t ) { +tape( 'the function returns 0 when N is 0', function test( t ) { var out; var D; var E; @@ -130,19 +145,46 @@ tape( 'the `ndarray` method returns 0 when N is 0', function test( t ) { D = new Float64Array( 0 ); E = new Float64Array( 0 ); - out = dlanst.ndarray( 'max', 0, D, 1, 0, E, 1, 0 ); + out = dlanst( '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 ); + out = dlanst( '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 ); + out = dlanst( 'infinity-norm', 0, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + out = dlanst( '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 ) { +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, 0, E, 1, 0 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + out = dlanst( 'one-norm', -1, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + out = dlanst( 'infinity-norm', -1, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + out = dlanst( 'frobenius-norm', -1, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing offsets', function test( t ) { + var expected; var out; var D; var E; @@ -151,16 +193,24 @@ tape( 'the `ndarray` method supports providing offsets', function test( t ) { 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 ); + out = dlanst( '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 ); + out = dlanst( 'one-norm', 4, D, 1, 1, E, 1, 1 ); t.strictEqual( out, 10.0, 'returns expected value' ); + out = dlanst( 'infinity-norm', 4, D, 1, 1, E, 1, 1 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + expected = sqrt( 74.0 ); + out = dlanst( 'frobenius-norm', 4, D, 1, 1, E, 1, 1 ); + t.strictEqual( out, expected, 'returns expected value' ); + t.end(); }); -tape( 'the `ndarray` method supports negative strides', function test( t ) { +tape( 'the function supports negative strides', function test( t ) { + var expected; var out; var D; var E; @@ -169,16 +219,24 @@ tape( 'the `ndarray` method supports negative strides', function test( t ) { 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 ); + out = dlanst( '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 ); + out = dlanst( 'one-norm', 4, D, -1, 3, E, -1, 2 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + out = dlanst( 'infinity-norm', 4, D, -1, 3, E, -1, 2 ); t.strictEqual( out, 10.0, 'returns expected value' ); + expected = sqrt( 74.0 ); + out = dlanst( 'frobenius-norm', 4, D, -1, 3, E, -1, 2 ); + t.strictEqual( out, expected, 'returns expected value' ); + t.end(); }); -tape( 'the `ndarray` method supports large strides', function test( t ) { +tape( 'the function supports large strides', function test( t ) { + var expected; var out; var D; var E; @@ -189,16 +247,23 @@ tape( 'the `ndarray` method supports large strides', function test( t ) { // 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 ); + out = dlanst( '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 ); + out = dlanst( 'one-norm', 4, D, 2, 0, E, 2, 0 ); t.strictEqual( out, 10.0, 'returns expected value' ); + out = dlanst( 'infinity-norm', 4, D, 2, 0, E, 2, 0 ); + t.strictEqual( out, 10.0, 'returns expected value' ); + + expected = sqrt( 74.0 ); + out = dlanst( 'frobenius-norm', 4, D, 2, 0, E, 2, 0 ); + t.strictEqual( out, expected, 'returns expected value' ); + t.end(); }); -tape( 'the `ndarray` method supports combined offsets and strides', function test( t ) { +tape( 'the function supports combined offsets and strides', function test( t ) { var expected; var out; var D; @@ -210,20 +275,20 @@ tape( 'the `ndarray` method supports combined offsets and strides', function tes // 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 ); + out = dlanst( '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 ); + out = dlanst( '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 ); + out = dlanst( 'frobenius-norm', 4, D, 2, 1, E, 2, 1 ); + t.strictEqual( out, expected, 'returns expected value' ); t.end(); }); -tape( 'the `ndarray` method computes the max norm (N=1)', function test( t ) { +tape( 'the function computes the max norm (N=1)', function test( t ) { var out; var D; var E; @@ -231,13 +296,13 @@ tape( 'the `ndarray` method computes the max norm (N=1)', function test( t ) { D = new Float64Array( [ -7.0 ] ); E = new Float64Array( 0 ); - out = dlanst.ndarray( 'max', 1, D, 1, 0, E, 1, 0 ); + out = dlanst( '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 ) { +tape( 'the function computes the Frobenius norm (N=1)', function test( t ) { var out; var D; var E; @@ -245,13 +310,41 @@ tape( 'the `ndarray` method computes the Frobenius norm (N=1)', function test( t D = new Float64Array( [ -7.0 ] ); E = new Float64Array( 0 ); - out = dlanst.ndarray( 'frobenius-norm', 1, D, 1, 0, E, 1, 0 ); + out = dlanst( '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 ) { +tape( 'the function 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( 'max', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( isnan( out ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function 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( 'one-norm', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( isnan( out ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function propagates NaN in infinity-norm', function test( t ) { var out; var D; var E; @@ -259,13 +352,13 @@ tape( 'the `ndarray` method propagates NaN in max norm', function test( t ) { 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' ); + out = dlanst( 'infinity-norm', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( isnan( out ), true, 'returns expected value' ); t.end(); }); -tape( 'the `ndarray` method propagates NaN in one-norm', function test( t ) { +tape( 'the function propagates NaN in the Frobenius norm', function test( t ) { var out; var D; var E; @@ -273,13 +366,42 @@ tape( 'the `ndarray` method propagates NaN in one-norm', function test( t ) { 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' ); + out = dlanst( 'frobenius-norm', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( isnan( out ), true, 'returns expected value' ); + + D = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + E = new Float64Array( [ NaN, 4.0 ] ); + + out = dlanst( 'frobenius-norm', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( isnan( out ), true, 'returns expected value' ); t.end(); }); -tape( 'the `ndarray` method handles all-zero matrices', function test( t ) { +tape( 'the function supports infinite values', function test( t ) { + var out; + var D; + var E; + + D = new Float64Array( [ 1.0, PINF, 3.0 ] ); + E = new Float64Array( [ 2.0, 4.0 ] ); + + out = dlanst( 'max', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, PINF, 'returns expected value' ); + + out = dlanst( 'one-norm', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, PINF, 'returns expected value' ); + + out = dlanst( 'infinity-norm', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, PINF, 'returns expected value' ); + + out = dlanst( 'frobenius-norm', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, PINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function handles all-zero matrices', function test( t ) { var out; var D; var E; @@ -287,19 +409,22 @@ tape( 'the `ndarray` method handles all-zero matrices', function test( t ) { 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 ); + out = dlanst( '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 ); + out = dlanst( '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 ); + out = dlanst( 'infinity-norm', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, 0.0, 'returns expected value' ); + + out = dlanst( '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 ) { +tape( 'the function computes the Frobenius norm (larger matrix)', function test( t ) { var expected; var out; var D; @@ -310,22 +435,44 @@ tape( 'the `ndarray` method computes the Frobenius norm (larger matrix)', functi expected = 8.0; - out = dlanst.ndarray( 'frobenius-norm', 5, D, 1, 0, E, 1, 0 ); - isApprox( t, out, expected, 2.0 ); + out = dlanst( 'frobenius-norm', 5, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, expected, 'returns expected value' ); t.end(); }); -tape( 'the `ndarray` method returns 0.0 if provided an invalid norm', function test( t ) { +tape( 'the function computes the Frobenius norm without intermediate overflow', function test( t ) { + var expected; var out; var D; var E; - D = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - E = new Float64Array( [ 1.0, 2.0 ] ); + D = new Float64Array( [ 1.0e300, -1.0e300, 1.0e300 ] ); + E = new Float64Array( [ 1.0e300, -1.0e300 ] ); - out = dlanst.ndarray( 'foo', 3, D, 1, 0, E, 1, 0 ); - t.strictEqual( out, 0.0, 'returns expected value' ); + // sqrt( 3*(1e300)^2 + 2*2*(1e300)^2 ) = sqrt(7)*1e300: + expected = sqrt( 7.0 ) * 1.0e300; + + out = dlanst( 'frobenius-norm', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function computes the Frobenius norm without intermediate underflow', function test( t ) { + var expected; + var out; + var D; + var E; + + D = new Float64Array( [ 1.0e-300, -1.0e-300, 1.0e-300 ] ); + E = new Float64Array( [ 1.0e-300, -1.0e-300 ] ); + + // sqrt( 3*(1e-300)^2 + 2*2*(1e-300)^2 ) = sqrt(7)*1e-300: + expected = sqrt( 7.0 ) * 1.0e-300; + + out = dlanst( 'frobenius-norm', 3, D, 1, 0, E, 1, 0 ); + t.strictEqual( out, expected, 'returns expected value' ); t.end(); });