File: flinalg.py

package info (click to toggle)
python-scipy 0.7.2%2Bdfsg1-1%2Bdeb6u1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 28,572 kB
  • ctags: 36,183
  • sloc: cpp: 216,880; fortran: 76,016; python: 71,833; ansic: 62,118; makefile: 243; sh: 17
file content (55 lines) | stat: -rw-r--r-- 1,703 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
## Automatically adapted for scipy Oct 18, 2005 by

#
# Author: Pearu Peterson, March 2002
#

__all__ = ['get_flinalg_funcs']

# The following ensures that possibly missing flavor (C or Fortran) is
# replaced with the available one. If none is available, exception
# is raised at the first attempt to use the resources.
try:
    import _flinalg
except ImportError:
    _flinalg = None
#    from numpy.distutils.misc_util import PostponedException
#    _flinalg = PostponedException()
#    print _flinalg.__doc__
    has_column_major_storage = lambda a:0

def has_column_major_storage(arr):
    return arr.flags['FORTRAN']

_type_conv = {'f':'s', 'd':'d', 'F':'c', 'D':'z'} # 'd' will be default for 'i',..

def get_flinalg_funcs(names,arrays=(),debug=0):
    """Return optimal available _flinalg function objects with
    names. arrays are used to determine optimal prefix."""
    ordering = []
    for i in range(len(arrays)):
        t = arrays[i].dtype.char
        if t not in _type_conv:
            t = 'd'
        ordering.append((t,i))
    if ordering:
        ordering.sort()
        required_prefix = _type_conv[ordering[0][0]]
    else:
        required_prefix = 'd'
    # Some routines may require special treatment.
    # Handle them here before the default lookup.

    # Default lookup:
    if ordering and has_column_major_storage(arrays[ordering[0][1]]):
        suffix1,suffix2 = '_c','_r'
    else:
        suffix1,suffix2 = '_r','_c'

    funcs = []
    for name in names:
        func_name = required_prefix + name
        func = getattr(_flinalg,func_name+suffix1,
                       getattr(_flinalg,func_name+suffix2,None))
        funcs.append(func)
    return tuple(funcs)