All files base.js

100% Statements 171/171
100% Branches 41/41
100% Functions 1/1
100% Lines 171/171

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 1723x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 128x 128x 128x 128x 128x 128x 128x 128x 128x 128x 128x 128x 4x 4x 124x 124x 124x 124x 128x 31x 31x 31x 88x 88x 4x 4x 88x 88x 4x 4x 88x 88x 4x 4x 88x 31x 31x 128x 29x 29x 6x 6x 23x 23x 23x 23x 23x 29x 21x 21x 23x 23x 29x 59x 59x 8x 8x 59x 23x 23x 128x 27x 27x 6x 6x 21x 21x 21x 21x 21x 27x 19x 19x 21x 21x 27x 53x 53x 8x 8x 53x 21x 21x 37x 37x 37x 37x 37x 128x 31x 31x 31x 37x 128x 3x 3x 3x 3x 3x  
/**
* @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, max-params */
 
'use strict';
 
// MODULES //
 
var abs = require( '@stdlib/math/base/special/abs' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var Float64Array = require( '@stdlib/array/float64' );
var dlassq = require( '@stdlib/lapack/base/dlassq' ).ndarray;
 
 
// VARIABLES //
 
var WORKSPACE = new Float64Array( 2 );
 
 
// MAIN //
 
/**
* Returns the value of the one-norm, Frobenius norm, infinity-norm, or the largest absolute value of any element of a real tridiagonal matrix `A`.
*
* ## Notes
*
* -   `norm` must be one of the following: `'M'` or `'m'` (largest absolute value of any element), `'1'`, `'O'`, or `'o'` (one norm), `'I'` or `'i'` (infinity norm), and `'F'`, `'f'`, `'E'`, or `'e'` (Frobenius norm).
* -   `DL` should have `N-1` indexed elements.
* -   `D` should have `N` indexed elements.
* -   `DU` should have `N-1` indexed elements.
*
* @private
* @param {string} norm - specifies the norm to be computed
* @param {NonNegativeInteger} N - order of the matrix `A`
* @param {Float64Array} DL - the first sub-diagonal of `A`
* @param {integer} strideDL - stride length for `DL`
* @param {NonNegativeInteger} offsetDL - starting index for `DL`
* @param {Float64Array} D - the diagonal of `A`
* @param {integer} strideD - stride length for `D`
* @param {NonNegativeInteger} offsetD - starting index for `D`
* @param {Float64Array} DU - the first super-diagonal of `A`
* @param {integer} strideDU - stride length for `DU`
* @param {NonNegativeInteger} offsetDU - starting index for `DU`
* @returns {number} matrix norm
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var DL = new Float64Array( [ 1.0, 2.0, 3.0 ] );
* var D = new Float64Array( [ 4.0, 5.0, 6.0, 7.0 ] );
* var DU = new Float64Array( [ 1.0, 1.0, 1.0 ] );
*
* var norm = dlangt( 'M', 4, DL, 1, 0, D, 1, 0, DU, 1, 0 );
* // returns 7.0
*/
function dlangt( norm, N, DL, strideDL, offsetDL, D, strideD, offsetD, DU, strideDU, offsetDU ) {
	var anorm;
	var scale;
	var sumsq;
	var temp;
	var out;
	var odl;
	var odu;
	var od;
	var i;
 
	if ( N <= 0 ) {
		return 0.0;
	}
	odl = offsetDL;
	od = offsetD;
	odu = offsetDU;
 
	if ( norm === 'M' || norm === 'm' ) {
		// Find max(abs(A(i,j)))
		anorm = abs( D[ od + ( ( N - 1 ) * strideD ) ] );
		for ( i = 0; i < N - 1; i++ ) {
			temp = abs( DL[ odl + ( i * strideDL ) ] );
			if ( anorm < temp || isnan( temp ) ) {
				anorm = temp;
			}
			temp = abs( D[ od + ( i * strideD ) ] );
			if ( anorm < temp || isnan( temp ) ) {
				anorm = temp;
			}
			temp = abs( DU[ odu + ( i * strideDU ) ] );
			if ( anorm < temp || isnan( temp ) ) {
				anorm = temp;
			}
		}
		return anorm;
	}
	if ( norm === 'O' || norm === 'o' || norm === '1' ) {
		// Find norm1(A) = max column sum
		if ( N === 1 ) {
			return abs( D[ od ] );
		}
		// First column: D[0] + DL[0]
		anorm = abs( D[ od ] ) + abs( DL[ odl ] );
 
		// Last column: D[N-1] + DU[N-2]
		temp = abs( D[ od + ( ( N - 1 ) * strideD ) ] ) + abs( DU[ odu + ( ( N - 2 ) * strideDU ) ] );
		if ( anorm < temp || isnan( temp ) ) {
			anorm = temp;
		}
 
		// Middle columns: D[i] + DL[i] + DU[i-1]
		for ( i = 1; i < N - 1; i++ ) {
			temp = abs( D[ od + ( i * strideD ) ] ) + abs( DL[ odl + ( i * strideDL ) ] ) + abs( DU[ odu + ( ( i - 1 ) * strideDU ) ] );
			if ( anorm < temp || isnan( temp ) ) {
				anorm = temp;
			}
		}
		return anorm;
	}
	if ( norm === 'I' || norm === 'i' ) {
		// Find normI(A) = max row sum
		if ( N === 1 ) {
			return abs( D[ od ] );
		}
		// First row: D[0] + DU[0]
		anorm = abs( D[ od ] ) + abs( DU[ odu ] );
 
		// Last row: D[N-1] + DL[N-2]
		temp = abs( D[ od + ( ( N - 1 ) * strideD ) ] ) + abs( DL[ odl + ( ( N - 2 ) * strideDL ) ] );
		if ( anorm < temp || isnan( temp ) ) {
			anorm = temp;
		}
 
		// Middle rows: D[i] + DU[i] + DL[i-1]
		for ( i = 1; i < N - 1; i++ ) {
			temp = abs( D[ od + ( i * strideD ) ] ) + abs( DU[ odu + ( i * strideDU ) ] ) + abs( DL[ odl + ( ( i - 1 ) * strideDL ) ] );
			if ( anorm < temp || isnan( temp ) ) {
				anorm = temp;
			}
		}
		return anorm;
	}
	// Find normF(A) = Frobenius norm
	out = WORKSPACE;
	scale = 0.0;
	sumsq = 1.0;
	dlassq( N, D, strideD, offsetD, scale, sumsq, out, 1, 0 );
	if ( N > 1 ) {
		dlassq( N - 1, DL, strideDL, offsetDL, out[ 0 ], out[ 1 ], out, 1, 0 );
		dlassq( N - 1, DU, strideDU, offsetDU, out[ 0 ], out[ 1 ], out, 1, 0 );
	}
	return out[ 0 ] * sqrt( out[ 1 ] );
}
 
 
// EXPORTS //
 
module.exports = dlangt;