All files / lapack/base/dlascl/lib base.js

96.98% Statements 514/530
89.28% Branches 50/56
100% Functions 8/8
96.98% Lines 514/530

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 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 5313x 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 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 30x 72x 72x 72x 30x 30x 12x 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 12x 12x 12x 12x 12x 12x 12x 6x 18x 36x 36x 18x 18x 6x 6x 18x 36x 36x 18x 18x 6x 12x 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 12x 12x 12x 12x 12x 12x 12x 7x 21x 42x 42x 21x 21x 12x 5x 15x 30x 30x 15x 15x 5x 12x 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 12x 12x 12x 12x 12x 12x 6x 6x 24x 78x 78x 24x 24x 6x 6x 6x 24x 78x 78x 24x 24x 6x 12x 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 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 6x 30x 90x 90x 30x 30x 6x 6x 30x 72x 72x 30x 30x 6x 12x 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 12x 12x 12x 12x 12x 12x 12x 12x 6x 18x 72x 72x 18x 18x 6x 6x 30x 72x 72x 30x 30x 6x 12x 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 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 60x 192x 192x 60x 60x 12x 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 84x 84x 84x 84x 84x 84x 84x 84x 84x 84x     84x 84x 84x 84x 84x 84x 84x 84x 84x 84x         84x 84x 84x         84x       84x       84x 84x 84x 84x 84x 84x 84x 12x 12x 12x 84x 12x 12x 12x 84x 12x 12x 12x 84x 12x 12x 12x 84x 12x 12x 12x 84x 12x 12x 12x 12x 12x 12x 12x 84x 84x 84x 84x 3x 3x 3x 3x 3x  
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
var abs = require( '@stdlib/math/base/special/abs' );
var dlamch = require( '@stdlib/lapack/base/dlamch' );
var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' );
var max = require( '@stdlib/math/base/special/fast/max' );
var min = require( '@stdlib/math/base/special/fast/min' );
 
 
// VARIABLES //
 
var smlnum = dlamch( 'safe minimum' );
var bignum = 1.0 / smlnum;
 
 
// FUNCTIONS //
 
/**
* Multiplies a real M by N general matrix `A` by a real scalar `mul`.
*
* @private
* @param {NonNegativeInteger} M - number of rows in matrix `A`
* @param {NonNegativeInteger} N - number of columns in matrix `A`
* @param {Float64Array} A - input matrix
* @param {integer} strideA1 - stride of the first dimension of `A`
* @param {integer} strideA2 - stride of the second dimension of `A`
* @param {NonNegativeInteger} offsetA - starting index for `A`
* @param {number} mul - scalar multiplier
* @returns {void}
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] );
*
* scaleGeneral( 3, 2, A, 2, 1, 0, 2.0 );
* // A => <Float64Array>[ 2.0, 8.0, 4.0, 10.0, 6.0, 12.0 ]
*/
function scaleGeneral( M, N, A, strideA1, strideA2, offsetA, mul ) {
	var da1;
	var da0;
	var S1;
	var S0;
	var ia;
	var i0;
	var i1;
	var o;
 
	// Resolve the loop interchange order:
	o = loopOrder( [ M, N ], [ strideA1, strideA2 ] );
	S0 = o.sh[ 0 ];
	S1 = o.sh[ 1 ];
	da0 = o.sx[ 0 ];
	da1 = o.sx[ 1 ] - ( S0 * o.sx[ 0 ] );
 
	// Set the pointers to the first indexed elements in the respective matrices...
	ia = offsetA;
 
	// Iterate over the matrix dimensions...
	for ( i1 = 0; i1 < S1; i1++ ) {
		for ( i0 = 0; i0 < S0; i0++ ) {
			A[ ia ] *= mul;
			ia += da0;
		}
		ia += da1;
	}
}
 
