Speed up reshape/ not use reshape Matlab

走远了吗. 提交于 2019-12-12 03:14:40

问题


I have this operation which is called multiple times:

longRowVector;
matrix = reshape(longRowVector, n, n)';
answer = matrix(:);

This operation using reshape is slow. Is there a way to get to answer without using reshape.


回答1:


There is no easy way to speed that up. if n exceeds a certain number (defined by your relevant cache size), the way in which the memory accesses will be ordered during the transpose operator. The cost is actually create in the transpose operation. Below i plot this cost for different matrix sizes. There is a jump at around 360, which is consistent with the cache size on my processor.

If you want to avoid this hit, then you need to create your "cache-optimized" reordering strategy, i.e. perform the reordering in m*m tiles where both of the vectors will fit in the cache.



来源:https://stackoverflow.com/questions/34831118/speed-up-reshape-not-use-reshape-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!