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!