/**
* Multiplies a real M by N upper triangular matrix `A` by a real scalar `mul`.
*
* @private
* @param {NonNegativeInteger} M - number of rows in matrix `A`
* @param {NonNegativeInteger} N - number of columns in matrix `A`
* @param {Float64Array} A - input matrix
* @param {integer} strideA1 - stride of the first dimension of `A`
* @param {integer} strideA2 - stride of the second dimension of `A`
* @param {NonNegativeInteger} offsetA - starting index for `A`
* @param {boolean} isrm - boolean indicating if the matrix is row-major
* @param {number} mul - scalar multiplier
* @returns {void}
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.0, 2.0, 4.0, 0.0, 3.0, 5.0, 0.0, 0.0, 6.0 ] );
*
* scaleUpper( 3, 3, A, 3, 1, 0, true, 2.0 );
* // A => <Float64Array>[ 2.0, 4.0, 8.0, 0.0, 6.0, 10.0, 0.0, 0.0, 12.0 ]
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.0, 0.0, 0.0, 2.0, 3.0, 0.0, 4.0, 5.0, 6.0 ] );
*
* scaleUpper( 3, 3, A, 1, 3, 0, false, 2.0 );
* // A => <Float64Array>[ 2.0, 0.0, 0.0, 4.0, 6.0, 0.0, 8.0, 10.0, 12.0 ]
*/
function scaleUpper( M, N, A, strideA1, strideA2, offsetA, isrm, mul ) {
	var ia;
	var i0;
	var i1;
 
	ia = offsetA;
	if ( isrm ) {
		for ( i1 = 0; i1 < M; i1++ ) {
			for ( i0 = i1; i0 < N; i0++ ) {
				A[ ia + ( i0 * strideA2 ) ] *= mul;
			}
			ia += strideA1;
		}
	} else {
		for ( i1 = 0; i1 < N; i1++ ) {
			for ( i0 = 0; i0 <= min( i1, M - 1 ); i0++ ) {
				A[ ia + ( i0 * strideA1 ) ] *= mul;
			}
			ia += strideA2;
		}
	}
}
 
/**
* Multiplies a real M by N lower triangular matrix `A` by a real scalar `mul`.
*
* @private
* @param {NonNegativeInteger} M - number of rows in matrix `A`
* @param {NonNegativeInteger} N - number of columns in matrix `A`
* @param {Float64Array} A - input matrix
* @param {integer} strideA1 - stride of the first dimension of `A`
* @param {integer} strideA2 - stride of the second dimension of `A`
* @param {NonNegativeInteger} offsetA - starting index for `A`
* @param {boolean} isrm - boolean indicating if the matrix is row-major
* @param {number} mul - scalar multiplier
* @returns {void}
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.0, 0.0, 0.0, 2.0, 4.0, 0.0, 3.0, 5.0, 6.0 ] );
*
* scaleLower( 3, 3, A, 3, 1, 0, true, 2.0 );
* // A => <Float64Array>[ 2.0, 0.0, 0.0, 4.0, 8.0, 0.0, 6.0, 10.0, 12.0 ]
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.0, 2.0, 3.0, 0.0, 4.0, 5.0, 0.0, 0.0, 6.0 ] );
*
* scaleLower( 3, 3, A, 1, 3, 0, false, 2.0 );
* // A => <Float64Array>[ 2.0, 4.0, 6.0, 0.0, 8.0, 10.0, 0.0, 0.0, 12.0 ]
*/
function scaleLower( M, N, A, strideA1, strideA2, offsetA, isrm, mul ) {
	var ia;
	var i0;
	var i1;
 
	ia = offsetA;
	if ( isrm ) {
		for ( i1 = 0; i1 < M; i1++ ) {
			for ( i0 = 0; i0 <= min( i1, N - 1 ); i0++ ) {
				A[ ia + ( i0 * strideA2 ) ] *= mul;
			}
			ia += strideA1;
		}
	} else {
		for ( i1 = 0; i1 < N; i1++ ) {
			for ( i0 = i1; i0 < M; i0++ ) {
				A[ ia + ( i0 * strideA1 ) ] *= mul;
			}
			ia += strideA2;
		}
	}
}
 
