strange power .^ operator behaviour
4 ビュー (過去 30 日間)
古いコメントを表示
For vectors of length greater than >~100 elements it is more efficient to use multiple x.^2 than x.^n, where n is an integer n>=3. The performance can be ~x10-x100 better depends on the vector length and power.
Looks like that MATLAB has not optimally implemented operator '.^'. Any comments regarding this strange behaviour of ".^" operator???
11 件のコメント
Adam
2020 年 2 月 21 日
@Michal Kvasnicka - I seem to remember it was you who was making a big fuss about what should be answer vs what should be a comment not so long ago. If you want answers look in the answers section. Comments can be either read or ignored as you wish, but do at least serve the purpose of keeping your thread from falling down the board without you having to keep editing your posts regularly to achieve the same thing!
回答 (2 件)
Steven Lord
2020 年 2 月 21 日
Performance is one key metric of whether a function is "effective". If you wanted a power function that was as performant as possible, we could implement the built-in equivalent of this:
fastestPower = @(x, n) [];
Obviously that's taking things to an absurd extreme. It should go without saying but I'll say it anyway, we wouldn't do that. As one of the people who would be asked to review such a proposal that would be an OMDB (Over My Dead Body) situation. [And I can imagine how Cleve would react if someone seriously proposed that!]
But that does illustrate a serious point, that performance is not the only key metric of whether a function is "effective". Accuracy is another key metric for a function. [The absurd example above maximizes performance while minimizing accuracy.] Balancing performance and accuracy and several other key metrics across the whole spectrum of input arguments (including taking into consideration how common each use case for a function is) is a multiobjective optimization problem.
If you know of a faster algorithm that we should consider, submit it as an enhancement request through Technical Support. It may be one we have already considered and rejected for various reasons (better performance but unacceptable loss of accuracy, for example, or it only performs better in extremely specific and uncommon cases for another example.) It may be something that we evaluate (or re-evaluate) and adopt.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!