summaryrefslogtreecommitdiff
path: root/numpy/random/setup.py
diff options
context:
space:
mode:
authorKevin Sheppard <kevin.k.sheppard@gmail.com>2019-05-24 00:37:22 +0100
committermattip <matti.picus@gmail.com>2019-05-27 22:58:35 +0300
commit3db5a7736cf26db59817eb8939b042ae18c482fa (patch)
treeba8864066444e53cbfa88c2ca4fd2a4d8fcf14a5 /numpy/random/setup.py
parentdabf42be29208a59bbacffd40d9d8dca6e200f49 (diff)
downloadnumpy-3db5a7736cf26db59817eb8939b042ae18c482fa.tar.gz
BLD: Improve setup
Attempt to avoid defining variables that are incorrect for some platforms
Diffstat (limited to 'numpy/random/setup.py')
-rw-r--r--numpy/random/setup.py204
1 files changed, 97 insertions, 107 deletions
diff --git a/numpy/random/setup.py b/numpy/random/setup.py
index 48a729179..b8b190b09 100644
--- a/numpy/random/setup.py
+++ b/numpy/random/setup.py
@@ -1,26 +1,17 @@
from __future__ import division, print_function
-from os.path import join
-import sys
import os
import platform
-import struct
-from distutils.dep_util import newer
-from distutils.msvccompiler import get_build_version as get_msvc_build_version
+import sys
+from os.path import join
-def needs_mingw_ftime_workaround():
- # We need the mingw workaround for _ftime if the msvc runtime version is
- # 7.1 or above and we build with mingw ...
- # ... but we can't easily detect compiler version outside distutils command
- # context, so we will need to detect in randomkit whether we build with gcc
- msver = get_msvc_build_version()
- if msver and msver >= 8:
- return True
+from numpy.distutils.system_info import platform_bits
- return False
+is_msvc = (platform.platform().startswith('Windows') and
+ platform.python_compiler().startswith('MS'))
-def configuration(parent_package='',top_path=None):
+def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration, get_mathlibs
config = Configuration('random', parent_package, top_path)
@@ -28,7 +19,7 @@ def configuration(parent_package='',top_path=None):
config_cmd = config.get_config_cmd()
libs = get_mathlibs()
if sys.platform == 'win32':
- libs.append('Advapi32')
+ libs.extend(['Advapi32', 'Kernel32'])
ext.libraries.extend(libs)
return None
@@ -40,124 +31,123 @@ def configuration(parent_package='',top_path=None):
defs = [('_FILE_OFFSET_BITS', '64'),
('_LARGEFILE_SOURCE', '1'),
('_LARGEFILE64_SOURCE', '1')]
- if needs_mingw_ftime_workaround():
- defs.append(("NPY_NEEDS_MINGW_TIME_WORKAROUND", None))
- libs = []
defs.append(('NPY_NO_DEPRECATED_API', 0))
config.add_data_dir('tests')
- ##############################
- # randomgen
- ##############################
-
- # Make a guess as to whether SSE2 is present for now, TODO: Improve
- DEBUG = False
EXTRA_LINK_ARGS = []
+ # Math lib
EXTRA_LIBRARIES = ['m'] if os.name != 'nt' else []
- EXTRA_COMPILE_ARGS = [] if os.name == 'nt' else [
- '-std=c99', '-U__GNUC_GNU_INLINE__']
- if os.name == 'nt':
- EXTRA_LINK_ARGS = ['/LTCG', '/OPT:REF', 'Advapi32.lib', 'Kernel32.lib']
- if DEBUG:
- EXTRA_LINK_ARGS += ['-debug']
- EXTRA_COMPILE_ARGS += ["-Zi", "/Od"]
+ # Some bit generators exclude GCC inlining
+ EXTRA_COMPILE_ARGS = ['-U__GNUC_GNU_INLINE__']
+
+ if is_msvc and platform_bits == 32:
+ # 32-bit windows requires explicit sse2 option
+ EXTRA_COMPILE_ARGS += ['/arch:SSE2']
+ elif not is_msvc:
+ # Some bit generators require c99
+ EXTRA_COMPILE_ARGS += ['-std=c99']
+ INTEL_LIKE = any([val in k.lower() for k in platform.uname()
+ for val in ('x86', 'i686', 'i386', 'amd64')])
+ if INTEL_LIKE:
+ # Assumes GCC or GCC-like compiler
+ EXTRA_COMPILE_ARGS += ['-msse2']
+ # Use legacy integer variable sizes
LEGACY_DEFS = [('NP_RANDOM_LEGACY', '1')]
+ # Required defined for DSFMT size and to allow it to detect SSE2 using
+ # config file information
DSFMT_DEFS = [('DSFMT_MEXP', '19937'), ("HAVE_NPY_CONFIG_H", "1")]
- INTEL_LIKE = any([val in k.lower() for k in platform.uname()
- for val in ('x86', 'i686', 'i386', 'amd64')])
- if os.name == 'nt':
- EXTRA_COMPILE_ARGS += ['/wd4146', '/GL']
- if struct.calcsize('P') < 8:
- EXTRA_COMPILE_ARGS += ['/arch:SSE2']
- elif INTEL_LIKE:
- EXTRA_COMPILE_ARGS += ['-msse2']
config.add_extension('entropy',
- sources=['entropy.c', 'src/entropy/entropy.c'],
- libraries=EXTRA_LIBRARIES,
- extra_compile_args=EXTRA_COMPILE_ARGS,
- extra_link_args=EXTRA_LINK_ARGS,
- depends=[join('src', 'splitmix64', 'splitmix.h'),
- join('src', 'entropy', 'entropy.h'),
- 'entropy.pyx',
- ],
- define_macros=defs,
- )
+ sources=['entropy.c', 'src/entropy/entropy.c'] +
+ [generate_libraries],
+ libraries=EXTRA_LIBRARIES,
+ extra_compile_args=EXTRA_COMPILE_ARGS,
+ extra_link_args=EXTRA_LINK_ARGS,
+ depends=[join('src', 'splitmix64', 'splitmix.h'),
+ join('src', 'entropy', 'entropy.h'),
+ 'entropy.pyx',
+ ],
+ define_macros=defs,
+ )
config.add_extension('dsfmt',
- sources=['dsfmt.c', 'src/dsfmt/dSFMT.c',
- 'src/dsfmt/dSFMT-jump.c',
- 'src/aligned_malloc/aligned_malloc.c'],
- include_dirs=['.', 'src', join('src', 'dsfmt')],
- libraries=EXTRA_LIBRARIES,
- extra_compile_args=EXTRA_COMPILE_ARGS,
- extra_link_args=EXTRA_LINK_ARGS,
- depends=[join('src', 'dsfmt', 'dsfmt.h'),
- 'dsfmt.pyx',
- ],
- define_macros=defs + DSFMT_DEFS,
- )
+ sources=['dsfmt.c', 'src/dsfmt/dSFMT.c',
+ 'src/dsfmt/dSFMT-jump.c',
+ 'src/aligned_malloc/aligned_malloc.c'],
+ include_dirs=['.', 'src', join('src', 'dsfmt')],
+ libraries=EXTRA_LIBRARIES,
+ extra_compile_args=EXTRA_COMPILE_ARGS,
+ extra_link_args=EXTRA_LINK_ARGS,
+ depends=[join('src', 'dsfmt', 'dsfmt.h'),
+ 'dsfmt.pyx',
+ ],
+ define_macros=defs + DSFMT_DEFS,
+ )
for gen in ['mt19937']:
# gen.pyx, src/gen/gen.c, src/gen/gen-jump.c
config.add_extension(gen,
- sources=['{0}.c'.format(gen), 'src/{0}/{0}.c'.format(gen),
- 'src/{0}/{0}-jump.c'.format(gen)],
- include_dirs=['.', 'src', join('src', gen)],
- libraries=EXTRA_LIBRARIES,
- extra_compile_args=EXTRA_COMPILE_ARGS,
- extra_link_args=EXTRA_LINK_ARGS,
- depends=['%s.pyx' % gen],
- define_macros=defs,
- )
+ sources=['{0}.c'.format(gen),
+ 'src/{0}/{0}.c'.format(gen),
+ 'src/{0}/{0}-jump.c'.format(gen)],
+ include_dirs=['.', 'src', join('src', gen)],
+ libraries=EXTRA_LIBRARIES,
+ extra_compile_args=EXTRA_COMPILE_ARGS,
+ extra_link_args=EXTRA_LINK_ARGS,
+ depends=['%s.pyx' % gen],
+ define_macros=defs,
+ )
for gen in ['philox', 'threefry', 'xoshiro256', 'xoshiro512']:
# gen.pyx, src/gen/gen.c
config.add_extension(gen,
- sources=['{0}.c'.format(gen), 'src/{0}/{0}.c'.format(gen)],
- include_dirs=['.', 'src', join('src', gen)],
- libraries=EXTRA_LIBRARIES,
- extra_compile_args=EXTRA_COMPILE_ARGS,
- extra_link_args=EXTRA_LINK_ARGS,
- depends=['%s.pyx' % gen],
- define_macros=defs,
- )
+ sources=['{0}.c'.format(gen),
+ 'src/{0}/{0}.c'.format(gen)],
+ include_dirs=['.', 'src', join('src', gen)],
+ libraries=EXTRA_LIBRARIES,
+ extra_compile_args=EXTRA_COMPILE_ARGS,
+ extra_link_args=EXTRA_LINK_ARGS,
+ depends=['%s.pyx' % gen],
+ define_macros=defs,
+ )
for gen in ['common']:
# gen.pyx
config.add_extension(gen,
- sources=['{0}.c'.format(gen)],
- libraries=EXTRA_LIBRARIES,
- extra_compile_args=EXTRA_COMPILE_ARGS,
- extra_link_args=EXTRA_LINK_ARGS,
- include_dirs=['.', 'src'],
- depends=['%s.pyx' % gen],
- define_macros=defs,
- )
+ sources=['{0}.c'.format(gen)],
+ libraries=EXTRA_LIBRARIES,
+ extra_compile_args=EXTRA_COMPILE_ARGS,
+ extra_link_args=EXTRA_LINK_ARGS,
+ include_dirs=['.', 'src'],
+ depends=['%s.pyx' % gen],
+ define_macros=defs,
+ )
for gen in ['generator', 'bounded_integers']:
# gen.pyx, src/distributions/distributions.c
config.add_extension(gen,
- sources=['{0}.c'.format(gen),
- join('src', 'distributions',
- 'distributions.c')],
- libraries=EXTRA_LIBRARIES,
- extra_compile_args=EXTRA_COMPILE_ARGS,
- include_dirs=['.', 'src'],
- extra_link_args=EXTRA_LINK_ARGS,
- depends=['%s.pyx' % gen],
- define_macros=defs,
- )
+ sources=['{0}.c'.format(gen),
+ join('src', 'distributions',
+ 'distributions.c')],
+ libraries=EXTRA_LIBRARIES,
+ extra_compile_args=EXTRA_COMPILE_ARGS,
+ include_dirs=['.', 'src'],
+ extra_link_args=EXTRA_LINK_ARGS,
+ depends=['%s.pyx' % gen],
+ define_macros=defs,
+ )
config.add_extension('mtrand',
- sources=['mtrand.c',
- 'src/legacy/distributions-boxmuller.c',
- 'src/distributions/distributions.c' ],
- include_dirs=['.', 'src', 'src/legacy'],
- libraries=EXTRA_LIBRARIES,
- extra_compile_args=EXTRA_COMPILE_ARGS,
- extra_link_args=EXTRA_LINK_ARGS,
- depends=['mtrand.pyx'],
- define_macros=defs + DSFMT_DEFS + LEGACY_DEFS,
- )
+ sources=['mtrand.c',
+ 'src/legacy/distributions-boxmuller.c',
+ 'src/distributions/distributions.c'],
+ include_dirs=['.', 'src', 'src/legacy'],
+ libraries=EXTRA_LIBRARIES,
+ extra_compile_args=EXTRA_COMPILE_ARGS,
+ extra_link_args=EXTRA_LINK_ARGS,
+ depends=['mtrand.pyx'],
+ define_macros=defs + DSFMT_DEFS + LEGACY_DEFS,
+ )
return config
+
if __name__ == '__main__':
from numpy.distutils.core import setup
+
setup(configuration=configuration)