Skip to content

Commit 54b8104

Browse files
aayush0325kgrytestdlib-bot
authored
feat: add lapack/base/dgttrf
PR-URL: #5754 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]> Co-authored-by: stdlib-bot <[email protected]>
1 parent cdd2f1a commit 54b8104

24 files changed

+3225
-0
lines changed

lib/node_modules/@stdlib/lapack/base/dgttrf/README.md

Lines changed: 436 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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 bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var Int32Array = require( '@stdlib/array/int32' );
27+
var Float64Array = require( '@stdlib/array/float64' );
28+
var pkg = require( './../package.json' ).name;
29+
var dgttrf = require( './../lib/dgttrf.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float64'
36+
};
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Creates a benchmark function.
43+
*
44+
* @private
45+
* @param {PositiveInteger} len - array length
46+
* @returns {Function} benchmark function
47+
*/
48+
function createBenchmark( len ) {
49+
var IPIV = new Int32Array( len );
50+
var DU2 = new Float64Array( len-2 );
51+
var DL = uniform( len-1, 0.0, 100.0, options );
52+
var DU = uniform( len-1, 0.0, 100.0, options );
53+
var D = uniform( len, 0.0, 100.0, options );
54+
return benchmark;
55+
56+
function benchmark( b ) {
57+
var d;
58+
var i;
59+
60+
b.tic();
61+
for ( i = 0; i < b.iterations; i++ ) {
62+
d = dgttrf( len, DL, D, DU, DU2, IPIV );
63+
if ( d < 0 ) {
64+
b.fail( 'should return a success status code' );
65+
}
66+
}
67+
b.toc();
68+
if ( d < 0 ) {
69+
b.fail( 'should return a success status code' );
70+
}
71+
b.pass( 'benchmark finished' );
72+
b.end();
73+
}
74+
}
75+
76+
77+
// MAIN //
78+
79+
/**
80+
* Main execution sequence.
81+
*
82+
* @private
83+
*/
84+
function main() {
85+
var len;
86+
var min;
87+
var max;
88+
var f;
89+
var i;
90+
91+
min = 1; // 10^min
92+
max = 6; // 10^max
93+
94+
for ( i = min; i <= max; i++ ) {
95+
len = pow( 10, i );
96+
f = createBenchmark( len );
97+
bench( pkg+':len='+len, f );
98+
}
99+
}
100+
101+
main();
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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 bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var Int32Array = require( '@stdlib/array/int32' );
27+
var Float64Array = require( '@stdlib/array/float64' );
28+
var pkg = require( './../package.json' ).name;
29+
var dgttrf = require( './../lib/ndarray.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float64'
36+
};
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Creates a benchmark function.
43+
*
44+
* @private
45+
* @param {PositiveInteger} len - array length
46+
* @returns {Function} benchmark function
47+
*/
48+
function createBenchmark( len ) {
49+
var IPIV = new Int32Array( len );
50+
var DU2 = new Float64Array( len-2 );
51+
var DL = uniform( len-1, 0.0, 100.0, options );
52+
var DU = uniform( len-1, 0.0, 100.0, options );
53+
var D = uniform( len, 0.0, 100.0, options );
54+
return benchmark;
55+
56+
function benchmark( b ) {
57+
var d;
58+
var i;
59+
60+
b.tic();
61+
for ( i = 0; i < b.iterations; i++ ) {
62+
d = dgttrf( len, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0 ); // eslint-disable-line max-len
63+
if ( d < 0 ) {
64+
b.fail( 'should return a success status code' );
65+
}
66+
}
67+
b.toc();
68+
if ( d < 0 ) {
69+
b.fail( 'should return a success status code' );
70+
}
71+
b.pass( 'benchmark finished' );
72+
b.end();
73+
}
74+
}
75+
76+
77+
// MAIN //
78+
79+
/**
80+
* Main execution sequence.
81+
*
82+
* @private
83+
*/
84+
function main() {
85+
var len;
86+
var min;
87+
var max;
88+
var f;
89+
var i;
90+
91+
min = 1; // 10^min
92+
max = 6; // 10^max
93+
94+
for ( i = min; i <= max; i++ ) {
95+
len = pow( 10, i );
96+
f = createBenchmark( len );
97+
bench( pkg+':ndarray:len='+len, f );
98+
}
99+
}
100+
101+
main();
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
2+
{{alias}}( N, DL, D, DU, DU2, IPIV )
3+
Computes an LU factorization of a real tridiagonal matrix `A` using
4+
elimination with partial pivoting and row interchanges.
5+
6+
Indexing is relative to the first index. To introduce an offset, use typed
7+
array views.
8+
9+
The function mutates `DL`, `D`, `DU`, `DU2`, and `IPIV`.
10+
11+
Parameters
12+
----------
13+
N: integer
14+
Number of rows/columns in `A`.
15+
16+
DL: Float64Array
17+
The first sub diagonal of `A`. Should have `N-1` indexed elements. `DL`
18+
is overwritten by the multipliers that define the matrix `L` from the LU
19+
factorization of `A`.
20+
21+
D: Float64Array
22+
The diagonal of `A`. Should have `N` indexed elements. `D` is
23+
overwritten by the diagonal elements of the upper triangular matrix `U`
24+
from the LU factorization of `A`.
25+
26+
DU: Float64Array
27+
The first super-diagonal of `A`. Should have `N-1` indexed elements.
28+
`DU` is overwritten by the elements of the first super-diagonal of `U`.
29+
30+
DU2: Float64Array
31+
The second super-diagonal of `U`. Should have `N-2` indexed elements.
32+
`DU2` is overwritten by the elements of the second super-diagonal of
33+
`U`.
34+
35+
IPIV: Int32Array
36+
Vector of pivot indices. Should have `N` indexed elements.
37+
38+
Returns
39+
-------
40+
info: integer
41+
Status code. The status code indicates the following conditions:
42+
43+
- if equal to zero, then the factorization was successful.
44+
- if greater than zero, then `U(k, k)` is exactly zero the factorization
45+
has been completed, but the factor `U` is exactly singular, and division
46+
by zero will occur if it is used to solve a system of equations where
47+
`k = StatusCode`.
48+
49+
Examples
50+
--------
51+
> var DL = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] );
52+
> var D = new {{alias:@stdlib/array/float64}}( [ 2.0, 3.0, 1.0 ] );
53+
> var DU = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] );
54+
> var DU2 = new {{alias:@stdlib/array/float64}}( 1 );
55+
> var IPIV = new {{alias:@stdlib/array/int32}}( 3 );
56+
> {{alias}}( 3, DL, D, DU, DU2, IPIV )
57+
0
58+
> DL
59+
<Float64Array>[ 0.5, 0.4 ]
60+
> D
61+
<Float64Array>[ 2.0, 2.5, 0.6 ]
62+
> DU
63+
<Float64Array>[ 1.0, 1.0 ]
64+
> DU2
65+
<Float64Array>[ 0.0 ]
66+
> IPIV
67+
<Int32Array>[ 0, 1, 2 ]
68+
69+
// Using typed array views:
70+
> var DL0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 1.0 ] );
71+
> var D0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 2.0, 3.0, 1.0 ] );
72+
> var DU0 = new {{alias:@stdlib/array/float64}}( [ 0.0, 1.0, 1.0 ] );
73+
> var DU20 = new {{alias:@stdlib/array/float64}}( 2 );
74+
> var IPIV0 = new {{alias:@stdlib/array/int32}}( 4 );
75+
> DL = new Float64Array( DL0.buffer, DL0.BYTES_PER_ELEMENT*1 );
76+
> D = new Float64Array( D0.buffer, D0.BYTES_PER_ELEMENT*1 );
77+
> DU = new Float64Array( DU0.buffer, DU0.BYTES_PER_ELEMENT*1 );
78+
> DU2 = new Float64Array( DU20.buffer, DU20.BYTES_PER_ELEMENT*1 );
79+
> IPIV = new Int32Array( IPIV0.buffer, IPIV0.BYTES_PER_ELEMENT*1 );
80+
> {{alias}}( 3, DL, D, DU, DU2, IPIV )
81+
0
82+
> DL0
83+
<Float64Array>[ 0.0, 0.5, 0.4 ]
84+
> D0
85+
<Float64Array>[ 0.0, 2.0, 2.5, 0.6 ]
86+
> DU0
87+
<Float64Array>[ 0.0, 1.0, 1.0 ]
88+
> DU20
89+
<Float64Array>[ 0.0, 0.0 ]
90+
> IPIV0
91+
<Int32Array>[ 0, 0, 1, 2 ]
92+
93+
94+
{{alias}}.ndarray(N, DL,sdl,odl, D,sd,od, DU,sdu,odu, DU2,sdu2,odu2, IPIV,si,oi)
95+
Computes an LU factorization of a real tridiagonal matrix `A` using
96+
elimination with partial pivoting and row interchanges and alternative
97+
indexing semantics.
98+
99+
While typed array views mandate a view offset based on the underlying
100+
buffer, the offset parameters support indexing semantics based on starting
101+
indices.
102+
103+
The function mutates `DL`, `D`, `DU`, `DU2`, and `IPIV`.
104+
105+
Parameters
106+
----------
107+
N: integer
108+
Number of rows/columns in `A`.
109+
110+
DL: Float64Array
111+
The first sub diagonal of `A`. Should have `N-1` indexed elements. `DL`
112+
is overwritten by the multipliers that define the matrix `L` from the LU
113+
factorization of `A`.
114+
115+
sdl: integer
116+
Stride length for `DL`.
117+
118+
odl: integer
119+
Starting index for `DL`.
120+
121+
D: Float64Array
122+
The diagonal of `A`. Should have `N` indexed elements. `D` is
123+
overwritten by the diagonal elements of the upper triangular matrix `U`
124+
from the LU factorization of `A`.
125+
126+
sd: integer
127+
Stride length for `D`.
128+
129+
od: integer
130+
Starting index for `D`.
131+
132+
DU: Float64Array
133+
The first super-diagonal of `A`. Should have `N-1` indexed elements.
134+
`DU` is overwritten by the elements of the first super-diagonal of `U`.
135+
136+
sdu: integer
137+
Stride length for `DU`.
138+
139+
odu: integer
140+
Starting index for `DU2`.
141+
142+
DU2: Float64Array
143+
The second super-diagonal of `U`. Should have `N-2` indexed elements.
144+
`DU2` is overwritten by the elements of the second super-diagonal of
145+
`U`.
146+
147+
sdu2: integer
148+
Stride length for `DU2`.
149+
150+
odu2: integer
151+
Starting index for `DU2`.
152+
153+
IPIV: Int32Array
154+
Vector of pivot indices. Should have `N` indexed elements.
155+
156+
si: integer
157+
Stride length for `IPIV`.
158+
159+
oi: integer
160+
Starting index for `IPIV`.
161+
162+
Returns
163+
-------
164+
info: integer
165+
Status code. The status code indicates the following conditions:
166+
167+
- if equal to zero, then the factorization was successful.
168+
- if greater than zero, then `U(k, k)` is exactly zero the factorization
169+
has been completed, but the factor `U` is exactly singular, and division
170+
by zero will occur if it is used to solve a system of equations where
171+
`k = StatusCode`.
172+
173+
Examples
174+
--------
175+
> var DL = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] );
176+
> var D = new {{alias:@stdlib/array/float64}}( [ 2.0, 3.0, 1.0 ] );
177+
> var DU = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0 ] );
178+
> var DU2 = new {{alias:@stdlib/array/float64}}( 1 );
179+
> var IPIV = new {{alias:@stdlib/array/int32}}( 3 );
180+
> {{alias}}.ndarray( 3, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0 )
181+
0
182+
> DL
183+
<Float64Array>[ 0.5, 0.4 ]
184+
> D
185+
<Float64Array>[ 2.0, 2.5, 0.6 ]
186+
> DU
187+
<Float64Array>[ 1.0, 1.0 ]
188+
> DU2
189+
<Float64Array>[ 0.0 ]
190+
> IPIV
191+
<Int32Array>[ 0, 1, 2 ]
192+
193+
See Also
194+
--------
195+

0 commit comments

Comments
 (0)