Matrix Product optimization with Bsxfun
Mostrar comentarios más antiguos
Dear community,
i am looking to do:
A % --> 128 x 128 (matrix)
B % --> 1 x 128 (vector)
And i need to calculate (repeated 1e5 times):
D = A*B'
% that is not the element wise A.*B
For speed, i have problem by doing the fast:
D = bsxfun(@mtimes, A, B');
That should be the same but gives me error.
How can i fix this regarding dimensions?
7 comentarios
A = rand(128);
B = rand(128,1);
D = A*B'
Davide Agostinelli
el 5 de Nov. de 2022
How should
bsxfun(@mtimes,A,B')
(even if it worked) be faster than
A*B'
?
Davide Agostinelli
el 5 de Nov. de 2022
Torsten
el 5 de Nov. de 2022
It doesn't apply to your case - it's a simple matrix-vector-product without any expansion or anything.
Nothing will be faster than
D = A*B.'
Steven Lord
el 5 de Nov. de 2022
Note that this question on Stack Overflow was asked ten years ago. Much has changed in MATLAB in the past decade, including the introduction of implicit expansion in release R2016b (as one of the answers on that question mentions.)
If you're computing the matrix product of a 128-by-128 matrix and a 128-by-1 vector, you need neither bsxfun nor implicit expansion. Just use normal matrix multiplication. If that's not what you're trying to do, please explain in more detail why you're asking about bsxfun or implicit expansion.
Davide Agostinelli
el 5 de Nov. de 2022
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
