Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/scipy/linalg/_flinalg_py.py: 21%
29 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-12 06:31 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-12 06:31 +0000
1#
2# Author: Pearu Peterson, March 2002
3#
5__all__ = ['get_flinalg_funcs']
7# The following ensures that possibly missing flavor (C or Fortran) is
8# replaced with the available one. If none is available, exception
9# is raised at the first attempt to use the resources.
10try:
11 from . import _flinalg
12except ImportError:
13 _flinalg = None
14# from numpy.distutils.misc_util import PostponedException
15# _flinalg = PostponedException()
16# print _flinalg.__doc__
17 has_column_major_storage = lambda a:0
20def has_column_major_storage(arr):
21 return arr.flags['FORTRAN']
24_type_conv = {'f':'s', 'd':'d', 'F':'c', 'D':'z'} # 'd' will be default for 'i',..
27def get_flinalg_funcs(names,arrays=(),debug=0):
28 """Return optimal available _flinalg function objects with
29 names. Arrays are used to determine optimal prefix."""
30 ordering = []
31 for i, ar in enumerate(arrays):
32 t = ar.dtype.char
33 if t not in _type_conv:
34 t = 'd'
35 ordering.append((t,i))
36 if ordering:
37 ordering.sort()
38 required_prefix = _type_conv[ordering[0][0]]
39 else:
40 required_prefix = 'd'
41 # Some routines may require special treatment.
42 # Handle them here before the default lookup.
44 # Default lookup:
45 if ordering and has_column_major_storage(arrays[ordering[0][1]]):
46 suffix1,suffix2 = '_c','_r'
47 else:
48 suffix1,suffix2 = '_r','_c'
50 funcs = []
51 for name in names:
52 func_name = required_prefix + name
53 func = getattr(_flinalg,func_name+suffix1,
54 getattr(_flinalg,func_name+suffix2,None))
55 funcs.append(func)
56 return tuple(funcs)