All files base.js

100% Statements 216/216
100% Branches 47/47
100% Functions 2/2
100% Lines 216/216

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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 2173x 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 179x 179x 179x 179x 179x 61x 61x 179x 184x 184x 13x 7x 6x 4x 4x 4x 4x 2x 2x 1x 1x 13x 2x 1x 1x 1x 1x 1x 1x 13x 176x 176x 176x 176x 179x 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 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 2x 2x 44x 44x 44x 44x 44x 46x 13x 13x 13x 13x 13x 31x 31x 13x 13x 1x 1x 13x 13x 46x 25x 25x 73x 73x 73x 73x 60x 73x 13x 13x 13x 13x 73x 25x 25x 25x 98x 98x 51x 98x 22x 32x 25x 25x 98x 98x 2x 2x 98x 46x 19x 19x 19x 81x 81x 43x 73x 19x 19x 19x 19x 81x 81x 1x 1x 81x 18x 19x 60x 60x 60x 60x 36x 60x 24x 24x 24x 24x 60x 19x 41x 46x 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 max = require( '@stdlib/math/base/special/max' );
var copysign = require( '@stdlib/math/base/special/copysign' );
var dlamch = require( '@stdlib/lapack/base/dlamch' );
 
 
// FUNCTIONS //
 
/**
* Divides `temp` by a diagonal element `ak`, scaling to avoid overflow and, optionally, perturbing very small diagonal elements, and writes the result to `Y`.
*
* @private
* @param {number} temp - dividend
* @param {number} ak - diagonal element
* @param {boolean} perturb - boolean indicating whether to perturb very small diagonal elements to avoid overflow
* @param {number} tol - tolerance controlling the magnitude of the perturbation
* @param {number} sfmin - safe minimum (i.e., smallest number for which `1/sfmin` does not overflow)
* @param {number} bignum - reciprocal of the safe minimum
* @param {Float64Array} Y - output array
* @param {integer} iy - index at which to write the result in `Y`
* @returns {boolean} boolean indicating whether the division could be performed without overflow
*/
function divide( temp, ak, perturb, tol, sfmin, bignum, Y, iy ) {
	var absak;
	var pert;
 
	if ( perturb ) {
		pert = copysign( tol, ak );
	}
	for ( ; ; ) {
		absak = abs( ak );
		if ( absak < 1.0 ) {
			if ( absak < sfmin ) {
				if ( absak === 0.0 || abs( temp )*sfmin > absak ) {
					if ( perturb ) {
						ak += pert;
						pert *= 2.0;
						continue;
					}
					return false;
				}
				temp *= bignum;
				ak *= bignum;
			} else if ( abs( temp ) > absak*bignum ) {
				if ( perturb ) {
					ak += pert;
					pert *= 2.0;
					continue;
				}
				return false;
			}
		}
		break;
	}
	Y[ iy ] = temp / ak;
	return true;
}
 
 
// MAIN //
 
