summaryrefslogtreecommitdiff
path: root/numpy/core/setup.py
diff options
context:
space:
mode:
authorAndres Guzman-Ballen <andres.guzman-ballen@intel.com>2017-03-06 12:11:34 -0600
committerAndres Guzman-Ballen <andres.guzman-ballen@intel.com>2017-03-10 12:11:05 -0600
commit21d2c7e16875e8d34fbc327cd30a40b50e9974f1 (patch)
tree963d86190b71cb7470d1e046b59b8af6eeb41b42 /numpy/core/setup.py
parent66f1b8a5411e8265ed87ff7bf97c67960af2624d (diff)
downloadnumpy-21d2c7e16875e8d34fbc327cd30a40b50e9974f1.tar.gz
ENH: Allows building npy_math with static inlining
Code Overview: Numpy currently decouples the math function definitions in `npy_math.c.src` from the function declarations found in `npy_math.h`. This patch allows definitions to be included along with the inclusion of the `npy_math.h` header. Keeping the declarations and definitions separate is usually the right approach, but mathematical code like this might be better off as an exception to this common practice. Because the definitions are in the source file instead of the header, the compiler does not have any clue what lies underneath these math functions. This means the compiler can't make important optimizations like inlining and vectorization. Extensions that utilize these functions could greatly benefit from this, specifically `loops.c.src` from the umath extension. Implementation Details: + Renames `npy_math.c.src` to `npy_math_internal.h.src` + Generates `npy_math_internal.h` from template by adding to `npymath_sources` list and adding `npymath` directory to include paths in `generate_numpyconfig_h` function of `numpy/core/setup.py` + Numpy's core distutils defines `#NPY_INTERNAL_BUILD` macro to make sure `npy_math_internal.h` is not included when other modules try to include public header `npy_math.h` - Currently do not know how to ship headers generated from template files + Adds `npy_math.c`, a file that includes the `npy_math_internal.h.src` file (but does not add NPY_INLINE static) - This is to keep the same static npy_math library as it exists now + Appends `numpy/npy_math.h` with `npy_math_internal.h` under condition that it's not being included in npy_math.c.src - The conditional macros mean `loops.c.src` will have definitions included, and the compiler will vectorize accordingly + Adds `NPY_INLINE` static to function declarations and definitions when necessary + Replaces `sqrtf` with `npy_sqrtf` in `numpy/core/src/umath/umath_tests.c` to make function portable - `_sqrtf` was not found on certain Windows environments compiling with Py2
Diffstat (limited to 'numpy/core/setup.py')
-rw-r--r--numpy/core/setup.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/numpy/core/setup.py b/numpy/core/setup.py
index 5bc2eec95..89f65f41a 100644
--- a/numpy/core/setup.py
+++ b/numpy/core/setup.py
@@ -4,6 +4,7 @@ import os
import sys
import pickle
import copy
+import sysconfig
import warnings
from os.path import join
from numpy.distutils import log
@@ -513,6 +514,7 @@ def configuration(parent_package='',top_path=None):
# put private include directory in build_dir on search path
# allows using code generation in headers headers
config.add_include_dirs(join(build_dir, "src", "private"))
+ config.add_include_dirs(join(build_dir, "src", "npymath"))
target = join(build_dir, header_dir, '_numpyconfig.h')
d = os.path.dirname(target)
@@ -605,6 +607,7 @@ def configuration(parent_package='',top_path=None):
config.add_include_dirs(join('src', 'umath'))
config.add_include_dirs(join('src', 'npysort'))
+ config.add_define_macros([("NPY_INTERNAL_BUILD", "1")]) # this macro indicates that Numpy build is in process
config.add_define_macros([("HAVE_NPY_CONFIG_H", "1")])
if sys.platform[:3] == "aix":
config.add_define_macros([("_LARGE_FILES", None)])
@@ -662,14 +665,16 @@ def configuration(parent_package='',top_path=None):
subst_dict["posix_mathlib"] = posix_mlib
subst_dict["msvc_mathlib"] = msvc_mlib
- npymath_sources = [join('src', 'npymath', 'npy_math.c.src'),
+ npymath_sources = [join('src', 'npymath', 'npy_math_internal.h.src'),
+ join('src', 'npymath', 'npy_math.c'),
join('src', 'npymath', 'ieee754.c.src'),
join('src', 'npymath', 'npy_math_complex.c.src'),
join('src', 'npymath', 'halffloat.c')
]
config.add_installed_library('npymath',
sources=npymath_sources + [get_mathlib_info],
- install_dir='lib')
+ install_dir='lib',
+ build_info={'include_dirs' : []}) # empty list required for creating npy_math_internal.h
config.add_npy_pkg_config("npymath.ini.in", "lib/npy-pkg-config",
subst_dict)
config.add_npy_pkg_config("mlib.ini.in", "lib/npy-pkg-config",