/**
* Multiplies a real M by N upper Hessenberg matrix `A` by a real scalar `mul`.
*
* @private
* @param {NonNegativeInteger} M - number of rows in matrix `A`
* @param {NonNegativeInteger} N - number of columns in matrix `A`
* @param {Float64Array} A - input matrix
* @param {integer} strideA1 - stride of the first dimension of `A`
* @param {integer} strideA2 - stride of the second dimension of `A`
* @param {NonNegativeInteger} offsetA - starting index for `A`
* @param {boolean} isrm - boolean indicating if the matrix is row-major
* @param {number} mul - scalar multiplier
* @returns {void}
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 0.0, 9.0, 10.0, 11.0, 0.0, 0.0, 12.0, 13.0 ] );
*
* scaleUpperHHessenberg( 4, 4, A, 4, 1, 0, true, 2.0 );
* // A => <Float64Array>[ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 0.0, 18.0, 20.0, 22.0, 0.0, 0.0, 24.0, 26.0 ]
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.0, 5.0, 0.0, 0.0, 2.0, 6.0, 9.0, 0.0, 3.0, 7.0, 10.0, 12.0, 4.0, 8.0, 11.0, 13.0 ] );
*
* scaleUpperHHessenberg( 4, 4, A, 1, 4, 0, false, 2.0 );
* // A => <Float64Array>[ 2.0, 10.0, 0.0, 0.0, 4.0, 12.0, 18.0, 0.0, 6.0, 14.0, 20.0, 24.0, 8.0, 16.0, 22.0, 26.0 ]
*/
function scaleUpperHHessenberg( M, N, A, strideA1, strideA2, offsetA, isrm, mul ) {
	var ia;
	var i0;
	var i1;
 
	if ( isrm ) {
		ia = offsetA;
		for ( i1 = 0; i1 < M; i1++ ) {
			for ( i0 = max( i1 - 1, 0 ); i0 < N; i0++ ) {
				A[ ia + ( i0 * strideA2 ) ] *= mul;
			}
			ia += strideA1;
		}
	} else {
		ia = offsetA;
		for ( i0 = 0; i0 < N; i0++ ) {
			for ( i1 = 0; i1 <= min( i0 + 1, M - 1 ); i1++ ) {
				A[ ia + ( i1 * strideA1 ) ] *= mul;
			}
			ia += strideA2;
		}
	}
}
 
/**
* Multiplies a real M by N symmetric banded lower matrix `A` by a real scalar `mul`.
*
* @private
* @param {NonNegativeInteger} KL - lower band width of `A`
* @param {NonNegativeInteger} M - number of rows in matrix `A`
* @param {NonNegativeInteger} N - number of columns in matrix `A`
* @param {Float64Array} A - input matrix
* @param {integer} strideA1 - stride of the first dimension of `A`
* @param {integer} strideA2 - stride of the second dimension of `A`
* @param {NonNegativeInteger} offsetA - starting index for `A`
* @param {boolean} isrm - boolean indicating if the matrix is row-major
* @param {number} mul - scalar multiplier
* @returns {void}
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.1, 2.2, 3.3, 4.4, 5.5, 6.1, 7.2, 8.3, 9.4, 0.0, 10.1, 11.2, 12.3, 0.0, 0.0 ] );
*
* scaleSymmetricBandedLower( 2, 5, 5, A, 5, 1, 0, true, 10.0 );
* // A => <Float64Array>[ 11.0, 22.0, 33.0, 44.0, 55.0, 61.0, 72.0, 83.0, 94.0, 0.0, 101.0, 112.0, 123.0, 0.0, 0.0 ]
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.1, 6.1, 10.1, 2.2, 7.2, 11.2, 3.3, 8.3, 12.3, 4.4, 9.4, 0.0, 5.5, 0.0, 0.0 ] );
*
* scaleSymmetricBandedLower( 2, 5, 5, A, 1, 3, 0, false, 10.0 );
* // A => <Float64Array>[ 11.0, 61.0, 101.0, 22.0, 72.0, 112.0, 33.0, 83.0, 123.0, 44.0, 94.0, 0.0, 55.0, 0.0, 0.0 ]
*/
function scaleSymmetricBandedLower( KL, M, N, A, strideA1, strideA2, offsetA, isrm, mul ) {
	var ia;
	var i0;
	var i1;
	var k3;
	var k4;
 
	ia = offsetA;
	k3 = KL + 1;
	k4 = N;
 
	if ( isrm ) {
		for ( i1 = 0; i1 < M; i1++ ) {
			for ( i0 = 0; i0 < ( N - i1 ); i0++ ) {
				A[ ia + ( i0 * strideA2 ) ] *= mul;
			}
			ia += strideA1;
		}
	} else {
		for ( i1 = 0; i1 < N; i1++ ) {
			for ( i0 = 0; i0 < min( k3, k4 - i1 ); i0++ ) {
				A[ ia + ( i0 * strideA1 ) ] *= mul;
			}
			ia += strideA2;
		}
	}
}
 
