setup.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import os
  2. import sys
  3. def configuration(parent_package='', top_path=None):
  4. from numpy.distutils.misc_util import Configuration
  5. from numpy.distutils.system_info import (
  6. get_info, system_info, lapack_opt_info, blas_opt_info)
  7. config = Configuration('linalg', parent_package, top_path)
  8. config.add_subpackage('tests')
  9. # Configure lapack_lite
  10. src_dir = 'lapack_lite'
  11. lapack_lite_src = [
  12. os.path.join(src_dir, 'python_xerbla.c'),
  13. os.path.join(src_dir, 'f2c_z_lapack.c'),
  14. os.path.join(src_dir, 'f2c_c_lapack.c'),
  15. os.path.join(src_dir, 'f2c_d_lapack.c'),
  16. os.path.join(src_dir, 'f2c_s_lapack.c'),
  17. os.path.join(src_dir, 'f2c_lapack.c'),
  18. os.path.join(src_dir, 'f2c_blas.c'),
  19. os.path.join(src_dir, 'f2c_config.c'),
  20. os.path.join(src_dir, 'f2c.c'),
  21. ]
  22. all_sources = config.paths(lapack_lite_src)
  23. if os.environ.get('NPY_USE_BLAS_ILP64', "0") != "0":
  24. lapack_info = get_info('lapack_ilp64_opt', 2)
  25. else:
  26. lapack_info = get_info('lapack_opt', 0) # and {}
  27. use_lapack_lite = not lapack_info
  28. if use_lapack_lite:
  29. # This makes numpy.distutils write the fact that lapack_lite
  30. # is being used to numpy.__config__
  31. class numpy_linalg_lapack_lite(system_info):
  32. def calc_info(self):
  33. info = {'language': 'c'}
  34. if sys.maxsize > 2**32:
  35. # Build lapack-lite in 64-bit integer mode.
  36. # The suffix is arbitrary (lapack_lite symbols follow it),
  37. # but use the "64_" convention here.
  38. info['define_macros'] = [
  39. ('HAVE_BLAS_ILP64', None),
  40. ('BLAS_SYMBOL_SUFFIX', '64_')
  41. ]
  42. self.set_info(**info)
  43. lapack_info = numpy_linalg_lapack_lite().get_info(2)
  44. def get_lapack_lite_sources(ext, build_dir):
  45. if use_lapack_lite:
  46. print("### Warning: Using unoptimized lapack ###")
  47. return all_sources
  48. else:
  49. if sys.platform == 'win32':
  50. print("### Warning: python_xerbla.c is disabled ###")
  51. return []
  52. return [all_sources[0]]
  53. config.add_extension(
  54. 'lapack_lite',
  55. sources=['lapack_litemodule.c', get_lapack_lite_sources],
  56. depends=['lapack_lite/f2c.h'],
  57. extra_info=lapack_info,
  58. )
  59. # umath_linalg module
  60. config.add_extension(
  61. '_umath_linalg',
  62. sources=['umath_linalg.c.src', get_lapack_lite_sources],
  63. depends=['lapack_lite/f2c.h'],
  64. extra_info=lapack_info,
  65. libraries=['npymath'],
  66. )
  67. config.add_data_files('*.pyi')
  68. return config
  69. if __name__ == '__main__':
  70. from numpy.distutils.core import setup
  71. setup(configuration=configuration)