~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/linalg/setup_linalg.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
from __future__ import nested_scopes
 
4
import os
 
5
import sys
 
6
import re
 
7
from distutils.dep_util import newer_group, newer
 
8
from glob import glob
 
9
from os.path import join
 
10
 
 
11
#-------------------
 
12
# To skip wrapping single precision atlas/lapack/blas routines, set
 
13
# the following flag to True:
 
14
skip_single_routines = 0
 
15
 
 
16
# Some OS distributions (e.g. Redhat, Suse) provide a blas library that
 
17
# is built using incomplete blas sources that come with lapack tar-ball.
 
18
# In order to use such a library in scipy.linalg, the following flag
 
19
# must be set to True:
 
20
using_lapack_blas = 0
 
21
 
 
22
#--------------------
 
23
 
 
24
def configuration(parent_package='',parent_path=None):
 
25
    from scipy_distutils.core import Extension
 
26
    from scipy_distutils.misc_util import dot_join, get_path, default_config_dict
 
27
    from scipy_distutils.system_info import get_info, dict_append, NotFoundError
 
28
 
 
29
    from interface_gen import generate_interface
 
30
 
 
31
    package = 'linalg'
 
32
    config = default_config_dict(package,parent_package)
 
33
    local_path = get_path(__name__,parent_path)
 
34
    def local_join(*paths):
 
35
        return os.path.join(*((local_path,)+paths))
 
36
 
 
37
    lapack_opt = get_info('lapack_opt')
 
38
 
 
39
    if not lapack_opt:
 
40
        raise NotFoundError,'no lapack/blas resources found'
 
41
 
 
42
    atlas_version = ([v[3:-3] for k,v in lapack_opt.get('define_macros',[]) \
 
43
                      if k=='ATLAS_INFO']+[None])[0] 
 
44
    if atlas_version:
 
45
        print 'ATLAS version',atlas_version
 
46
 
 
47
    target_dir = ''
 
48
    skip_names = {'clapack':[],'flapack':[],'cblas':[],'fblas':[]}
 
49
    if skip_single_routines:
 
50
        target_dir = 'dbl'
 
51
        skip_names['clapack'].extend(\
 
52
            'sgesv cgesv sgetrf cgetrf sgetrs cgetrs sgetri cgetri'\
 
53
            ' sposv cposv spotrf cpotrf spotrs cpotrs spotri cpotri'\
 
54
            ' slauum clauum strtri ctrtri'.split())
 
55
        skip_names['flapack'].extend(skip_names['clapack'])
 
56
        skip_names['flapack'].extend(\
 
57
            'sgesdd cgesdd sgelss cgelss sgeqrf cgeqrf sgeev cgeev'\
 
58
            ' sgegv cgegv ssyev cheev slaswp claswp sgees cgees'
 
59
            ' sggev cggev'.split())
 
60
        skip_names['cblas'].extend('saxpy caxpy'.split())
 
61
        skip_names['fblas'].extend(skip_names['cblas'])
 
62
        skip_names['fblas'].extend(\
 
63
            'srotg crotg srotmg srot csrot srotm sswap cswap sscal cscal'\
 
64
            ' csscal scopy ccopy sdot cdotu cdotc snrm2 scnrm2 sasum scasum'\
 
65
            ' isamax icamax sgemv cgemv chemv ssymv strmv ctrmv'\
 
66
            ' sgemm cgemm'.split())
 
67
 
 
68
    if using_lapack_blas:
 
69
        target_dir = join(target_dir,'blas')
 
70
        skip_names['fblas'].extend(\
 
71
            'drotmg srotmg drotm srotm'.split())
 
72
 
 
73
    if atlas_version=='3.2.1_pre3.3.6':
 
74
        target_dir = join(target_dir,'atlas321')
 
75
        skip_names['clapack'].extend(\
 
76
            'sgetri dgetri cgetri zgetri spotri dpotri cpotri zpotri'\
 
77
            ' slauum dlauum clauum zlauum strtri dtrtri ctrtri ztrtri'.split())
 
78
    elif atlas_version>'3.4.0' and atlas_version<='3.5.12':
 
79
        skip_names['clapack'].extend('cpotrf zpotrf'.split())
 
80
 
 
81
    def generate_pyf(extension, build_dir):
 
82
        name = extension.name.split('.')[-1]
 
83
        target = join(build_dir,target_dir,name+'.pyf')
 
84
        if name[0]=='c' and atlas_version is None and newer(__file__,target):
 
85
            f = open(target,'w')
 
86
            f.write('python module '+name+'\n')
 
87
            f.write('usercode void empty_module(void) {}\n')
 
88
            f.write('interface\n')
 
89
            f.write('subroutine empty_module()\n')
 
90
            f.write('intent(c) empty_module\n')
 
91
            f.write('end subroutine empty_module\n')
 
92
            f.write('end interface\nend python module'+name+'\n')
 
