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 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | 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 3x 3x 3x 1x 1x 1x 1x 1x 3x 2x 2x 2x 2x 2x 2x 3x 3x 9x 27x 27x 27x 9x 9x 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 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 122x 6x 6x 122x 64x 64x 64x 64x 100x 52x 52x 52x 52x 52x 122x 3x 3x 3x 113x 122x 107x 122x 12x 36x 108x 108x 108x 108x 108x 108x 108x 108x 54x 54x 54x 108x 108x 36x 12x 12x 101x 122x 82x 122x 25x 75x 225x 225x 225x 225x 225x 225x 225x 225x 171x 171x 171x 225x 225x 75x 25x 25x 76x 122x 70x 122x 12x 36x 108x 108x 108x 108x 108x 108x 108x 54x 54x 54x 54x 54x 108x 108x 36x 12x 12x 64x 122x 57x 122x 13x 39x 117x 117x 117x 117x 117x 117x 117x 63x 63x 117x 54x 54x 117x 117x 39x 13x 13x 51x 122x 45x 122x 14x 42x 24x 24x 24x 72x 72x 72x 24x 42x 126x 126x 126x 42x 42x 42x 42x 42x 126x 126x 126x 42x 42x 42x 14x 14x 37x 122x 31x 122x 12x 36x 18x 18x 18x 54x 54x 54x 18x 36x 108x 108x 108x 36x 36x 36x 36x 36x 108x 108x 108x 36x 36x 36x 12x 12x 25x 122x 19x 122x 13x 39x 117x 117x 117x 54x 81x 63x 63x 117x 117x 117x 117x 117x 117x 39x 13x 13x 12x 122x 36x 108x 108x 108x 54x 54x 54x 54x 108x 108x 108x 108x 108x 108x 108x 36x 12x 122x 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-statements, max-lines-per-function */ 'use strict'; // MODULES // var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); var f32 = require( '@stdlib/number/float64/base/to-float32' ); // FUNCTIONS // /** * Fills a matrix with zeros. * * @private * @param {NonNegativeInteger} M - number of rows * @param {NonNegativeInteger} N - number of columns * @param {Float32Array} X - matrix to fill * @param {integer} strideX1 - stride of the first dimension of `X` * @param {integer} strideX2 - stride of the second dimension of `X` * @param {NonNegativeInteger} offsetX - starting index for `X` * @returns {Float32Array} input matrix * * @example * var Float32Array = require( '@stdlib/array/float32' ); * * var X = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); * * zeros( 2, 3, X, 3, 1, 0 ); * // X => <Float32Array>[ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] * * @example * var Float32Array = require( '@stdlib/array/float32' ); * * var X = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); * * zeros( 2, 3, X, 1, 2, 0 ); * // X => <Float32Array>[ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] */ function zeros( M, N, X, strideX1, strideX2, offsetX ) { // TODO: consider moving to a separate package var dx0; var dx1; var S0; var S1; var i0; var i1; var ix; if ( isRowMajor( [ strideX1, strideX2 ] ) ) { // For row-major matrices, the last dimension has the fastest changing index... S0 = N; S1 = M; dx0 = strideX2; // offset increment for innermost loop dx1 = strideX1 - ( S0*strideX2 ); // offset increment for outermost loop } else { // column-major // For column-major matrices, the first dimension has the fastest changing index... S0 = M; S1 = N; dx0 = strideX1; // offset increment for innermost loop dx1 = strideX2 - ( S0*strideX1 ); // offset increment for outermost loop } ix = offsetX; for ( i1 = 0; i1 < S1; i1++ ) { for ( i0 = 0; i0 < S0; i0++ ) { X[ ix ] = 0.0; ix += dx0; } ix += dx1; } return X; } // MAIN // /** * Performs one of the matrix-matrix operations `B = α * op(A) * B` or `B = α * B * op(A)` where α is a scalar, `B` is an `M` by `N` matrix, A is a unit, or non-unit, upper or lower triangular matrix and `op( A )` is one of `op( A ) = A` or `op( A ) = A**T`. * * @private * @param {string} side - specifies whether `op( A )` multiplies `B` from the left or right * @param {string} uplo - specifies whether the upper or lower triangular part of the matrix `A` is supplied * @param {string} transa - specifies the form of `op( A )` to be used in matrix multiplication * @param {string} diag - specifies whether or not `A` is unit triangular * @param {NonNegativeInteger} M - number of rows in `B` * @param {NonNegativeInteger} N - number of columns in `B` * @param {number} alpha - scalar constant * @param {Float32Array} A - input matrix `A` * @param {integer} strideA1 - stride of the first dimension of `A` * @param {integer} strideA2 - stride of the second dimension of `A` * @param {NonNegativeInteger} offsetA - starting index for `A` * @param {Float32Array} B - input matrix `B` * @param {integer} strideB1 - stride of the first dimension of `B` * @param {integer} strideB2 - stride of the second dimension of `B` * @param {NonNegativeInteger} offsetB - starting index for `B` * @returns {Float32Array} `B` * * @example * var Float32Array = require( '@stdlib/array/float32' ); * * var A = new Float32Array( [ 1.0, 0.0, 0.0, 2.0, 3.0, 0.0, 4.0, 5.0, 6.0 ] ); * var B = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ] ); * * strmm( 'left', 'lower', 'no-transpose', 'unit', 3, 3, 1.0, A, 3, 1, 0, B, 3, 1, 0 ); * // B => <Float32Array>[ 1.0, 2.0, 3.0, 6.0, 9.0, 12.0, 31.0, 41.0, 51.0 ] */ function strmm( side, uplo, transa, diag, M, N, alpha, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB ) { // eslint-disable-line max-params var nonunit; var isrma; var tmp; var oa2; var ob2; var sa0; var sa1; var sb0; var sb1; var ob; var i; var j; var k; isrma = isRowMajor( [ strideA1, strideA2 ] ); nonunit = ( diag === 'non-unit' ); if ( M === 0 || N === 0 ) { return B; } if ( isrma ) { sa0 = strideA2; sa1 = strideA1; sb0 = strideB2; sb1 = strideB1; } else { sa0 = strideA1; sa1 = strideA2; sb0 = strideB1; sb1 = strideB2; } if ( alpha === 0.0 ) { zeros( M, N, B, sb0, sb1, offsetB ); return B; } if ( ( isrma && side === 'left' && uplo === 'upper' && transa === 'no-transpose' ) || ( !isrma && side === 'right' && uplo === 'lower' && transa === 'no-transpose' ) ) { for ( j = 0; j < N; j++ ) { for ( k = 0; k < M; k++ ) { ob2 = offsetB + ( k * sb1 ) + ( j * sb0 ); tmp = alpha * B[ ob2 ]; for ( i = 0; i < k; i++ ) { oa2 = offsetA + ( i * sa1 ) + ( k * sa0 ); ob = offsetB + ( i * sb1 ) + ( j * sb0 ); B[ ob ] = f32( B[ ob ] + ( tmp * A[ oa2 ] ) ); } if ( nonunit ) { oa2 = offsetA + ( k * sa1 ) + ( k * sa0 ); tmp = f32( tmp * A[ oa2 ] ); } B[ ob2 ] = tmp; } } return B; } if ( ( isrma && side === 'left' && uplo === 'lower' && transa === 'no-transpose' ) || ( !isrma && side === 'right' && uplo === 'upper' && transa === 'no-transpose' ) ) { for ( j = 0; j < N; j++ ) { for ( k = M - 1; k >= 0; k-- ) { ob2 = offsetB + ( k * sb1 ) + ( j * sb0 ); tmp = alpha * B[ ob2 ]; for ( i = k + 1; i < M; i++ ) { oa2 = offsetA + ( i * sa1 ) + ( k * sa0 ); ob = offsetB + ( i * sb1 ) + ( j * sb0 ); B[ ob ] = f32( B[ ob ] + ( tmp * A[ oa2 ] ) ); } if ( nonunit ) { oa2 = offsetA + ( k * sa1 ) + ( k * sa0 ); tmp = f32( tmp * A[ oa2 ] ); } B[ ob2 ] = tmp; } } return B; } if ( ( isrma && side === 'left' && uplo === 'upper' && transa !== 'no-transpose' ) || ( !isrma && side === 'right' && uplo === 'lower' && transa !== 'no-transpose' ) ) { for ( j = 0; j < N; j++ ) { for ( i = M - 1; i >= 0; i-- ) { ob2 = offsetB + ( i * sb1 ) + ( j * sb0 ); tmp = 0.0; for ( k = 0; k < i; k++ ) { oa2 = offsetA + ( k * sa1 ) + ( i * sa0 ); tmp += f32( A[ oa2 ] * B[ offsetB + ( k * sb1 ) + ( j * sb0 ) ] ); } if ( nonunit ) { oa2 = offsetA + ( i * sa1 ) + ( i * sa0 ); tmp = f32( tmp + ( A[ oa2 ] * B[ ob2 ] ) ); } else { tmp = f32( tmp + B[ ob2 ] ); } B[ ob2 ] = f32( alpha * tmp ); } } return B; } if ( ( isrma && side === 'left' && uplo === 'lower' && transa !== 'no-transpose' ) || ( !isrma && side === 'right' && uplo === 'upper' && transa === 'transpose' ) ) { for ( j = 0; j < N; j++ ) { for ( i = 0; i < M; i++ ) { ob2 = offsetB + ( i * sb1 ) + ( j * sb0 ); tmp = 0.0; for ( k = i + 1; k < M; k++ ) { oa2 = offsetA + ( k * sa1 ) + ( i * sa0 ); tmp += f32( A[ oa2 ] * B[ offsetB + ( k * sb1 ) + ( j * sb0 ) ] ); } if ( nonunit ) { oa2 = offsetA + ( i * sa1 ) + ( i * sa0 ); tmp = f32( tmp + ( A[ oa2 ] * B[ ob2 ] ) ); } else { tmp = f32( tmp + B[ ob2 ] ); } B[ ob2 ] = f32( alpha * tmp ); } } return B; } if ( ( isrma && side === 'right' && uplo === 'upper' && transa === 'no-transpose' ) || ( !isrma && side === 'left' && uplo === 'lower' && transa === 'no-transpose' ) ) { for ( j = N - 1; j >= 0; j-- ) { if ( nonunit ) { oa2 = offsetA + ( j * sa1 ) + ( j * sa0 ); tmp = f32( A[ oa2 ] ); for ( i = 0; i < M; i++ ) { ob2 = offsetB + ( i * sb1 ) + ( j * sb0 ); B[ ob2 ] = f32( B[ ob2 ] * tmp ); } } for ( i = 0; i < M; i++ ) { ob2 = offsetB + ( i * sb1 ) + ( j * sb0 ); B[ ob2 ] = f32( B[ ob2 ] * alpha ); } for ( k = 0; k < j; k++ ) { oa2 = offsetA + ( k * sa1 ) + ( j * sa0 ); if ( A[ oa2 ] !== 0.0 ) { tmp = f32( alpha * A[ oa2 ] ); for ( i = 0; i < M; i++ ) { ob2 = offsetB + ( i * sb1 ) + ( j * sb0 ); B[ ob2 ] = f32( B[ ob2 ] + ( tmp * B[ offsetB + ( i * sb1 ) + ( k * sb0 ) ] ) ); } } } } return B; } if ( ( isrma && side === 'right' && uplo === 'lower' && transa === 'no-transpose' ) || ( !isrma && side === 'left' && uplo === 'upper' && transa === 'no-transpose' ) ) { for ( j = 0; j < N; j++ ) { if ( nonunit ) { oa2 = offsetA + ( j * sa1 ) + ( j * sa0 ); tmp = f32( A[ oa2 ] ); for ( i = 0; i < M; i++ ) { ob2 = offsetB + ( i * sb1 ) + ( j * sb0 ); B[ ob2 ] = f32( B[ ob2 ] * tmp ); } } for ( i = 0; i < M; i++ ) { ob2 = offsetB + ( i * sb1 ) + ( j * sb0 ); B[ ob2 ] = f32( B[ ob2 ] * alpha ); } for ( k = j + 1; k < N; k++ ) { oa2 = offsetA + ( k * sa1 ) + ( j * sa0 ); if ( A[ oa2 ] !== 0.0 ) { tmp = f32( alpha * A[ oa2 ] ); for ( i = 0; i < M; i++ ) { ob2 = offsetB + ( i * sb1 ) + ( j * sb0 ); B[ ob2 ] = f32( B[ ob2 ] + ( tmp * B[ offsetB + ( i * sb1 ) + ( k * sb0 ) ] ) ); } } } } return B; } if ( ( isrma && side === 'right' && uplo === 'upper' && transa !== 'no-transpose' ) || ( !isrma && side === 'left' && uplo === 'lower' && transa !== 'no-transpose' ) ) { for ( j = 0; j < N; j++ ) { for ( i = 0; i < M; i++ ) { ob2 = offsetB + ( i * sb1 ) + ( j * sb0 ); oa2 = offsetA + ( j * sa1 ) + ( j * sa0 ); if ( nonunit ) { tmp = f32( B[ ob2 ] * A[ oa2 ] ); } else { tmp = B[ ob2 ]; } for ( k = j + 1; k < N; k++ ) { oa2 = offsetA + ( j * sa1 ) + ( k * sa0 ); tmp = f32( tmp + ( B[ offsetB + ( i * sb1 ) + ( k * sb0 ) ] * A[ oa2 ] ) ); } B[ ob2 ] = f32( alpha * tmp ); } } return B; } // ( isrma && side === 'right' && uplo === 'lower' && transa !== 'no-transpose' ) || ( !isrma && side === 'left' && uplo === 'upper' && transa !== 'no-transpose' ) for ( i = 0; i < M; i++ ) { for ( j = N - 1; j >= 0; j-- ) { ob2 = offsetB + ( i * sb1 ) + ( j * sb0 ); oa2 = offsetA + ( j * sa1 ) + ( j * sa0 ); if ( nonunit ) { tmp = f32( B[ ob2 ] * A[ oa2 ] ); } else { tmp = B[ ob2 ]; } for ( k = 0; k < j; k++ ) { oa2 = offsetA + ( j * sa1 ) + ( k * sa0 ); tmp = f32( tmp + ( B[ offsetB + ( i * sb1 ) + ( k * sb0 ) ] * A[ oa2 ] ) ); } B[ ob2 ] = f32( alpha * tmp ); } } return B; } // EXPORTS // module.exports = strmm; |