3 ms·
Which parts are you unable to read and understand? I'm sure some of us here could help explain if you have specific questions or hangups.
by Kilenaitor 5y ago
Which parts are you unable to read and understand? I'm sure some of us here could help explain if you have specific questions or hangups.
- wheelerof4te 5y agoThe math stuff :) JavaScript code is readable, at least.
- Kilenaitor 5y agoIs "the math stuff" all the optimizations being performed e.g. vectorizing multiplication? Not trying to sound dismissive here but the core math the post is working with is actually a pretty straightforward matrix multiplication. The bulk of the discussion focuses on optimizing the execution of that straightforward multiplication algorithm [triple-nested for loop; O(n^3)] rather than making algorithmic/mathematic optimizations. And again, specific questions are easier to answer. :)
- djur 5y agoMatrix multiplication isn't exactly intuitive if you've never worked with it before.
- bruce343434 5y agoI don't understand the naming and notation of this article because the author is assuming context that I don't have. Section baseline: What are N, M, K? 3 matrices or? Laid out as a flat array, or what? `c[m * N + n] += a[m * K + k] * b[k * N + n];`, ah, apparently a b and c are the matrices? How does this work? Section body: What is the mathy "C′=αC+A⋅B"? derivative of a constant is the angle times the constant plus the dot product of A and B???
- conradludgate 5y agoThere are 3 matrices in question: A, B and C. They have dimensions (M * K), (K * N) and (M * N) respectively. They are laid out, rather than nested arrays, as a single continuous collection of bytes that can be interpreted as having a matrix shape. That's where the `m * N + n` comes from (m rows down and n cols in) C' = alpha C + A.B This is the 'generalised matrix-matrix multiplication' (GEMM) operation. It's multiplying the matrices A and B, adding it to a scales version of C and inserting it back into C. Setting alpha to 0 gets you basic matmul
- wheelerof4te 5y agoThank you for this detailed explanation. Making the matrix one-dimensional makes sense from the performance standpoint.