Matrix Product optimization with Bsxfun
显示 更早的评论
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 个评论
A = rand(128);
B = rand(128,1);
D = A*B'
Davide Agostinelli
2022-11-5
How should
bsxfun(@mtimes,A,B')
(even if it worked) be faster than
A*B'
?
Davide Agostinelli
2022-11-5
Torsten
2022-11-5
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
2022-11-5
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
2022-11-5
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
