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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | 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 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 160x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 155x 155x 155x 160x 85x 85x 50x 50x 50x 50x 50x 50x 15x 15x 15x 5x 15x 10x 10x 15x 5x 5x 15x 10x 10x 5x 5x 10x 5x 5x 10x 10x 10x 50x 35x 35x 35x 35x 35x 20x 20x 20x 5x 5x 5x 5x 5x 5x 15x 15x 35x 15x 15x 15x 5x 5x 5x 5x 5x 5x 10x 15x 5x 5x 5x 5x 5x 5x 5x 5x 5x 20x 20x 20x 20x 20x 20x 5x 5x 15x 20x 5x 5x 5x 5x 5x 5x 10x 10x 20x 5x 5x 5x 5x 15x 15x 15x 35x 5x 5x 35x 85x 30x 30x 30x 30x 30x 30x 30x 30x 30x 30x 5x 5x 5x 5x 5x 5x 25x 25x 25x 30x 20x 20x 20x 20x 20x 20x 5x 5x 15x 20x 5x 5x 5x 5x 5x 5x 10x 10x 20x 5x 5x 5x 5x 15x 15x 20x 30x 5x 5x 35x 5x 5x 5x 5x 5x 5x 5x 5x 5x 160x 35x 35x 30x 30x 30x 30x 30x 5x 5x 5x 5x 5x 5x 25x 25x 25x 25x 30x 15x 15x 30x 30x 5x 5x 5x 5x 5x 5x 25x 25x 25x 30x 5x 5x 20x 20x 15x 20x 20x 20x 20x 20x 30x 5x 30x 15x 15x 15x 35x 5x 5x 5x 5x 5x 5x 5x 35x 30x 30x 30x 30x 25x 25x 25x 5x 5x 5x 5x 5x 5x 20x 20x 25x 15x 15x 20x 5x 5x 5x 5x 5x 5x 15x 15x 20x 5x 5x 10x 10x 15x 15x 15x 15x 15x 25x 10x 25x 5x 5x 30x 5x 5x 5x 5x 35x 5x 5x 5x 5x 105x 105x 105x 105x 105x 105x 105x 105x 105x 105x 160x 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';
// MODULES //
var max = require( '@stdlib/math/base/special/max' );
var min = require( '@stdlib/math/base/special/min' );
var sqrt = require( '@stdlib/math/base/special/sqrt' );
// MAIN //
/**
* Computes an approximation to the smallest eigenvalue using values of d from the previous transform.
*
* ## Notes
*
* - `Z` is a 1-D array of length >= `4*N0` storing interleaved q/e values.
* - `PP` is `0` for ping, `1` for pong.
* - `TAU` is approximation to the smallest eigenvalue and is used as a shift to accelerate convergence of the dqds iteration.
* - `TTYPE` is an integer flag describing how TAU was computed.
* - `G` is a state variable that is preserved across successive calls and is used to regulate the magnitude of fallback shifts.
*
* @private
* @param {integer} I0 - first index
* @param {integer} N0 - last index
* @param {Float64Array} Z - qd array
* @param {integer} strideZ - stride length for `Z`
* @param {NonNegativeInteger} offsetZ - starting index for `Z`
* @param {integer} PP - ping-pong flag (0 or 1)
* @param {integer} N0IN - value of `N0` at the start of `EIGTEST`
* @param {number} DMIN - minimum value of `d`
* @param {number} DMIN1 - minimum value of `d`, excluding `D(N0)`
* @param {number} DMIN2 - minimum value of `d`, excluding `D(N0)` and `D(N0-1)`
* @param {number} DN - `d(N)`
* @param {number} DN1 - `d(N-1)`
* @param {number} DN2 - `d(N-2)`
* @param {number} G - saved state carried across calls
* @param {Float64Array} out - output array containing `tau`, `ttype`, and `G`
* @param {integer} strideOut - stride length for `out`
* @param {NonNegativeInteger} offsetOut - starting index for `out`
* @returns {Float64Array} output array
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var out = new Float64Array( 3 );
* var Z = new Float64Array( [ 5, 0, 7, 0, 9, 0, 3, 0, 10, 0, 4.5, 0, 18, 0, 0, 0 ] );
*
* dlasq4( 0, 3, Z, 1, 0, 0, 3, 0.2, 0.15, 0.1, 0.8, 0.7, 0.6, -6, out, 1, 0 );
* // out => <Float64Array>[ ~0.05, -6, 0.25 ]
*/
function dlasq4( I0, N0, Z, strideZ, offsetZ, PP, N0IN, DMIN, DMIN1, DMIN2, DN, DN1, DN2, G, out, strideOut, offsetOut ) { // eslint-disable-line max-len, max-params
var CNST1;
var CNST2;
var CNST3;
var ttype;
var idx2;
var gap1;
var gap2;
var gam;
var idx;
var tau;
var a2;
var b1;
var b2;
var i4;
var nn;
var np;
var s;
CNST1 = 0.563;
CNST2 = 1.010;
CNST3 = 1.050;
// A negative DMIN forces the shift to take that absolute value TTYPE records the type of shift.
if ( DMIN <= 0 ) {
tau = -DMIN;
ttype = -1;
idx2 = offsetOut;
out[ idx2 ] = tau;
idx2 += strideOut;
out[ idx2 ] = ttype;
idx2 += strideOut;
out[ idx2 ] = G;
return out;
}
nn = offsetZ + ( strideZ*( ( 4*N0 ) + PP + 3 ) );
if ( N0IN === N0 ) {
// No eigenvalues deflated.
if ( DMIN === DN || DMIN === DN1 ) {
b1 = sqrt( Z[ nn - ( 3*strideZ ) ] )*sqrt( Z[ nn - ( 5*strideZ ) ] );
b2 = sqrt( Z[ nn - ( 7*strideZ ) ] )*sqrt( Z[ nn - ( 9*strideZ ) ] );
a2 = Z[ nn - ( 7*strideZ ) ] + Z[ nn - ( 5*strideZ ) ];
// Cases 2 and 3.
if ( DMIN === DN && DMIN1 === DN1 ) {
gap2 = DMIN2 - a2 - ( DMIN2*0.25 );
if ( gap2 > 0 && gap2 > b2 ) {
gap1 = a2 - DN - ( ( b2 / gap2 )*b2 );
} else {
gap1 = a2 - DN - ( b1 + b2 );
}
if ( gap1 > 0 && gap1 > b1 ) {
s = max( DN - ( ( b1 / gap1 )*b1 ), 0.5*DMIN );
ttype = -2;
} else {
s = 0;
if ( DN > b1 ) {
s = DN - b1;
}
if ( a2 > ( b1 + b2 ) ) {
s = min( s, a2 - ( b1 + b2 ) );
}
s = max( s, 0.333*DMIN );
ttype = -3;
}
} else {
// Case 4.
ttype = -4;
s = 0.25*DMIN;
if ( DMIN === DN ) {
gam = DN;
a2 = 0;
if ( Z[ nn - ( 5*strideZ ) ] > Z[ nn - ( 7*strideZ ) ] ) {
idx2 = offsetOut + strideOut;
out[ idx2 ] = ttype;
idx2 += strideOut;
out[ idx2 ] = G;
return out;
}
b2 = Z[ nn - ( 5*strideZ ) ] / Z[ nn - ( 7*strideZ ) ];
np = nn - ( 9*strideZ );
} else {
np = nn - ( 2*PP*strideZ );
gam = DN1;
if ( Z[ np - ( 4*strideZ ) ] > Z[ np - ( 2*strideZ ) ] ) {
idx2 = offsetOut + strideOut;
out[ idx2 ] = ttype;
idx2 += strideOut;
out[ idx2 ] = G;
return out;
}
a2 = Z[ np - ( 4*strideZ ) ] / Z[ np - ( 2*strideZ ) ];
if ( Z[ nn - ( 9*strideZ ) ] > Z[ nn - ( 11*strideZ ) ] ) {
idx2 = offsetOut + strideOut;
out[ idx2 ] = ttype;
idx2 += strideOut;
out[ idx2 ] = G;
return out;
}
b2 = Z[ nn - ( 9*strideZ ) ] / Z[ nn - ( 11*strideZ ) ];
np = nn - ( 13*strideZ );
}
// Approximate contribution to norm squared from I < NN-1.
a2 += b2;
i4 = np;
for ( idx = ( np - offsetZ ) / strideZ; idx >= ( 4*I0 ) + PP + 2; idx -= 4 ) {
if ( b2 === 0 ) {
break;
}
b1 = b2;
if ( Z[ i4 ] > Z[ i4 - ( 2*strideZ ) ] ) {
idx2 = offsetOut + strideOut;
out[ idx2 ] = ttype;
idx2 += strideOut;
out[ idx2 ] = G;
return out;
}
b2 *= Z[ i4 ] / Z[ i4 - ( 2*strideZ ) ];
a2 += b2;
if ( ( 100*max( b2, b1 ) ) < a2 || CNST1 < a2 ) {
break;
}
i4 -= 4*strideZ;
}
a2 *= CNST3;
// Rayleigh quotient residual bound.
if ( a2 < CNST1 ) {
s = gam*( 1 - sqrt( a2 ) ) / ( 1 + a2 );
}
}
} else if ( DMIN === DN2 ) {
// Case 5.
ttype = -5;
s = 0.25*DMIN;
// Compute contribution to norm squared from I > NN-2.
np = nn - ( 2*PP*strideZ );
b1 = Z[ np - ( 2*strideZ ) ];
b2 = Z[ np - ( 6*strideZ ) ];
gam = DN2;
if ( Z[ np - ( 8*strideZ ) ] > b2 || Z[ np - ( 4*strideZ ) ] > b1 ) {
idx2 = offsetOut + strideOut;
out[ idx2 ] = ttype;
idx2 += strideOut;
out[ idx2 ] = G;
return out;
}
a2 = ( Z[ np - ( 8*strideZ ) ] / b2 )*( 1 + ( Z[ np - ( 4*strideZ ) ] / b1 ) );
// Approximate contribution to norm squared from I < NN-2.
if ( ( N0 - I0 ) > 2 ) {
b2 = Z[ nn - ( 13*strideZ ) ] / Z[ nn - ( 15*strideZ ) ];
a2 += b2;
i4 = nn - ( strideZ*17 );
for ( idx = ( ( nn - offsetZ ) / strideZ ) - 17; idx >= ( 4*I0 ) + PP + 2; idx -= 4 ) {
if ( b2 === 0 ) {
break;
}
b1 = b2;
if ( Z[ i4 ] > Z[ i4 - ( 2*strideZ ) ] ) {
idx2 = offsetOut + strideOut;
out[ idx2 ] = ttype;
idx2 += strideOut;
out[ idx2 ] = G;
return out;
}
b2 *= ( Z[ i4 ] / Z[ i4 - ( 2*strideZ ) ] );
a2 += b2;
if ( ( 100*max( b2, b1 ) ) < a2 || CNST1 < a2 ) {
break;
}
i4 -= 4*strideZ;
}
a2 *= CNST3;
}
if ( a2 < CNST1 ) {
s = gam * ( 1 - sqrt( a2 ) ) / ( 1 + a2 );
}
} else {
// Case 6, no information to guide us.
if ( ttype === -6 ) { // Case when `ttype` is previously set by another routine.
G += 0.333*( 1 - G );
} else if ( ttype === -18 ) { // Case when `ttype` is previously set by another routine.
G += 0.25*0.333;
} else {
G = 0.25;
}
s = G*DMIN;
ttype = -6;
}
} else if ( N0IN === ( N0 + 1 ) ) {
// 1 eigenvalue just deflated. Use DMIN1, DN1 for DMIN and DN.
if ( DMIN1 === DN1 && DMIN2 === DN2 ) {
// Cases 7 and 8.
ttype = -7;
s = 0.3330*DMIN1;
if ( Z[ nn - ( 5*strideZ ) ] > Z[ nn - ( 7*strideZ ) ] ) {
idx2 = offsetOut + strideOut;
out[ idx2 ] = ttype;
idx2 += strideOut;
out[ idx2 ] = G;
return out;
}
b1 = Z[ nn - ( 5*strideZ ) ] / Z[ nn - ( 7*strideZ ) ];
b2 = b1;
if ( b2 !== 0 ) {
i4 = offsetZ + ( strideZ*( ( 4*N0 ) - 6 + PP ) );
for ( idx = 2; idx >= 0; idx-- ) {
a2 = b1;
if ( Z[ i4 ] > Z[ i4 - ( 2*strideZ ) ] ) {
idx2 = offsetOut + strideOut;
out[ idx2 ] = ttype;
idx2 += strideOut;
out[ idx2 ] = G;
return out;
}
b1 *= Z[ i4 ] / Z[ i4 - ( 2*strideZ ) ];
b2 += b1;
if ( ( 100*max( b1, a2 ) ) < b2 ) {
break;
}
i4 -= 4*strideZ;
}
}
b2 = sqrt( CNST3*b2 );
a2 = DMIN1 / ( 1 + ( b2*b2 ) );
gap2 = ( 0.5*DMIN2 ) - a2;
if ( gap2 > 0 && gap2 > ( b2*a2 ) ) {
s = max( s, a2*( 1 - ( CNST2*a2*( b2 / gap2 )*b2 ) ) );
} else {
s = max( s, a2*( 1 - ( CNST2*b2 ) ) );
ttype = -8;
}
} else {
// Case 9.
s = 0.25*DMIN1;
if ( DMIN1 === DN1 ) {
s = 0.5*DMIN1;
}
ttype = -9;
}
} else if ( N0IN === ( N0 + 2 ) ) {
// 2 eigenvalues deflated. Use DMIN2, DN2 for DMIN and DN.
// Cases 10 and 11.
if ( DMIN2 === DN2 && ( 2*Z[ nn - ( 5*strideZ ) ] ) < Z[ nn - ( 7*strideZ ) ] ) {
ttype = -10;
s = 0.3330*DMIN2;
if ( Z[ nn - ( 5*strideZ ) ] > Z[ nn - ( 7*strideZ ) ] ) {
idx2 = offsetOut + strideOut;
out[ idx2 ] = ttype;
idx2 += strideOut;
out[ idx2 ] = G;
return out;
}
b1 = Z[ nn - ( 5*strideZ ) ] / Z[ nn - ( 7*strideZ ) ];
b2 = b1;
if ( b2 !== 0 ) {
i4 = offsetZ + ( strideZ*( ( 4*N0 ) - 6 + PP ) );
for ( idx = 1; idx >= 0; idx-- ) {
if ( Z[ i4 ] > Z[ i4 - ( 2*strideZ ) ] ) {
idx2 = offsetOut + strideOut;
out[ idx2 ] = ttype;
idx2 += strideOut;
out[ idx2 ] = G;
return out;
}
b1 *= ( Z[ i4 ] / Z[ i4 - ( 2*strideZ ) ] );
b2 += b1;
if ( ( 100*b1 ) < b2 ) {
break;
}
i4 -= 4*strideZ;
}
}
b2 = sqrt( CNST3*b2 );
a2 = DMIN2 / ( 1 + ( b2*b2 ) );
gap2 = Z[ nn - ( 7*strideZ ) ] + Z[ nn - ( 9*strideZ ) ] - ( sqrt( Z[ nn - ( 11*strideZ ) ] )*sqrt( Z[ nn - ( 9*strideZ ) ] ) ) - a2;
if ( gap2 > 0 && gap2 > ( b2*a2 ) ) {
s = max( s, a2*( 1 - ( CNST2*a2*( b2 / gap2 )*b2 ) ) );
} else {
s = max( s, a2*( 1 - ( CNST2*b2 ) ) );
}
} else {
// Case 11.
s = 0.25*DMIN2;
ttype = -11;
}
} else if ( N0IN > ( N0 + 2 ) ) {
// Case 12, more than 2 eigenvalues deflated. No information.
s = 0;
ttype = -12;
}
tau = s;
idx2 = offsetOut;
out[ idx2 ] = tau;
idx2 += strideOut;
out[ idx2 ] = ttype;
idx2 += strideOut;
out[ idx2 ] = G;
return out;
}
// EXPORTS //
module.exports = dlasq4;
|