필터 지우기
필터 지우기

bsxfun vs implicit expansion

조회 수: 11 (최근 30일)
Bradley Treeby
Bradley Treeby 2023년 9월 7일
답변: Gagan Agarwal 2023년 9월 20일
The MATLAB docs recommend that calls to bsxfun are replaced with direct calls to the functions and operators that support implicit expansion. I have seen this same recommendation in several places on the file exchange (etc). However, a simple benchmark (see attached) seems to show that bsxfun is noticably faster, at least for this particular use case I'm interested in (complex vector times a complex 2D or 3D matrix with relatively large dimensions). The output image below is running in MATLAB 2023a. I get the same trend under both Windows and Linux on both new and old hardware. Is this an expected result? I couldn't find many details of what actually happens under the hood for both of these approaches and when it might be better to use one over the other.
  댓글 수: 7
Walter Roberson
Walter Roberson 2023년 9월 8일
Historically, some of the frequent volunteers have found that bsxfun was faster for some situations but not all; implicit expansion is faster for some operations.
As far as I know, there is no guideance from Mathworks as to when each of the two would be expected to be faster.
Joss Knight
Joss Knight 2023년 9월 8일
GPU is faster because consecutive operations can be fused in the implicit case. Not sure about the CPU case. I'll ask.

댓글을 달려면 로그인하십시오.

답변 (1개)

Gagan Agarwal
Gagan Agarwal 2023년 9월 20일
Hi Bradley,
I understand that you want to know the scenarios for which ‘bxfun is preferred and the scenarios for which use of implicit expansion is preferred.
In general, it has been observed that implicit expansion tends to be faster than bsxfun. This is especially true when working with GPUs, where implicit expansion often outperforms bsxfun. However, I couldn't find any specific scenarios that definitely determine when to use one over the other. Therefore, the best approach would be to decide on a case-to-case basis.
I hope this helps!

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by