/**
* Multiplies a real M by N symmetric banded upper matrix `A` by a real scalar `mul`.
*
* @private
* @param {NonNegativeInteger} KU - upper band width of `A`
* @param {NonNegativeInteger} M - number of rows in matrix `A`
* @param {NonNegativeInteger} N - number of columns in matrix `A`
* @param {Float64Array} A - input matrix
* @param {integer} strideA1 - stride of the first dimension of `A`
* @param {integer} strideA2 - stride of the second dimension of `A`
* @param {NonNegativeInteger} offsetA - starting index for `A`
* @param {boolean} isrm - boolean indicating if the matrix is row-major
* @param {number} mul - scalar multiplier
* @returns {void}
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 0.0, 0.0, 10.1, 11.2, 12.3, 0.0, 6.1, 7.2, 8.3, 9.4, 1.1, 2.2, 3.3, 4.4, 5.5 ] );
*
* scaleSymmetricBandedUpper( 2, 5, 5, A, 5, 1, 0, true, 10.0 );
* // A => <Float64Array>[ 0.0, 0.0, 101.0, 112.0, 123.0, 0.0, 61.0, 72.0, 83.0, 94.0, 11.0, 22.0, 33.0, 44.0, 55.0 ]
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 0.0, 0.0, 1.1, 0.0, 6.1, 2.2, 10.1, 7.2, 3.3, 11.2, 8.3, 4.4, 12.3, 9.4, 5.5 ] );
*
* scaleSymmetricBandedUpper( 2, 5, 5, A, 1, 3, 0, false, 10.0 );
* // A => <Float64Array>[ 0.0, 0.0, 11.0, 0.0, 61.0, 22.0, 101.0, 72.0, 33.0, 112.0, 83.0, 44.0, 123.0, 94.0, 55.0 ]
*/
function scaleSymmetricBandedUpper( KU, M, N, A, strideA1, strideA2, offsetA, isrm, mul ) {
	var ia;
	var i0;
	var i1;
 
	ia = offsetA;
 
	if ( isrm ) {
		for ( i1 = 0; i1 <= KU; i1++ ) {
			for ( i0 = max( KU - i1, 0 ); i0 < N; i0++ ) {
				A[ ia + ( i0 * strideA2 ) ] *= mul;
			}
			ia += strideA1;
		}
	} else {
		for ( i1 = 0; i1 < N; i1++ ) {
			for ( i0 = max( KU - i1, 0 ); i0 <= KU; i0++ ) {
				A[ ia + ( i0 * strideA1 ) ] *= mul;
			}
			ia += strideA2;
		}
	}
}
 
/**
* Multiplies a real M by N banded matrix `A` by a real scalar `mul`.
*
* @private
* @param {NonNegativeInteger} KL - lower band width of `A`
* @param {NonNegativeInteger} KU - upper band width of `A`
* @param {NonNegativeInteger} M - number of rows in matrix `A`
* @param {NonNegativeInteger} N - number of columns in matrix `A`
* @param {Float64Array} A - input matrix
* @param {integer} strideA1 - stride of the first dimension of `A`
* @param {integer} strideA2 - stride of the second dimension of `A`
* @param {NonNegativeInteger} offsetA - starting index for `A`
* @param {number} mul - scalar multiplier
* @returns {void}
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.2, 2.3, 3.4, 4.5, 1.1, 2.2, 3.3, 4.4, 5.5, 2.1, 3.2, 4.3, 5.4, 0.0, 3.1, 4.2, 5.3, 0.0, 0.0 ] );
*
* scaleBanded( 2, 1, 5, 5, A, 5, 1, 0, 10.0 );
* // A => <Float64Array>[ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 12.0, 23.0, 34.0, 45.0, 11.0, 22.0, 33.0, 44.0, 55.0, 21.0, 32.0, 43.0, 54.0, 0.0, 31.0, 42.0, 53.0, 0.0, 0.0 ]
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 0.0, 0.0, 0.0, 1.1, 2.1, 3.1, 0.0, 0.0, 1.2, 2.2, 3.2, 4.2, 0.0, 0.0, 2.3, 3.3, 4.3, 5.3, 0.0, 0.0, 3.4, 4.4, 5.4, 0.0, 0.0, 0.0, 4.5, 5.5, 0.0, 0.0 ] );
*
* scaleBanded( 2, 1, 5, 5, A, 1, 6, 0, 10.0 );
* // A => <Float64Array>[ 0.0, 0.0, 0.0, 11.0, 21.0, 31.0, 0.0, 0.0, 12.0, 22.0, 32.0, 42.0, 0.0, 0.0, 23.0, 33.0, 43.0, 53.0, 0.0, 0.0, 34.0, 44.0, 54.0, 0.0, 0.0, 0.0, 45.0, 55.0, 0.0, 0.0 ]
*/
function scaleBanded( KL, KU, M, N, A, strideA1, strideA2, offsetA, mul ) {
	var ia;
	var i0;
	var i1;
	var k1;
	var k2;
	var k3;
	var k4;
 
	k1 = KL + KU;
	k2 = KL;
	k3 = ( 2 * KL ) + KU;
	k4 = KL + KU + M - 1;
	ia = offsetA;
 
	for ( i1 = 0; i1 < N; i1++ ) {
		for ( i0 = max( k1 - i1, k2 ); i0 <= min( k3, k4 - i1 ); i0++ ) {
			A[ ia + ( i0 * strideA1 ) ] *= mul;
		}
		ia += strideA2;
	}
}
 
 
// MAIN //
 
