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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | 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 223x 223x 223x 223x 223x 223x 93x 93x 223x 236x 236x 236x 32x 18x 16x 18x 2x 2x 2x 32x 4x 4x 32x 236x 216x 216x 20x 236x 7x 7x 13x 13x 13x 216x 216x 223x 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 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 63x 2x 2x 61x 61x 61x 61x 61x 63x 19x 19x 18x 18x 19x 19x 19x 19x 41x 41x 41x 41x 41x 19x 19x 2x 2x 19x 19x 63x 37x 37x 37x 37x 37x 93x 79x 93x 14x 14x 14x 14x 93x 93x 93x 93x 37x 37x 37x 37x 37x 37x 37x 130x 63x 130x 30x 67x 37x 37x 130x 130x 4x 4x 126x 126x 126x 126x 126x 63x 24x 24x 24x 24x 24x 24x 24x 93x 46x 93x 23x 30x 24x 24x 93x 93x 3x 3x 90x 90x 90x 90x 90x 21x 21x 21x 21x 24x 64x 38x 64x 26x 26x 26x 26x 64x 64x 64x 64x 24x 54x 63x 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.
*/
'use strict';
/* eslint-disable max-len, max-params */
// 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 overflow;
var absak;
var pert;
if ( perturb ) {
pert = copysign( tol, ak );
}
while ( true ) {
absak = abs( ak );
overflow = false;
if ( absak < 1.0 ) {
if ( absak < sfmin ) {
if ( absak === 0.0 || abs( temp )*sfmin > absak ) {
overflow = true;
} else {
temp *= bignum;
ak *= bignum;
}
} else if ( abs( temp ) > absak*bignum ) {
overflow = true;
}
}
if ( !overflow ) {
break;
}
// The division would overflow. If perturbing is disabled, signal failure; otherwise, perturb the diagonal element and retry...
if ( !perturb ) {
return false;
}
ak += pert;
pert *= 2.0;
}
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 ia;
var ib;
var ic;
var id;
var ii;
var iy;
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 ] ) );
}
ia = offsetA + ( 2*strideA );
ib = offsetB + strideB;
id = offsetD;
for ( k = 0; k < N-2; k++ ) {
tol = max( max( max( tol, abs( A[ ia ] ) ), abs( B[ ib ] ) ), abs( D[ id ] ) );
ia += strideA;
ib += strideB;
id += 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`...
iy = offsetY + strideY;
ii = offsetIN;
ic = offsetC;
for ( k = 0; k < N-1; k++ ) {
if ( IN[ ii ] === 0 ) {
Y[ iy ] -= C[ ic ]*Y[ iy-strideY ];
} else {
temp = Y[ iy-strideY ];
Y[ iy-strideY ] = Y[ iy ];
Y[ iy ] = temp - ( C[ ic ]*Y[ iy ] );
}
iy += strideY;
ii += strideIN;
ic += strideC;
}
// Solve the upper triangular system `U*x = y`...
perturb = ( job === -1 );
iy = offsetY + ( (N-1)*strideY );
ia = offsetA + ( (N-1)*strideA );
ib = offsetB + ( (N-1)*strideB );
id = offsetD + ( (N-1)*strideD );
for ( k = N-1; k >= 0; k-- ) {
if ( k <= N-3 ) {
temp = Y[ iy ] - ( B[ ib ]*Y[ iy+strideY ] ) - ( D[ id ]*Y[ iy+(2*strideY) ] );
} else if ( k === N-2 ) {
temp = Y[ iy ] - ( B[ ib ]*Y[ iy+strideY ] );
} else {
temp = Y[ iy ];
}
ak = A[ ia ];
if ( !divide( temp, ak, perturb, tol, sfmin, bignum, Y, iy ) ) {
return k + 1;
}
iy -= strideY;
ia -= strideA;
ib -= strideB;
id -= strideD;
}
} else {
// Solve the transposed upper triangular system `U^T*x = y`...
perturb = ( job === -2 );
iy = offsetY;
ia = offsetA;
ib = offsetB - strideB;
id = offsetD - ( 2*strideD );
for ( k = 0; k < N; k++ ) {
if ( k >= 2 ) {
temp = Y[ iy ] - ( B[ ib ]*Y[ iy-strideY ] ) - ( D[ id ]*Y[ iy-(2*strideY) ] );
} else if ( k === 1 ) {
temp = Y[ iy ] - ( B[ ib ]*Y[ iy-strideY ] );
} else {
temp = Y[ iy ];
}
ak = A[ ia ];
if ( !divide( temp, ak, perturb, tol, sfmin, bignum, Y, iy ) ) {
return k + 1;
}
iy += strideY;
ia += strideA;
ib += strideB;
id += strideD;
}
// Apply the transposed unit lower bidiagonal matrix `L^T` and the permutation `P`...
iy = offsetY + ( (N-1)*strideY );
ii = offsetIN + ( (N-2)*strideIN );
ic = offsetC + ( (N-2)*strideC );
for ( k = 0; k < N-1; k++ ) {
if ( IN[ ii ] === 0 ) {
Y[ iy-strideY ] -= C[ ic ]*Y[ iy ];
} else {
temp = Y[ iy-strideY ];
Y[ iy-strideY ] = Y[ iy ];
Y[ iy ] = temp - ( C[ ic ]*Y[ iy ] );
}
iy -= strideY;
ii -= strideIN;
ic -= strideC;
}
}
return 0;
}
// EXPORTS //
module.exports = dlagts;
|