/**
* Solves a system of equations with a tridiagonal matrix `T` following a precomputed factorization of `T - lambda*I`.
*
* @private
* @param {integer} job - specifies the job to be performed
* @param {NonNegativeInteger} N - order of the matrix `T`
* @param {Float64Array} A - diagonal elements of `U`
* @param {integer} strideA - stride length for `A`
* @param {NonNegativeInteger} offsetA - starting index for `A`
* @param {Float64Array} B - first super-diagonal elements of `U`
* @param {integer} strideB - stride length for `B`
* @param {NonNegativeInteger} offsetB - starting index for `B`
* @param {Float64Array} C - sub-diagonal elements of `L`
* @param {integer} strideC - stride length for `C`
* @param {NonNegativeInteger} offsetC - starting index for `C`
* @param {Float64Array} D - second super-diagonal elements of `U`
* @param {integer} strideD - stride length for `D`
* @param {NonNegativeInteger} offsetD - starting index for `D`
* @param {Int32Array} IN - details of the matrix `P`
* @param {integer} strideIN - stride length for `IN`
* @param {NonNegativeInteger} offsetIN - starting index for `IN`
* @param {Float64Array} Y - right-hand side vector which is overwritten by the solution vector
* @param {integer} strideY - stride length for `Y`
* @param {NonNegativeInteger} offsetY - starting index for `Y`
* @param {Float64Array} TOL - tolerance used to perturb very small diagonal elements when `job` is negative
* @param {NonNegativeInteger} offsetTOL - index for `TOL`
* @returns {integer} status code
*/
function dlagts( job, N, A, strideA, offsetA, B, strideB, offsetB, C, strideC, offsetC, D, strideD, offsetD, IN, strideIN, offsetIN, Y, strideY, offsetY, TOL, offsetTOL ) {
	var perturb;
	var bignum;
	var sfmin;
	var temp;
	var tol;
	var eps;
	var ak;
	var iy;
	var ii;
	var ic;
	var k;
 
	if ( N === 0 ) {
		return 0;
	}
	eps = dlamch( 'E' );
	sfmin = dlamch( 'S' );
	bignum = 1.0 / sfmin;
 
	tol = TOL[ offsetTOL ];
	if ( job < 0 && tol <= 0.0 ) {
		tol = abs( A[ offsetA ] );
		if ( N > 1 ) {
			tol = max( max( tol, abs( A[ offsetA+strideA ] ) ), abs( B[ offsetB ] ) );
		}
		for ( k = 3; k <= N; k++ ) {
			tol = max( max( max( tol, abs( A[ offsetA+((k-1)*strideA) ] ) ), abs( B[ offsetB+((k-2)*strideB) ] ) ), abs( D[ offsetD+((k-3)*strideD) ] ) );
		}
		tol *= eps;
		if ( tol === 0.0 ) {
			tol = eps;
		}
		TOL[ offsetTOL ] = tol;
	}
	if ( abs( job ) === 1 ) {
		// Apply the permutation `P` and the unit lower bidiagonal matrix `L`...
		for ( k = 2; k <= N; k++ ) {
			iy = offsetY + ( (k-1)*strideY );
			ii = offsetIN + ( (k-2)*strideIN );
			ic = offsetC + ( (k-2)*strideC );
			if ( IN[ ii ] === 0 ) {
				Y[ iy ] = Y[ iy ] - ( C[ ic ]*Y[ iy-strideY ] );
			} else {
				temp = Y[ iy-strideY ];
				Y[ iy-strideY ] = Y[ iy ];
				Y[ iy ] = temp - ( C[ ic ]*Y[ iy ] );
			}
		}
		// Solve the upper triangular system `U*x = y`...
		perturb = ( job === -1 );
		for ( k = N; k >= 1; k-- ) {
			iy = offsetY + ( (k-1)*strideY );
			if ( k <= N-2 ) {
				temp = Y[ iy ] - ( B[ offsetB+((k-1)*strideB) ]*Y[ iy+strideY ] ) - ( D[ offsetD+((k-1)*strideD) ]*Y[ iy+(2*strideY) ] );
			} else if ( k === N-1 ) {
				temp = Y[ iy ] - ( B[ offsetB+((k-1)*strideB) ]*Y[ iy+strideY ] );
			} else {
				temp = Y[ iy ];
			}
			ak = A[ offsetA+((k-1)*strideA) ];
			if ( !divide( temp, ak, perturb, tol, sfmin, bignum, Y, iy ) ) {
				return k;
			}
		}
	} else {
		// Solve the transposed upper triangular system `U^T*x = y`...
		perturb = ( job === -2 );
		for ( k = 1; k <= N; k++ ) {
			iy = offsetY + ( (k-1)*strideY );
			if ( k >= 3 ) {
				temp = Y[ iy ] - ( B[ offsetB+((k-2)*strideB) ]*Y[ iy-strideY ] ) - ( D[ offsetD+((k-3)*strideD) ]*Y[ iy-(2*strideY) ] );
			} else if ( k === 2 ) {
				temp = Y[ iy ] - ( B[ offsetB+((k-2)*strideB) ]*Y[ iy-strideY ] );
			} else {
				temp = Y[ iy ];
			}
			ak = A[ offsetA+((k-1)*strideA) ];
			if ( !divide( temp, ak, perturb, tol, sfmin, bignum, Y, iy ) ) {
				return k;
			}
		}
		// Apply the transposed unit lower bidiagonal matrix `L^T` and the permutation `P`...
		for ( k = N; k >= 2; k-- ) {
			iy = offsetY + ( (k-1)*strideY );
			ii = offsetIN + ( (k-2)*strideIN );
			ic = offsetC + ( (k-2)*strideC );
			if ( IN[ ii ] === 0 ) {
				Y[ iy-strideY ] = Y[ iy-strideY ] - ( C[ ic ]*Y[ iy ] );
			} else {
				temp = Y[ iy-strideY ];
				Y[ iy-strideY ] = Y[ iy ];
				Y[ iy ] = temp - ( C[ ic ]*Y[ iy ] );
			}
		}
	}
	return 0;
}
 
 
// EXPORTS //
 
module.exports = dlagts;