Implicit casting overhead from real to complex when multiplying two matrices
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Daniele Giovannini
el 11 de Ag. de 2022
Respondida: James Tursa
el 10 de Jul. de 2023
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);
tic
D1 = B*A;
toc
tic
D2 = B*C;
toc
0 comentarios
Respuesta aceptada
Benjamin Thompson
el 11 de Ag. de 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.
1 comentario
Más respuestas (1)
James Tursa
el 10 de Jul. de 2023
This is not a natively supported operation (to use your terms). Yes, the real matrix must be first upconverted to a complex matrix (deep data copy with interleaved 0's) in order to call the BLAS matrix multiply routines in the background, since the BLAS library has no mixed complex-real routines. This will be a performance hit because of the deep data copy and all those unnecessary 0 multiplies. See the related discussion and explanations here:
0 comentarios
Ver también
Categorías
Más información sobre Performance and Memory en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!