93
            f.close()
 
94
            return target
 
95
        if newer_group(extension.depends,target):
 
96
            generate_interface(name,
 
97
                               extension.depends[0],
 
98
                               target,
 
99
                               skip_names[name])
 
100
        return target
 
101
 
 
102
    # fblas:
 
103
    ext_args = {'name': dot_join(parent_package,package,'fblas'),
 
104
                'sources': [generate_pyf,
 
105
                            local_join('src','fblaswrap.f')],
 
106
                'depends': map(local_join,['generic_fblas.pyf',
 
107
                                           'generic_fblas1.pyf',
 
108
                                           'generic_fblas2.pyf',
 
109
                                           'generic_fblas3.pyf',
 
110
                                           'interface_gen.py'])
 
111
                }
 
112
    dict_append(ext_args,**lapack_opt)
 
113
    ext = Extension(**ext_args)
 
114
    config['ext_modules'].append(ext)
 
115
 
 
116
    # cblas:
 
117
    ext_args = {'name': dot_join(parent_package,package,'cblas'),
 
118
                'sources': [generate_pyf],
 
119
                'depends': map(local_join,['generic_cblas.pyf',
 
120
                                           'generic_cblas1.pyf',
 
121
                                           'interface_gen.py'])
 
122
                }
 
123
    dict_append(ext_args,**lapack_opt)
 
124
    ext = Extension(**ext_args)
 
125
    config['ext_modules'].append(ext)
 
126
 
 
127
    # flapack:
 
128
    ext_args = {'name': dot_join(parent_package,package,'flapack'),
 
129
                'sources': [generate_pyf],
 
130
                'depends': map(local_join,['generic_flapack.pyf',
 
131
                                           'flapack_user_routines.pyf',
 
132
                                           'interface_gen.py'])
 
133
                }
 
134
    dict_append(ext_args,**lapack_opt)
 
135
    ext = Extension(**ext_args)
 
136
    config['ext_modules'].append(ext)
 
137
 
 
138
    # clapack:
 
139
    ext_args = {'name': dot_join(parent_package,package,'clapack'),
 
140
                'sources': [generate_pyf],
 
141
                'depends': map(local_join,['generic_clapack.pyf',
 
142
                                           'interface_gen.py'])
 
143
                }
 
144
    dict_append(ext_args,**lapack_opt)
 
145
    ext = Extension(**ext_args)
 
146
    config['ext_modules'].append(ext)
 
147
 
 
148
    # _flinalg:
 
149
    ext_args = {'name':dot_join(parent_package,package,'_flinalg'),
 
150
                'sources':[local_join('src','det.f'),
 
151
                           local_join('src','lu.f')]
 
152
                }
 
153
    dict_append(ext_args,**lapack_opt)
 
154
    config['ext_modules'].append(Extension(**ext_args))
 
155
 
 
156
    # calc_lwork:
 
157
    ext_args = {'name':dot_join(parent_package,package,'calc_lwork'),
 
158
                'sources':[local_join('src','calc_lwork.f')],
 
159
                }
 
160
    dict_append(ext_args,**lapack_opt)
 
161
    config['ext_modules'].append(Extension(**ext_args))
 
162
 
 
163
    # atlas_version:
 
164
    ext_args = {'name':dot_join(parent_package,package,'atlas_version'),
 
165
                'sources':[os.path.join(local_path,'atlas_version.c')]}
 
166
    dict_append(ext_args,**lapack_opt)
 
167
    ext = Extension(**ext_args)
 
168
    config['ext_modules'].append(ext)
 
169
 
 
170
    # iterative methods
 
171
    methods = ['BiCGREVCOM.f.src',
 
172
               'BiCGSTABREVCOM.f.src',
 
173
               'CGREVCOM.f.src',
 
174
               'CGSREVCOM.f.src',
 
175
#               'ChebyREVCOM.f.src',
 
176
               'GMRESREVCOM.f.src',
 
177
#               'JacobiREVCOM.f.src',
 
178
               'QMRREVCOM.f.src',
 
179
#               'SORREVCOM.f.src'
 
180
               ]
 
181
    Util = ['STOPTEST2.f.src','getbreak.f.src']
 
182
    sources = Util + methods + ['_iterative.pyf.src']
 
183
    ext_args = {
 
184
        'name': dot_join(parent_package,package,'_iterative'),
 
185
        'sources': [local_join('iterative',x) for x in sources]
 
186
        }
 
187
    dict_append(ext_args, **lapack_opt)
 
188
    ext = Extension(**ext_args)
 
189
    config['ext_modules'].append(ext)    
 
190
 
 
191
    return config
 
192
 
 
193
if __name__ == '__main__':
 
194
    from scipy_distutils.core import setup
 
195
    from linalg_version import linalg_version
 
196
 
 
197
    setup(version=linalg_version,
 
198
          **configuration(parent_path=''))