开发者

Why is vectorization beneficial for Matlab programs? Is it the same for NumPy and Boost(uBLAS)?

Using vectorization to replace for-loops may increase Matlab programs' speed significantly. Is it because the vectorized codes are runned in parallel?

Is vectorizatio开发者_运维知识库n also beneficial for program using NumPy or uBLAS?


"Vectorized" code is usually faster in interpreted environments like Matlab and numpy because the vectorized versions often (but not always) run pre-compiled and optimized code written in C or FORTRAN. Parallel execution may, or may not, play a role in this.

Use vectorization in numpy usually results in performance improvement for this reason - often the routines are compiled C or FORTRAN which run much faster than native python code which must be run on the interpreter. Also numpy, being written largely in C, can sidestep the python global interpreter lock, which can greatly improve responsiveness in python code which uses threads.


I think that part of what makes vectorization faster is that it reduces the overhead associated with multiple function calls. Passing a vector to a function corresponds to a single call, whereas individually passing each element of that vector to the function corresponds to multiple calls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