setup.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. from __future__ import division, print_function
  2. import os
  3. import platform
  4. import sys
  5. from os.path import join
  6. from numpy.distutils.system_info import platform_bits
  7. is_msvc = (platform.platform().startswith('Windows') and
  8. platform.python_compiler().startswith('MS'))
  9. def configuration(parent_package='', top_path=None):
  10. from numpy.distutils.misc_util import Configuration, get_mathlibs
  11. config = Configuration('random', parent_package, top_path)
  12. def generate_libraries(ext, build_dir):
  13. config_cmd = config.get_config_cmd()
  14. libs = get_mathlibs()
  15. if sys.platform == 'win32':
  16. libs.extend(['Advapi32', 'Kernel32'])
  17. ext.libraries.extend(libs)
  18. return None
  19. # enable unix large file support on 32 bit systems
  20. # (64 bit off_t, lseek -> lseek64 etc.)
  21. if sys.platform[:3] == "aix":
  22. defs = [('_LARGE_FILES', None)]
  23. else:
  24. defs = [('_FILE_OFFSET_BITS', '64'),
  25. ('_LARGEFILE_SOURCE', '1'),
  26. ('_LARGEFILE64_SOURCE', '1')]
  27. defs.append(('NPY_NO_DEPRECATED_API', 0))
  28. config.add_data_dir('tests')
  29. config.add_data_dir('_examples')
  30. EXTRA_LINK_ARGS = []
  31. # Math lib
  32. EXTRA_LIBRARIES = ['m'] if os.name != 'nt' else []
  33. # Some bit generators exclude GCC inlining
  34. EXTRA_COMPILE_ARGS = ['-U__GNUC_GNU_INLINE__']
  35. if is_msvc and platform_bits == 32:
  36. # 32-bit windows requires explicit sse2 option
  37. EXTRA_COMPILE_ARGS += ['/arch:SSE2']
  38. elif not is_msvc:
  39. # Some bit generators require c99
  40. EXTRA_COMPILE_ARGS += ['-std=c99']
  41. # Use legacy integer variable sizes
  42. LEGACY_DEFS = [('NP_RANDOM_LEGACY', '1')]
  43. PCG64_DEFS = []
  44. # One can force emulated 128-bit arithmetic if one wants.
  45. #PCG64_DEFS += [('PCG_FORCE_EMULATED_128BIT_MATH', '1')]
  46. for gen in ['mt19937']:
  47. # gen.pyx, src/gen/gen.c, src/gen/gen-jump.c
  48. config.add_extension('_{0}'.format(gen),
  49. sources=['_{0}.c'.format(gen),
  50. 'src/{0}/{0}.c'.format(gen),
  51. 'src/{0}/{0}-jump.c'.format(gen)],
  52. include_dirs=['.', 'src', join('src', gen)],
  53. libraries=EXTRA_LIBRARIES,
  54. extra_compile_args=EXTRA_COMPILE_ARGS,
  55. extra_link_args=EXTRA_LINK_ARGS,
  56. depends=['_%s.pyx' % gen],
  57. define_macros=defs,
  58. )
  59. for gen in ['philox', 'pcg64', 'sfc64']:
  60. # gen.pyx, src/gen/gen.c
  61. _defs = defs + PCG64_DEFS if gen == 'pcg64' else defs
  62. config.add_extension('_{0}'.format(gen),
  63. sources=['_{0}.c'.format(gen),
  64. 'src/{0}/{0}.c'.format(gen)],
  65. include_dirs=['.', 'src', join('src', gen)],
  66. libraries=EXTRA_LIBRARIES,
  67. extra_compile_args=EXTRA_COMPILE_ARGS,
  68. extra_link_args=EXTRA_LINK_ARGS,
  69. depends=['_%s.pyx' % gen, '_bit_generator.pyx',
  70. '_bit_generator.pxd'],
  71. define_macros=_defs,
  72. )
  73. for gen in ['_common', '_bit_generator']:
  74. # gen.pyx
  75. config.add_extension(gen,
  76. sources=['{0}.c'.format(gen)],
  77. libraries=EXTRA_LIBRARIES,
  78. extra_compile_args=EXTRA_COMPILE_ARGS,
  79. extra_link_args=EXTRA_LINK_ARGS,
  80. include_dirs=['.', 'src'],
  81. depends=['%s.pyx' % gen, '%s.pxd' % gen,],
  82. define_macros=defs,
  83. )
  84. config.add_data_files('{0}.pxd'.format(gen))
  85. other_srcs = [
  86. 'src/distributions/logfactorial.c',
  87. 'src/distributions/distributions.c',
  88. 'src/distributions/random_mvhg_count.c',
  89. 'src/distributions/random_mvhg_marginals.c',
  90. 'src/distributions/random_hypergeometric.c',
  91. ]
  92. for gen in ['_generator', '_bounded_integers']:
  93. # gen.pyx, src/distributions/distributions.c
  94. config.add_extension(gen,
  95. sources=['{0}.c'.format(gen)] + other_srcs,
  96. libraries=EXTRA_LIBRARIES,
  97. extra_compile_args=EXTRA_COMPILE_ARGS,
  98. include_dirs=['.', 'src'],
  99. extra_link_args=EXTRA_LINK_ARGS,
  100. depends=['%s.pyx' % gen],
  101. define_macros=defs,
  102. )
  103. config.add_data_files('_bounded_integers.pxd')
  104. config.add_extension('mtrand',
  105. sources=['mtrand.c',
  106. 'src/legacy/legacy-distributions.c',
  107. 'src/distributions/logfactorial.c',
  108. 'src/distributions/distributions.c'],
  109. include_dirs=['.', 'src', 'src/legacy'],
  110. libraries=EXTRA_LIBRARIES,
  111. extra_compile_args=EXTRA_COMPILE_ARGS,
  112. extra_link_args=EXTRA_LINK_ARGS,
  113. depends=['mtrand.pyx'],
  114. define_macros=defs + LEGACY_DEFS,
  115. )
  116. config.add_data_files('__init__.pxd')
  117. return config
  118. if __name__ == '__main__':
  119. from numpy.distutils.core import setup
  120. setup(configuration=configuration)