All files ndarray.js

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

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 1092x 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 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` to `scale`, the infinity-norm of `X` to `xnorm`, and a status code to `info`. The status code is `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} scale - array containing an element which is overwritten by the scaling factor
* @param {NonNegativeInteger} offsetScale - index of the element in `scale`
* @param {Float64Array} xnorm - array containing an element which is overwritten by the infinity-norm of `X`
* @param {NonNegativeInteger} offsetXnorm - index of the element in `xnorm`
* @param {Int32Array} info - array containing an element which is overwritten by the status code
* @param {NonNegativeInteger} offsetInfo - index of the element in `info`
* @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 {Float64Array} `X`
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
* var Int32Array = require( '@stdlib/array/int32' );
*
* 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 scale = new Float64Array( 1 );
* var xnorm = new Float64Array( 1 );
* var info = new Int32Array( 1 );
*
* 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, scale, 0, xnorm, 0, info, 0 );
* // X => <Float64Array>[ ~-0.087, ~1.391 ]
* // scale => <Float64Array>[ 1.0 ]
* // xnorm => <Float64Array>[ ~1.391 ]
* // info => <Int32Array>[ 0 ]
*/
function dlaln2( trans, NA, NW, smin, ca, A, strideA1, strideA2, offsetA, d1, d2, B, strideB1, strideB2, offsetB, wr, wi, X, strideX1, strideX2, offsetX, scale, offsetScale, xnorm, offsetXnorm, info, offsetInfo ) { // 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, scale, offsetScale, xnorm, offsetXnorm, info, offsetInfo );
}
 
 
// EXPORTS //
 
module.exports = dlaln2;