All files base.js

100% Statements 100/100
100% Branches 11/11
100% Functions 1/1
100% Lines 100/100

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 1013x 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 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 25x 25x 25x 25x 24x 5x 5x 24x 15x 15x 24x 25x 1x 1x 1x 1x 25x 11x 11x 25x 15x 15x 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 idamax = require( '@stdlib/blas/base/idamax' ).ndarray;
var dscal = require( '@stdlib/blas/base/dscal' ).ndarray;
var dswap = require( '@stdlib/blas/base/dswap' ).ndarray;
var dger = require( '@stdlib/blas/base/dger' ).ndarray;
 
 
// MAIN //
 
/**
* Computes an `LU` factorization of a real general matrix `A` using elimination with partial pivoting and row interchanges.
*
* @private
*
* ## Notes
*
* -   The factorization has the form `A = P * L * U`, where `P` is a permutation matrix, `L` is lower triangular or trapezoidal with unit diagonal elements, and `U` is upper triangular or trapezoidal.
* -   `A` is overwritten in-place. The strictly lower triangular part contains the multipliers defining `L`, and the upper triangular part contains `U`. The unit diagonal of `L` is not stored.
* -   `IPIV` contains zero-based pivot indices. For each `i` in `0 <= i < min(M,N)`, row `i` is interchanged with row `IPIV(i)`.
* -   If the returned status code is greater than zero, `U(k,k)` is exactly zero for `k` equal to the status code. The factorization has been completed, but `U` is singular.
* @param {NonNegativeInteger} M - number of rows in `A`
* @param {NonNegativeInteger} N - number of columns in `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 {Int32Array} IPIV - vector of pivot indices
* @param {integer} strideIPIV - stride length for `IPIV`
* @param {NonNegativeInteger} offsetIPIV - starting index for `IPIV`
* @returns {integer} status code
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
* var Int32Array = require( '@stdlib/array/int32' );
*
* var A = new Float64Array( [ 1.0, 3.0, 2.0, 4.0 ] );
* var IPIV = new Int32Array( 2 );
*
* dgetrf( 2, 2, A, 1, 2, 0, IPIV, 1, 0 );
* // A => <Float64Array>[ 3, 0.333..., 4, 0.666... ]
* // IPIV => <Int32Array>[ 1, 1 ]
*/
function dgetrf( M, N, A, strideA1, strideA2, offsetA, IPIV, strideIPIV, offsetIPIV ) { // eslint-disable-line max-params, max-len
	var mn;
	var info;
	var ia;
	var jp;
	var j;
 
	mn = M < N ? M : N;
	info = 0;
	for ( j = 0; j < mn; j++ ) {
		ia = offsetA + ( j * strideA2 ) + ( j * strideA1 );
		jp = j + idamax( M-j, A, strideA1, ia );
		IPIV[ offsetIPIV + ( j * strideIPIV ) ] = jp;
		if ( A[ offsetA + ( jp * strideA1 ) + ( j * strideA2 ) ] !== 0.0 ) {
			if ( jp !== j ) {
				dswap( N, A, strideA2, offsetA+(j*strideA1), A, strideA2, offsetA+(jp*strideA1) ); // eslint-disable-line max-len
			}
			if ( j < M-1 ) {
				dscal( M-j-1, 1.0/A[ ia ], A, strideA1, ia+strideA1 );
			}
		}
		if ( A[ ia ] === 0.0 ) {
			if ( info === 0 ) {
				info = j+1;
			}
		}
		if ( A[ ia ] !== 0.0 && j < mn-1 ) {
			dger( M-j-1, N-j-1, -1.0, A, strideA1, ia+strideA1, A, strideA2, ia+strideA2, A, strideA1, strideA2, ia+strideA1+strideA2 );
		}
	}
	return info;
}
 
 
// EXPORTS //
 
module.exports = dgetrf;