Implicit casting overhead from real to complex when multiplying two matrices
2 views (last 30 days)
Daniele Giovannini on 11 Aug 2022
Is there an implicit casting overhead when multiplying a complex matrix by a real matrix to upcast the real matrix to complex or is it a natively-supported operation?
I have tried the following sample code but I get inconsistent results when changing the matrices dimension N.
N = 100;
A = rand(N);
B = rand(N);
C = complex(A);
D1 = B*A;
D2 = B*C;
Benjamin Thompson on 11 Aug 2022
Multiplying a complex matrix by a real matrix requires fewer calculations so should take less time. Your test is a little too simple since B would have already been cached into memory for the second part. If you do B*A twice, it is a lot faster the second time.