Skip to content

Commit e62a7ca

Browse files
committed
feat/dgttrf
1 parent 3aca89e commit e62a7ca

22 files changed

+1282
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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 pkg = require( './../package.json' ).name;
25+
var dgttrf = require( './../lib' );
26+
27+
28+
// MAIN //
29+
30+
bench( pkg, function benchmark( b ) {
31+
var out;
32+
var du;
33+
var dl;
34+
var d;
35+
var n;
36+
var i;
37+
38+
n = 1000;
39+
40+
dl = [];
41+
d = [];
42+
du = [];
43+
44+
// Fill diagonals with some values:
45+
for ( i = 0; i < n - 1; i++ ) {
46+
dl.push( 2.0 );
47+
du.push( 1.0 );
48+
}
49+
for ( i = 0; i < n; i++ ) {
50+
d.push( 4.0 );
51+
}
52+
53+
b.tic();
54+
for ( i = 0; i < b.iterations; i++ ) {
55+
// Use fresh copies to avoid in-place modification issues:
56+
out = dgttrf( dl.slice(), d.slice(), du.slice() );
57+
if ( typeof out !== 'object' || out === null ) {
58+
b.fail( 'should return an object' );
59+
}
60+
}
61+
b.toc();
62+
if ( typeof out !== 'object' || out === null ) {
63+
b.fail( 'should return an object' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
} );
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{{alias}}( dl, d, du )
2+
Computes the LU factorization of a real tridiagonal matrix using
3+
partial pivoting.
4+
5+
Parameters
6+
----------
7+
dl: Array
8+
Sub-diagonal (length n-1).
9+
d: Array
10+
Main diagonal (length n).
11+
du: Array
12+
Super-diagonal (length n-1).
13+
14+
Returns
15+
-------
16+
out: Object
17+
Factorization result with fields:
18+
- dl: Array, modified sub-diagonal (L multipliers).
19+
- d: Array, modified main diagonal (U diagonal).
20+
- du: Array, modified super-diagonal (U first super-diagonal).
21+
- du2: Array, second super-diagonal (used for pivoting).
22+
- ipiv: Array, pivot indices.
23+
- info: Integer, 0 if successful, or the (1-based) index of
24+
the first zero or NaN pivot.
25+
26+
Examples
27+
--------
28+
> var dgttrf = require( '@stdlib/lapack/base/dgttrf' );
29+
> var dl = [2.0, 3.0];
30+
> var d = [4.0, 5.0, 6.0];
31+
> var du = [1.0, 2.0];
32+
> var out = dgttrf(dl, d, du);
33+
> out;
34+
35+
See Also
36+
--------
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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+
// TypeScript Version: 4.1
20+
21+
/**
22+
* LU factorization result object.
23+
*/
24+
interface DgttrfResult {
25+
dl: Array<number> | Float64Array;
26+
d: Array<number> | Float64Array;
27+
du: Array<number> | Float64Array;
28+
du2: Array<number> | Float64Array;
29+
ipiv: Array<number> | Int32Array;
30+
info: number;
31+
}
32+
33+
/**
34+
* Performs LU factorization of a real tridiagonal matrix A of order n.
35+
*
36+
* @param dl - sub-diagonal array of length n-1 (will be overwritten with multipliers)
37+
* @param d - main diagonal array of length n (will be overwritten with U diagonal)
38+
* @param du - super-diagonal array of length n-1 (will be overwritten with U first super-diagonal)
39+
* @returns factorization result
40+
*
41+
* @example
42+
* var dl = [2.0, 3.0];
43+
* var d = [4.0, 5.0, 6.0];
44+
* var du = [1.0, 2.0];
45+
* var out = dgttrf(dl, d, du);
46+
* // returns { dl: [...], d: [...], du: [...], du2: [...], ipiv: [...], info: 0 }
47+
*/
48+
declare function dgttrf(
49+
dl: Array<number> | Float64Array,
50+
d: Array<number> | Float64Array,
51+
du: Array<number> | Float64Array
52+
): DgttrfResult;
53+
54+
// EXPORTS //
55+
56+
export = dgttrf;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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+
import dgttrf = require('./index');
20+
21+
// TESTS //
22+
23+
// The function returns a DgttrfResult object...
24+
{
25+
const dl = [2.0, 3.0];
26+
const d = [4.0, 5.0, 6.0];
27+
const du = [1.0, 2.0];
28+
const out = dgttrf(dl, d, du);
29+
// $ExpectType { dl: number[] | Float64Array; d: number[] | Float64Array; du: number[] | Float64Array; du2: number[] | Float64Array; ipiv: number[] | Int32Array; info: number; }
30+
}
31+
32+
// The compiler throws an error if the function is provided arguments of invalid types...
33+
{
34+
// $ExpectError
35+
dgttrf(1, [4.0, 5.0, 6.0], [1.0, 2.0]);
36+
// $ExpectError
37+
dgttrf([2.0, 3.0], 'foo', [1.0, 2.0]);
38+
// $ExpectError
39+
dgttrf([2.0, 3.0], [4.0, 5.0, 6.0], {});
40+
}
41+
42+
// The compiler throws an error if the function is provided an unsupported number of arguments...
43+
{
44+
// $ExpectError
45+
dgttrf();
46+
// $ExpectError
47+
dgttrf([2.0, 3.0]);
48+
// $ExpectError
49+
dgttrf([2.0, 3.0], [4.0, 5.0, 6.0]);
50+
// $ExpectError
51+
dgttrf([2.0, 3.0], [4.0, 5.0, 6.0], [1.0, 2.0], [0.0]);
52+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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+
var dgttrf = require( './../lib' );
22+
23+
var dl = [2.0, 3.0];
24+
var d = [4.0, 5.0, 6.0];
25+
var du = [1.0, 2.0];
26+
27+
var out = dgttrf( dl, d, du );
28+
console.log( out );
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 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+
/**
22+
* LU factorization of a real tridiagonal matrix (DGTTRF, LAPACK).
23+
*
24+
* @module @stdlib/lapack/base/dgttrf
25+
*
26+
* @example
27+
* var dgttrf = require( '@stdlib/lapack/base/dgttrf' );
28+
* var dl = [2.0, 3.0];
29+
* var d = [4.0, 5.0, 6.0];
30+
* var du = [1.0, 2.0];
31+
* var out = dgttrf( dl, d, du );
32+
* // returns { dl: [...], d: [...], du: [...], du2: [...], ipiv: [...], info: 0 }
33+
*/
34+
35+
// MODULES //
36+
37+
var main = require( './main.js' );
38+
39+
40+
// EXPORTS //
41+
42+
module.exports = main;

0 commit comments

Comments
 (0)