MCPcopy Create free account
hub / github.com/numpy/numpy / get_cblas_libs

Method get_cblas_libs

numpy/distutils/system_info.py:2236–2299  ·  view source on GitHub ↗

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.

(self, info)

Source from the content-addressed store, hash-verified

2234 self.set_info(**info)
2235
2236 def get_cblas_libs(self, info):
2237 """ Check whether we can link with CBLAS interface
2238
2239 This method will search through several combinations of libraries
2240 to check whether CBLAS is present:
2241
2242 1. Libraries in ``info['libraries']``, as is
2243 2. As 1. but also explicitly adding ``'cblas'`` as a library
2244 3. As 1. but also explicitly adding ``'blas'`` as a library
2245 4. Check only library ``'cblas'``
2246 5. Check only library ``'blas'``
2247
2248 Parameters
2249 ----------
2250 info : dict
2251 system information dictionary for compilation and linking
2252
2253 Returns
2254 -------
2255 libraries : list of str or None
2256 a list of libraries that enables the use of CBLAS interface.
2257 Returns None if not found or a compilation error occurs.
2258
2259 Since 1.17 returns a list.
2260 """
2261 # primitive cblas check by looking for the header and trying to link
2262 # cblas or blas
2263 c = customized_ccompiler()
2264 tmpdir = tempfile.mkdtemp()
2265 s = textwrap.dedent("""\
2266 #include <cblas.h>
2267 int main(int argc, const char *argv[])
2268 {
2269 double a[4] = {1,2,3,4};
2270 double b[4] = {5,6,7,8};
2271 return cblas_ddot(4, a, 1, b, 1) > 10;
2272 }""")
2273 src = os.path.join(tmpdir, 'source.c')
2274 try:
2275 with open(src, 'w') as f:
2276 f.write(s)
2277
2278 try:
2279 # check we can compile (find headers)
2280 obj = c.compile([src], output_dir=tmpdir,
2281 include_dirs=self.get_include_dirs())
2282 except (distutils.ccompiler.CompileError, distutils.ccompiler.LinkError):
2283 return None
2284
2285 # check we can link (find library)
2286 # some systems have separate cblas and blas libs.
2287 for libs in [info['libraries'], ['cblas'] + info['libraries'],
2288 ['blas'] + info['libraries'], ['cblas'], ['blas']]:
2289 try:
2290 c.link_executable(obj, os.path.join(tmpdir, "a.out"),
2291 libraries=libs,
2292 library_dirs=info['library_dirs'],
2293 extra_postargs=info.get('extra_link_args', []))

Callers 1

calc_infoMethod · 0.95

Calls 7

openFunction · 0.85
get_include_dirsMethod · 0.80
customized_ccompilerFunction · 0.70
joinMethod · 0.45
writeMethod · 0.45
compileMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected