Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 42x 12x 12x 12x 12x 12x 12x 12x 12x 12x 24x 24x 24x 24x 24x 12x 42x 30x 90x 90x 90x 90x 90x 90x 90x 90x 180x 126x 180x 54x 54x 54x 54x 180x 90x 30x 42x 42x 42x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 12x 12x 24x 24x 24x 24x 24x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 31x 19x 57x 114x 96x 114x 18x 18x 18x 18x 114x 57x 57x 57x 57x 57x 57x 57x 57x 57x 19x 31x 31x 31x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 74x 74x 1x 1x 74x 31x 31x 31x 42x 42x 74x 3x 3x 3x 3x 3x | /** * @license Apache-2.0 * * Copyright (c) 2025 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* eslint-disable max-len, max-params */ 'use strict'; // FUNCTIONS // /** * Solve AT * X = B using the LU factorization of A computed by `dgttrf`, overwriting B with the solution. * * @private * @param {NonNegativeInteger} N - order of the matrix A * @param {NonNegativeInteger} nrhs - number of right-hand sides, i.e., the number of columns of the matrix B * @param {Float64Array} DL - multipliers that define the matrix L * @param {integer} sdl - stride length for DL * @param {NonNegativeInteger} odl - starting index of DL * @param {Float64Array} D - N diagonal elements of the upper triangular matrix U * @param {integer} sd - stride length for D * @param {NonNegativeInteger} od - starting index of D * @param {Float64Array} DU - elements of the first super-diagonal of U * @param {integer} sdu - stride length for DU * @param {NonNegativeInteger} odu - starting index of DU * @param {Float64Array} DU2 - elements of the second super-diagonal of U * @param {integer} sdu2 - stride length for DU2 * @param {NonNegativeInteger} odu2 - starting index of DU2 * @param {Int32Array} IPIV - vector of pivot indices * @param {integer} si - stride length for IPIV * @param {NonNegativeInteger} oi - starting index for IPIV * @param {Float64Array} B - right-hand side matrix B, overwritten by the solution matrix X * @param {integer} sb1 - stride of the first dimension of B * @param {integer} sb2 - stride of the second dimension of B * @param {NonNegativeInteger} ob - starting index of B * @returns {Float64Array} the solution matrix X * * @example * var Float64Array = require( '@stdlib/array/float64' ); * var Int32Array = require( '@stdlib/array/int32' ); * * var DL = new Float64Array( [ 0.25, 0.26666667 ] ); * var D = new Float64Array( [ 4.0, 3.75, 3.73333333 ] ); * var DU = new Float64Array( [ 1.0, 0.73333333 ] ); * var DU2 = new Float64Array( [ 0.0 ] ); * var IPIV = new Int32Array( [ 0, 1, 2 ] ); * var B = new Float64Array( [ 7.0, 8.0, 7.0 ] ); * * var out = transpose( 3, 1, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0, B, 1, 1, 0 ); * // out => <Float64Array>[ ~1.44, ~1.25, ~1.55 ] */ function transpose( N, nrhs, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2, odu2, IPIV, si, oi, B, sb1, sb2, ob ) { var idu2; var temp; var ipi; var idu; var idl; var id; var ib; var ip; var i; var j; ip = oi; ib = ob; idl = odl; id = od; idu = odu; idu2 = odu2; if ( nrhs <= 1 ) { for ( j = 0; j < nrhs; j++) { B[ ib + (sb2*j) ] = B[ ib + (sb2*j) ] / D[ id ]; if ( N > 1 ) { B[ ib + sb1 + (sb2*j) ] = ( B[ ib + sb1 + (sb2*j) ] - ( DU[ idu ] * B[ ib + (sb2*j) ] ) ) / D[ id + sd ]; } for ( i = 2; i < N; i++ ) { B[ ib + (sb1*i) + (sb2*j) ] = ( B[ ib + (sb1*i) + (sb2*j) ] - ( DU[ idu + (sdu*(i-1)) ] * B[ ib + (sb1*(i-1)) + (sb2*j) ] ) - ( DU2[ idu2 + (sdu2*(i-2)) ] * B[ ib + (sb1*(i-2)) + (sb2*j) ] ) ) / D[ id + (sd*i) ]; } for (i = N - 2; i >= 0; i--) { ipi = IPIV[ ip + (i*si) ]; temp = B[ ib + (sb1*i) + (sb2*j) ] - ( DL[ idl + (sdl*i) ] * B[ ib + (sb1*(i+1)) + (sb2*j) ] ); B[ ib + (sb1*i) + (sb2*j) ] = B[ ib + (sb1*ipi) + (sb2*j) ]; B[ ib + (sb1*ipi) + (sb2*j) ] = temp; } } } else { for ( j = 0; j < nrhs; j++ ) { B[ ib + (sb2*j) ] /= D[ id ]; if ( N > 1 ) { B[ ib + sb1 + (sb2*j) ] = ( B[ ib + sb1 + (sb2*j) ] - ( DU[idu] * B[ ib + (sb2*j) ] ) ) / D[ id + sd ]; } for ( i = 2; i < N; i++ ) { B[ ib + (sb1*i) + (sb2*j) ] = ( B[ ib + (sb1*i) + (sb2*j) ] - ( DU[ idu + (sdu*(i-1)) ] * B[ ib + (sb1*(i-1)) + (sb2*j) ] ) - ( DU2[ idu2 + (sdu2*(i-2)) ] * B[ ib + (sb1*(i-2)) + (sb2*j) ] ) ) / D[ id + (sd*i) ]; } for ( i = N - 2; i >= 0; i-- ) { if ( IPIV[ ip + (i * si) ] === i ) { B[ ib + (sb1*i) + (sb2*j) ] -= DL[ idl + (sdl*i) ] * B[ ib + (sb1*(i+1)) + (sb2*j) ]; } else { temp = B[ ib + (sb1*(i+1)) + (sb2*j) ]; B[ ib + (sb1*(i+1)) + (sb2*j) ] = B[ ib + (sb1*i) + (sb2*j) ] - ( DL[ idl + (sdl*i) ] * temp ); B[ ib + (sb1*i) + (sb2*j) ] = temp; } } } } return B; } /** * Solve A * X = B using the LU factorization of A computed by `dgttrf`, overwriting B with the solution. * * @private * @param {NonNegativeInteger} N - order of the matrix A * @param {NonNegativeInteger} nrhs - number of right-hand sides, i.e., the number of columns of the matrix B * @param {Float64Array} DL - multipliers that define the matrix L * @param {integer} sdl - stride length for DL * @param {NonNegativeInteger} odl - starting index of DL * @param {Float64Array} D - N diagonal elements of the upper triangular matrix U * @param {integer} sd - stride length for D * @param {NonNegativeInteger} od - starting index of D * @param {Float64Array} DU - elements of the first super-diagonal of U * @param {integer} sdu - stride length for DU * @param {NonNegativeInteger} odu - starting index of DU * @param {Float64Array} DU2 - elements of the second super-diagonal of U * @param {integer} sdu2 - stride length for DU2 * @param {NonNegativeInteger} odu2 - starting index of DU2 * @param {Int32Array} IPIV - vector of pivot indices * @param {integer} si - stride length for IPIV * @param {NonNegativeInteger} oi - starting index for IPIV * @param {Float64Array} B - right-hand side matrix B, overwritten by the solution matrix X * @param {integer} sb1 - stride of the first dimension of B * @param {integer} sb2 - stride of the second dimension of B * @param {NonNegativeInteger} ob - starting index of B * @returns {Float64Array} the solution matrix X * * @example * var Float64Array = require( '@stdlib/array/float64' ); * var Int32Array = require( '@stdlib/array/int32' ); * * var DL = new Float64Array( [ 0.25, 0.26666667 ] ); * var D = new Float64Array( [ 4.0, 3.75, 3.73333333 ] ); * var DU = new Float64Array( [ 1.0, 0.73333333 ] ); * var DU2 = new Float64Array( [ 0.0 ] ); * var IPIV = new Int32Array( [ 0, 1, 2 ] ); * var B = new Float64Array( [ 7.0, 8.0, 7.0 ] ); * * var out = noTranspose( 3, 1, DL, 1, 0, D, 1, 0, DU, 1, 0, DU2, 1, 0, IPIV, 1, 0, B, 1, 1, 0 ); * // out => <Float64Array>[ ~1.40, ~1.39, ~1.43 ] */ function noTranspose( N, nrhs, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2, odu2, IPIV, si, oi, B, sb1, sb2, ob ) { var temp; var idu2; var ipi; var idl; var idu; var ip; var ib; var id; var j; var i; ip = oi; ib = ob; idl = odl; id = od; idu = odu; idu2 = odu2; if ( nrhs <= 1 ) { for ( j = 0; j < nrhs; j++ ) { for ( i = 0; i < N - 1; i++ ) { ipi = IPIV[ ip+(si*i) ]; temp = B[ ib + (sb1*(i+1-ipi+i)) + (sb2*j) ] - ( DL[ idl + (i*sdl) ] * B[ ib + (sb1*ipi) + (sb2*j) ] ); B[ ib + (sb1*i) + (sb2*j) ] = B[ ib + (sb1*ipi) + (sb2*j) ]; B[ ib + (sb1*(i+1)) + (sb2*j) ] = temp; } B[ ib + (sb1*(N-1)) + (sb2*j) ] /= D[ id + (sd*(N-1)) ]; if ( N > 1 ) { B[ ib + (sb1*(N-2)) + (sb2*j) ] = ( B[ ib + (sb1*(N-2)) + (sb2*j) ] - ( DU[ idu + (sdu*(N-2)) ] * B[ ib + (sb1*(N-1)) + (sb2*j) ] ) ) / D[ id + (sd*(N-2)) ]; } for ( i = N - 3; i >= 0; i-- ) { B[ ib + (sb1*i) + (sb2*j) ] = ( B[ ib + (sb1*i) + (sb2*j) ] - ( DU[ idu + (sdu*i) ] * B[ ib + (sb1*(i+1)) + (sb2*j) ] ) - ( DU2[ idu2 + (sdu2*i) ] * B[ ib + (sb1*(i+2)) + (sb2*j) ] ) ) / D[ id + (sd*i) ]; } } } else { for ( j = 0; j < nrhs; j++ ) { for ( i = 0; i < N - 1; i++ ) { if ( IPIV[ ip + (si*i) ] === i ) { B[ ib + (sb1*(i+1)) + (sb2*j) ] -= DL[ idl + (i*sdl) ] * B[ ib + (sb1*i) + (sb2*j) ]; } else { temp = B[ ib + (sb1*i) + (sb2*j) ]; B[ ib + (sb1*i) + (sb2*j) ] = B[ ib + (sb1*(i+1)) + (sb2*j) ]; B[ ib + (sb1*(i+1)) + (sb2*j) ] = temp - ( DL[ idl + (i*sdl) ] * B[ ib + (sb1*i) + (sb2*j) ] ); } } B[ ib + (sb1*(N-1)) + (sb2*j) ] /= D[ id + (sd*(N-1)) ]; if ( N > 1 ) { B[ ib + (sb1*(N-2)) + (sb2 * j) ] = ( B[ ib + (sb1*(N-2)) + (sb2*j) ] - ( DU[ idu + (sdu*(N-2)) ] * B[ ib + (sb1*(N-1)) + (sb2*j) ] ) ) / D[ id + (sd*(N-2)) ]; } for ( i = N - 3; i >= 0; i-- ) { B[ ib + (sb1*i) + (sb2*j) ] = ( B[ ib + (sb1*i) + (sb2*j) ] - ( DU[ idu + (sdu*i) ] * B[ ib + (sb1*(i+1)) + (sb2*j) ] ) - ( DU2[ idu2 + (sdu2*i) ] * B[ ib + (sb1*(i+2)) + (sb2*j) ] ) ) / D[ id + (sd*i) ]; } } } return B; } // MAIN // /** * Solves a system of linear equations with a tri diagonal matrix using the LU factorization computed by `dgttrf`. * * ## Notes * * - To solve A * X = B (no transpose), use itrans = 0. * - To solve AT * X = B (transpose), use itrans = 1. * - To solve AT * X = B (conjugate transpose = transpose), use itrans = 2. * * @param {integer} itrans - specifies the form of the system of equations * @param {NonNegativeInteger} N - order of the matrix A * @param {NonNegativeInteger} nrhs - number of right-hand sides, i.e., the number of columns of the matrix B * @param {Float64Array} DL - multipliers that define the matrix L * @param {integer} sdl - stride length for DL * @param {NonNegativeInteger} odl - starting index of DL * @param {Float64Array} D - N diagonal elements of the upper triangular matrix U * @param {integer} sd - stride length for D * @param {NonNegativeInteger} od - starting index of D * @param {Float64Array} DU - elements of the first super-diagonal of U * @param {integer} sdu - stride length for DU * @param {NonNegativeInteger} odu - starting index of DU * @param {Float64Array} DU2 - elements of the second super-diagonal of U * @param {integer} sdu2 - stride length for DU2 * @param {NonNegativeInteger} odu2 - starting index of DU2 * @param {Int32Array} IPIV - vector of pivot indices * @param {integer} si - stride length for IPIV * @param {NonNegativeInteger} oi - starting index for IPIV * @param {Float64Array} B - right-hand side matrix B, overwritten by the solution matrix X * @param {integer} sb1 - stride of the first dimension of B * @param {integer} sb2 - stride of the second dimension of B * @param {NonNegativeInteger} ob - starting index of B * @returns {Float64Array} the solution matrix X * * @example * var Float64Array = require( '@stdlib/array/float64' ); * var Int32Array = require( '@stdlib/array/int32' ); * * var DL = new Float64Array( [ 0.25, 0.26666667 ] ); * var D = new Float64Array( [ 4.0, 3.75, 3.73333333 ] ); * var DU = new Float64Array( [ 1.0, 0.73333333 ] ); * var DU2 = new Float64Array( [ 0.0 ] ); * var IPIV = new Int32Array( [ 0, 1, 2 ] ); * var B = new Float64Array( [ 7.0, 8.0, 7.0 ] ); * * 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 ); * // out => <Float64Array>[ ~1.44, ~1.25, ~1.55 ] */ function dgtts2( itrans, N, nrhs, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2, odu2, IPIV, si, oi, B, sb1, sb2, ob ) { if ( N === 0 || nrhs === 0 ) { return B; } if ( itrans === 0 ) { // Solve A * X = B using the LU factorization of A, overwriting B with the solution return noTranspose( N, nrhs, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2, odu2, IPIV, si, oi, B, sb1, sb2, ob ); } // Solve Solve A**T * X = B using the LU factorization of A, overwriting B with the solution. return transpose( N, nrhs, DL, sdl, odl, D, sd, od, DU, sdu, odu, DU2, sdu2, odu2, IPIV, si, oi, B, sb1, sb2, ob ); } // EXPORTS // module.exports = dgtts2; |