|
| 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 | + |
0 commit comments