/**
* Multiplies a real M by N matrix `A` by a real scalar `CTO/CFROM`.
*
* @param {string} type - specifies the type of matrix `A`
* @param {NonNegativeInteger} KL - lower band width of `A`. Referenced only if type is `symmetric-banded-lower` or `banded`.
* @param {NonNegativeInteger} KU - upper band width of `A`. Referenced only if type is `symmetric-banded-upper` or `banded`.
* @param {number} CFROM - the matrix `A` is multiplied by `CTO / CFROM`
* @param {number} CTO - the matrix `A` is multiplied by `CTO / CFROM`
* @param {NonNegativeInteger} M - number of rows in matrix `A`
* @param {NonNegativeInteger} N - number of columns in matrix `A`
* @param {Float64Array} A - input matrix
* @param {integer} strideA1 - stride of the first dimension of `A`
* @param {integer} strideA2 - stride of the second dimension of `A`
* @param {NonNegativeInteger} offsetA - starting index for `A`
* @returns {Float64Array} scaled matrix `A`
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
*
* dlascl( 'general', 0, 0, 1.0, 2.0, 3, 2, A, 2, 1, 0 );
* // A => <Float64Array>[ 2.0, 4.0, 6.0, 8.0, 10.0, 12.0 ]
*/
function dlascl( type, KL, KU, CFROM, CTO, M, N, A, strideA1, strideA2, offsetA ) { // eslint-disable-line max-params
	var cfromc;
	var cfrom1;
	var isrm;
	var ctoc;
	var cto1;
	var done;
	var mul;
 
	if ( N === 0 || M === 0 ) {
		return A;
	}
 
	done = false;
 
	cfromc = CFROM;
	ctoc = CTO;
	isrm = isRowMajor( [ strideA1, strideA2 ] );
 
	while ( !done ) {
		cfrom1 = CTO * smlnum;
		if ( cfrom1 === cfromc ) {
			// cfromc is Infinity, multiply by a correctly signed zero for finite ctoc or NaN
			mul = ctoc / cfromc;
			done = true;
			cto1 = ctoc;
		} else {
			cto1 = ctoc / bignum;
			if ( cto1 === ctoc ) {
				// ctoc is either zero or Infinity, thus ctoc itself is a correct multiplication factor
				mul = ctoc;
				done = true;
				cfromc = 1.0;
			} else if ( abs( cfrom1 ) > abs( ctoc ) && ctoc !== 0.0 ) {
				mul = smlnum;
				done = false;
				ctoc = cto1;
			} else if ( abs( cto1 ) > abs( cfromc ) ) {
				mul = bignum;
				done = false;
				ctoc = cto1;
			} else {
				mul = ctoc / cfromc;
				done = true;
			}
		}
 
		if ( type === 'general' ) {
			scaleGeneral( M, N, A, strideA1, strideA2, offsetA, mul );
			continue;
		}
		if ( type === 'upper' ) {
			scaleUpper( M, N, A, strideA1, strideA2, offsetA, isrm, mul );
			continue;
		}
		if ( type === 'lower' ) {
			scaleLower( M, N, A, strideA1, strideA2, offsetA, isrm, mul );
			continue;
		}
		if ( type === 'upper-hessenberg' ) {
			scaleUpperHHessenberg( M, N, A, strideA1, strideA2, offsetA, isrm, mul );
			continue;
		}
		if ( type === 'symmetric-banded-lower' ) {
			scaleSymmetricBandedLower( KL, M, N, A, strideA1, strideA2, offsetA, isrm, mul );
			continue;
		}
		if ( type === 'symmetric-banded-upper' ) {
			scaleSymmetricBandedUpper( KU, M, N, A, strideA1, strideA2, offsetA, isrm, mul );
			continue;
		}
		if ( type === 'banded' ) {
			scaleBanded( KL, KU, M, N, A, strideA1, strideA2, offsetA, mul );
			continue;
		}
	}
 
	return A;
}
 
 
// EXPORTS //
 
module.exports = dlascl;