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

Using vectorization to replace for-loops can significantly increase the speed of Matlab programs. Is it because vectorized codes run in parallel?

Is vectorization useful for a program using NumPy or uBLAS?

+4
source share
2 answers

Vectorized code is usually faster in interpreted environments such as Matlab and numpy, because vectorized versions often (but not always) run precompiled and optimized code written in C or FORTRAN. Concurrent execution may or may not play a role in this.

Using vectorization in numpy usually results in better performance for this reason - often routines are compiled with C or FORTRAN, which run much faster than native Python code that must be executed on the interpreter. In addition, numpy, written primarily in C, can bypass the locking of the global python interpreter, which can significantly improve responsiveness in python code that uses threads.

+8
source

I think part of speeding up vectorization is that it reduces the overhead associated with multiple function calls. Passing a vector into a function corresponds to one call, while an individual transition of each element of this vector to a function corresponds to several calls.

+2
source

All Articles