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!
