diff options
author | Frederick Muriuki Muriithi | 2022-05-21 12:11:34 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2022-05-21 12:13:12 +0300 |
commit | b662fcb763488121a95a2b73d2e83c1c0abb8d70 (patch) | |
tree | 2645eb8ecdf4f9e34921c8702d07f76bbb23bcb0 /gn3 | |
parent | 3e80ab10048d82069a86b29930d48738d4a6484f (diff) | |
download | genenetwork3-b662fcb763488121a95a2b73d2e83c1c0abb8d70.tar.gz |
Use multiprocessing to improve performance
Diffstat (limited to 'gn3')
-rw-r--r-- | gn3/computations/partial_correlations.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/gn3/computations/partial_correlations.py b/gn3/computations/partial_correlations.py index c12b4ec..530dd71 100644 --- a/gn3/computations/partial_correlations.py +++ b/gn3/computations/partial_correlations.py @@ -7,6 +7,7 @@ GeneNetwork1. import math import warnings +from multiprocessing import Pool, cpu_count from functools import reduce, partial from typing import Any, Tuple, Union, Sequence, Generator @@ -325,11 +326,15 @@ def compute_partial( This implementation reworks the child function `compute_partial` which will then be used in the place of `determinPartialsByR`. """ - return ( - result for result in ( - compute_trait_info( - primary_vals, control_vals, (target[data_start_pos:], target[0]), method) - for target in targets) + with Pool(processes=(cpu_count() - 1)) as pool: + return ( + result for result in ( + pool.starmap( + compute_trait_info, + (( + primary_vals, control_vals, + (target[data_start_pos:], target[0]), method) + for target in targets))) if result is not None) def partial_correlations_normal(# pylint: disable=R0913 |