diff --git a/common/ffi_wrapper.py b/common/ffi_wrapper.py index a228b40256..01741c6f42 100644 --- a/common/ffi_wrapper.py +++ b/common/ffi_wrapper.py @@ -1,55 +1,8 @@ -import os -import sys -import fcntl -import hashlib import platform -from cffi import FFI + def suffix(): if platform.system() == "Darwin": return ".dylib" else: return ".so" - -def ffi_wrap(name, c_code, c_header, tmpdir="/tmp/ccache", cflags="", libraries=None): - if libraries is None: - libraries = [] - - cache = name + "_" + hashlib.sha1(c_code.encode('utf-8')).hexdigest() - try: - os.mkdir(tmpdir) - except OSError: - pass - - fd = os.open(tmpdir, 0) - fcntl.flock(fd, fcntl.LOCK_EX) - try: - sys.path.append(tmpdir) - try: - mod = __import__(cache) - except Exception: - print(f"cache miss {cache}") - compile_code(cache, c_code, c_header, tmpdir, cflags, libraries) - mod = __import__(cache) - finally: - os.close(fd) - - return mod.ffi, mod.lib - - -def compile_code(name, c_code, c_header, directory, cflags="", libraries=None): - if libraries is None: - libraries = [] - - ffibuilder = FFI() - ffibuilder.set_source(name, c_code, source_extension='.cpp', libraries=libraries) - ffibuilder.cdef(c_header) - os.environ['OPT'] = "-fwrapv -O2 -DNDEBUG -std=c++1z" - os.environ['CFLAGS'] = cflags - ffibuilder.compile(verbose=True, debug=False, tmpdir=directory) - - -def wrap_compiled(name, directory): - sys.path.append(directory) - mod = __import__(name) - return mod.ffi, mod.lib diff --git a/common/lazy_property.py b/common/lazy_property.py deleted file mode 100644 index 919dd9e87e..0000000000 --- a/common/lazy_property.py +++ /dev/null @@ -1,12 +0,0 @@ -class lazy_property(): - """Defines a property whose value will be computed only once and as needed. - - This can only be used on instance methods. - """ - def __init__(self, func): - self._func = func - - def __get__(self, obj_self, cls): - value = self._func(obj_self) - setattr(obj_self, self._func.__name__, value) - return value diff --git a/common/numpy_helpers.py b/common/numpy_helpers.py deleted file mode 100644 index 7b1efe8976..0000000000 --- a/common/numpy_helpers.py +++ /dev/null @@ -1,22 +0,0 @@ -import numpy as np - - -def deep_interp_np(x, xp, fp, axis=None): - if axis is not None: - fp = fp.swapaxes(0,axis) - x = np.atleast_1d(x) - xp = np.array(xp) - if len(xp) < 2: - return np.repeat(fp, len(x), axis=0) - if min(np.diff(xp)) < 0: - raise RuntimeError('Bad x array for interpolation') - j = np.searchsorted(xp, x) - 1 - j = np.clip(j, 0, len(xp)-2) - d = np.divide(x - xp[j], xp[j + 1] - xp[j], out=np.ones_like(x, dtype=np.float64), where=xp[j + 1] - xp[j] != 0) - vals_interp = (fp[j].T*(1 - d)).T + (fp[j + 1].T*d).T - if axis is not None: - vals_interp = vals_interp.swapaxes(0,axis) - if len(vals_interp) == 1: - return vals_interp[0] - else: - return vals_interp