From 9c905229f57238d202c9ab8bb3b86a2c71d47e0a Mon Sep 17 00:00:00 2001 From: Shing Zhan Date: Mon, 18 Sep 2023 16:54:25 +0100 Subject: [PATCH] Replace float64 and int64 with float32 and int32, respectively --- python/tests/beagle.py | 24 ++++++++++++------------ python/tests/beagle_numba.py | 16 ++++++++-------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/python/tests/beagle.py b/python/tests/beagle.py index df2046c5e0..d2fd8d2c3e 100644 --- a/python/tests/beagle.py +++ b/python/tests/beagle.py @@ -87,9 +87,9 @@ def get_weights(genotyped_pos, ungenotyped_pos): genotyped_cm = convert_to_genetic_map_position(genotyped_pos) ungenotyped_cm = convert_to_genetic_map_position(ungenotyped_pos) # Calculate weights for ungenotyped markers. - weights = np.zeros(x, dtype=np.float64) + weights = np.zeros(x, dtype=np.float32) # Identify genotype markers k and k + 1 sandwiching marker i. - marker_interval_start = np.zeros(x, dtype=np.int64) + marker_interval_start = np.zeros(x, dtype=np.int32) for i in np.arange(x): if ungenotyped_pos[i] < genotyped_pos[0]: # Ungenotyped marker is before the first genotyped marker. @@ -126,7 +126,7 @@ def get_mismatch_prob(pos, miscall_rate): assert isinstance(miscall_rate, float) if miscall_rate >= 0.5: miscall_rate = 0.5 - mu = np.zeros(len(pos), dtype=np.float64) + miscall_rate + mu = np.zeros(len(pos), dtype=np.float32) + miscall_rate return mu @@ -150,7 +150,7 @@ def get_switch_prob(pos, h, ne): assert isinstance(ne, float), "Effective population size is not a float." # Get genetic distance between adjacent markers. cm = convert_to_genetic_map_position(pos) - d = np.zeros(len(pos), dtype=np.float64) + d = np.zeros(len(pos), dtype=np.float32) d[0] = cm[0] d[1:] = cm[1:] - cm[:-1] assert len(d) == len(pos) @@ -185,7 +185,7 @@ def compute_forward_probability_matrix(ref_h, query_h, rho, mu): assert m == len(mu) assert 0 <= np.min(rho) and np.max(rho) <= 1 assert 0 <= np.min(mu) and np.max(mu) <= 0.5 - fm = np.zeros((m, h), dtype=np.float64) + fm = np.zeros((m, h), dtype=np.float32) last_sum = 1.0 # Part of normalization factor for i in np.arange(m): # Get site-specific parameters. @@ -236,7 +236,7 @@ def compute_backward_probability_matrix(ref_h, query_h, rho, mu): assert m == len(mu) assert 0 <= np.min(rho) and np.max(rho) <= 1 assert 0 <= np.min(mu) and np.max(mu) <= 0.5 - bm = np.zeros((m, h), dtype=np.float64) + bm = np.zeros((m, h), dtype=np.float32) bm[-1, :] = 1.0 / h # Initialise the last column for i in np.arange(m - 2, -1, -1): query_a = query_h[i + 1] @@ -330,9 +330,9 @@ def _compute_state_probability_matrix(fm, bm, ref_h, query_h, rho, mu): assert 0 <= np.min(rho) and np.max(rho) <= 1 assert 0 <= np.min(mu) and np.max(mu) <= 0.5 # m + 1 columns to allow for imputed markers right of the last genotyped marker. - sm = np.zeros((m + 1, h), dtype=np.float64) - fwd_hap_probs = np.zeros((m, 4), dtype=np.float64) - bwd_hap_probs = np.zeros((m, 4), dtype=np.float64) + sm = np.zeros((m + 1, h), dtype=np.float32) + fwd_hap_probs = np.zeros((m, 4), dtype=np.float32) + bwd_hap_probs = np.zeros((m, 4), dtype=np.float32) for i in np.arange(m - 1, -1, -1): for j in np.arange(h): sm[i, j] = fm[i, j] * bm[i, j] @@ -384,7 +384,7 @@ def _interpolate_allele_probabilities( assert x == len(imputed_cm) weights, _ = get_weights(genotyped_cm, imputed_cm) assert x == len(weights) - i_hap_probs = np.zeros((x, 2), dtype=np.float64) + i_hap_probs = np.zeros((x, 2), dtype=np.float32) for i in np.arange(x): # Identify the genotyped markers k and k + 1 sandwiching ungenotyped marker i. if ungenotyped_pos[i] < genotyped_pos[0]: @@ -426,7 +426,7 @@ def compute_state_probability_matrix(fm, bm): assert not np.any(bm < 0), "Backward probability matrix has negative values." assert not np.any(np.isnan(bm)), "Backward probability matrix has NaN values." # m + 1 columns to allow for imputed markers right of the last genotyped marker. - sm = np.zeros((m + 1, h), dtype=np.float64) + sm = np.zeros((m + 1, h), dtype=np.float32) sm[:-1, :] = np.multiply(fm, bm) sm[m, :] = sm[m - 1, :] # Not in BEAGLE return sm @@ -464,7 +464,7 @@ def interpolate_allele_probabilities(sm, ref_h, genotyped_pos, ungenotyped_pos): weights, marker_interval_start = get_weights(genotyped_pos, ungenotyped_pos) assert x == len(weights) assert x == len(marker_interval_start) - p = np.zeros((x, len(alleles)), dtype=np.float64) + p = np.zeros((x, len(alleles)), dtype=np.float32) # Compute allele probabilities as per Equation 1 in BB2016. for a in alleles: # Going from left to right. diff --git a/python/tests/beagle_numba.py b/python/tests/beagle_numba.py index cd249ef055..845442d52e 100644 --- a/python/tests/beagle_numba.py +++ b/python/tests/beagle_numba.py @@ -47,9 +47,9 @@ def get_weights(genotyped_pos, ungenotyped_pos): genotyped_cm = convert_to_genetic_map_position(genotyped_pos) ungenotyped_cm = convert_to_genetic_map_position(ungenotyped_pos) # Calculate weights for ungenotyped markers. - weights = np.zeros(x, dtype=np.float64) + weights = np.zeros(x, dtype=np.float32) # Identify genotype markers k and k + 1 sandwiching ungenotyped marker i. - marker_interval_start = np.zeros(x, dtype=np.int64) + marker_interval_start = np.zeros(x, dtype=np.int32) idx_m = m - 1 # Going from right to left. for idx_x in np.arange(x - 1, -1, -1): @@ -86,7 +86,7 @@ def get_mismatch_prob(pos, miscall_rate): """ if miscall_rate >= 0.5: miscall_rate = 0.5 - mu = np.zeros(len(pos), dtype=np.float64) + miscall_rate + mu = np.zeros(len(pos), dtype=np.float32) + miscall_rate return mu @@ -107,7 +107,7 @@ def get_switch_prob(pos, h, ne): """ # Get genetic distances between adjacent markers. cm = convert_to_genetic_map_position(pos) - d = np.zeros(len(pos), dtype=np.float64) + d = np.zeros(len(pos), dtype=np.float32) d[0] = cm[0] d[1:] = cm[1:] - cm[:-1] rho = -np.expm1(-(4 * ne * d / h)) @@ -131,7 +131,7 @@ def compute_forward_probability_matrix(ref_h, query_h, rho, mu): """ m = ref_h.shape[0] h = ref_h.shape[1] - fm = np.zeros((m, h), dtype=np.float64) + fm = np.zeros((m, h), dtype=np.float32) last_sum = 1.0 # Part of normalization factor for i in np.arange(m): # Get site-specific parameters @@ -173,7 +173,7 @@ def compute_backward_probability_matrix(ref_h, query_h, rho, mu): """ m = ref_h.shape[0] h = ref_h.shape[1] - bm = np.zeros((m, h), dtype=np.float64) + bm = np.zeros((m, h), dtype=np.float32) bm[-1, :] = 1.0 / h # Initialise the last column for i in np.arange(m - 2, -1, -1): query_a = query_h[i + 1] @@ -211,7 +211,7 @@ def compute_state_probability_matrix(fm, bm): m = fm.shape[0] h = bm.shape[1] # m + 1 columns to allow for imputed markers right of the last genotyped marker. - sm = np.zeros((m + 1, h), dtype=np.float64) + sm = np.zeros((m + 1, h), dtype=np.float32) sm[:-1, :] = np.multiply(fm, bm) sm[m, :] = sm[m - 1, :] # Not in BEAGLE return sm @@ -242,7 +242,7 @@ def interpolate_allele_probabilities(sm, ref_h, genotyped_pos, ungenotyped_pos): alleles = np.arange(4) # ACGT encoding x = len(ungenotyped_pos) weights, marker_interval_start = get_weights(genotyped_pos, ungenotyped_pos) - p = np.zeros((x, len(alleles)), dtype=np.float64) + p = np.zeros((x, len(alleles)), dtype=np.float32) for a in alleles: for i in np.arange(x): # Identify genotyped markers k and k + 1 sandwiching ungenotyped marker i.