"Does Matlab Take Full Advantage of the BLAS Routines?"
No. At least it didn't used to and I am assuming that is still the case. The parser is responsible for translating MATLAB source code into BLAS / LAPACK calls. Some syntax will be recognized and some will not. The rules for this are not published and subject to change from release to release.
"It's my understanding that Matlab uses BLAS routines under the hood for many matrix algebra operations. Is that correct?"
Yes. But as stated above, it relies on the parser recognizing certain syntax to take advantage of this, and I don't think it recognizes every possibility.
"If so, how does Matlab handle an expression like
C = alpha*A'*B' + beta*C
... I don't expect either transpose to be formed explicitly."
I don't know about that. The MATLAB * operator is left-to-right, so the alpha*A' would theoretically be done first. That means the transpose will be done explicitly. And probably the B' will be done explicitly as well. To do otherwise you would probably have to use parentheses around the (A'*B'). But ... this all depends on the parser. I don't think the parser is smart enough to recognize this pattern, but I haven't explicitly checked this either. Would have to code this up in a mex routine and look at numerical and timing results to verify all of this.
That being said, there is more going on here than you realize. From the documentation for DGEMM here:
* SUBROUTINE DGEMM(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
:
*> DGEMM performs one of the matrix-matrix operations
*>
*> C := alpha*op( A )*op( B ) + beta*C,
You can see that the DGEMM routine performs the operation in-place for the C matrix. MATLAB would in all likelihood not do this for the syntax you proposed because of the variable-sharing stuff going on in the background. To do so, it would have to evaluate C in real-time to see if it was shared or not and if an in-place operation was safe. If it happened to be unshared at the time you executed that line of code, then it could in theory make the DGEMM call directly. If it happened to be shared at the time you executed that line of code, then it would have to unshare it first before making the DGEMM call. Could be done, but I doubt the parser is smart enough to translate that line of code into the required code branching stuff needed to make it work properly. Because of all this, I highly doubt that MATLAB currently calls DGEMM directly for this particular line of code. A mex routine would be needed to verify what it actually does.
E.g., Windows R2021a
>> alpha = 1e300;
>> A = 1e300 * ones(2,2);
>> B = 1e-300 * ones(2,2);
>> alpha * A' * B'
ans =
Inf Inf
Inf Inf
>> alpha * (A' * B')
ans =
1.0e+300 *
2.0000 2.0000
2.0000 2.0000
It's clear that the leftmost * operation is done first. And online MATLAB:
alpha * A' * B'
ans =
Inf Inf
Inf Inf
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
We would expect inf for the answer if the leftmost * is done first, and that is what we got.