Skip to content

Commit e31c8b8

Browse files
committed
feat: add base algorithm
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 0a7e54e commit e31c8b8

File tree

1 file changed

+146
-0
lines changed
  • lib/node_modules/@stdlib/lapack/base/dgttrf/lib

1 file changed

+146
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var abs = require( '@stdlib/math/base/special/abs' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Computes an LU factorization of a real tri diagonal matrix A using elimination with partial pivoting and row interchanges.
30+
*
31+
* @private
32+
* @param {NonNegativeInteger} N - order of `A`
33+
* @param {Float64Array} DL - sub diagonal elements of `A`
34+
* @param {integer} strideDL - stride of the sub diagonal elements of `A`
35+
* @param {NonNegativeInteger} offsetDL - offset of the sub diagonal elements of `A`
36+
* @param {Float64Array} D - diagonal elements of `A`
37+
* @param {integer} strideD - stride of the diagonal elements of `A`
38+
* @param {NonNegativeInteger} offsetD - offset of the diagonal elements of `A`
39+
* @param {Float64Array} DU - diagonal elements of `A`
40+
* @param {integer} strideDU - stride of the first super diagonal elements of `A`
41+
* @param {NonNegativeInteger} offsetDU - offset of the first super diagonal elements of `A`
42+
* @param {Float64Array} DU2 - diagonal elements of `A`
43+
* @param {integer} strideDU2 - stride of the second super diagonal elements of `A`
44+
* @param {NonNegativeInteger} offsetDU2 - offset of the second super diagonal elements of `A`
45+
* @param {Int32Array} IPIV - vector of pivot indices
46+
* @param {integer} strideIPIV - `IPIV` stride length
47+
* @param {NonNegativeInteger} offsetIPIV - index offset for `IPIV`
48+
* @returns {integer} status code
49+
*
50+
* @example
51+
* var Float64Array = require( '@stdlib/array/float64' );
52+
*
53+
* var DL = new Float64Array( [ 1.0, 1.0 ] );
54+
* var D = new Float64Array( [ 2.0, 3.0, 1.0 ] );
55+
* var DU = new Float64Array( [ 1.0, 1.0 ] );
56+
* var DU2 = new Float64Array( [ 0.0 ] );
57+
* var IPIV = new Int32Array( [ 0, 1, 2 ] );
58+
*
59+
* dgttrf( 3, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0 );
60+
* // DL => <Float64Array>[ 0.5, 0.4 ]
61+
* // D => <Float64Array>[ 2, 2.5, 0.6 ]
62+
* // DU => <Float64Array>[ 1, 1 ]
63+
* // DU2 => <Float64Array>[ 0 ]
64+
*/
65+
function dgttrf( N, DL, strideDL, offsetDL, D, strideD, offsetD, DU, strideDU, offsetDU, DU2, strideDU2, offsetDU2, IPIV, strideIPIV, offsetIPIV ) { // eslint-disable-line max-len, max-params
66+
var fact;
67+
var temp;
68+
var idu2;
69+
var idu;
70+
var idl;
71+
var id;
72+
var ip;
73+
var i;
74+
75+
if ( N === 0 ) {
76+
return 0;
77+
}
78+
79+
idl = offsetDL;
80+
idu2 = offsetDU2;
81+
82+
ip = offsetIPIV;
83+
for ( i = 0; i < N; i++ ) {
84+
IPIV[ ip + (strideIPIV*i) ] = i;
85+
}
86+
87+
idu = offsetDU;
88+
for ( i = 0; i < N-2; i++ ) {
89+
DU2[ idu + (strideDU*i) ] = 0;
90+
}
91+
92+
idl = offsetDL;
93+
idu2 = offsetDU2;
94+
id = offsetD;
95+
for ( i = 0; i < N-2; i++ ) {
96+
if ( abs( D[ id + (strideD*i) ] ) >= abs( DL[ idl + (strideDL*i) ] ) ) { // no row interchange required
97+
if ( D[ id ] !== 0.0 ) {
98+
fact = DL[ idl + (strideDL*i) ] / D[ id + (strideD*i) ];
99+
DL[ idl + (strideDL*i) ] = fact;
100+
D[ id + (strideD*(i+1)) ] = D[ id + (strideD*(i+1)) ] - ( fact*DU[ idu + (strideDU*i) ] ); // eslint-disable-line max-len
101+
}
102+
} else {
103+
fact = D[ id+(strideD*i) ] / DL[ idl+(strideDL*i) ];
104+
D[ id+(strideD*i) ] = DL[ idl+(strideDL*i) ];
105+
DL[ idl+(strideDL*i) ] = fact;
106+
temp = DU[ idu+(strideDU*i) ];
107+
DU[ idu+(strideDU*i) ] = D[ id + (strideD*(i+1)) ];
108+
D[ id+(strideD*(i+1)) ] = temp - ( fact*D[ id+(strideD*(i+1)) ] );
109+
DU2[ idu2+(strideDU2*i) ] = DU[ idu+(strideDU*(i+1)) ];
110+
DU[ idu+(strideDU*(i+1)) ] = -fact*DU[ idu+(strideDU*(i+1)) ];
111+
IPIV[ ip+(strideIPIV*i) ] = i + 1;
112+
}
113+
}
114+
115+
if ( N > 1 ) {
116+
i = N - 2;
117+
if ( abs( D[ id + (strideD*i) ] ) >= abs( DL[ idl + (strideDL*i) ] ) ) {
118+
if ( D[ id + (strideD*i) ] !== 0 ) {
119+
fact = DL[ idl + (strideDL*i) ] / D[ id + (strideD*i) ];
120+
DL[ idl + (strideDL*i) ] = fact;
121+
D[ id + (strideD*(i+1)) ] = D[ id + (strideD*(i+1)) ] - (fact*DU[ idu + (strideDU*i) ]); // eslint-disable-line max-len
122+
}
123+
} else {
124+
fact = D[ id+(strideD*i) ] / DL[ idl+(strideDL*i) ];
125+
D[ id+(strideD*i) ] = DL[ idl+(strideDL*i) ];
126+
DL[ idl+(strideDL*i) ] = fact;
127+
temp = DU[ idu+(strideDU*i) ];
128+
DU[ idu+(strideDU*i) ] = D[ id + (strideD*(i+1)) ];
129+
D[ id+(strideD*(i+1)) ] = temp - ( fact*D[ id+(strideD*(i+1)) ] );
130+
IPIV[ ip+(strideIPIV*i) ] = i + 1;
131+
}
132+
}
133+
134+
for ( i = 0; i < N; i++ ) {
135+
if ( D[ id+(strideD*i) ] === 0.0 ) {
136+
return i;
137+
}
138+
}
139+
140+
return 0;
141+
}
142+
143+
144+
// EXPORTS //
145+
146+
module.exports = dgttrf;

0 commit comments

Comments
 (0)