Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.9/dist-packages/scipy/linalg/_flinalg_py.py: 21%
28 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-23 06:43 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-23 06:43 +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
16def has_column_major_storage(arr):
17 return arr.flags['FORTRAN']
20_type_conv = {'f':'s', 'd':'d', 'F':'c', 'D':'z'} # 'd' will be default for 'i',..
23def get_flinalg_funcs(names,arrays=(),debug=0):
24 """Return optimal available _flinalg function objects with
25 names. Arrays are used to determine optimal prefix."""
26 ordering = []
27 for i, ar in enumerate(arrays):
28 t = ar.dtype.char
29 if t not in _type_conv:
30 t = 'd'
31 ordering.append((t,i))
32 if ordering:
33 ordering.sort()
34 required_prefix = _type_conv[ordering[0][0]]
35 else:
36 required_prefix = 'd'
37 # Some routines may require special treatment.
38 # Handle them here before the default lookup.
40 # Default lookup:
41 if ordering and has_column_major_storage(arrays[ordering[0][1]]):
42 suffix1,suffix2 = '_c','_r'
43 else:
44 suffix1,suffix2 = '_r','_c'
46 funcs = []
47 for name in names:
48 func_name = required_prefix + name
49 func = getattr(_flinalg,func_name+suffix1,
50 getattr(_flinalg,func_name+suffix2,None))
51 funcs.append(func)
52 return tuple(funcs)