NumPy is a Python library for scientific computing and is often used in fields such as data mining or machine learning or scientific statistics .
In the actual business, in order to play NumPy's high performance, when compiling numpy, it relies on some specially optimized third-party scientific computing libraries. For first-time newcomers to numpy, it is often not a simple task to install a numpy that relies on an external library from source code compilation .
In fact, theNumPy python package itself can be compiled and installed without relying on any third-party libraries , but its computational performance is affected .
This note notes how to compile and use numpy without relying on external libraries, in order to clarify the relationship between NumPy and third-party libraries (I believe many numpy beginners will not be clear numpy and a few rare third-party library relationship, that there is no third party libraries will not compile using numpy).
Note 1: The following installation of the NumPy package is done with virtualenv in an isolated Python environment, so assume that we have passed "Virtualenv numpy-env" The command creates and enters the isolated environment through the activate operation.
NOTE 2: the GCC version used in this note is a 3.4.5 version of GCC, but it is still possible to compile the latest version of the NumPy v1.9.2.
1. High-performance numpy packages typically rely on Lapack and Atlas libraries
Lapack and Atlas are two of the most highly powerful tool libraries for linear algebra operations in the field of scientific computing, and their descriptions can be viewed separately on the LAPACK website and Description of the Atlas website.
Often with these two libraries appear together with a Blas library, its official website is here.
For the relationship between these 3 libraries, you can refer to StackOverflow's question and answer post, what's the relation between BLAS, LAPACK and ATLAS .
2. How to compile numpy without relying on third-party computing libraries
According to NumPy official documentation building and installing numpy in the building from source section about linear Algebra libraries, these two libraries are not mandatory for installing numpy packages.
Here are the steps to compile/install the NumPy package without relying on the Lapack and Atlas libraries.
Download the NumPy source code from the official website (take the latest version of numpy-1.9.2.tar.gz as an example), unzip and CD to unzip the directory, you can install the non-optimized NumPy library by the following methods:
$ export blas=none$ export lapack=none$ export atlas=none$ python setup.py build > bld.log$ python setup.py install
After the compilation/installation is complete, you can verify that:
>>> import numpy>>> numpy.__version__ ' 1.9.2 '
Examples of complex points:
>>> import NumPy as NP >>> from numpy.linalg import *>>> >>> a = Np.array ([[1.0, 2 .0], [3.0, 4.0]]) >>> print a[[1. 2.] [3. 4.]]>>> a.transpose () array ([[1., 3.], [2., 4.]) >>> INV (a) array ([[ -2., 1.], [1.5,-0.5]])
It can be seen that numpy, which does not rely on any third-party computing libraries, is really working.
3. How does it affect numpy without relying on third-party computing libraries
So far, although it did compile successfully and use numpy properly, looking at the Bld.log log file of the compilation process output, you can see a hint:
Building extension "Numpy.linalg.lapack_lite" sourcescreating build/src.linux-x86_64-2.7/numpy/linalg### Warning: Using unoptimized Lapack # # # adding ' numpy/linalg/lapack_litemodule.c ' to sources. Adding ' numpy/linalg/lapack_lite/python_xerbla.c ' to sources. Adding ' numpy/linalg/lapack_lite/zlapack_lite.c ' to sources. Adding ' numpy/linalg/lapack_lite/dlapack_lite.c ' to sources. Adding ' numpy/linalg/lapack_lite/blas_lite.c ' to sources. Adding ' numpy/linalg/lapack_lite/dlamch.c ' to sources. Adding ' numpy/linalg/lapack_lite/f2c_lite.c ' to sources.building extension "Numpy.linalg._umath_linalg" sources### Warning:using unoptimized Lapack # # # adding ' numpy/linalg/umath_linalg.c.src ' to sources. Adding ' numpy/linalg/lapack_lite/python_xerbla.c ' to sources. Adding ' numpy/linalg/lapack_lite/zlapack_lite.c ' to sources. Adding ' numpy/linalg/lapack_lite/dlapack_lite.c ' to sources. Adding ' numpy/linalg/lapack_lite/blas_lite.c ' to sources. Adding ' numpy/linalg/lapack_lite/dlamch.c 'to sources. Adding ' numpy/linalg/lapack_lite/f2c_lite.c ' to sources.conv_template:> build/src.linux-x86_64-2.7/numpy/linalg /umath_linalg.c
of which, "warning:using unoptimized lapack"indicates that when compiling numpy-related linear algebra libraries (LINALG), the Lapack library is an unmodified implementation of NumPy's own.
some of the relevant notes are as follows:
1) View the source code under the Numpy-1.9.2/numpy/linalg directory to see that the lapack_litemodule.c file is the "interface" file for the C language extension library numpy for Python, This file defines a series of interface functions that Python interacts with C. Have writtenPython C extension, it should be easy to see, there is no fat
2)several C files under the Linalg/lapack_lite directory are implementation files of NumPy's own non-optimized linear algebra algorithm
3) after the installation will blas/lapack/atlas several environment variables export to none, the NumPy setup script will not attempt to search for the optimized versions of these libraries under other paths, at which point the compilation script uses its own linalg/ Lapack_lite Meshrecorded by the non-optimized implementation of the compilation of the dynamic library lapack_lite.so for the upper layer of the Python application call
In summary,whether NumPy relies on lapack and Atlas libraries, the main impact is its performance, and its functionality is unaffected.
In addition, in a real-world development environment, where numpy is often used for scipy, scipy is dependent on the Lapack and Atlas libraries, so numpy libraries used in real projects often rely on Lapack and Atlas.
The NumPy library that relies on Lapack and Atlas libraries from source code often requires a few caveats, and the next note will give a description.
Resources
1. NumPy official website
2. LAPACK official website
3. Atlas Website
4. Blas official website
5. Stackoverflow-what is the relation between BLAS, LAPACK and ATLAS
6. Building and installing NumPy
7. scipy.org- Building from Source on Linux
====================== EOF ======================
How Python notes compiles numpy packages that do not rely on the Lapack and Atlas libraries