setup.py 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197
  1. import os
  2. import sys
  3. import sysconfig
  4. import pickle
  5. import copy
  6. import warnings
  7. import textwrap
  8. import glob
  9. from os.path import join
  10. from numpy.distutils import log
  11. from numpy.distutils.msvccompiler import lib_opts_if_msvc
  12. from distutils.dep_util import newer
  13. from sysconfig import get_config_var
  14. from numpy.compat import npy_load_module
  15. from setup_common import * # noqa: F403
  16. # Set to True to enable relaxed strides checking. This (mostly) means
  17. # that `strides[dim]` is ignored if `shape[dim] == 1` when setting flags.
  18. NPY_RELAXED_STRIDES_CHECKING = (os.environ.get('NPY_RELAXED_STRIDES_CHECKING', "1") != "0")
  19. if not NPY_RELAXED_STRIDES_CHECKING:
  20. raise SystemError(
  21. "Support for NPY_RELAXED_STRIDES_CHECKING=0 has been remove as of "
  22. "NumPy 1.23. This error will eventually be removed entirely.")
  23. # Put NPY_RELAXED_STRIDES_DEBUG=1 in the environment if you want numpy to use a
  24. # bogus value for affected strides in order to help smoke out bad stride usage
  25. # when relaxed stride checking is enabled.
  26. NPY_RELAXED_STRIDES_DEBUG = (os.environ.get('NPY_RELAXED_STRIDES_DEBUG', "0") != "0")
  27. NPY_RELAXED_STRIDES_DEBUG = NPY_RELAXED_STRIDES_DEBUG and NPY_RELAXED_STRIDES_CHECKING
  28. # Set NPY_DISABLE_SVML=1 in the environment to disable the vendored SVML
  29. # library. This option only has significance on a Linux x86_64 host and is most
  30. # useful to avoid improperly requiring SVML when cross compiling.
  31. NPY_DISABLE_SVML = (os.environ.get('NPY_DISABLE_SVML', "0") == "1")
  32. # XXX: ugly, we use a class to avoid calling twice some expensive functions in
  33. # config.h/numpyconfig.h. I don't see a better way because distutils force
  34. # config.h generation inside an Extension class, and as such sharing
  35. # configuration information between extensions is not easy.
  36. # Using a pickled-based memoize does not work because config_cmd is an instance
  37. # method, which cPickle does not like.
  38. #
  39. # Use pickle in all cases, as cPickle is gone in python3 and the difference
  40. # in time is only in build. -- Charles Harris, 2013-03-30
  41. class CallOnceOnly:
  42. def __init__(self):
  43. self._check_types = None
  44. self._check_ieee_macros = None
  45. self._check_complex = None
  46. def check_types(self, *a, **kw):
  47. if self._check_types is None:
  48. out = check_types(*a, **kw)
  49. self._check_types = pickle.dumps(out)
  50. else:
  51. out = copy.deepcopy(pickle.loads(self._check_types))
  52. return out
  53. def check_ieee_macros(self, *a, **kw):
  54. if self._check_ieee_macros is None:
  55. out = check_ieee_macros(*a, **kw)
  56. self._check_ieee_macros = pickle.dumps(out)
  57. else:
  58. out = copy.deepcopy(pickle.loads(self._check_ieee_macros))
  59. return out
  60. def check_complex(self, *a, **kw):
  61. if self._check_complex is None:
  62. out = check_complex(*a, **kw)
  63. self._check_complex = pickle.dumps(out)
  64. else:
  65. out = copy.deepcopy(pickle.loads(self._check_complex))
  66. return out
  67. def can_link_svml():
  68. """SVML library is supported only on x86_64 architecture and currently
  69. only on linux
  70. """
  71. if NPY_DISABLE_SVML:
  72. return False
  73. platform = sysconfig.get_platform()
  74. return ("x86_64" in platform
  75. and "linux" in platform
  76. and sys.maxsize > 2**31)
  77. def check_svml_submodule(svmlpath):
  78. if not os.path.exists(svmlpath + "/README.md"):
  79. raise RuntimeError("Missing `SVML` submodule! Run `git submodule "
  80. "update --init` to fix this.")
  81. return True
  82. def pythonlib_dir():
  83. """return path where libpython* is."""
  84. if sys.platform == 'win32':
  85. return os.path.join(sys.prefix, "libs")
  86. else:
  87. return get_config_var('LIBDIR')
  88. def is_npy_no_signal():
  89. """Return True if the NPY_NO_SIGNAL symbol must be defined in configuration
  90. header."""
  91. return sys.platform == 'win32'
  92. def is_npy_no_smp():
  93. """Return True if the NPY_NO_SMP symbol must be defined in public
  94. header (when SMP support cannot be reliably enabled)."""
  95. # Perhaps a fancier check is in order here.
  96. # so that threads are only enabled if there
  97. # are actually multiple CPUS? -- but
  98. # threaded code can be nice even on a single
  99. # CPU so that long-calculating code doesn't
  100. # block.
  101. return 'NPY_NOSMP' in os.environ
  102. def win32_checks(deflist):
  103. from numpy.distutils.misc_util import get_build_architecture
  104. a = get_build_architecture()
  105. # Distutils hack on AMD64 on windows
  106. print('BUILD_ARCHITECTURE: %r, os.name=%r, sys.platform=%r' %
  107. (a, os.name, sys.platform))
  108. if a == 'AMD64':
  109. deflist.append('DISTUTILS_USE_SDK')
  110. # On win32, force long double format string to be 'g', not
  111. # 'Lg', since the MS runtime does not support long double whose
  112. # size is > sizeof(double)
  113. if a == "Intel" or a == "AMD64":
  114. deflist.append('FORCE_NO_LONG_DOUBLE_FORMATTING')
  115. def check_math_capabilities(config, ext, moredefs, mathlibs):
  116. def check_func(
  117. func_name,
  118. decl=False,
  119. headers=["feature_detection_math.h", "feature_detection_cmath.h"],
  120. ):
  121. return config.check_func(
  122. func_name,
  123. libraries=mathlibs,
  124. decl=decl,
  125. call=True,
  126. call_args=FUNC_CALL_ARGS[func_name],
  127. headers=headers,
  128. )
  129. def check_funcs_once(
  130. funcs_name,
  131. headers=["feature_detection_math.h", "feature_detection_cmath.h"],
  132. add_to_moredefs=True):
  133. call = dict([(f, True) for f in funcs_name])
  134. call_args = dict([(f, FUNC_CALL_ARGS[f]) for f in funcs_name])
  135. st = config.check_funcs_once(
  136. funcs_name,
  137. libraries=mathlibs,
  138. decl=False,
  139. call=call,
  140. call_args=call_args,
  141. headers=headers,
  142. )
  143. if st and add_to_moredefs:
  144. moredefs.extend([(fname2def(f), 1) for f in funcs_name])
  145. return st
  146. def check_funcs(
  147. funcs_name,
  148. headers=["feature_detection_math.h", "feature_detection_cmath.h"]):
  149. # Use check_funcs_once first, and if it does not work, test func per
  150. # func. Return success only if all the functions are available
  151. if not check_funcs_once(funcs_name, headers=headers):
  152. # Global check failed, check func per func
  153. for f in funcs_name:
  154. if check_func(f, headers=headers):
  155. moredefs.append((fname2def(f), 1))
  156. return 0
  157. else:
  158. return 1
  159. # GH-14787: Work around GCC<8.4 bug when compiling with AVX512
  160. # support on Windows-based platforms
  161. def check_gh14787(fn):
  162. if fn == 'attribute_target_avx512f':
  163. if (sys.platform in ('win32', 'cygwin') and
  164. config.check_compiler_gcc() and
  165. not config.check_gcc_version_at_least(8, 4)):
  166. ext.extra_compile_args.extend(
  167. ['-ffixed-xmm%s' % n for n in range(16, 32)])
  168. #use_msvc = config.check_decl("_MSC_VER")
  169. if not check_funcs_once(MANDATORY_FUNCS, add_to_moredefs=False):
  170. raise SystemError("One of the required function to build numpy is not"
  171. " available (the list is %s)." % str(MANDATORY_FUNCS))
  172. # Standard functions which may not be available and for which we have a
  173. # replacement implementation. Note that some of these are C99 functions.
  174. # XXX: hack to circumvent cpp pollution from python: python put its
  175. # config.h in the public namespace, so we have a clash for the common
  176. # functions we test. We remove every function tested by python's
  177. # autoconf, hoping their own test are correct
  178. for f in OPTIONAL_FUNCS_MAYBE:
  179. if config.check_decl(fname2def(f), headers=["Python.h"]):
  180. OPTIONAL_FILE_FUNCS.remove(f)
  181. check_funcs(OPTIONAL_FILE_FUNCS, headers=["feature_detection_stdio.h"])
  182. check_funcs(OPTIONAL_MISC_FUNCS, headers=["feature_detection_misc.h"])
  183. for h in OPTIONAL_HEADERS:
  184. if config.check_func("", decl=False, call=False, headers=[h]):
  185. h = h.replace(".", "_").replace(os.path.sep, "_")
  186. moredefs.append((fname2def(h), 1))
  187. # Try with both "locale.h" and "xlocale.h"
  188. locale_headers = [
  189. "stdlib.h",
  190. "xlocale.h",
  191. "feature_detection_locale.h",
  192. ]
  193. if not check_funcs(OPTIONAL_LOCALE_FUNCS, headers=locale_headers):
  194. # It didn't work with xlocale.h, maybe it will work with locale.h?
  195. locale_headers[1] = "locale.h"
  196. check_funcs(OPTIONAL_LOCALE_FUNCS, headers=locale_headers)
  197. for tup in OPTIONAL_INTRINSICS:
  198. headers = None
  199. if len(tup) == 2:
  200. f, args, m = tup[0], tup[1], fname2def(tup[0])
  201. elif len(tup) == 3:
  202. f, args, headers, m = tup[0], tup[1], [tup[2]], fname2def(tup[0])
  203. else:
  204. f, args, headers, m = tup[0], tup[1], [tup[2]], fname2def(tup[3])
  205. if config.check_func(f, decl=False, call=True, call_args=args,
  206. headers=headers):
  207. moredefs.append((m, 1))
  208. for dec, fn in OPTIONAL_FUNCTION_ATTRIBUTES:
  209. if config.check_gcc_function_attribute(dec, fn):
  210. moredefs.append((fname2def(fn), 1))
  211. check_gh14787(fn)
  212. platform = sysconfig.get_platform()
  213. if ("x86_64" in platform):
  214. for dec, fn in OPTIONAL_FUNCTION_ATTRIBUTES_AVX:
  215. if config.check_gcc_function_attribute(dec, fn):
  216. moredefs.append((fname2def(fn), 1))
  217. check_gh14787(fn)
  218. for dec, fn, code, header in (
  219. OPTIONAL_FUNCTION_ATTRIBUTES_WITH_INTRINSICS_AVX):
  220. if config.check_gcc_function_attribute_with_intrinsics(
  221. dec, fn, code, header):
  222. moredefs.append((fname2def(fn), 1))
  223. for fn in OPTIONAL_VARIABLE_ATTRIBUTES:
  224. if config.check_gcc_variable_attribute(fn):
  225. m = fn.replace("(", "_").replace(")", "_")
  226. moredefs.append((fname2def(m), 1))
  227. def check_complex(config, mathlibs):
  228. priv = []
  229. pub = []
  230. # Check for complex support
  231. st = config.check_header('complex.h')
  232. if st:
  233. priv.append(('HAVE_COMPLEX_H', 1))
  234. pub.append(('NPY_USE_C99_COMPLEX', 1))
  235. for t in C99_COMPLEX_TYPES:
  236. st = config.check_type(t, headers=["complex.h"])
  237. if st:
  238. pub.append(('NPY_HAVE_%s' % type2def(t), 1))
  239. def check_prec(prec):
  240. flist = [f + prec for f in C99_COMPLEX_FUNCS]
  241. decl = dict([(f, True) for f in flist])
  242. if not config.check_funcs_once(flist, call=decl, decl=decl,
  243. libraries=mathlibs):
  244. for f in flist:
  245. if config.check_func(f, call=True, decl=True,
  246. libraries=mathlibs):
  247. priv.append((fname2def(f), 1))
  248. else:
  249. priv.extend([(fname2def(f), 1) for f in flist])
  250. check_prec('')
  251. check_prec('f')
  252. check_prec('l')
  253. return priv, pub
  254. def check_ieee_macros(config):
  255. priv = []
  256. pub = []
  257. macros = []
  258. def _add_decl(f):
  259. priv.append(fname2def("decl_%s" % f))
  260. pub.append('NPY_%s' % fname2def("decl_%s" % f))
  261. # XXX: hack to circumvent cpp pollution from python: python put its
  262. # config.h in the public namespace, so we have a clash for the common
  263. # functions we test. We remove every function tested by python's
  264. # autoconf, hoping their own test are correct
  265. _macros = ["isnan", "isinf", "signbit", "isfinite"]
  266. for f in _macros:
  267. py_symbol = fname2def("decl_%s" % f)
  268. already_declared = config.check_decl(py_symbol,
  269. headers=["Python.h", "math.h"])
  270. if already_declared:
  271. if config.check_macro_true(py_symbol,
  272. headers=["Python.h", "math.h"]):
  273. pub.append('NPY_%s' % fname2def("decl_%s" % f))
  274. else:
  275. macros.append(f)
  276. # Normally, isnan and isinf are macro (C99), but some platforms only have
  277. # func, or both func and macro version. Check for macro only, and define
  278. # replacement ones if not found.
  279. # Note: including Python.h is necessary because it modifies some math.h
  280. # definitions
  281. for f in macros:
  282. st = config.check_decl(f, headers=["Python.h", "math.h"])
  283. if st:
  284. _add_decl(f)
  285. return priv, pub
  286. def check_types(config_cmd, ext, build_dir):
  287. private_defines = []
  288. public_defines = []
  289. # Expected size (in number of bytes) for each type. This is an
  290. # optimization: those are only hints, and an exhaustive search for the size
  291. # is done if the hints are wrong.
  292. expected = {'short': [2], 'int': [4], 'long': [8, 4],
  293. 'float': [4], 'double': [8], 'long double': [16, 12, 8],
  294. 'Py_intptr_t': [8, 4], 'PY_LONG_LONG': [8], 'long long': [8],
  295. 'off_t': [8, 4]}
  296. # Check we have the python header (-dev* packages on Linux)
  297. result = config_cmd.check_header('Python.h')
  298. if not result:
  299. python = 'python'
  300. if '__pypy__' in sys.builtin_module_names:
  301. python = 'pypy'
  302. raise SystemError(
  303. "Cannot compile 'Python.h'. Perhaps you need to "
  304. "install {0}-dev|{0}-devel.".format(python))
  305. res = config_cmd.check_header("endian.h")
  306. if res:
  307. private_defines.append(('HAVE_ENDIAN_H', 1))
  308. public_defines.append(('NPY_HAVE_ENDIAN_H', 1))
  309. res = config_cmd.check_header("sys/endian.h")
  310. if res:
  311. private_defines.append(('HAVE_SYS_ENDIAN_H', 1))
  312. public_defines.append(('NPY_HAVE_SYS_ENDIAN_H', 1))
  313. # Check basic types sizes
  314. for type in ('short', 'int', 'long'):
  315. res = config_cmd.check_decl("SIZEOF_%s" % sym2def(type), headers=["Python.h"])
  316. if res:
  317. public_defines.append(('NPY_SIZEOF_%s' % sym2def(type), "SIZEOF_%s" % sym2def(type)))
  318. else:
  319. res = config_cmd.check_type_size(type, expected=expected[type])
  320. if res >= 0:
  321. public_defines.append(('NPY_SIZEOF_%s' % sym2def(type), '%d' % res))
  322. else:
  323. raise SystemError("Checking sizeof (%s) failed !" % type)
  324. for type in ('float', 'double', 'long double'):
  325. already_declared = config_cmd.check_decl("SIZEOF_%s" % sym2def(type),
  326. headers=["Python.h"])
  327. res = config_cmd.check_type_size(type, expected=expected[type])
  328. if res >= 0:
  329. public_defines.append(('NPY_SIZEOF_%s' % sym2def(type), '%d' % res))
  330. if not already_declared and not type == 'long double':
  331. private_defines.append(('SIZEOF_%s' % sym2def(type), '%d' % res))
  332. else:
  333. raise SystemError("Checking sizeof (%s) failed !" % type)
  334. # Compute size of corresponding complex type: used to check that our
  335. # definition is binary compatible with C99 complex type (check done at
  336. # build time in npy_common.h)
  337. complex_def = "struct {%s __x; %s __y;}" % (type, type)
  338. res = config_cmd.check_type_size(complex_def,
  339. expected=[2 * x for x in expected[type]])
  340. if res >= 0:
  341. public_defines.append(('NPY_SIZEOF_COMPLEX_%s' % sym2def(type), '%d' % res))
  342. else:
  343. raise SystemError("Checking sizeof (%s) failed !" % complex_def)
  344. for type in ('Py_intptr_t', 'off_t'):
  345. res = config_cmd.check_type_size(type, headers=["Python.h"],
  346. library_dirs=[pythonlib_dir()],
  347. expected=expected[type])
  348. if res >= 0:
  349. private_defines.append(('SIZEOF_%s' % sym2def(type), '%d' % res))
  350. public_defines.append(('NPY_SIZEOF_%s' % sym2def(type), '%d' % res))
  351. else:
  352. raise SystemError("Checking sizeof (%s) failed !" % type)
  353. # We check declaration AND type because that's how distutils does it.
  354. if config_cmd.check_decl('PY_LONG_LONG', headers=['Python.h']):
  355. res = config_cmd.check_type_size('PY_LONG_LONG', headers=['Python.h'],
  356. library_dirs=[pythonlib_dir()],
  357. expected=expected['PY_LONG_LONG'])
  358. if res >= 0:
  359. private_defines.append(('SIZEOF_%s' % sym2def('PY_LONG_LONG'), '%d' % res))
  360. public_defines.append(('NPY_SIZEOF_%s' % sym2def('PY_LONG_LONG'), '%d' % res))
  361. else:
  362. raise SystemError("Checking sizeof (%s) failed !" % 'PY_LONG_LONG')
  363. res = config_cmd.check_type_size('long long',
  364. expected=expected['long long'])
  365. if res >= 0:
  366. #private_defines.append(('SIZEOF_%s' % sym2def('long long'), '%d' % res))
  367. public_defines.append(('NPY_SIZEOF_%s' % sym2def('long long'), '%d' % res))
  368. else:
  369. raise SystemError("Checking sizeof (%s) failed !" % 'long long')
  370. if not config_cmd.check_decl('CHAR_BIT', headers=['Python.h']):
  371. raise RuntimeError(
  372. "Config wo CHAR_BIT is not supported"
  373. ", please contact the maintainers")
  374. return private_defines, public_defines
  375. def check_mathlib(config_cmd):
  376. # Testing the C math library
  377. mathlibs = []
  378. mathlibs_choices = [[], ["m"], ["cpml"]]
  379. mathlib = os.environ.get("MATHLIB")
  380. if mathlib:
  381. mathlibs_choices.insert(0, mathlib.split(","))
  382. for libs in mathlibs_choices:
  383. if config_cmd.check_func(
  384. "log",
  385. libraries=libs,
  386. call_args="0",
  387. decl="double log(double);",
  388. call=True
  389. ):
  390. mathlibs = libs
  391. break
  392. else:
  393. raise RuntimeError(
  394. "math library missing; rerun setup.py after setting the "
  395. "MATHLIB env variable"
  396. )
  397. return mathlibs
  398. def visibility_define(config):
  399. """Return the define value to use for NPY_VISIBILITY_HIDDEN (may be empty
  400. string)."""
  401. hide = '__attribute__((visibility("hidden")))'
  402. if config.check_gcc_function_attribute(hide, 'hideme'):
  403. return hide
  404. else:
  405. return ''
  406. def configuration(parent_package='',top_path=None):
  407. from numpy.distutils.misc_util import (Configuration, dot_join,
  408. exec_mod_from_location)
  409. from numpy.distutils.system_info import (get_info, blas_opt_info,
  410. lapack_opt_info)
  411. from numpy.distutils.ccompiler_opt import NPY_CXX_FLAGS
  412. from numpy.version import release as is_released
  413. config = Configuration('core', parent_package, top_path)
  414. local_dir = config.local_path
  415. codegen_dir = join(local_dir, 'code_generators')
  416. # Check whether we have a mismatch between the set C API VERSION and the
  417. # actual C API VERSION. Will raise a MismatchCAPIError if so.
  418. check_api_version(C_API_VERSION, codegen_dir)
  419. generate_umath_py = join(codegen_dir, 'generate_umath.py')
  420. n = dot_join(config.name, 'generate_umath')
  421. generate_umath = exec_mod_from_location('_'.join(n.split('.')),
  422. generate_umath_py)
  423. header_dir = 'include/numpy' # this is relative to config.path_in_package
  424. cocache = CallOnceOnly()
  425. def generate_config_h(ext, build_dir):
  426. target = join(build_dir, header_dir, 'config.h')
  427. d = os.path.dirname(target)
  428. if not os.path.exists(d):
  429. os.makedirs(d)
  430. if newer(__file__, target):
  431. config_cmd = config.get_config_cmd()
  432. log.info('Generating %s', target)
  433. # Check sizeof
  434. moredefs, ignored = cocache.check_types(config_cmd, ext, build_dir)
  435. # Check math library and C99 math funcs availability
  436. mathlibs = check_mathlib(config_cmd)
  437. moredefs.append(('MATHLIB', ','.join(mathlibs)))
  438. check_math_capabilities(config_cmd, ext, moredefs, mathlibs)
  439. moredefs.extend(cocache.check_ieee_macros(config_cmd)[0])
  440. moredefs.extend(cocache.check_complex(config_cmd, mathlibs)[0])
  441. # Signal check
  442. if is_npy_no_signal():
  443. moredefs.append('__NPY_PRIVATE_NO_SIGNAL')
  444. # Windows checks
  445. if sys.platform == 'win32' or os.name == 'nt':
  446. win32_checks(moredefs)
  447. # C99 restrict keyword
  448. moredefs.append(('NPY_RESTRICT', config_cmd.check_restrict()))
  449. # Inline check
  450. inline = config_cmd.check_inline()
  451. if can_link_svml():
  452. moredefs.append(('NPY_CAN_LINK_SVML', 1))
  453. # Use bogus stride debug aid to flush out bugs where users use
  454. # strides of dimensions with length 1 to index a full contiguous
  455. # array.
  456. if NPY_RELAXED_STRIDES_DEBUG:
  457. moredefs.append(('NPY_RELAXED_STRIDES_DEBUG', 1))
  458. else:
  459. moredefs.append(('NPY_RELAXED_STRIDES_DEBUG', 0))
  460. # Get long double representation
  461. rep = check_long_double_representation(config_cmd)
  462. moredefs.append(('HAVE_LDOUBLE_%s' % rep, 1))
  463. if check_for_right_shift_internal_compiler_error(config_cmd):
  464. moredefs.append('NPY_DO_NOT_OPTIMIZE_LONG_right_shift')
  465. moredefs.append('NPY_DO_NOT_OPTIMIZE_ULONG_right_shift')
  466. moredefs.append('NPY_DO_NOT_OPTIMIZE_LONGLONG_right_shift')
  467. moredefs.append('NPY_DO_NOT_OPTIMIZE_ULONGLONG_right_shift')
  468. # Generate the config.h file from moredefs
  469. with open(target, 'w') as target_f:
  470. if sys.platform == 'darwin':
  471. target_f.write(
  472. "/* may be overridden by numpyconfig.h on darwin */\n"
  473. )
  474. for d in moredefs:
  475. if isinstance(d, str):
  476. target_f.write('#define %s\n' % (d))
  477. else:
  478. target_f.write('#define %s %s\n' % (d[0], d[1]))
  479. # define inline to our keyword, or nothing
  480. target_f.write('#ifndef __cplusplus\n')
  481. if inline == 'inline':
  482. target_f.write('/* #undef inline */\n')
  483. else:
  484. target_f.write('#define inline %s\n' % inline)
  485. target_f.write('#endif\n')
  486. # add the guard to make sure config.h is never included directly,
  487. # but always through npy_config.h
  488. target_f.write(textwrap.dedent("""
  489. #ifndef NUMPY_CORE_SRC_COMMON_NPY_CONFIG_H_
  490. #error config.h should never be included directly, include npy_config.h instead
  491. #endif
  492. """))
  493. log.info('File: %s' % target)
  494. with open(target) as target_f:
  495. log.info(target_f.read())
  496. log.info('EOF')
  497. else:
  498. mathlibs = []
  499. with open(target) as target_f:
  500. for line in target_f:
  501. s = '#define MATHLIB'
  502. if line.startswith(s):
  503. value = line[len(s):].strip()
  504. if value:
  505. mathlibs.extend(value.split(','))
  506. # Ugly: this can be called within a library and not an extension,
  507. # in which case there is no libraries attributes (and none is
  508. # needed).
  509. if hasattr(ext, 'libraries'):
  510. ext.libraries.extend(mathlibs)
  511. incl_dir = os.path.dirname(target)
  512. if incl_dir not in config.numpy_include_dirs:
  513. config.numpy_include_dirs.append(incl_dir)
  514. return target
  515. def generate_numpyconfig_h(ext, build_dir):
  516. """Depends on config.h: generate_config_h has to be called before !"""
  517. # put common include directory in build_dir on search path
  518. # allows using code generation in headers
  519. config.add_include_dirs(join(build_dir, "src", "common"))
  520. config.add_include_dirs(join(build_dir, "src", "npymath"))
  521. target = join(build_dir, header_dir, '_numpyconfig.h')
  522. d = os.path.dirname(target)
  523. if not os.path.exists(d):
  524. os.makedirs(d)
  525. if newer(__file__, target):
  526. config_cmd = config.get_config_cmd()
  527. log.info('Generating %s', target)
  528. # Check sizeof
  529. ignored, moredefs = cocache.check_types(config_cmd, ext, build_dir)
  530. if is_npy_no_signal():
  531. moredefs.append(('NPY_NO_SIGNAL', 1))
  532. if is_npy_no_smp():
  533. moredefs.append(('NPY_NO_SMP', 1))
  534. else:
  535. moredefs.append(('NPY_NO_SMP', 0))
  536. mathlibs = check_mathlib(config_cmd)
  537. moredefs.extend(cocache.check_ieee_macros(config_cmd)[1])
  538. moredefs.extend(cocache.check_complex(config_cmd, mathlibs)[1])
  539. if NPY_RELAXED_STRIDES_DEBUG:
  540. moredefs.append(('NPY_RELAXED_STRIDES_DEBUG', 1))
  541. # Check whether we can use inttypes (C99) formats
  542. if config_cmd.check_decl('PRIdPTR', headers=['inttypes.h']):
  543. moredefs.append(('NPY_USE_C99_FORMATS', 1))
  544. # visibility check
  545. hidden_visibility = visibility_define(config_cmd)
  546. moredefs.append(('NPY_VISIBILITY_HIDDEN', hidden_visibility))
  547. # Add the C API/ABI versions
  548. moredefs.append(('NPY_ABI_VERSION', '0x%.8X' % C_ABI_VERSION))
  549. moredefs.append(('NPY_API_VERSION', '0x%.8X' % C_API_VERSION))
  550. # Add moredefs to header
  551. with open(target, 'w') as target_f:
  552. for d in moredefs:
  553. if isinstance(d, str):
  554. target_f.write('#define %s\n' % (d))
  555. else:
  556. target_f.write('#define %s %s\n' % (d[0], d[1]))
  557. # Define __STDC_FORMAT_MACROS
  558. target_f.write(textwrap.dedent("""
  559. #ifndef __STDC_FORMAT_MACROS
  560. #define __STDC_FORMAT_MACROS 1
  561. #endif
  562. """))
  563. # Dump the numpyconfig.h header to stdout
  564. log.info('File: %s' % target)
  565. with open(target) as target_f:
  566. log.info(target_f.read())
  567. log.info('EOF')
  568. config.add_data_files((header_dir, target))
  569. return target
  570. def generate_api_func(module_name):
  571. def generate_api(ext, build_dir):
  572. script = join(codegen_dir, module_name + '.py')
  573. sys.path.insert(0, codegen_dir)
  574. try:
  575. m = __import__(module_name)
  576. log.info('executing %s', script)
  577. h_file, c_file, doc_file = m.generate_api(os.path.join(build_dir, header_dir))
  578. finally:
  579. del sys.path[0]
  580. config.add_data_files((header_dir, h_file),
  581. (header_dir, doc_file))
  582. return (h_file,)
  583. return generate_api
  584. generate_numpy_api = generate_api_func('generate_numpy_api')
  585. generate_ufunc_api = generate_api_func('generate_ufunc_api')
  586. config.add_include_dirs(join(local_dir, "src", "common"))
  587. config.add_include_dirs(join(local_dir, "src"))
  588. config.add_include_dirs(join(local_dir))
  589. config.add_data_dir('include/numpy')
  590. config.add_include_dirs(join('src', 'npymath'))
  591. config.add_include_dirs(join('src', 'multiarray'))
  592. config.add_include_dirs(join('src', 'umath'))
  593. config.add_include_dirs(join('src', 'npysort'))
  594. config.add_include_dirs(join('src', '_simd'))
  595. config.add_define_macros([("NPY_INTERNAL_BUILD", "1")]) # this macro indicates that Numpy build is in process
  596. config.add_define_macros([("HAVE_NPY_CONFIG_H", "1")])
  597. if sys.platform[:3] == "aix":
  598. config.add_define_macros([("_LARGE_FILES", None)])
  599. else:
  600. config.add_define_macros([("_FILE_OFFSET_BITS", "64")])
  601. config.add_define_macros([('_LARGEFILE_SOURCE', '1')])
  602. config.add_define_macros([('_LARGEFILE64_SOURCE', '1')])
  603. config.numpy_include_dirs.extend(config.paths('include'))
  604. deps = [join('src', 'npymath', '_signbit.c'),
  605. join('include', 'numpy', '*object.h'),
  606. join(codegen_dir, 'genapi.py'),
  607. ]
  608. #######################################################################
  609. # npymath library #
  610. #######################################################################
  611. subst_dict = dict([("sep", os.path.sep), ("pkgname", "numpy.core")])
  612. def get_mathlib_info(*args):
  613. # Another ugly hack: the mathlib info is known once build_src is run,
  614. # but we cannot use add_installed_pkg_config here either, so we only
  615. # update the substitution dictionary during npymath build
  616. config_cmd = config.get_config_cmd()
  617. # Check that the toolchain works, to fail early if it doesn't
  618. # (avoid late errors with MATHLIB which are confusing if the
  619. # compiler does not work).
  620. for lang, test_code, note in (
  621. ('c', 'int main(void) { return 0;}', ''),
  622. ('c++', (
  623. 'int main(void)'
  624. '{ auto x = 0.0; return static_cast<int>(x); }'
  625. ), (
  626. 'note: A compiler with support for C++11 language '
  627. 'features is required.'
  628. )
  629. ),
  630. ):
  631. is_cpp = lang == 'c++'
  632. if is_cpp:
  633. # this a workaround to get rid of invalid c++ flags
  634. # without doing big changes to config.
  635. # c tested first, compiler should be here
  636. bk_c = config_cmd.compiler
  637. config_cmd.compiler = bk_c.cxx_compiler()
  638. # Check that Linux compiler actually support the default flags
  639. if hasattr(config_cmd.compiler, 'compiler'):
  640. config_cmd.compiler.compiler.extend(NPY_CXX_FLAGS)
  641. config_cmd.compiler.compiler_so.extend(NPY_CXX_FLAGS)
  642. st = config_cmd.try_link(test_code, lang=lang)
  643. if not st:
  644. # rerun the failing command in verbose mode
  645. config_cmd.compiler.verbose = True
  646. config_cmd.try_link(test_code, lang=lang)
  647. raise RuntimeError(
  648. f"Broken toolchain: cannot link a simple {lang.upper()} "
  649. f"program. {note}"
  650. )
  651. if is_cpp:
  652. config_cmd.compiler = bk_c
  653. mlibs = check_mathlib(config_cmd)
  654. posix_mlib = ' '.join(['-l%s' % l for l in mlibs])
  655. msvc_mlib = ' '.join(['%s.lib' % l for l in mlibs])
  656. subst_dict["posix_mathlib"] = posix_mlib
  657. subst_dict["msvc_mathlib"] = msvc_mlib
  658. npymath_sources = [join('src', 'npymath', 'npy_math_internal.h.src'),
  659. join('src', 'npymath', 'npy_math.c'),
  660. # join('src', 'npymath', 'ieee754.cpp'),
  661. join('src', 'npymath', 'ieee754.c.src'),
  662. join('src', 'npymath', 'npy_math_complex.c.src'),
  663. join('src', 'npymath', 'halffloat.c'),
  664. ]
  665. config.add_installed_library('npymath',
  666. sources=npymath_sources + [get_mathlib_info],
  667. install_dir='lib',
  668. build_info={
  669. 'include_dirs' : [], # empty list required for creating npy_math_internal.h
  670. 'extra_compiler_args': [lib_opts_if_msvc],
  671. })
  672. config.add_npy_pkg_config("npymath.ini.in", "lib/npy-pkg-config",
  673. subst_dict)
  674. config.add_npy_pkg_config("mlib.ini.in", "lib/npy-pkg-config",
  675. subst_dict)
  676. #######################################################################
  677. # multiarray_tests module #
  678. #######################################################################
  679. config.add_extension('_multiarray_tests',
  680. sources=[join('src', 'multiarray', '_multiarray_tests.c.src'),
  681. join('src', 'common', 'mem_overlap.c'),
  682. join('src', 'common', 'npy_argparse.c'),
  683. join('src', 'common', 'npy_hashtable.c')],
  684. depends=[join('src', 'common', 'mem_overlap.h'),
  685. join('src', 'common', 'npy_argparse.h'),
  686. join('src', 'common', 'npy_hashtable.h'),
  687. join('src', 'common', 'npy_extint128.h')],
  688. libraries=['npymath'])
  689. #######################################################################
  690. # _multiarray_umath module - common part #
  691. #######################################################################
  692. common_deps = [
  693. join('src', 'common', 'dlpack', 'dlpack.h'),
  694. join('src', 'common', 'array_assign.h'),
  695. join('src', 'common', 'binop_override.h'),
  696. join('src', 'common', 'cblasfuncs.h'),
  697. join('src', 'common', 'lowlevel_strided_loops.h'),
  698. join('src', 'common', 'mem_overlap.h'),
  699. join('src', 'common', 'npy_argparse.h'),
  700. join('src', 'common', 'npy_cblas.h'),
  701. join('src', 'common', 'npy_config.h'),
  702. join('src', 'common', 'npy_ctypes.h'),
  703. join('src', 'common', 'npy_dlpack.h'),
  704. join('src', 'common', 'npy_extint128.h'),
  705. join('src', 'common', 'npy_import.h'),
  706. join('src', 'common', 'npy_hashtable.h'),
  707. join('src', 'common', 'npy_longdouble.h'),
  708. join('src', 'common', 'npy_svml.h'),
  709. join('src', 'common', 'templ_common.h.src'),
  710. join('src', 'common', 'ucsnarrow.h'),
  711. join('src', 'common', 'ufunc_override.h'),
  712. join('src', 'common', 'umathmodule.h'),
  713. join('src', 'common', 'numpyos.h'),
  714. join('src', 'common', 'npy_cpu_dispatch.h'),
  715. join('src', 'common', 'simd', 'simd.h'),
  716. ]
  717. common_src = [
  718. join('src', 'common', 'array_assign.c'),
  719. join('src', 'common', 'mem_overlap.c'),
  720. join('src', 'common', 'npy_argparse.c'),
  721. join('src', 'common', 'npy_hashtable.c'),
  722. join('src', 'common', 'npy_longdouble.c'),
  723. join('src', 'common', 'templ_common.h.src'),
  724. join('src', 'common', 'ucsnarrow.c'),
  725. join('src', 'common', 'ufunc_override.c'),
  726. join('src', 'common', 'numpyos.c'),
  727. join('src', 'common', 'npy_cpu_features.c'),
  728. ]
  729. if os.environ.get('NPY_USE_BLAS_ILP64', "0") != "0":
  730. blas_info = get_info('blas_ilp64_opt', 2)
  731. else:
  732. blas_info = get_info('blas_opt', 0)
  733. have_blas = blas_info and ('HAVE_CBLAS', None) in blas_info.get('define_macros', [])
  734. if have_blas:
  735. extra_info = blas_info
  736. # These files are also in MANIFEST.in so that they are always in
  737. # the source distribution independently of HAVE_CBLAS.
  738. common_src.extend([join('src', 'common', 'cblasfuncs.c'),
  739. join('src', 'common', 'python_xerbla.c'),
  740. ])
  741. else:
  742. extra_info = {}
  743. #######################################################################
  744. # _multiarray_umath module - multiarray part #
  745. #######################################################################
  746. multiarray_deps = [
  747. join('src', 'multiarray', 'abstractdtypes.h'),
  748. join('src', 'multiarray', 'arrayobject.h'),
  749. join('src', 'multiarray', 'arraytypes.h.src'),
  750. join('src', 'multiarray', 'arrayfunction_override.h'),
  751. join('src', 'multiarray', 'array_coercion.h'),
  752. join('src', 'multiarray', 'array_method.h'),
  753. join('src', 'multiarray', 'npy_buffer.h'),
  754. join('src', 'multiarray', 'calculation.h'),
  755. join('src', 'multiarray', 'common.h'),
  756. join('src', 'multiarray', 'common_dtype.h'),
  757. join('src', 'multiarray', 'convert_datatype.h'),
  758. join('src', 'multiarray', 'convert.h'),
  759. join('src', 'multiarray', 'conversion_utils.h'),
  760. join('src', 'multiarray', 'ctors.h'),
  761. join('src', 'multiarray', 'descriptor.h'),
  762. join('src', 'multiarray', 'dtypemeta.h'),
  763. join('src', 'multiarray', 'dtype_transfer.h'),
  764. join('src', 'multiarray', 'dragon4.h'),
  765. join('src', 'multiarray', 'einsum_debug.h'),
  766. join('src', 'multiarray', 'einsum_sumprod.h'),
  767. join('src', 'multiarray', 'experimental_public_dtype_api.h'),
  768. join('src', 'multiarray', 'getset.h'),
  769. join('src', 'multiarray', 'hashdescr.h'),
  770. join('src', 'multiarray', 'iterators.h'),
  771. join('src', 'multiarray', 'legacy_dtype_implementation.h'),
  772. join('src', 'multiarray', 'mapping.h'),
  773. join('src', 'multiarray', 'methods.h'),
  774. join('src', 'multiarray', 'multiarraymodule.h'),
  775. join('src', 'multiarray', 'nditer_impl.h'),
  776. join('src', 'multiarray', 'number.h'),
  777. join('src', 'multiarray', 'refcount.h'),
  778. join('src', 'multiarray', 'scalartypes.h'),
  779. join('src', 'multiarray', 'sequence.h'),
  780. join('src', 'multiarray', 'shape.h'),
  781. join('src', 'multiarray', 'strfuncs.h'),
  782. join('src', 'multiarray', 'typeinfo.h'),
  783. join('src', 'multiarray', 'usertypes.h'),
  784. join('src', 'multiarray', 'vdot.h'),
  785. join('src', 'multiarray', 'textreading', 'readtext.h'),
  786. join('include', 'numpy', 'arrayobject.h'),
  787. join('include', 'numpy', '_neighborhood_iterator_imp.h'),
  788. join('include', 'numpy', 'npy_endian.h'),
  789. join('include', 'numpy', 'arrayscalars.h'),
  790. join('include', 'numpy', 'noprefix.h'),
  791. join('include', 'numpy', 'npy_interrupt.h'),
  792. join('include', 'numpy', 'npy_3kcompat.h'),
  793. join('include', 'numpy', 'npy_math.h'),
  794. join('include', 'numpy', 'halffloat.h'),
  795. join('include', 'numpy', 'npy_common.h'),
  796. join('include', 'numpy', 'npy_os.h'),
  797. join('include', 'numpy', 'utils.h'),
  798. join('include', 'numpy', 'ndarrayobject.h'),
  799. join('include', 'numpy', 'npy_cpu.h'),
  800. join('include', 'numpy', 'numpyconfig.h'),
  801. join('include', 'numpy', 'ndarraytypes.h'),
  802. join('include', 'numpy', 'npy_1_7_deprecated_api.h'),
  803. # add library sources as distuils does not consider libraries
  804. # dependencies
  805. ] + npymath_sources
  806. multiarray_src = [
  807. join('src', 'multiarray', 'abstractdtypes.c'),
  808. join('src', 'multiarray', 'alloc.c'),
  809. join('src', 'multiarray', 'arrayobject.c'),
  810. join('src', 'multiarray', 'arraytypes.h.src'),
  811. join('src', 'multiarray', 'arraytypes.c.src'),
  812. join('src', 'multiarray', 'argfunc.dispatch.c.src'),
  813. join('src', 'multiarray', 'array_coercion.c'),
  814. join('src', 'multiarray', 'array_method.c'),
  815. join('src', 'multiarray', 'array_assign_scalar.c'),
  816. join('src', 'multiarray', 'array_assign_array.c'),
  817. join('src', 'multiarray', 'arrayfunction_override.c'),
  818. join('src', 'multiarray', 'buffer.c'),
  819. join('src', 'multiarray', 'calculation.c'),
  820. join('src', 'multiarray', 'compiled_base.c'),
  821. join('src', 'multiarray', 'common.c'),
  822. join('src', 'multiarray', 'common_dtype.c'),
  823. join('src', 'multiarray', 'convert.c'),
  824. join('src', 'multiarray', 'convert_datatype.c'),
  825. join('src', 'multiarray', 'conversion_utils.c'),
  826. join('src', 'multiarray', 'ctors.c'),
  827. join('src', 'multiarray', 'datetime.c'),
  828. join('src', 'multiarray', 'datetime_strings.c'),
  829. join('src', 'multiarray', 'datetime_busday.c'),
  830. join('src', 'multiarray', 'datetime_busdaycal.c'),
  831. join('src', 'multiarray', 'descriptor.c'),
  832. join('src', 'multiarray', 'dlpack.c'),
  833. join('src', 'multiarray', 'dtypemeta.c'),
  834. join('src', 'multiarray', 'dragon4.c'),
  835. join('src', 'multiarray', 'dtype_transfer.c'),
  836. join('src', 'multiarray', 'einsum.c.src'),
  837. join('src', 'multiarray', 'einsum_sumprod.c.src'),
  838. join('src', 'multiarray', 'experimental_public_dtype_api.c'),
  839. join('src', 'multiarray', 'flagsobject.c'),
  840. join('src', 'multiarray', 'getset.c'),
  841. join('src', 'multiarray', 'hashdescr.c'),
  842. join('src', 'multiarray', 'item_selection.c'),
  843. join('src', 'multiarray', 'iterators.c'),
  844. join('src', 'multiarray', 'legacy_dtype_implementation.c'),
  845. join('src', 'multiarray', 'lowlevel_strided_loops.c.src'),
  846. join('src', 'multiarray', 'mapping.c'),
  847. join('src', 'multiarray', 'methods.c'),
  848. join('src', 'multiarray', 'multiarraymodule.c'),
  849. join('src', 'multiarray', 'nditer_templ.c.src'),
  850. join('src', 'multiarray', 'nditer_api.c'),
  851. join('src', 'multiarray', 'nditer_constr.c'),
  852. join('src', 'multiarray', 'nditer_pywrap.c'),
  853. join('src', 'multiarray', 'number.c'),
  854. join('src', 'multiarray', 'refcount.c'),
  855. join('src', 'multiarray', 'sequence.c'),
  856. join('src', 'multiarray', 'shape.c'),
  857. join('src', 'multiarray', 'scalarapi.c'),
  858. join('src', 'multiarray', 'scalartypes.c.src'),
  859. join('src', 'multiarray', 'strfuncs.c'),
  860. join('src', 'multiarray', 'temp_elide.c'),
  861. join('src', 'multiarray', 'typeinfo.c'),
  862. join('src', 'multiarray', 'usertypes.c'),
  863. join('src', 'multiarray', 'vdot.c'),
  864. join('src', 'common', 'npy_sort.h.src'),
  865. join('src', 'npysort', 'x86-qsort.dispatch.cpp'),
  866. join('src', 'npysort', 'quicksort.cpp'),
  867. join('src', 'npysort', 'mergesort.cpp'),
  868. join('src', 'npysort', 'timsort.cpp'),
  869. join('src', 'npysort', 'heapsort.cpp'),
  870. join('src', 'npysort', 'radixsort.cpp'),
  871. join('src', 'common', 'npy_partition.h'),
  872. join('src', 'npysort', 'selection.cpp'),
  873. join('src', 'common', 'npy_binsearch.h'),
  874. join('src', 'npysort', 'binsearch.cpp'),
  875. join('src', 'multiarray', 'textreading', 'conversions.c'),
  876. join('src', 'multiarray', 'textreading', 'field_types.c'),
  877. join('src', 'multiarray', 'textreading', 'growth.c'),
  878. join('src', 'multiarray', 'textreading', 'readtext.c'),
  879. join('src', 'multiarray', 'textreading', 'rows.c'),
  880. join('src', 'multiarray', 'textreading', 'stream_pyobject.c'),
  881. join('src', 'multiarray', 'textreading', 'str_to_int.c'),
  882. join('src', 'multiarray', 'textreading', 'tokenize.cpp'),
  883. # Remove this once scipy macos arm64 build correctly
  884. # links to the arm64 npymath library,
  885. # see gh-22673
  886. join('src', 'npymath', 'arm64_exports.c'),
  887. ]
  888. #######################################################################
  889. # _multiarray_umath module - umath part #
  890. #######################################################################
  891. def generate_umath_c(ext, build_dir):
  892. target = join(build_dir, header_dir, '__umath_generated.c')
  893. dir = os.path.dirname(target)
  894. if not os.path.exists(dir):
  895. os.makedirs(dir)
  896. script = generate_umath_py
  897. if newer(script, target):
  898. with open(target, 'w') as f:
  899. f.write(generate_umath.make_code(generate_umath.defdict,
  900. generate_umath.__file__))
  901. return []
  902. def generate_umath_doc_header(ext, build_dir):
  903. from numpy.distutils.misc_util import exec_mod_from_location
  904. target = join(build_dir, header_dir, '_umath_doc_generated.h')
  905. dir = os.path.dirname(target)
  906. if not os.path.exists(dir):
  907. os.makedirs(dir)
  908. generate_umath_doc_py = join(codegen_dir, 'generate_umath_doc.py')
  909. if newer(generate_umath_doc_py, target):
  910. n = dot_join(config.name, 'generate_umath_doc')
  911. generate_umath_doc = exec_mod_from_location(
  912. '_'.join(n.split('.')), generate_umath_doc_py)
  913. generate_umath_doc.write_code(target)
  914. umath_src = [
  915. join('src', 'umath', 'umathmodule.c'),
  916. join('src', 'umath', 'reduction.c'),
  917. join('src', 'umath', 'funcs.inc.src'),
  918. join('src', 'umath', 'simd.inc.src'),
  919. join('src', 'umath', 'loops.h.src'),
  920. join('src', 'umath', 'loops_utils.h.src'),
  921. join('src', 'umath', 'loops.c.src'),
  922. join('src', 'umath', 'loops_unary_fp.dispatch.c.src'),
  923. join('src', 'umath', 'loops_arithm_fp.dispatch.c.src'),
  924. join('src', 'umath', 'loops_arithmetic.dispatch.c.src'),
  925. join('src', 'umath', 'loops_minmax.dispatch.c.src'),
  926. join('src', 'umath', 'loops_trigonometric.dispatch.c.src'),
  927. join('src', 'umath', 'loops_umath_fp.dispatch.c.src'),
  928. join('src', 'umath', 'loops_exponent_log.dispatch.c.src'),
  929. join('src', 'umath', 'loops_hyperbolic.dispatch.c.src'),
  930. join('src', 'umath', 'loops_modulo.dispatch.c.src'),
  931. join('src', 'umath', 'loops_comparison.dispatch.c.src'),
  932. join('src', 'umath', 'matmul.h.src'),
  933. join('src', 'umath', 'matmul.c.src'),
  934. join('src', 'umath', 'clip.h'),
  935. join('src', 'umath', 'clip.cpp'),
  936. join('src', 'umath', 'dispatching.c'),
  937. join('src', 'umath', 'legacy_array_method.c'),
  938. join('src', 'umath', 'wrapping_array_method.c'),
  939. join('src', 'umath', 'ufunc_object.c'),
  940. join('src', 'umath', 'extobj.c'),
  941. join('src', 'umath', 'scalarmath.c.src'),
  942. join('src', 'umath', 'ufunc_type_resolution.c'),
  943. join('src', 'umath', 'override.c'),
  944. join('src', 'umath', 'string_ufuncs.cpp'),
  945. # For testing. Eventually, should use public API and be separate:
  946. join('src', 'umath', '_scaled_float_dtype.c'),
  947. ]
  948. umath_deps = [
  949. generate_umath_py,
  950. join('include', 'numpy', 'npy_math.h'),
  951. join('include', 'numpy', 'halffloat.h'),
  952. join('src', 'multiarray', 'common.h'),
  953. join('src', 'multiarray', 'number.h'),
  954. join('src', 'common', 'templ_common.h.src'),
  955. join('src', 'umath', 'simd.inc.src'),
  956. join('src', 'umath', 'override.h'),
  957. join(codegen_dir, 'generate_ufunc_api.py'),
  958. join(codegen_dir, 'ufunc_docstrings.py'),
  959. ]
  960. svml_path = join('numpy', 'core', 'src', 'umath', 'svml')
  961. svml_objs = []
  962. # we have converted the following into universal intrinsics
  963. # so we can bring the benefits of performance for all platforms
  964. # not just for avx512 on linux without performance/accuracy regression,
  965. # actually the other way around, better performance and
  966. # after all maintainable code.
  967. svml_filter = (
  968. )
  969. if can_link_svml() and check_svml_submodule(svml_path):
  970. svml_objs = glob.glob(svml_path + '/**/*.s', recursive=True)
  971. svml_objs = [o for o in svml_objs if not o.endswith(svml_filter)]
  972. # The ordering of names returned by glob is undefined, so we sort
  973. # to make builds reproducible.
  974. svml_objs.sort()
  975. config.add_extension('_multiarray_umath',
  976. # Forcing C language even though we have C++ sources.
  977. # It forces the C linker and don't link C++ runtime.
  978. language = 'c',
  979. sources=multiarray_src + umath_src +
  980. common_src +
  981. [generate_config_h,
  982. generate_numpyconfig_h,
  983. generate_numpy_api,
  984. join(codegen_dir, 'generate_numpy_api.py'),
  985. join('*.py'),
  986. generate_umath_c,
  987. generate_umath_doc_header,
  988. generate_ufunc_api,
  989. ],
  990. depends=deps + multiarray_deps + umath_deps +
  991. common_deps,
  992. libraries=['npymath'],
  993. extra_objects=svml_objs,
  994. extra_info=extra_info,
  995. extra_cxx_compile_args=NPY_CXX_FLAGS)
  996. #######################################################################
  997. # umath_tests module #
  998. #######################################################################
  999. config.add_extension('_umath_tests', sources=[
  1000. join('src', 'umath', '_umath_tests.c.src'),
  1001. join('src', 'umath', '_umath_tests.dispatch.c'),
  1002. join('src', 'common', 'npy_cpu_features.c'),
  1003. ])
  1004. #######################################################################
  1005. # custom rational dtype module #
  1006. #######################################################################
  1007. config.add_extension('_rational_tests',
  1008. sources=[join('src', 'umath', '_rational_tests.c')])
  1009. #######################################################################
  1010. # struct_ufunc_test module #
  1011. #######################################################################
  1012. config.add_extension('_struct_ufunc_tests',
  1013. sources=[join('src', 'umath', '_struct_ufunc_tests.c')])
  1014. #######################################################################
  1015. # operand_flag_tests module #
  1016. #######################################################################
  1017. config.add_extension('_operand_flag_tests',
  1018. sources=[join('src', 'umath', '_operand_flag_tests.c')])
  1019. #######################################################################
  1020. # SIMD module #
  1021. #######################################################################
  1022. config.add_extension('_simd',
  1023. sources=[
  1024. join('src', 'common', 'npy_cpu_features.c'),
  1025. join('src', '_simd', '_simd.c'),
  1026. join('src', '_simd', '_simd_inc.h.src'),
  1027. join('src', '_simd', '_simd_data.inc.src'),
  1028. join('src', '_simd', '_simd.dispatch.c.src'),
  1029. ], depends=[
  1030. join('src', 'common', 'npy_cpu_dispatch.h'),
  1031. join('src', 'common', 'simd', 'simd.h'),
  1032. join('src', '_simd', '_simd.h'),
  1033. join('src', '_simd', '_simd_inc.h.src'),
  1034. join('src', '_simd', '_simd_data.inc.src'),
  1035. join('src', '_simd', '_simd_arg.inc'),
  1036. join('src', '_simd', '_simd_convert.inc'),
  1037. join('src', '_simd', '_simd_easyintrin.inc'),
  1038. join('src', '_simd', '_simd_vector.inc'),
  1039. ],
  1040. libraries=['npymath']
  1041. )
  1042. config.add_subpackage('tests')
  1043. config.add_data_dir('tests/data')
  1044. config.add_data_dir('tests/examples')
  1045. config.add_data_files('*.pyi')
  1046. config.make_svn_version_py()
  1047. return config
  1048. if __name__ == '__main__':
  1049. from numpy.distutils.core import setup
  1050. setup(configuration=configuration)