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 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | 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 191x 191x 191x 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 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 3x 3x 8x 24x 24x 24x 8x 8x 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 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 3x 3x 8x 24x 24x 24x 8x 8x 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 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 20x 20x 80x 80x 80x 80x 80x 20x 20x 10x 10x 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 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 49x 98x 98x 392x 392x 392x 392x 392x 98x 98x 49x 49x 49x 49x 49x 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 77x 77x 77x 77x 77x 77x 77x 77x 77x 12x 12x 65x 77x 3x 77x 3x 3x 65x 77x 6x 6x 59x 59x 59x 59x 59x 77x 34x 19x 2x 2x 2x 19x 3x 3x 3x 19x 77x 15x 2x 2x 2x 15x 3x 3x 3x 15x 49x 77x 25x 25x 77x 24x 24x 24x 77x 21x 21x 77x 28x 28x 28x 49x 49x 77x 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'; // MODULES // var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); var gdot = require( '@stdlib/blas/base/gdot' ).ndarray; var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' ); // VARIABLES // var bsize = blockSize( 'float64' ); // TODO: consider using a larger block size // FUNCTIONS // /** * Tests whether a provided string indicates to transpose a matrix. * * @private * @param {string} str - input string * @returns {boolean} boolean indicating whether to transpose a matrix * * @example * var bool = isTransposed( 'transpose' ); * // returns true * * @example * var bool = isTransposed( 'conjugate-transpose' ); * // returns true * * @example * var bool = isTransposed( 'no-transpose' ); * // returns false */ function isTransposed( str ) { // TODO: consider moving to a separate helper utility package return ( str !== 'no-transpose' ); } /** * Fills a matrix with zeros. * * @private * @param {NonNegativeInteger} M - number of rows * @param {NonNegativeInteger} N - number of columns * @param {Object} X - matrix object to fill * @param {Collection} X.data - matrix data to fill * @param {Array<Function>} X.accessors - array element accessors * @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 {Collection} matrix object to fill * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * * var X = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; * * zeros( 2, 3, arraylike2object( toAccessorArray( X ) ), 3, 1, 0 ); * // X => [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * * var X = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; * * zeros( 2, 3, arraylike2object( toAccessorArray( X ) ), 1, 2, 0 ); * // X => [ 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 xbuf; var set; var dx0; var dx1; var S0; var S1; var i0; var i1; var ix; // Cache references to array data: xbuf = X.data; // Cache references to element accessors: set = X.accessors[ 1 ]; 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++ ) { set( xbuf, ix, 0.0 ); ix += dx0; } ix += dx1; } return X; } /** * Scales each element in a matrix by a scalar `β`. * * @private * @param {NonNegativeInteger} M - number of rows * @param {NonNegativeInteger} N - number of columns * @param {number} beta - scalar * @param {Object} X - matrix object to fill * @param {Collection} X.data - matrix data to fill * @param {Array<Function>} X.accessors - array element accessors * @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 {Collection} matrix object to fill * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * * var X = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; * * scal( 2, 3, 5.0, arraylike2object( toAccessorArray( X ) ), 3, 1, 0 ); * // X => [ 5.0, 10.0, 15.0, 20.0, 25.0, 30.0 ] * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * * var X = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; * * scal( 2, 3, 5.0, arraylike2object( toAccessorArray( X ) ), 1, 2, 0 ); * // X => [ 5.0, 10.0, 15.0, 20.0, 25.0, 30.0 ] */ function scal( M, N, beta, X, strideX1, strideX2, offsetX ) { // TODO: consider moving to a separate package var xbuf; var get; var set; var dx0; var dx1; var S0; var S1; var i0; var i1; var ix; // Cache references to array data: xbuf = X.data; // Cache references to element accessors: get = X.accessors[ 0 ]; set = X.accessors[ 1 ]; 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++ ) { set( xbuf, ix, get( xbuf, ix ) * beta ); ix += dx0; } ix += dx1; } return X; } /** * Performs matrix multiplication using a naive algorithm which is cache-optimal when `A` is row-major and `B` is column-major. * * @private * @param {NonNegativeInteger} M - number of rows in the matrix `op(A)` and in the matrix `C` * @param {NonNegativeInteger} N - number of columns in the matrix `op(B)` and in the matrix `C` * @param {NonNegativeInteger} K - number of columns in the matrix `op(A)` and number of rows in the matrix `op(B)` * @param {number} alpha - scalar constant * @param {Object} A - first matrix object * @param {Collection} A.data - first matrix data * @param {Array<Function>} A.accessors - array element accessors * @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 {Object} B - second matrix object * @param {Collection} B.data - second matrix data * @param {Array<Function>} B.accessors - array element accessors * @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` * @param {Object} C - third matrix object * @param {Collection} C.data - third matrix data * @param {Array<Function>} C.accessors - array element accessors * @param {integer} strideC1 - stride of the first dimension of `C` * @param {integer} strideC2 - stride of the second dimension of `C` * @param {NonNegativeInteger} offsetC - starting index for `C` * @returns {Float64Array} `C` * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * * var A = [ 1.0, 2.0, 3.0, 4.0 ]; * var B = [ 1.0, 1.0, 0.0, 1.0 ]; * var C = [ 1.0, 2.0, 3.0, 4.0 ]; * * naive( 2, 2, 2, 1.0, arraylike2object( toAccessorArray( A ) ), 2, 1, 0, arraylike2object( toAccessorArray( B ) ), 2, 1, 0, arraylike2object( toAccessorArray( C ) ), 2, 1, 0 ); * // C => [ 2.0, 5.0, 6.0, 11.0 ] */ function naive( M, N, K, alpha, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB, C, strideC1, strideC2, offsetC ) { var abuf; var bbuf; var cbuf; var get; var set; var da0; var db0; var dc0; var dc1; var S0; var S1; var i0; var i1; var ia; var ib; var ic; var v; // Note on variable naming convention: S#, da#, db#, dc#, i# where # corresponds to the loop number, with `0` being the innermost loop... S0 = N; S1 = M; da0 = strideA2; db0 = strideB1; dc0 = strideC2; // offset increment for innermost loop dc1 = strideC1 - ( S0*strideC2 ); // offset increment for outermost loop // Cache references to array data: abuf = A.data; bbuf = B.data; cbuf = C.data; // Cache references to element accessors: get = C.accessors[ 0 ]; set = C.accessors[ 1 ]; ic = offsetC; for ( i1 = 0; i1 < S1; i1++ ) { ia = offsetA + ( i1*strideA1 ); for ( i0 = 0; i0 < S0; i0++ ) { ib = offsetB + ( i0*strideB2 ); v = alpha * gdot( K, abuf, da0, ia, bbuf, db0, ib ); set( cbuf, ic, get( cbuf, ic ) + v ); ic += dc0; } ic += dc1; } return C; } /** * Performs matrix multiplication using loop tiling. * * @private * @param {NonNegativeInteger} M - number of rows in the matrix `op(A)` and in the matrix `C` * @param {NonNegativeInteger} N - number of columns in the matrix `op(B)` and in the matrix `C` * @param {NonNegativeInteger} K - number of columns in the matrix `op(A)` and number of rows in the matrix `op(B)` * @param {number} alpha - scalar constant * @param {Object} A - first matrix object * @param {Collection} A.data - first matrix data * @param {Array<Function>} A.accessors - array element accessors * @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 {Object} B - second matrix object * @param {Collection} B.data - second matrix data * @param {Array<Function>} B.accessors - array element accessors * @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` * @param {Object} C - third matrix object * @param {Collection} C.data - third matrix data * @param {Array<Function>} C.accessors - array element accessors * @param {integer} strideC1 - stride of the first dimension of `C` * @param {integer} strideC2 - stride of the second dimension of `C` * @param {NonNegativeInteger} offsetC - starting index for `C` * @returns {Float64Array} `C` * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * * var A = [ 1.0, 2.0, 3.0, 4.0 ]; * var B = [ 1.0, 1.0, 0.0, 1.0 ]; * var C = [ 1.0, 2.0, 3.0, 4.0 ]; * * blocked( 2, 2, 2, 1.0, arraylike2object( toAccessorArray( A ) ), 2, 1, 0, arraylike2object( toAccessorArray( B ) ), 2, 1, 0, arraylike2object( toAccessorArray( C ) ), 2, 1, 0 ); * // C => [ 2.0, 5.0, 6.0, 11.0 ] */ function blocked( M, N, K, alpha, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB, C, strideC1, strideC2, offsetC ) { var abuf; var bbuf; var cbuf; var get; var set; var da0; var db0; var dc0; var dc1; var oa1; var ob0; var oc0; var oc1; var S0; var S1; var s0; var s1; var sk; var i0; var i1; var j0; var j1; var ia; var ib; var ic; var oa; var ob; var k; var v; // Note on variable naming convention: S#, da#, db#, dc#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... S0 = N; S1 = M; // Define increments for the innermost loop: da0 = strideA2; db0 = strideB1; dc0 = strideC2; // Cache references to array data: abuf = A.data; bbuf = B.data; cbuf = C.data; // Cache references to element accessors: get = C.accessors[ 0 ]; set = C.accessors[ 1 ]; // Iterate over blocks... for ( j1 = S1; j1 > 0; ) { if ( j1 < bsize ) { s1 = j1; j1 = 0; } else { s1 = bsize; j1 -= bsize; } oa1 = offsetA + ( j1*strideA1 ); oc1 = offsetC + ( j1*strideC1 ); for ( j0 = S0; j0 > 0; ) { if ( j0 < bsize ) { s0 = j0; j0 = 0; } else { s0 = bsize; j0 -= bsize; } ob0 = offsetB + ( j0*strideB2 ); oc0 = oc1 + ( j0*strideC2 ); // index offset for `C` for the current block dc1 = strideC1 - ( s0*strideC2 ); // loop offset increment for `C` for ( k = K; k > 0; ) { if ( k < bsize ) { sk = k; k = 0; } else { sk = bsize; k -= bsize; } oa = oa1 + ( k*strideA2 ); ob = ob0 + ( k*strideB1 ); ic = oc0; for ( i1 = 0; i1 < s1; i1++ ) { ia = oa + ( i1*strideA1 ); for ( i0 = 0; i0 < s0; i0++ ) { ib = ob + ( i0*strideB2 ); v = alpha * gdot( sk, abuf, da0, ia, bbuf, db0, ib ); set( cbuf, ic, get( cbuf, ic ) + v ); ic += dc0; } ic += dc1; } } } } return C; } // MAIN // /** * Performs the matrix-matrix operation `C = α*op(A)*op(B) + β*C` where `op(X)` is either `op(X) = X` or `op(X) = X^T`, `α` and `β` are scalars, `A`, `B`, and `C` are matrices, with `op(A)` an `M` by `K` matrix, `op(B)` a `K` by `N` matrix, and `C` an `M` by `N` matrix. * * @private * @param {string} transA - specifies whether `A` should be transposed, conjugate-transposed, or not transposed * @param {string} transB - specifies whether `B` should be transposed, conjugate-transposed, or not transposed * @param {NonNegativeInteger} M - number of rows in the matrix `op(A)` and in the matrix `C` * @param {NonNegativeInteger} N - number of columns in the matrix `op(B)` and in the matrix `C` * @param {NonNegativeInteger} K - number of columns in the matrix `op(A)` and number of rows in the matrix `op(B)` * @param {number} alpha - scalar constant * @param {Object} A - first matrix object * @param {Collection} A.data - first matrix data * @param {Array<Function>} A.accessors - array element accessors * @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 {Object} B - second matrix object * @param {Collection} B.data - second matrix data * @param {Array<Function>} B.accessors - array element accessors * @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` * @param {number} beta - scalar constant * @param {Object} C - third matrix object * @param {Collection} C.data - third matrix data * @param {Array<Function>} C.accessors - array element accessors * @param {integer} strideC1 - stride of the first dimension of `C` * @param {integer} strideC2 - stride of the second dimension of `C` * @param {NonNegativeInteger} offsetC - starting index for `C` * @returns {Float64Array} `C` * * @example * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * * var A = [ 1.0, 2.0, 3.0, 4.0 ]; * var B = [ 1.0, 1.0, 0.0, 1.0 ]; * var C = [ 1.0, 2.0, 3.0, 4.0 ]; * * ggemm( 'no-transpose', 'no-transpose', 2, 2, 2, 1.0, arraylike2object( toAccessorArray( A ) ), 2, 1, 0, arraylike2object( toAccessorArray( B ) ), 2, 1, 0, 1.0, arraylike2object( toAccessorArray( C ) ), 2, 1, 0 ); * // C => [ 2.0, 5.0, 6.0, 11.0 ] */ function ggemm( transA, transB, M, N, K, alpha, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB, beta, C, strideC1, strideC2, offsetC ) { var isrma; var isrmb; var sa1; var sa2; var sb1; var sb2; if ( M === 0 || N === 0 || ( ( beta === 1.0 ) && ( ( alpha === 0.0 ) || ( K === 0 ) ) ) ) { return C; } // Form: C = β⋅C if ( beta === 0.0 ) { C = zeros( M, N, C, strideC1, strideC2, offsetC ); } else if ( beta !== 1.0 ) { C = scal( M, N, beta, C, strideC1, strideC2, offsetC ); } // Check whether we can early return... if ( alpha === 0.0 ) { return C; } // Determine the memory layouts of `A` and `B`... isrma = isRowMajor( [ strideA1, strideA2 ] ); isrmb = isRowMajor( [ strideB1, strideB2 ] ); // Check whether we can avoid loop tiling and simply use the "naive" (cache-optimal) algorithm for performing matrix multiplication... if ( isrma ) { // orderA === 'row-major' if ( !isTransposed( transA ) ) { if ( !isrmb && !isTransposed( transB ) ) { // orderB === 'column-major' // Form: C = α⋅A⋅B + C return naive( M, N, K, alpha, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB, C, strideC1, strideC2, offsetC ); } if ( isrmb && isTransposed( transB ) ) { // orderB === 'row-major' // Form: C = α⋅A⋅B^T + C return naive( M, N, K, alpha, A, strideA1, strideA2, offsetA, B, strideB2, strideB1, offsetB, C, strideC1, strideC2, offsetC ); } } } else if ( isTransposed( transA ) ) { // orderA === 'column-major' if ( isrmb && isTransposed( transB ) ) { // orderB === 'row-major' // Form: C = α⋅A^T⋅B^T + C return naive( M, N, K, alpha, A, strideA2, strideA1, offsetA, B, strideB2, strideB1, offsetB, C, strideC1, strideC2, offsetC ); } if ( !isrmb && !isTransposed( transB ) ) { // orderB === 'column-major' // Form: C = α⋅A^T⋅B + C return naive( M, N, K, alpha, A, strideA2, strideA1, offsetA, B, strideB1, strideB2, offsetB, C, strideC1, strideC2, offsetC ); } } // Swap strides to perform transposes... if ( isTransposed( transA ) ) { sa1 = strideA2; sa2 = strideA1; } else { sa1 = strideA1; sa2 = strideA2; } if ( isTransposed( transB ) ) { sb1 = strideB2; sb2 = strideB1; } else { sb1 = strideB1; sb2 = strideB2; } // Perform loop tiling to promote cache locality: return blocked( M, N, K, alpha, A, sa1, sa2, offsetA, B, sb1, sb2, offsetB, C, strideC1, strideC2, offsetC ); } // EXPORTS // module.exports = ggemm; |