diff options
| author | Matti Picus <matti.picus@gmail.com> | 2019-04-10 10:55:12 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-10 10:55:12 +0300 |
| commit | 412975de43e6c5e4b6f1051f3a04968c629240c7 (patch) | |
| tree | ecbe25408af7f0f025e6afdca51bcce539678fdc | |
| parent | d6a8cabd725e93a1dcfc03f0b4154dd96fd4ce8f (diff) | |
| parent | 4401740df728ce02ce7aee39ee17bc535f8dbe76 (diff) | |
| download | numpy-412975de43e6c5e4b6f1051f3a04968c629240c7.tar.gz | |
Merge pull request #13161 from zerothi/linalg-cblas
BLD: streamlined CBLAS linkage tries, default to try libraries *as-is*
| -rw-r--r-- | numpy/distutils/system_info.py | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/numpy/distutils/system_info.py b/numpy/distutils/system_info.py index 4d923ad26..8a42434ff 100644 --- a/numpy/distutils/system_info.py +++ b/numpy/distutils/system_info.py @@ -1689,23 +1689,46 @@ class blas_info(system_info): else: info['include_dirs'] = self.get_include_dirs() if platform.system() == 'Windows': - # The check for windows is needed because has_cblas uses the + # The check for windows is needed because get_cblas_libs uses the # same compiler that was used to compile Python and msvc is # often not installed when mingw is being used. This rough # treatment is not desirable, but windows is tricky. info['language'] = 'f77' # XXX: is it generally true? else: - lib = self.has_cblas(info) + lib = self.get_cblas_libs(info) if lib is not None: info['language'] = 'c' - info['libraries'] = [lib] + info['libraries'] = lib info['define_macros'] = [('HAVE_CBLAS', None)] self.set_info(**info) - def has_cblas(self, info): + def get_cblas_libs(self, info): + """ Check whether we can link with CBLAS interface + + This method will search through several combinations of libraries + to check whether CBLAS is present: + + 1. Libraries in ``info['libraries']``, as is + 2. As 1. but also explicitly adding ``'cblas'`` as a library + 3. As 1. but also explicitly adding ``'blas'`` as a library + 4. Check only library ``'cblas'`` + 5. Check only library ``'blas'`` + + Parameters + ---------- + info : dict + system information dictionary for compilation and linking + + Returns + ------- + libraries : list of str or None + a list of libraries that enables the use of CBLAS interface. + Returns None if not found or a compilation error occurs. + + Since 1.17 returns a list. + """ # primitive cblas check by looking for the header and trying to link # cblas or blas - res = False c = customized_ccompiler() tmpdir = tempfile.mkdtemp() s = """#include <cblas.h> @@ -1724,29 +1747,26 @@ class blas_info(system_info): # check we can compile (find headers) obj = c.compile([src], output_dir=tmpdir, include_dirs=self.get_include_dirs()) + except (distutils.ccompiler.CompileError, distutils.ccompiler.LinkError): + return None - # check we can link (find library) - # some systems have separate cblas and blas libs. First - # check for cblas lib, and if not present check for blas lib. + # check we can link (find library) + # some systems have separate cblas and blas libs. + for libs in [info['libraries'], ['cblas'] + info['libraries'], + ['blas'] + info['libraries'], ['cblas'], ['blas']]: try: c.link_executable(obj, os.path.join(tmpdir, "a.out"), - libraries=["cblas"], + libraries=libs, library_dirs=info['library_dirs'], extra_postargs=info.get('extra_link_args', [])) - res = "cblas" + return libs + # This breaks the for loop + break except distutils.ccompiler.LinkError: - c.link_executable(obj, os.path.join(tmpdir, "a.out"), - libraries=["blas"], - library_dirs=info['library_dirs'], - extra_postargs=info.get('extra_link_args', [])) - res = "blas" - except distutils.ccompiler.CompileError: - res = None - except distutils.ccompiler.LinkError: - res = None + pass finally: shutil.rmtree(tmpdir) - return res + return None class openblas_info(blas_info): |
