Skip to content

Commit f22e05a

Browse files
committed
docs: add README and update examples
--- 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: passed - 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 518459c commit f22e05a

File tree

4 files changed

+311
-11
lines changed

4 files changed

+311
-11
lines changed
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
<!-- lint disable max-len -->
22+
23+
# dgtts2
24+
25+
> Solve a system of linear equations with a tridiagonal matrix using the LU factorization computed by [dgttrf][lapack-dgttrf].
26+
27+
<section class="usage">
28+
29+
## Usage
30+
31+
```javascript
32+
var dgtts2 = require( '@stdlib/lapack/base/dgtts2' );
33+
```
34+
35+
#### dgtts2( order, itrans, N, nrhs, DL, D, DU, DU2, IPIV, B, LDB )
36+
37+
Solves a system of linear equations with a tri diagonal matrix using the LU factorization computed by [dgttrf][lapack-dgttrf].
38+
39+
```javascript
40+
var Float64Array = require( '@stdlib/array/float64' );
41+
var Int32Array = require( '@stdlib/array/int32' );
42+
43+
var DL = new Float64Array( [ 0.25, 0.26666667 ] );
44+
var D = new Float64Array( [ 4.0, 3.75, 3.73333333 ] );
45+
var DU = new Float64Array( [ 1.0, 0.73333333 ] );
46+
var DU2 = new Float64Array( [ 0.0 ] );
47+
var IPIV = new Int32Array( [ 0, 1, 2 ] );
48+
var B = new Float64Array( [ 7.0, 8.0, 7.0 ] );
49+
50+
var out = dgtts2( 'column-major', 1, 3, 1, DL, D, DU, DU2, IPIV, B, 3 );
51+
// out => <Float64Array>[ ~1.44, ~1.25, ~1.55 ]
52+
```
53+
54+
The function has the following parameters:
55+
56+
- **order**: storage layout.
57+
- **itrans**: specifies the form of the system of equations.
58+
- **N**: order of the matrix `A`.
59+
- **nrhs**: number of right-hand sides, i.e., the number of columns of the matrix `B`.
60+
- **DL**: multipliers that define the matrix `L`.
61+
- **D**: diagonal elements of the upper triangular matrix `U`.
62+
- **DU**: elements of the first super-diagonal of `U`.
63+
- **DU2**: elements of the second super-diagonal of `U`.
64+
- **IPIV**: vector of pivot indices.
65+
- **B**: right-hand side matrix B, overwritten by the solution matrix `X`.
66+
- **LDB**: stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`).
67+
68+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
69+
70+
<!-- eslint-disable stdlib/capitalized-comments -->
71+
72+
```javascript
73+
var Float64Array = require( '@stdlib/array/float64' );
74+
var Int32Array = require( '@stdlib/array/int32' );
75+
76+
// Initial arrays...
77+
var DL0 = new Float64Array( [ 0.0, 0.25, 0.26666667 ] );
78+
var D0 = new Float64Array( [ 0.0, 4.0, 3.75, 3.73333333 ] );
79+
var DU0 = new Float64Array( [ 0.0, 1.0, 0.73333333 ] );
80+
var DU20 = new Float64Array( [ 0.0, 0.0 ] );
81+
var IPIV0 = new Int32Array( [ 0, 0, 1, 2 ] );
82+
var B0 = new Float64Array( [ 0.0, 7.0, 8.0, 7.0 ] );
83+
84+
// Create offset views...
85+
var DL = new Float64Array( DL0.buffer, DL0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
86+
var D = new Float64Array( D0.buffer, D0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
87+
var DU = new Float64Array( DU0.buffer, DU0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
88+
var DU2 = new Float64Array( DU20.buffer, DU20.BYTES_PER_ELEMENT*1 ); // start at 2nd element
89+
var IPIV = new Int32Array( IPIV0.buffer, IPIV0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
90+
var B = new Float64Array( B0.buffer, B0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
91+
92+
dgtts2( 'column-major', 1, 3, 1, DL, D, DU, DU2, IPIV, B, 3 );
93+
// B0 => <Float64Array>[ 0.0, ~1.44, ~1.25, ~1.55 ]
94+
```
95+
96+
#### dgtts2.ndarray( itrans, N, nrhs, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2, odu2, IPIV, si, oi, B, sb1, sb2, ob )
97+
98+
Solves a system of linear equations with a tri diagonal matrix using the LU factorization computed by [dgttrf][lapack-dgttrf] and alternative indexing semantics.
99+
100+
```javascript
101+
var Float64Array = require( '@stdlib/array/float64' );
102+
var Int32Array = require( '@stdlib/array/int32' );
103+
104+
var DL = new Float64Array( [ 0.25, 0.26666667 ] );
105+
var D = new Float64Array( [ 4.0, 3.75, 3.73333333 ] );
106+
var DU = new Float64Array( [ 1.0, 0.73333333 ] );
107+
var DU2 = new Float64Array( [ 0.0 ] );
108+
var IPIV = new Int32Array( [ 0, 1, 2 ] );
109+
var B = new Float64Array( [ 7.0, 8.0, 7.0 ] );
110+
111+
var out = dgtts2.ndarray( 1, 3, 1, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0, B, 1, 1, 0 );
112+
// out => <Float64Array>[ ~1.44, ~1.25, ~1.55 ]
113+
```
114+
115+
The function has the following parameters:
116+
117+
- **itrans**: specifies the form of the system of equations.
118+
- **N**: order of the matrix `A`.
119+
- **nrhs**: number of right-hand sides, i.e., the number of columns of the matrix `B`.
120+
- **DL**: multipliers that define the matrix `L`.
121+
- **sdl**: stride length for `DL`.
122+
- **odl**: starting index for `DL`.
123+
- **D**: diagonal elements of the upper triangular matrix `U`.
124+
- **sd**: stride length for `D`.
125+
- **od**: starting index for `D`.
126+
- **DU**: elements of the first super-diagonal of `U`.
127+
- **sdu**: stride length for `DU`.
128+
- **odu**: starting index for `DU`.
129+
- **DU2**: elements of the second super-diagonal of `U`.
130+
- **sdu2**: stride length for `DU2`.
131+
- **odu2**: starting index for `DU2`.
132+
- **IPIV**: vector of pivot indices.
133+
- **si**: stride length for `IPIV`.
134+
- **oi**: starting index for `IPIV`.
135+
- **B**: right-hand side matrix B, overwritten by the solution matrix `X`.
136+
- **sb1**: stride length for first dimension of `B`.
137+
- **sb2**: stride length for second dimension of `B`.
138+
- **ob**: starting index for `B`.
139+
140+
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,
141+
142+
```javascript
143+
var Float64Array = require( '@stdlib/array/float64' );
144+
var Int32Array = require( '@stdlib/array/int32' );
145+
146+
var DL = new Float64Array( [ 0.0, 0.25, 0.26666667 ] );
147+
var D = new Float64Array( [ 0.0, 4.0, 3.75, 3.73333333 ] );
148+
var DU = new Float64Array( [ 0.0, 1.0, 0.73333333 ] );
149+
var DU2 = new Float64Array( [ 0.0, 0.0 ] );
150+
var IPIV = new Int32Array( [ 0, 0, 1, 2 ] );
151+
var B = new Float64Array( [ 0.0, 7.0, 8.0, 7.0 ] );
152+
153+
var out = dgtts2.ndarray( 1, 3, 1, DL, 1, 1, D, 1, 1, DU, 1, 1, DU2, 1, 1, IPIV, 1, 1, B, 1, 1, 1 );
154+
// out => <Float64Array>[ 0.0, ~1.44, ~1.25, ~1.55 ]
155+
```
156+
157+
</section>
158+
159+
<!-- /.usage -->
160+
161+
<section class="notes">
162+
163+
## Notes
164+
165+
- `dgtts2()` corresponds to the [LAPACK][lapack] routine [`dgtts2`][lapack-dgtts2].
166+
167+
</section>
168+
169+
<!-- /.notes -->
170+
171+
<section class="examples">
172+
173+
## Examples
174+
175+
<!-- eslint no-undef: "error" -->
176+
177+
```javascript
178+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
179+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
180+
var Float64Array = require( '@stdlib/array/float64' );
181+
var Int32Array = require( '@stdlib/array/int32' );
182+
var dgtts2 = require( '@stdlib/lapack/base/dgtts2' );
183+
184+
var shape = [ 3, 3 ];
185+
var order = 'row-major';
186+
var strides = shape2strides( shape, order );
187+
188+
var B = new Float64Array( [ 7.0, 8.0, 7.0, 2.0, 3.0, 4.0, 1.0, 1.5, 2.0 ] );
189+
console.log( ndarray2array( B, shape, strides, 0, order ) );
190+
191+
var DL = new Float64Array( [ 0.25, 0.26666667 ] );
192+
var D = new Float64Array( [ 4.0, 3.75, 3.73333333 ] );
193+
var DU = new Float64Array( [ 1.0, 0.73333333 ] );
194+
var DU2 = new Float64Array( [ 0.0 ] );
195+
var IPIV = new Int32Array( [ 0, 1, 2 ] );
196+
197+
var X = dgtts2( 'row-major', 1, 3, 3, DL, D, DU, DU2, IPIV, B, 3 );
198+
console.log( ndarray2array( X, shape, strides, 0, order ) );
199+
```
200+
201+
</section>
202+
203+
<!-- /.examples -->
204+
205+
<!-- C interface documentation. -->
206+
207+
* * *
208+
209+
<section class="c">
210+
211+
## C APIs
212+
213+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
214+
215+
<section class="intro">
216+
217+
</section>
218+
219+
<!-- /.intro -->
220+
221+
<!-- C usage documentation. -->
222+
223+
<section class="usage">
224+
225+
### Usage
226+
227+
```c
228+
TODO
229+
```
230+
231+
#### TODO
232+
233+
TODO.
234+
235+
```c
236+
TODO
237+
```
238+
239+
TODO
240+
241+
```c
242+
TODO
243+
```
244+
245+
</section>
246+
247+
<!-- /.usage -->
248+
249+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
250+
251+
<section class="notes">
252+
253+
</section>
254+
255+
<!-- /.notes -->
256+
257+
<!-- C API usage examples. -->
258+
259+
<section class="examples">
260+
261+
### Examples
262+
263+
```c
264+
TODO
265+
```
266+
267+
</section>
268+
269+
<!-- /.examples -->
270+
271+
</section>
272+
273+
<!-- /.c -->
274+
275+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
276+
277+
<section class="related">
278+
279+
</section>
280+
281+
<!-- /.related -->
282+
283+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
284+
285+
<section class="links">
286+
287+
[lapack]: https://www.netlib.org/lapack/explore-html/
288+
289+
[lapack-dgtts2]: https://www.netlib.org/lapack/explore-html/d2/dea/group__gtts2_gae123fb2b13f2398457e4c47f5c7f7fcd.html#gae123fb2b13f2398457e4c47f5c7f7fcd
290+
291+
[lapack-dgttrf]: https://www.netlib.org/lapack/explore-html/d6/d46/group__gttrf_ga8d1e46216e6c861c89bd4328b8be52a1.html#ga8d1e46216e6c861c89bd4328b8be52a1
292+
293+
[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
294+
295+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
296+
297+
</section>
298+
299+
<!-- /.links -->
300+

lib/node_modules/@stdlib/lapack/base/dgtts2/lib/base.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
* var IPIV = new Int32Array( [ 0, 1, 2 ] );
6161
* var B = new Float64Array( [ 7.0, 8.0, 7.0 ] );
6262
*
63-
* transpose( 3, 1, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0, B, 1, 1, 0 );
64-
* // B => <Float64Array>[ 1.4365079379889456, 1.2539682480442178, 1.5476190504889455 ]
63+
* var out = transpose( 3, 1, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0, B, 1, 1, 0 );
64+
* // out => <Float64Array>[ ~1.44, ~1.25, ~1.55 ]
6565
*/
6666
function transpose( N, nrhs, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2, odu2, IPIV, si, oi, B, sb1, sb2, ob ) {
6767
var idu2;
@@ -160,8 +160,8 @@ function transpose( N, nrhs, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2, o
160160
* var IPIV = new Int32Array( [ 0, 1, 2 ] );
161161
* var B = new Float64Array( [ 7.0, 8.0, 7.0 ] );
162162
*
163-
* noTranspose( 3, 1, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0, B, 1, 1, 0 );
164-
* // B => <Float64Array>[ 1.4031746026466836, 1.3873015894132654, 1.4285714242665817 ]
163+
* var out = noTranspose( 3, 1, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0, B, 1, 1, 0 );
164+
* // out => <Float64Array>[ ~1.40, ~1.39, ~1.43 ]
165165
*/
166166
function noTranspose( N, nrhs, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2, odu2, IPIV, si, oi, B, sb1, sb2, ob ) {
167167
var temp;
@@ -266,8 +266,8 @@ function noTranspose( N, nrhs, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2,
266266
* var IPIV = new Int32Array( [ 0, 1, 2 ] );
267267
* var B = new Float64Array( [ 7.0, 8.0, 7.0 ] );
268268
*
269-
* base( 1, 3, 1, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0, B, 1, 1, 0 );
270-
* // B => <Float64Array>[ 1.4365079379889456, 1.2539682480442178, 1.5476190504889455 ]
269+
* var out = base( 1, 3, 1, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0, B, 1, 1, 0 );
270+
* // out => <Float64Array>[ ~1.44, ~1.25, ~1.55 ]
271271
*/
272272
function base( itrans, N, nrhs, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2, odu2, IPIV, si, oi, B, sb1, sb2, ob ) {
273273
if ( N === 0 || nrhs === 0 ) {

lib/node_modules/@stdlib/lapack/base/dgtts2/lib/dgtts2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var base = require( './base.js' );
3535
* @param {NonNegativeInteger} N - order of the matrix A
3636
* @param {NonNegativeInteger} nrhs - number of right-hand sides, i.e., the number of columns of the matrix B
3737
* @param {Float64Array} DL - multipliers that define the matrix L
38-
* @param {Float64Array} D - N diagonal elements of the upper triangular matrix U
38+
* @param {Float64Array} D - diagonal elements of the upper triangular matrix U
3939
* @param {Float64Array} DU - elements of the first super-diagonal of U
4040
* @param {Float64Array} DU2 - elements of the second super-diagonal of U
4141
* @param {Int32Array} IPIV - vector of pivot indices

lib/node_modules/@stdlib/lapack/base/dgtts2/lib/ndarray.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ var base = require( './base.js' );
4747
* @param {integer} si - stride length for IPIV
4848
* @param {NonNegativeInteger} oi - starting index for IPIV
4949
* @param {Float64Array} B - right-hand side matrix B, overwritten by the solution matrix X
50-
* @param {integer} sb1 - stride of the first dimension of B
51-
* @param {integer} sb2 - stride of the second dimension of B
50+
* @param {integer} sb1 - stride length for the first dimension of B
51+
* @param {integer} sb2 - stride for the second dimension of B
5252
* @param {NonNegativeInteger} ob - starting index of B
5353
* @returns {Float64Array} the solution matrix X
5454
*
@@ -63,8 +63,8 @@ var base = require( './base.js' );
6363
* var IPIV = new Int32Array( [ 0, 1, 2 ] );
6464
* var B = new Float64Array( [ 7.0, 8.0, 7.0 ] );
6565
*
66-
* dgtts2( 1, 3, 1, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0, B, 1, 1, 0 );
67-
* // B => <Float64Array>[ 1.4365079379889456, 1.2539682480442178, 1.5476190504889455 ]
66+
* var out = dgtts2( 1, 3, 1, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0, B, 1, 1, 0 );
67+
* // out => <Float64Array>[ ~1.44, ~1.25, ~1.55 ]
6868
*/
6969
function dgtts2( itrans, N, nrhs, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2, odu2, IPIV, si, oi, B, sb1, sb2, ob ) { // eslint-disable-line max-len, max-params
7070
return base( itrans, N, nrhs, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2, odu2, IPIV, si, oi, B, sb1, sb2, ob ); // eslint-disable-line max-len

0 commit comments

Comments
 (0)