Jay
Jay

Reputation: 410

How to find the cpython source code file for a specific 3rd party (NumPy for instance) API?

This question comes from this post.

I am digging out the underlying logic for numpy.linalg.eig.

w, v = np.linalg.eig(C.T*C)
v
matrix([[-0.9486833 , -0.31622777],
        [ 0.31622777, -0.9486833 ]])

the implementation of np.linalg.eig

w, vt = _umath_linalg.eig(a, signature=signature, extobj=extobj)

is linked here, which links to _umath_linalg.py

_umath_linalg.py corresponds to <python3.6>/site-packages/numpy/linalg/_umath_linalg.cpython-36m-darwin.so

I searched lots of keywords comes from _umath_linalg.eig on the cpython source code gh repo and got nothing related.

in this case, how to find the cpython source code file for _umath_linalg.cpython-36m-darwin.so or _umath_linalg.eig?

Upvotes: 0

Views: 853

Answers (1)

MatsLindh
MatsLindh

Reputation: 52852

Exactly where the different libraries live outside of PyPi isn't a common location across all modules, but usually they're somewhere on github. In this case you're not looking for the source of cpython itself, but of the linalg module inside numpy. Asking a search engine for numpy linalg github will give you the location.

You can also use pip download to download the source code of any module available on PyPi to a directory of your choice. This can be useful for fetching a specific version and to see what has been uploaded to PyPi:

pip download numpy -d <directory>

Upvotes: 1

Related Questions