diff --git a/pyopenjtalk/htsengine.pyx b/pyopenjtalk/htsengine.pyx index 868c07a..cdc6018 100644 --- a/pyopenjtalk/htsengine.pyx +++ b/pyopenjtalk/htsengine.pyx @@ -117,9 +117,9 @@ cdef class HTSEngine: cdef size_t nsamples = HTS_Engine_get_nsamples(self.engine) cdef np.ndarray[np.float64_t, ndim=1] speech = np.zeros([nsamples], dtype=np.float64) cdef double[::1] speech_view = speech - cdef size_t index + cdef int index for index in prange(nsamples, nogil=True): - speech_view[index] = HTS_Engine_get_generated_speech(self.engine, index) + speech_view[index] = HTS_Engine_get_generated_speech(self.engine, index) return speech cpdef inline str get_fullcontext_label_format(self): diff --git a/pyopenjtalk/openjtalk.pyx b/pyopenjtalk/openjtalk.pyx index 1ef7923..4f37112 100644 --- a/pyopenjtalk/openjtalk.pyx +++ b/pyopenjtalk/openjtalk.pyx @@ -1,6 +1,6 @@ # coding: utf-8 # cython: language_level=3 -# cython: boundscheck=False, wraparound=False +# cython: boundscheck=False, wraparound=True # cython: c_string_type=unicode, c_string_encoding=ascii, cdivision=True from libc.stdint cimport uint8_t diff --git a/setup.py b/setup.py index 971a08b..8a6ddcc 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ import os import subprocess import sys +import platform from distutils.errors import DistutilsExecError from distutils.spawn import spawn from distutils.version import LooseVersion @@ -70,6 +71,24 @@ def build_extensions(self): if not os.path.exists(join("pyopenjtalk", "openjtalk" + ext)): raise RuntimeError("Cython is required to generate C++ code") +# make openmp available +system = platform.system() +if system == "Windows": + extra_compile_args = [] + extra_link_args = ['/openmp'] +elif system == "Linux": + extra_compile_args = ['-fopenmp'] + extra_link_args = ['-fopenmp'] +elif system == "Darwin": + os.system("brew install llvm libomp") + os.system("brew install clang-omp") + # os.environ["CPP"] = "/usr/local/opt/llvm/bin/clang" + extra_compile_args = ["-Xpreprocessor", "-fopenmp"] + extra_link_args = ["-Xpreprocessor", "-fopenmp"] +else: + extra_compile_args = ['-fopenmp'] + extra_link_args = ['-fopenmp'] + # Workaround for `distutils.spawn` problem on Windows python < 3.9 # See details: [bpo-39763: distutils.spawn now uses subprocess (GH-18743)] @@ -180,8 +199,8 @@ def escape_macros(macros): name="pyopenjtalk.openjtalk", sources=[join("pyopenjtalk", "openjtalk" + ext)] + all_src, include_dirs=[np.get_include()] + include_dirs, - extra_compile_args=['-fopenmp'], - extra_link_args=['-fopenmp'], + extra_compile_args=extra_compile_args, + extra_link_args=extra_link_args, language="c++", define_macros=custom_define_macros( [ @@ -204,8 +223,8 @@ def escape_macros(macros): name="pyopenjtalk.htsengine", sources=[join("pyopenjtalk", "htsengine" + ext)] + all_htsengine_src, include_dirs=[np.get_include(), join(htsengine_src_top, "include")], - extra_compile_args=['-fopenmp'], - extra_link_args=['-fopenmp'], + extra_compile_args=extra_compile_args, + extra_link_args=extra_link_args, libraries=["winmm"] if platform_is_windows else [], language="c++", define_macros=custom_define_macros(