Skip to content

CONFIG: add config option for LAPACK compile #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
# - There can't be any leading "-"s - All newlines will be removed, so use
# ";"s
sudo: false # To use travis container infrastructure
addons:
apt:
packages:
- libblas-dev
- liblapack-dev
language: python
cache:
directories:
Expand All @@ -27,14 +32,17 @@ matrix:
- python: 2.7
env:
- DEPENDS="numpy==1.6.0 scipy==0.7.0 sympy==0.7.0 nibabel==1.2.0"
# Test compiling against external lapack
- python: 3.4
env:
- NIPY_EXTERNAL_LAPACK=1
before_install:
- source tools/travis_tools.sh
- virtualenv --python=python venv
- source venv/bin/activate
- python --version # just to check
- retry pip install nose # always
- wheelhouse_pip_install $DEPENDS
# - sudo apt-get install -qq libatlas-dev libatlas-base-dev gfortran libpng-dev
- if [ "${COVERAGE}" == "1" ]; then
pip install coverage;
pip install coveralls;
Expand Down
15 changes: 0 additions & 15 deletions nipy/algorithms/clustering/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@ def configuration(parent_package='',top_path=None):
config = Configuration('clustering', parent_package, top_path)
config.add_subpackage('tests')

# We need this because libcstat.a is linked to lapack, which can
# be a fortran library, and the linker needs this information.
from numpy.distutils.system_info import get_info
lapack_info = get_info('lapack_opt',0)
if 'libraries' not in lapack_info:
# But on OSX that may not give us what we need, so try with 'lapack'
# instead. NOTE: scipy.linalg uses lapack_opt, not 'lapack'...
lapack_info = get_info('lapack',0)

#config.add_extension(
# '_clustering',
# sources=['clustering.c'],
# libraries=['cstat'],
# extra_info=lapack_info,
# )
return config


Expand Down
18 changes: 3 additions & 15 deletions nipy/labs/bindings/setup.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
import os, sys

def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration('bindings', parent_package, top_path)
config.add_subpackage('tests')
config.add_subpackage('benchmarks')
# We need this because libcstat.a is linked to lapack, which can
# be a fortran library, and the linker needs this information.
from numpy.distutils.system_info import get_info
lapack_info = get_info('lapack_opt',0)
if 'libraries' not in lapack_info:
# But on OSX that may not give us what we need, so try with 'lapack'
# instead. NOTE: scipy.linalg uses lapack_opt, not 'lapack'...
lapack_info = get_info('lapack',0)
config.add_extension('linalg', sources=['linalg.pyx'],
libraries=['cstat'],
extra_info=lapack_info)
libraries=['cstat'])
config.add_extension('array', sources=['array.pyx'],
libraries=['cstat'],
extra_info=lapack_info)
libraries=['cstat'])
config.add_extension('wrapper', sources=['wrapper.pyx'],
libraries=['cstat'],
extra_info=lapack_info)
libraries=['cstat'])
return config


Expand Down
11 changes: 1 addition & 10 deletions nipy/labs/glm/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@

def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
# We need this because libcstat.a is linked to lapack, which can
# be a fortran library, and the linker needs this information.
from numpy.distutils.system_info import get_info
lapack_info = get_info('lapack_opt', 0)
if 'libraries' not in lapack_info:
# But on OSX that may not give us what we need, so try with 'lapack'
# instead. NOTE: scipy.linalg uses lapack_opt, not 'lapack'...
lapack_info = get_info('lapack', 0)
config = Configuration('glm', parent_package, top_path)
config.add_subpackage('tests')
config.add_subpackage('benchmarks')
config.add_extension(
'kalman',
sources=['kalman.pyx'],
libraries=['cstat'],
extra_info=lapack_info,
libraries=['cstat']
)
return config

Expand Down
17 changes: 3 additions & 14 deletions nipy/labs/group/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,22 @@ def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration
# We need this because libcstat.a is linked to lapack, which can
# be a fortran library, and the linker needs this information.
from numpy.distutils.system_info import get_info
# First, try 'lapack_info', as that seems to provide more details on Linux
# (both 32 and 64 bits):
lapack_info = get_info('lapack_opt', 0)
if 'libraries' not in lapack_info:
# But on OSX that may not give us what we need, so try with 'lapack'
# instead. NOTE: scipy.linalg uses lapack_opt, not 'lapack'...
lapack_info = get_info('lapack',0)
config = Configuration('group', parent_package, top_path)
config.add_subpackage('tests')
config.add_extension(
'onesample',
sources=['onesample.pyx'],
libraries=['cstat'],
extra_info=lapack_info,
libraries=['cstat']
)
config.add_extension(
'twosample',
sources=['twosample.pyx'],
libraries=['cstat'],
extra_info=lapack_info,
libraries=['cstat']
)
config.add_extension(
'glm_twolevel',
sources=['glm_twolevel.pyx'],
libraries=['cstat'],
extra_info=lapack_info,
libraries=['cstat']
)
return config

