Skip to content

Commit 9c90522

Browse files
committed
Replace float64 and int64 with float32 and int32, respectively
1 parent 45064fb commit 9c90522

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

python/tests/beagle.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ def get_weights(genotyped_pos, ungenotyped_pos):
8787
genotyped_cm = convert_to_genetic_map_position(genotyped_pos)
8888
ungenotyped_cm = convert_to_genetic_map_position(ungenotyped_pos)
8989
# Calculate weights for ungenotyped markers.
90-
weights = np.zeros(x, dtype=np.float64)
90+
weights = np.zeros(x, dtype=np.float32)
9191
# Identify genotype markers k and k + 1 sandwiching marker i.
92-
marker_interval_start = np.zeros(x, dtype=np.int64)
92+
marker_interval_start = np.zeros(x, dtype=np.int32)
9393
for i in np.arange(x):
9494
if ungenotyped_pos[i] < genotyped_pos[0]:
9595
# Ungenotyped marker is before the first genotyped marker.
@@ -126,7 +126,7 @@ def get_mismatch_prob(pos, miscall_rate):
126126
assert isinstance(miscall_rate, float)
127127
if miscall_rate >= 0.5:
128128
miscall_rate = 0.5
129-
mu = np.zeros(len(pos), dtype=np.float64) + miscall_rate
129+
mu = np.zeros(len(pos), dtype=np.float32) + miscall_rate
130130
return mu
131131

132132

