Skip to content

Commit e5cc221

Browse files
Pranavchikukgryte
authored andcommitted
feat: add lapack/base/dpttrf
PR-URL: stdlib-js#2578 Ref: stdlib-js#2464 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent 56cc029 commit e5cc221

File tree

16 files changed

+1886
-0
lines changed

16 files changed

+1886
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# dpttrf
22+
23+
> Compute the `L * D * L^T` factorization of a real symmetric positive definite tridiagonal matrix `A`.
24+
25+
<section class = "usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var dpttrf = require( '@stdlib/lapack/base/dpttrf' );
31+
```
32+
33+
#### dpttrf( N, D, E )
34+
35+
Computes the `L * D * L^T` factorization of a real symmetric positive definite tridiagonal matrix `A`.
36+
37+
```javascript
38+
var Float64Array = require( '@stdlib/array/float64' );
39+
40+
var D = new Float64Array( [ 4.0, 5.0, 6.0 ] );
41+
var E = new Float64Array( [ 1.0, 2.0 ] );
42+
43+
dpttrf( 3, D, E );
44+
// D => <Float64Array>[ 4, 4.75, ~5.15789 ]
45+
// E => <Float64Array>[ 0.25, ~0.4210 ]
46+
```
47+
48+
The function has the following parameters:
49+
50+
- **N**: order of matrix `A`.
51+
- **D**: the `N` diagonal elements of `A` as a [`Float64Array`][mdn-float64array].
52+
- **E**: the N-1 subdiagonal elements of `A` as a [`Float64Array`][mdn-float64array].
53+
54+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
55+
56+
<!-- eslint-disable stdlib/capitalized-comments -->
57+
58+
```javascript
59+
var Float64Array = require( '@stdlib/array/float64' );
60+
61+
// Initial arrays...
62+
var D0 = new Float64Array( [ 0.0, 4.0, 5.0, 6.0 ] );
63+
var E0 = new Float64Array( [ 0.0, 1.0, 2.0 ] );
64+
65+
// Create offset views...
66+
var D1 = new Float64Array( D0.buffer, D0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
67+
var E1 = new Float64Array( E0.buffer, E0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
68+
69+
dpttrf( 3, D1, E1 );
70+
// D0 => <Float64Array>[ 0.0, 4.0, 4.75, ~5.15789 ]
71+
// E0 => <Float64Array>[ 0.0, 0.25, ~0.4210 ]
72+
```
73+
74+
#### dpttrf.ndarray( N, D, strideD, offsetD, E, strideE, offsetE )
75+
76+
Computes the `L * D * L^T` factorization of a real symmetric positive definite tridiagonal matrix `A` using alternative indexing semantics.
77+
78+
```javascript
79+
var Float64Array = require( '@stdlib/array/float64' );
80+
81+
var D = new Float64Array( [ 4.0, 5.0, 6.0 ] );
82+
var E = new Float64Array( [ 1.0, 2.0 ] );
83+
84+
dpttrf.ndarray( 3, D, 1, 0, E, 1, 0 );
85+
// D => <Float64Array>[ 4, 4.75, ~5.15789 ]
86+
// E => <Float64Array>[ 0.25, ~0.4210 ]
87+
```
88+
89+
The function has the following additional parameters:
90+
91+
- **strideD**: stride length for `D`.
92+
- **offsetD**: starting index for `D`.
93+
- **strideE**: stride length for `E`.
94+
- **offsetE**: starting index for `E`.
95+
96+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example,
97+
98+
<!-- eslint-disable max-len -->
99+
100+
```javascript
101+
var Float64Array = require( '@stdlib/array/float64' );
102+
103+
var D = new Float64Array( [ 0.0, 4.0, 5.0, 6.0 ] );
104+
var E = new Float64Array( [ 0.0, 1.0, 2.0 ] );
105+
106+
dpttrf.ndarray( 3, D, 1, 1, E, 1, 1 );
107+
// D => <Float64Array>[ 0.0, 4.0, 4.75, ~5.15789 ]
108+
// E => <Float64Array>[ 0.0, 0.25, ~0.4210 ]
109+
```
110+
111+
</section>
112+
113+
<!-- /.usage -->
114+
115+
<section class="notes">
116+
117+
## Notes
118+
119+
- Both functions mutate the input arrays `D` and `E`.
120+
121+
- Both functions return a status code indicating success or failure. A status code indicates the following conditions:
122+
123+
- `0`: factorization was successful.
124+
- `<0`: the k-th argument had an illegal value, where `-k` equals the status code value.
125+
- `0 < k < N`: the leading principal minor of order `k` is not positive and factorization could not be completed, where `k` equals the status code value.
126+
- `N`: the leading principal minor of order `N` is not positive, and factorization was completed.
127+
128+
- `dpttrf()` corresponds to the [LAPACK][LAPACK] routine [`dpttrf`][lapack-dpttrf].
129+
130+
</section>
131+
132+
<!-- /.notes -->
133+
134+
<section class="examples">
135+
136+
## Examples
137+
138+
<!-- eslint no-undef: "error" -->
139+
140+
```javascript
141+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
142+
var dpttrf = require( '@stdlib/lapack/base/dpttrf' );
143+
144+
var opts = {
145+
'dtype': 'float64'
146+
};
147+
var D = discreteUniform( 5, 1, 5, opts );
148+
console.log( D );
149+
150+
var E = discreteUniform( D.length-1, 1, 5, opts );
151+
console.log( E );
152+
153+
// Perform the `L * D * L^T` factorization:
154+
var info = dpttrf( D.length, D, E );
155+
console.log( D );
156+
console.log( E );
157+
console.log( info );
158+
```
159+
160+
</section>
161+
162+
<!-- /.examples -->
163+
164+
<!-- C interface documentation. -->
165+
166+
* * *
167+
168+
<section class="c">
169+
170+
## C APIs
171+
172+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
173+
174+
<section class="intro">
175+
176+
</section>
177+
178+
<!-- /.intro -->
179+
180+
<!-- C usage documentation. -->
181+
182+
<section class="usage">
183+
184+
### Usage
185+
186+
```c
187+
TODO
188+
```
189+
190+
#### TODO
191+
192+
TODO.
193+
194+
```c
195+
TODO
196+
```
197+
198+
TODO
199+
200+
```c
201+
TODO
202+
```
203+
204+
</section>
205+
206+
<!-- /.usage -->
207+
208+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
209+
210+
<section class="notes">
211+
212+
</section>
213+
214+
<!-- /.notes -->
215+
216+
<!-- C API usage examples. -->
217+
218+
<section class="examples">
219+
220+
### Examples
221+
222+
```c
223+
TODO
224+
```
225+
226+
</section>
227+
228+
<!-- /.examples -->
229+
230+
</section>
231+
232+
<!-- /.c -->
233+
234+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
235+
236+
<section class="related">
237+
238+
</section>
239+
240+
<!-- /.related -->
241+
242+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
243+
244+
<section class="links">
245+
246+
[lapack]: https://www.netlib.org/lapack/explore-html/
247+
248+
[lapack-dpttrf]: https://www.netlib.org/lapack/explore-html/d4/d2c/group__pttrf_ga8f112041da2b9b443f8761a1eaaf15b6.html#ga8f112041da2b9b443f8761a1eaaf15b6
249+
250+
[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
251+
252+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
253+
254+
</section>
255+
256+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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 uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var pkg = require( './../package.json' ).name;
28+
var dpttrf = require( './../lib/dpttrf.js' );
29+
30+
31+
// VARIABLES //
32+
33+
var options = {
34+
'dtype': 'float64'
35+
};
36+
37+
38+
// FUNCTIONS //
39+
40+
/**
41+
* Creates a benchmark function.
42+
*
43+
* @private
44+
* @param {PositiveInteger} len - array length
45+
* @returns {Function} benchmark function
46+
*/
47+
function createBenchmark( len ) {
48+
var D = uniform( len, 0.0, 100.0, options );
49+
var E = uniform( len, 0.0, 100.0, options );
50+
return benchmark;
51+
52+
function benchmark( b ) {
53+
var d;
54+
var i;
55+
56+
b.tic();
57+
for ( i = 0; i < b.iterations; i++ ) {
58+
d = dpttrf( len, D, E );
59+
if ( isnan( d ) ) {
60+
b.fail( 'should not return NaN' );
61+
}
62+
}
63+
b.toc();
64+
if ( isnan( d ) ) {
65+
b.fail( 'should not return NaN' );
66+
}
67+
b.pass( 'benchmark finished' );
68+
b.end();
69+
}
70+
}
71+
72+
73+
// MAIN //
74+
75+
/**
76+
* Main execution sequence.
77+
*
78+
* @private
79+
*/
80+
function main() {
81+
var len;
82+
var min;
83+
var max;
84+
var f;
85+
var i;
86+
87+
min = 1; // 10^min
88+
max = 6; // 10^max
89+
90+
for ( i = min; i <= max; i++ ) {
91+
len = pow( 10, i );
92+
f = createBenchmark( len );
93+
bench( pkg+':len='+len, f );
94+
}
95+
}
96+
97+
main();

0 commit comments

Comments
 (0)