All files dlaln2.js

100% Statements 142/142
100% Branches 25/25
100% Functions 1/1
100% Lines 142/142

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 1432x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 83x 83x 83x 83x 83x 83x 83x 83x 83x 13x 13x 83x 13x 13x 83x 5x 5x 83x 5x 5x 83x 2x 2x 83x 16x 2x 2x 16x 2x 2x 12x 12x 12x 12x 12x 12x 83x 29x 2x 2x 29x 2x 2x 25x 25x 25x 25x 25x 25x 25x 37x 83x 2x 2x 2x 2x 2x  
/**
* @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 */
 
'use strict';
 
// MODULES //
 
var isTransposeOperation = require( '@stdlib/blas/base/assert/is-transpose-operation' );
var isLayout = require( '@stdlib/blas/base/assert/is-layout' );
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
var transposeOperations = require( '@stdlib/blas/base/transpose-operations' );
var join = require( '@stdlib/array/base/join' );
var format = require( '@stdlib/string/format' );
var base = require( './base.js' );
 
 
// MAIN //
 
/**
* Solves a system of the form `(ca*A - w*D) X = s*B` or `(ca*A^T - w*D) X = s*B` with possible scaling and perturbation of `A`, where `A` is an `NA` by `NA` real matrix (`NA` is 1 or 2), `ca` is a real scalar, `D` is an `NA` by `NA` real diagonal matrix, and `w` is a real or complex scalar.
*
* ## Notes
*
* -   If `w` is complex (`NW = 2`), `X` and `B` are `NA` by `2` matrices whose first column contains the real part and whose second column contains the imaginary part.
* -   `s` is a scaling factor (`<= 1`) chosen so that `X` can be computed without overflow. `X` is further scaled if necessary to assure that `norm(ca*A - w*D) * norm(X)` is less than overflow.
* -   The function writes the scaling factor `s` and the infinity-norm of `X` to the first and second elements of `out`, respectively.
* -   The function returns `1` if `ca*A - w*D` had to be perturbed to make its smallest (or only) singular value greater than `smin` and `0` otherwise.
*
* @param {string} order - storage layout
* @param {string} trans - specifies whether `A` should be transposed
* @param {PositiveInteger} NA - size of the matrix `A` (either `1` or `2`)
* @param {PositiveInteger} NW - `1` if `w` is real and `2` if `w` is complex
* @param {number} smin - desired lower bound on the singular values of `A`
* @param {number} ca - coefficient by which `A` is multiplied
* @param {Float64Array} A - input matrix
* @param {PositiveInteger} LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
* @param {number} d1 - first diagonal element of `D`
* @param {number} d2 - second diagonal element of `D` (not used if `NA = 1`)
* @param {Float64Array} B - right-hand side matrix
* @param {PositiveInteger} LDB - stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`)
* @param {number} wr - real part of `w`
* @param {number} wi - imaginary part of `w` (not used if `NW = 1`)
* @param {Float64Array} X - output matrix
* @param {PositiveInteger} LDX - stride of the first dimension of `X` (a.k.a., leading dimension of the matrix `X`)
* @param {Float64Array} out - output array containing the scaling factor and the infinity-norm of `X`
* @throws {TypeError} first argument must be a valid order
* @throws {TypeError} second argument must be a valid transpose operation
* @throws {RangeError} third argument must be either `1` or `2`
* @throws {RangeError} fourth argument must be either `1` or `2`
* @throws {RangeError} eighth argument must be a valid stride
* @throws {RangeError} twelfth argument must be a valid stride
* @throws {RangeError} sixteenth argument must be a valid stride
* @returns {integer} status code
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* var A = new Float64Array( [ 5.0, 1.0, 1.0, 2.0 ] );
* var B = new Float64Array( [ 1.0, 2.0 ] );
* var X = new Float64Array( 2 );
* var out = new Float64Array( 2 );
*
* var info = dlaln2( 'row-major', 'no-transpose', 2, 1, 1.0e-3, 1.0, A, 2, 1.0, 1.0, B, 1, 0.5, 0.0, X, 1, out );
* // returns 0
*
* // X => <Float64Array>[ ~-0.087, ~1.391 ]
* // out => <Float64Array>[ 1.0, ~1.391 ]
*/
function dlaln2( order, trans, NA, NW, smin, ca, A, LDA, d1, d2, B, LDB, wr, wi, X, LDX, out ) { // eslint-disable-line max-params
	var sa1;
	var sa2;
	var sb1;
	var sb2;
	var sx1;
	var sx2;
 
	if ( !isLayout( order ) ) {
		throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) );
	}
	if ( !isTransposeOperation( trans ) ) {
		throw new TypeError( format( 'invalid argument. Second argument must be one of the following: "%s". Value: `%s`.', join( transposeOperations(), '", "' ), trans ) );
	}
	if ( NA !== 1 && NA !== 2 ) {
		throw new RangeError( format( 'invalid argument. Third argument must be either 1 or 2. Value: `%d`.', NA ) );
	}
	if ( NW !== 1 && NW !== 2 ) {
		throw new RangeError( format( 'invalid argument. Fourth argument must be either 1 or 2. Value: `%d`.', NW ) );
	}
	if ( LDA < NA ) {
		throw new RangeError( format( 'invalid argument. Eighth argument must be greater than or equal to %d. Value: `%d`.', NA, LDA ) );
	}
	if ( isColumnMajor( order ) ) {
		if ( LDB < NA ) {
			throw new RangeError( format( 'invalid argument. Twelfth argument must be greater than or equal to %d. Value: `%d`.', NA, LDB ) );
		}
		if ( LDX < NA ) {
			throw new RangeError( format( 'invalid argument. Sixteenth argument must be greater than or equal to %d. Value: `%d`.', NA, LDX ) );
		}
		sa1 = 1;
		sa2 = LDA;
		sb1 = 1;
		sb2 = LDB;
		sx1 = 1;
		sx2 = LDX;
	} else { // order === 'row-major'
		if ( LDB < NW ) {
			throw new RangeError( format( 'invalid argument. Twelfth argument must be greater than or equal to %d. Value: `%d`.', NW, LDB ) );
		}
		if ( LDX < NW ) {
			throw new RangeError( format( 'invalid argument. Sixteenth argument must be greater than or equal to %d. Value: `%d`.', NW, LDX ) );
		}
		sa1 = LDA;
		sa2 = 1;
		sb1 = LDB;
		sb2 = 1;
		sx1 = LDX;
		sx2 = 1;
	}
	return base( trans, NA, NW, smin, ca, A, sa1, sa2, 0, d1, d2, B, sb1, sb2, 0, wr, wi, X, sx1, sx2, 0, out, 1, 0 );
}
 
 
// EXPORTS //
 
module.exports = dlaln2;