@@ -150,7 +150,7 @@ def get_switch_prob(pos, h, ne):
150150
assert isinstance(ne, float), "Effective population size is not a float."
151151
# Get genetic distance between adjacent markers.
152152
cm = convert_to_genetic_map_position(pos)
153-
d = np.zeros(len(pos), dtype=np.float64)
153+
d = np.zeros(len(pos), dtype=np.float32)
154154
d[0] = cm[0]
155155
d[1:] = cm[1:] - cm[:-1]
156156
assert len(d) == len(pos)
@@ -185,7 +185,7 @@ def compute_forward_probability_matrix(ref_h, query_h, rho, mu):
185185
assert m == len(mu)
186186
assert 0 <= np.min(rho) and np.max(rho) <= 1
187187
assert 0 <= np.min(mu) and np.max(mu) <= 0.5
188-
fm = np.zeros((m, h), dtype=np.float64)
188+
fm = np.zeros((m, h), dtype=np.float32)
189189
last_sum = 1.0 # Part of normalization factor
190190
for i in np.arange(m):
191191
# Get site-specific parameters.
@@ -236,7 +236,7 @@ def compute_backward_probability_matrix(ref_h, query_h, rho, mu):
236236
assert m == len(mu)
237237
assert 0 <= np.min(rho) and np.max(rho) <= 1
238238
assert 0 <= np.min(mu) and np.max(mu) <= 0.5
239-
bm = np.zeros((m, h), dtype=np.float64)
239+
bm = np.zeros((m, h), dtype=np.float32)
240240
bm[-1, :] = 1.0 / h # Initialise the last column
241241
for i in np.arange(m - 2, -1, -1):
242242
query_a = query_h[i + 1]
@@ -330,9 +330,9 @@ def _compute_state_probability_matrix(fm, bm, ref_h, query_h, rho, mu):
330330
assert 0 <= np.min(rho) and np.max(rho) <= 1
331331
assert 0 <= np.min(mu) and np.max(mu) <= 0.5
332332
# m + 1 columns to allow for imputed markers right of the last genotyped marker.
333-
sm = np.zeros((m + 1, h), dtype=np.float64)
334-
fwd_hap_probs = np.zeros((m, 4), dtype=np.float64)
335-
bwd_hap_probs = np.zeros((m, 4), dtype=np.float64)
333+
sm = np.zeros((m + 1, h), dtype=np.float32)
334+
fwd_hap_probs = np.zeros((m, 4), dtype=np.float32)
335+
bwd_hap_probs = np.zeros((m, 4), dtype=np.float32)
336336
for i in np.arange(m - 1, -1, -1):
337337
for j in np.arange(h):
338338
sm[i, j] = fm[i, j] * bm[i, j]
@@ -384,7 +384,7 @@ def _interpolate_allele_probabilities(
384384
assert x == len(imputed_cm)
385385
weights, _ = get_weights(genotyped_cm, imputed_cm)
386386
assert x == len(weights)
387-
i_hap_probs = np.zeros((x, 2), dtype=np.float64)
387+
i_hap_probs = np.zeros((x, 2), dtype=np.float32)
388388
for i in np.arange(x):
389389
# Identify the genotyped markers k and k + 1 sandwiching ungenotyped marker i.
390390
if ungenotyped_pos[i] < genotyped_pos[0]:
@@ -426,7 +426,7 @@ def compute_state_probability_matrix(fm, bm):
426426
assert not np.any(bm < 0), "Backward probability matrix has negative values."
427427
assert not np.any(np.isnan(bm)), "Backward probability matrix has NaN values."
428428
# m + 1 columns to allow for imputed markers right of the last genotyped marker.
429-
sm = np.zeros((m + 1, h), dtype=np.float64)
429+
sm = np.zeros((m + 1, h), dtype=np.float32)
430430
sm[:-1, :] = np.multiply(fm, bm)
431431
sm[m, :] = sm[m - 1, :] # Not in BEAGLE
432432
return sm
@@ -464,7 +464,7 @@ def interpolate_allele_probabilities(sm, ref_h, genotyped_pos, ungenotyped_pos):
464464
weights, marker_interval_start = get_weights(genotyped_pos, ungenotyped_pos)
465465
assert x == len(weights)
466466
assert x == len(marker_interval_start)
467-
p = np.zeros((x, len(alleles)), dtype=np.float64)
467+
p = np.zeros((x, len(alleles)), dtype=np.float32)
468468
# Compute allele probabilities as per Equation 1 in BB2016.
469469
for a in alleles:
470470
# Going from left to right.

python/tests/beagle_numba.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def get_weights(genotyped_pos, ungenotyped_pos):
4747
genotyped_cm = convert_to_genetic_map_position(genotyped_pos)
4848
ungenotyped_cm = convert_to_genetic_map_position(ungenotyped_pos)
4949
# Calculate weights for ungenotyped markers.
50-
weights = np.zeros(x, dtype=np.float64)
50+
weights = np.zeros(x, dtype=np.float32)
5151
# Identify genotype markers k and k + 1 sandwiching ungenotyped marker i.
52-
marker_interval_start = np.zeros(x, dtype=np.int64)
52+
marker_interval_start = np.zeros(x, dtype=np.int32)
5353
idx_m = m - 1
5454
# Going from right to left.
5555
for idx_x in np.arange(x - 1, -1, -1):
@@ -86,7 +86,7 @@ def get_mismatch_prob(pos, miscall_rate):
8686
"""
8787
if miscall_rate >= 0.5:
8888
miscall_rate = 0.5
89-
mu = np.zeros(len(pos), dtype=np.float64) + miscall_rate
89+
mu = np.zeros(len(pos), dtype=np.float32) + miscall_rate
9090
return mu
9191

9292

@@ -107,7 +107,7 @@ def get_switch_prob(pos, h, ne):
107107
"""
108108
# Get genetic distances between adjacent markers.
109109
cm = convert_to_genetic_map_position(pos)
110-
d = np.zeros(len(pos), dtype=np.float64)
110+
d = np.zeros(len(pos), dtype=np.float32)
111111
d[0] = cm[0]
112112
d[1:] = cm[1:] - cm[:-1]
113113
rho = -np.expm1(-(4 * ne * d / h))
@@ -131,7 +131,7 @@ def compute_forward_probability_matrix(ref_h, query_h, rho, mu):
131131
"""
132132
m = ref_h.shape[0]
133133
h = ref_h.shape[1]
134-
fm = np.zeros((m, h), dtype=np.float64)
134+
fm = np.zeros((m, h), dtype=np.float32)
135135
last_sum = 1.0 # Part of normalization factor
136136
for i in np.arange(m):
137137
# Get site-specific parameters
@@ -173,7 +173,7 @@ def compute_backward_probability_matrix(ref_h, query_h, rho, mu):
173173
"""
174174
m = ref_h.shape[0]
175175
h = ref_h.shape[1]
176-
bm = np.zeros((m, h), dtype=np.float64)
176+
bm = np.zeros((m, h), dtype=np.float32)
177177
bm[-1, :] = 1.0 / h # Initialise the last column
178178
for i in np.arange(m - 2, -1, -1):
179179
query_a = query_h[i + 1]
@@ -211,7 +211,7 @@ def compute_state_probability_matrix(fm, bm):
211211
m = fm.shape[0]
212212
h = bm.shape[1]
213213
# m + 1 columns to allow for imputed markers right of the last genotyped marker.
214-
sm = np.zeros((m + 1, h), dtype=np.float64)
214+
sm = np.zeros((m + 1, h), dtype=np.float32)
215215
sm[:-1, :] = np.multiply(fm, bm)
216216
sm[m, :] = sm[m - 1, :] # Not in BEAGLE
217217
return sm
@@ -242,7 +242,7 @@ def interpolate_allele_probabilities(sm, ref_h, genotyped_pos, ungenotyped_pos):
242242
alleles = np.arange(4) # ACGT encoding
243243
x = len(ungenotyped_pos)
244244
weights, marker_interval_start = get_weights(genotyped_pos, ungenotyped_pos)
245-
p = np.zeros((x, len(alleles)), dtype=np.float64)
245+
p = np.zeros((x, len(alleles)), dtype=np.float32)
246246
for a in alleles:
247247
for i in np.arange(x):
248248
# Identify genotyped markers k and k + 1 sandwiching ungenotyped marker i.

0 commit comments

Comments
 (0)