Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Source code location and explanation of vectorized array operations

Tags:

python

numpy

I am trying to locate the NumPy .c file that contains basic vectorized array operations. For instance, I'd like to know what piece of code runs when you do something simple like a scalar addition to an array like a + 5 or perform an aggregation like a.sum(). I believe the ndarray object gets declared here.

I'd also like to know if any of the linear algebra libraries like BLAS or LAPACK are involved with these basic arithmetic operations? Is the code as simple as a for-loop iterating over a C array or is there some magical way that computers do basic operations on contiguous arrays without for-loops?

like image 535
Ted Petrou Avatar asked Jul 25 '26 05:07

Ted Petrou


1 Answers

Most of that stuff is in numpy/core/src/umath/loops.c.src. This is a template file NumPy uses to generate lots and lots of very similar C functions. No BLAS or LAPACK calls are involved.

like image 188
user2357112 supports Monica Avatar answered Jul 27 '26 19:07

user2357112 supports Monica