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 | 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 280x 280x 280x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 6x 6x 6x 6x 6x 6x 6x 6x 6x 4x 4x 4x 12x 6x 6x 6x 6x 6x 6x 12x 12x 24x 24x 24x 12x 6x 2x 2x 2x 6x 3x 3x 3x 3x 3x 3x 6x 6x 12x 12x 12x 6x 2x 6x 6x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 7x 7x 7x 7x 7x 7x 7x 7x 7x 6x 6x 6x 18x 12x 12x 18x 6x 6x 6x 18x 18x 36x 36x 36x 18x 7x 1x 1x 1x 3x 3x 3x 3x 3x 3x 6x 6x 6x 3x 1x 7x 7x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 60x 30x 30x 30x 30x 30x 30x 60x 60x 60x 60x 60x 120x 120x 120x 120x 60x 20x 20x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 95x 71x 71x 95x 24x 24x 24x 95x 95x 95x 263x 95x 95x 263x 168x 168x 168x 263x 263x 263x 221x 263x 84x 84x 179x 179x 263x 851x 179x 179x 851x 672x 672x 672x 851x 851x 851x 11401x 11401x 5201x 5201x 3696x 3696x 5201x 11401x 6200x 6200x 6200x 4704x 4704x 6200x 11401x 11401x 11401x 11401x 11401x 141802x 141802x 141802x 141802x 11401x 851x 263x 95x 71x 71x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 112x 112x 112x 112x 112x 112x 112x 112x 112x 12x 12x 100x 112x 6x 112x 7x 7x 100x 112x 9x 9x 91x 91x 91x 91x 91x 112x 48x 26x 4x 4x 4x 26x 6x 6x 6x 26x 112x 21x 4x 4x 4x 21x 6x 6x 6x 21x 71x 112x 33x 33x 86x 38x 38x 38x 112x 33x 33x 86x 38x 38x 38x 71x 71x 112x 3x 3x 3x 3x 3x | /**
* @license Apache-2.0
*
* Copyright (c) 2026 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 sdot = require( '@stdlib/blas/base/sdot' ).ndarray;
var blockSize = require( '@stdlib/ndarray/base/unary-tiling-block-size' );
var f32 = require( '@stdlib/number/float64/base/to-float32' );
// VARIABLES //
var bsize = blockSize( 'float32', 'float32' ); // 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 the referenced (upper or lower) triangle of a matrix with zeros.
*
* @private
* @param {string} uplo - specifies whether to reference the upper or lower triangular part of `X`
* @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( 'upper', 2, 3, X, 3, 1, 0 );
* // X => <Float32Array>[ 0.0, 0.0, 0.0, 4.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( 'upper', 2, 3, X, 1, 2, 0 );
* // X => <Float32Array>[ 0.0, 2.0, 0.0, 0.0, 0.0, 0.0 ]
*/
function zeros( uplo, M, N, X, strideX1, strideX2, offsetX ) { // TODO: consider moving to a separate package
var dx0;
var hi;
var lo;
var i0;
var i1;
var ix;
if ( isRowMajor( [ strideX1, strideX2 ] ) ) {
// For row-major matrices, the row index is the slow (outer) index and the column index is the fast (inner) index...
dx0 = strideX2;
for ( i1 = 0; i1 < M; i1++ ) {
if ( uplo === 'upper' ) {
lo = i1;
hi = N;
} else {
lo = 0;
hi = ( i1+1 < N ) ? i1+1 : N;
}
ix = offsetX + ( i1*strideX1 ) + ( lo*strideX2 );
for ( i0 = lo; i0 < hi; i0++ ) {
X[ ix ] = 0.0;
ix += dx0;
}
}
} else { // column-major
// For column-major matrices, the column index is the slow (outer) index and the row index is the fast (inner) index...
dx0 = strideX1;
for ( i1 = 0; i1 < N; i1++ ) {
if ( uplo === 'upper' ) {
lo = 0;
hi = ( i1+1 < M ) ? i1+1 : M;
} else {
lo = i1;
hi = M;
}
ix = offsetX + ( i1*strideX2 ) + ( lo*strideX1 );
for ( i0 = lo; i0 < hi; i0++ ) {
X[ ix ] = 0.0;
ix += dx0;
}
}
}
return X;
}
/**
* Scales each element in the referenced (upper or lower) triangle of a matrix by a scalar `β`.
*
* @private
* @param {string} uplo - specifies whether to reference the upper or lower triangular part of `X`
* @param {NonNegativeInteger} M - number of rows
* @param {NonNegativeInteger} N - number of columns
* @param {number} beta - scalar constant
* @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 ] );
*
* scal( 'upper', 2, 3, 5.0, X, 3, 1, 0 );
* // X => <Float32Array>[ 5.0, 10.0, 15.0, 4.0, 25.0, 30.0 ]
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
*
* var X = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
*
* scal( 'upper', 2, 3, 5.0, X, 1, 2, 0 );
* // X => <Float32Array>[ 5.0, 2.0, 15.0, 20.0, 25.0, 30.0 ]
*/
function scal( uplo, M, N, beta, X, strideX1, strideX2, offsetX ) { // TODO: consider moving to a separate package
var dx0;
var hi;
var lo;
var i0;
var i1;
var ix;
if ( isRowMajor( [ strideX1, strideX2 ] ) ) {
// For row-major matrices, the row index is the slow (outer) index and the column index is the fast (inner) index...
dx0 = strideX2;
for ( i1 = 0; i1 < M; i1++ ) {
if ( uplo === 'upper' ) {
lo = i1;
hi = N;
} else {
lo = 0;
hi = ( i1+1 < N ) ? i1+1 : N;
}
ix = offsetX + ( i1*strideX1 ) + ( lo*strideX2 );
for ( i0 = lo; i0 < hi; i0++ ) {
X[ ix ] *= beta;
ix += dx0;
}
}
} else { // column-major
// For column-major matrices, the column index is the slow (outer) index and the row index is the fast (inner) index...
dx0 = strideX1;
for ( i1 = 0; i1 < N; i1++ ) {
if ( uplo === 'upper' ) {
lo = 0;
hi = ( i1+1 < M ) ? i1+1 : M;
} else {
lo = i1;
hi = M;
}
ix = offsetX + ( i1*strideX2 ) + ( lo*strideX1 );
for ( i0 = lo; i0 < hi; i0++ ) {
X[ ix ] *= beta;
ix += dx0;
}
}
}
return X;
}
/**
* Performs matrix multiplication, updating only the referenced (upper or lower) triangle of `C`, using a naive algorithm which is cache-optimal when `A` is row-major and `B` is column-major.
*
* @private
* @param {string} uplo - specifies whether to update the upper or lower triangular part of `C`
* @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 {Float32Array} A - first matrix
* @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 - second matrix
* @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 {Float32Array} C - third matrix
* @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 {Float32Array} `C`
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
*
* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );
* var B = new Float32Array( [ 1.0, 1.0, 0.0, 1.0 ] );
* var C = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );
*
* naive( 'upper', 2, 2, 2, 1.0, A, 2, 1, 0, B, 2, 1, 0, C, 2, 1, 0 );
* // C => <Float32Array>[ 2.0, 5.0, 3.0, 11.0 ]
*/
function naive( uplo, M, N, K, alpha, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB, C, strideC1, strideC2, offsetC ) {
var da0;
var db0;
var dc0;
var hi;
var lo;
var i0;
var i1;
var ia;
var ib;
var ic;
// Note on variable naming convention: da#, db#, dc# where # corresponds to the loop number, with `0` being the innermost loop...
da0 = strideA2;
db0 = strideB1;
dc0 = strideC2;
for ( i1 = 0; i1 < M; i1++ ) {
if ( uplo === 'upper' ) {
lo = i1;
hi = N;
} else {
lo = 0;
hi = ( i1+1 < N ) ? i1+1 : N;
}
if ( lo >= hi ) {
continue;
}
ia = offsetA + ( i1*strideA1 );
ib = offsetB + ( lo*strideB2 );
ic = offsetC + ( i1*strideC1 ) + ( lo*strideC2 );
for ( i0 = lo; i0 < hi; i0++ ) {
C[ ic ] += f32( alpha * sdot( K, A, da0, ia, B, db0, ib ) );
ic += dc0;
ib += strideB2;
}
}
return C;
}
/**
* Performs matrix multiplication, updating only the referenced (upper or lower) triangle of `C`, using loop tiling.
*
* @private
* @param {string} uplo - specifies whether to update the upper or lower triangular part of `C`
* @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 {Float32Array} A - first matrix
* @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 - second matrix
* @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 {Float32Array} C - third matrix
* @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 {Float32Array} `C`
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
*
* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );
* var B = new Float32Array( [ 1.0, 1.0, 0.0, 1.0 ] );
* var C = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );
*
* blocked( 'upper', 2, 2, 2, 1.0, A, 2, 1, 0, B, 2, 1, 0, C, 2, 1, 0 );
* // C => <Float32Array>[ 2.0, 5.0, 3.0, 11.0 ]
*/
function blocked( uplo, M, N, K, alpha, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB, C, strideC1, strideC2, offsetC ) {
var da0;
var db0;
var dc0;
var oa1;
var ob0;
var oc0;
var oc1;
var S0;
var S1;
var s0;
var s1;
var sk;
var hi;
var lo;
var gr;
var i0;
var i1;
var j0;
var j1;
var ia;
var ib;
var ic;
var oa;
var ob;
var k;
// 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;
// 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;
}
// Skip blocks which lie entirely outside the referenced triangle...
if (
( uplo === 'upper' && ( j0+s0 ) <= j1 ) ||
( uplo === 'lower' && ( j1+s1 ) <= j0 )
) {
continue;
}
ob0 = offsetB + ( j0*strideB2 );
oc0 = oc1 + ( j0*strideC2 ); // index offset for `C` for the current block
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 );
for ( i1 = 0; i1 < s1; i1++ ) {
gr = j1 + i1; // global row index
if ( uplo === 'upper' ) {
lo = gr - j0;
if ( lo < 0 ) {
lo = 0;
}
hi = s0;
} else {
lo = 0;
hi = ( gr-j0 ) + 1;
if ( hi > s0 ) {
hi = s0;
}
}
if ( lo >= hi ) {
continue;
}
ia = oa + ( i1*strideA1 );
ib = ob + ( lo*strideB2 );
ic = oc0 + ( i1*strideC1 ) + ( lo*strideC2 );
for ( i0 = lo; i0 < hi; i0++ ) {
C[ ic ] += f32( alpha * sdot( sk, A, da0, ia, B, db0, ib ) );
ic += dc0;
ib += strideB2;
}
}
}
}
}
return C;
}
// MAIN //
/**
* Performs the matrix-matrix operation `uplo(C) = uplo(α*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, and only the elements in the upper or lower triangle of `C` are updated.
*
* @private
* @param {string} uplo - specifies whether to update the upper or lower triangular part of `C`
* @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 {Float32Array} A - first matrix
* @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 - second matrix
* @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 {Float32Array} C - third matrix
* @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 {Float32Array} `C`
*
* @example
* var Float32Array = require( '@stdlib/array/float32' );
*
* var A = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );
* var B = new Float32Array( [ 1.0, 1.0, 0.0, 1.0 ] );
* var C = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );
*
* sgemmtr( 'upper', 'no-transpose', 'no-transpose', 2, 2, 2, 1.0, A, 2, 1, 0, B, 2, 1, 0, 1.0, C, 2, 1, 0 );
* // C => <Float32Array>[ 2.0, 5.0, 3.0, 11.0 ]
*/
function sgemmtr( uplo, 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: uplo(C) = β⋅uplo(C)
if ( beta === 0.0 ) {
C = zeros( uplo, M, N, C, strideC1, strideC2, offsetC );
} else if ( beta !== 1.0 ) {
C = scal( uplo, 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: uplo(C) = uplo(α⋅A⋅B + C)
return naive( uplo, M, N, K, alpha, A, strideA1, strideA2, offsetA, B, strideB1, strideB2, offsetB, C, strideC1, strideC2, offsetC );
}
if ( isrmb && isTransposed( transB ) ) { // orderB === 'row-major'
// Form: uplo(C) = uplo(α⋅A⋅B^T + C)
return naive( uplo, 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: uplo(C) = uplo(α⋅A^T⋅B^T + C)
return naive( uplo, M, N, K, alpha, A, strideA2, strideA1, offsetA, B, strideB2, strideB1, offsetB, C, strideC1, strideC2, offsetC );
}
if ( !isrmb && !isTransposed( transB ) ) { // orderB === 'column-major'
// Form: uplo(C) = uplo(α⋅A^T⋅B + C)
return naive( uplo, 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( uplo, M, N, K, alpha, A, sa1, sa2, offsetA, B, sb1, sb2, offsetB, C, strideC1, strideC2, offsetC );
}
// EXPORTS //
module.exports = sgemmtr;
|