Matrix Product optimization with Bsxfun

9 visualizaciones (últimos 30 días)
Davide Agostinelli
Davide Agostinelli el 5 de Nov. de 2022
Comentada: Bruno Luong el 5 de Nov. de 2022
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
Steven Lord
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
Davide Agostinelli el 5 de Nov. de 2022
OK, thanbk you Steven.

Iniciar sesión para comentar.

Respuesta aceptada

Bruno Luong
Bruno Luong el 5 de Nov. de 2022
Editada: Bruno Luong el 5 de Nov. de 2022
You simply cannot invent something that does not exist (support) in MATLAB, the function mtimes is not supported by bsxfun see fun — Binary function to apply
Beside that I have the hard time to figure out what you would ;do with matrix multiplication with expansion
  14 comentarios
Rik
Rik el 5 de Nov. de 2022
Note that there is a big difference between ' and .' for complex data, and only you know which one you mean:
A=[1 1+i];
A' , A.'
ans =
1.0000 + 0.0000i 1.0000 - 1.0000i
ans =
1.0000 + 0.0000i 1.0000 + 1.0000i
Bruno Luong
Bruno Luong el 5 de Nov. de 2022
The runtime should be about the same even for complex data between matrix vector multiplcation with ' and .', since it takes care by the Blas and there is no conjugate explicitly performed.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by