All files ndarray.js

100% Statements 103/103
100% Branches 10/10
100% Functions 1/1
100% Lines 103/103

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 1042x 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 2x 72x 72x 13x 13x 72x 5x 5x 72x 5x 5x 49x 72x 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 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` using alternative indexing semantics, 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} 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 {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} 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 {integer} strideB1 - stride of the first dimension of `B`
* @param {integer} strideB2 - stride of the second dimension of `B`
* @param {NonNegativeInteger} offsetB - starting index for `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 {integer} strideX1 - stride of the first dimension of `X`
* @param {integer} strideX2 - stride of the second dimension of `X`
* @param {NonNegativeInteger} offsetX - starting index for `X`
* @param {Float64Array} out - output array containing the scaling factor and the infinity-norm of `X`
* @param {integer} strideOut - stride length for `out`
* @param {NonNegativeInteger} offsetOut - starting index for `out`
* @throws {TypeError} first argument must be a valid transpose operation
* @throws {RangeError} second argument must be either `1` or `2`
* @throws {RangeError} third argument must be either `1` or `2`
* @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( 'no-transpose', 2, 1, 1.0e-3, 1.0, A, 1, 2, 0, 1.0, 1.0, B, 1, 2, 0, 0.5, 0.0, X, 1, 2, 0, out, 1, 0 );
* // returns 0
*
* // X => <Float64Array>[ ~-0.087, ~1.391 ]
* // out => <Float64Array>[ 1.0, ~1.391 ]
*/
function dlaln2( trans, NA, NW, smin, ca, A, strideA1, strideA2, offsetA, d1, d2, B, strideB1, strideB2, offsetB, wr, wi, X, strideX1, strideX2, offsetX, out, strideOut, offsetOut ) { // eslint-disable-line max-params
	if ( !isTransposeOperation( trans ) ) {
		throw new TypeError( format( 'invalid argument. First argument must be one of the following: "%s". Value: `%s`.', join( transposeOperations(), '", "' ), trans ) );
	}
	if ( NA !== 1 && NA !== 2 ) {
		throw new RangeError( format( 'invalid argument. Second argument must be either 1 or 2. Value: `%d`.', NA ) );
	}
	if ( NW !== 1 && NW !== 2 ) {
		throw new RangeError( format( 'invalid argument. Third argument must be either 1 or 2. Value: `%d`.', NW ) );
	}
	return base( trans, NA, NW, smin, ca, A, strideA1, strideA2, offsetA, d1, d2, B, strideB1, strideB2, offsetB, wr, wi, X, strideX1, strideX2, offsetX, out, strideOut, offsetOut );
}
 
 
// EXPORTS //
 
module.exports = dlaln2;