Expand Down
60 changes: 47 additions & 13 deletions nipy/labs/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,48 @@
import os
from distutils import log

try:
from configparser import ConfigParser, NoSectionError, NoOptionError
except ImportError:
from ConfigParser import ConfigParser, NoSectionError, NoOptionError

# Global variables
LIBS = os.path.realpath('lib')

# The following variable disables linking with Lapack by default. So
# far, the only way to attempt at linking with Lapack is to edit this
# file and set WANT_LAPACK_LINKING=True. We might later want to pass
# in this variable as an optional argument of `python setup.py build`.
WANT_LAPACK_LINKING = False
# Stuff for reading setup file
SETUP_FILE = 'setup.cfg'
SECTION = 'lapack'
KEY = 'external'
EXTERNAL_LAPACK_VAR = 'NIPY_EXTERNAL_LAPACK'

def get_link_external():
""" Return True if we should link to system BLAS / LAPACK

If True, attempt to link to system BLAS / LAPACK. Otherwise, compile
lapack_lite, and link to that.

First check ``setup.cfg`` file for section ``[lapack]`` key ``external``.

If this value undefined, then get string from environment variable
NIPY_EXTERNAL_LAPACK.

If value from ``setup.cfg`` or environment variable is not 'False' or '0',
then return True.
"""
config = ConfigParser()
try:
config.read(SETUP_FILE)
external_link = config.get(SECTION, KEY)
except (IOError, KeyError, NoOptionError, NoSectionError):
external_link = os.environ.get(EXTERNAL_LAPACK_VAR)
if external_link is None:
return False
return external_link.lower() not in ('0', 'false')


def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs
from numpy.distutils.system_info import get_info, system_info
from numpy.distutils.system_info import get_info

config = Configuration('labs', parent_package, top_path)

Expand Down Expand Up @@ -50,16 +80,20 @@ def configuration(parent_package='',top_path=None):
# If lapack linking not required or no lapack install is found, we
# use the rescue lapack lite distribution included in the package
# (sources have been translated to C using f2c)
if not WANT_LAPACK_LINKING or not lapack_info:
if WANT_LAPACK_LINKING:
log.warn('Lapack not found')
log.warn('Building Lapack lite distribution')
want_lapack_link = get_link_external()
if not want_lapack_link:
log.warn('Building with (slow) Lapack lite distribution: '
'set {0} environment variable or use setup.cfg '
'to enable link to optimized BLAS / LAPACK'.format(
EXTERNAL_LAPACK_VAR)
)
sources.append(os.path.join(LIBS,'lapack_lite','*.c'))
library_dirs = []
libraries = []

# Best-case scenario: lapack found
else:
else: # Best-case scenario: external lapack found
if not lapack_info:
raise RuntimeError('Specified external lapack linking but '
'numpy does not report external lapack')
log.warn('Linking with system Lapack')
library_dirs = lapack_info['library_dirs']
libraries = lapack_info['libraries']
Expand Down
12 changes: 1 addition & 11 deletions nipy/labs/utils/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,12 @@

def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
# We need this because libcstat.a is linked to lapack, which can
# be a fortran library, and the linker needs this information.
from numpy.distutils.system_info import get_info
lapack_info = get_info('lapack_opt', 0)
if 'libraries' not in lapack_info:
# But on OSX that may not give us what we need, so try with 'lapack'
# instead. NOTE: scipy.linalg uses lapack_opt, not 'lapack'...
lapack_info = get_info('lapack', 0)

config = Configuration('utils', parent_package, top_path)
config.add_subpackage('tests')
config.add_extension(
'routines',
sources=['routines.pyx'],
libraries=['cstat'],
extra_info=lapack_info,
libraries=['cstat']
)

return config
Expand Down
8 changes: 8 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ cover-package = nipy
#with-doctest=1
doctest-extension=rst

# In this section specify if you want to link to external BLAS / LAPACK
[lapack]
# Value of 0 or False implies compile of, link to lapack_lite
# Value of 1 or True will cause setup to try and link to external BLAS /
# LAPACK as identified with the numpy configuration. Default is False.
# The value in this file overrides the equivalent setting in the environment
# variable NIPY_EXTERNAL_LAPACK.
#external = False