From 4a9d50e8a4acf010fce82d429de75091e890a5f9 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Mon, 17 Apr 2023 17:43:18 +0200 Subject: [PATCH] refactor Log-Gaussian susceptibility --- src/nmreval/distributions/loggaussian.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/nmreval/distributions/loggaussian.py b/src/nmreval/distributions/loggaussian.py index db50640..8c381a1 100644 --- a/src/nmreval/distributions/loggaussian.py +++ b/src/nmreval/distributions/loggaussian.py @@ -48,18 +48,17 @@ class LogGaussian(Distribution): _omega = np.atleast_1d(omega) _tau = np.atleast_1d(tau0) - pool = Pool(processes=min(cpu_count(), 4)) - integration_ranges = [(omega_i, tau_j, sigma) for (omega_i, tau_j) in product(_omega, _tau)] + if HAS_C_FUNCS: + res_real = _integration_parallel(_omega, _tau, sigma, _integrate_process_imag) + res_imag = _integration_parallel(_omega, _tau, sigma, _integrate_process_real) + else: + res_real = None + res_imag = None - with np.errstate(divide='ignore'): - res_real = np.array(pool.map(_integrate_process_imag, integration_ranges)) - res_imag = np.array(pool.map(_integrate_process_real, integration_ranges)) - ret_val = (res_real+1j*res_imag).reshape((_omega.shape[0], _tau.shape[0])) - - return ret_val.squeeze() + return (res_real + 1j * res_imag).squeeze() @staticmethod - def specdens(omega: ArrayLike, tau: ArrayLike, sigma: float): + def specdens(omega: ArrayLike, tau: ArrayLike, sigma: float) -> np.ndarray: _omega = np.atleast_1d(omega) _tau = np.atleast_1d(tau) @@ -106,8 +105,7 @@ def _integrate_specdens_c(omega: np.ndarray, tau: np.ndarray, sigma: float) -> n return res -def _integrate_process_imag(args): - omega_i, tau_j, sigma = args +def _integrate_process_imag(omega_i, tau_j, sigma): area = quad(_integrand_freq_imag_high, 0, 50, args=(omega_i, tau_j, sigma))[0] area += quad(_integrand_freq_imag_low, -50, 0, args=(omega_i, tau_j, sigma))[0]