How to accelerate exponent (exp) calculation in MATLAB?

11 ビュー (過去 30 日間)
Tian
Tian 2017 年 4 月 21 日
回答済み: Rangeet Mitra 2018 年 11 月 10 日
Hello everyone. I developed a program and I find it spends lots of time on calculating exp(-ax). So is there any way to accelerate such calculations exp(-ax)? Many thanks~
  4 件のコメント
Tian
Tian 2017 年 4 月 21 日
Not a symbolic calculation, just need to calculate tens of thousands of simple exp(ax). I have tried to use arrayfun, or matrix calculation, but too much memory is required.
Walter Roberson
Walter Roberson 2017 年 4 月 21 日
ZZZ = rand(1,1E6);
timeit(@() exp(ZZZ),0)
This is about 0.0045 seconds, so even 10^8 exp() would take less than 1/2 second.

サインインしてコメントする。

採用された回答

Jan
Jan 2017 年 4 月 21 日
編集済み: Jan 2017 年 4 月 21 日
No. exp() is an expensive operation. The only way to accelerate it is to reduce repeated calls with the same argument.
I've experimented with the implementation of netlib.org, but did not found a significant acceleration and the results are lesss accurate. I assume this is the reason why it is not used in Matlab (in opposite to e.g. acos, which is taken from netlib).
A parfor loop might help to distribute the calculation to multiple cores.
Note: Think twice. If there would be a way to accelerate the computation of a specific function, it would have been included by Mathworks certainly. It is very pitty, but there are no magic tricks to make Matlab faster.
  3 件のコメント
Adam
Adam 2017 年 4 月 21 日
Make sure you vectorise calls to exp as much as yo can too.
Tian
Tian 2017 年 4 月 21 日
OK, thanks a lot.

サインインしてコメントする。

その他の回答 (1 件)

Rangeet Mitra
Rangeet Mitra 2018 年 11 月 10 日
Try replacing exp() by a custom function using a Hermite approximation for exp() (which is learnt a-priori for the dynamic range of your code). Without loss of performance, you will get a considerable speedup!!!

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!