Skip to content

Commit e7b1a4e

Browse files
Do not share buffers in LdCalculator.
Closes #396
1 parent 628db5d commit e7b1a4e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

python/CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
In development.
66

7+
**Bugfixes**
8+
9+
- Do not reuse buffers in LdCalculator (:user:`jeromekelleher`). See :pr:`397` and
10+
:issue:`396`.
11+
712

813
--------------------
914
[0.2.2] - 2019-09-01

python/tskit/stats.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ def __init__(self, tree_sequence):
5454
self._tree_sequence = tree_sequence
5555
self._ll_ld_calculator = _tskit.LdCalculator(
5656
tree_sequence.get_ll_tree_sequence())
57-
item_size = struct.calcsize('d')
58-
self._buffer = bytearray(
59-
tree_sequence.get_num_mutations() * item_size)
6057
# To protect low-level C code, only one method may execute on the
6158
# low-level objects at one time.
6259
self._instance_lock = threading.Lock()
@@ -130,11 +127,13 @@ def r2_array(self, a, direction=1, max_mutations=None, max_distance=None):
130127
max_mutations = -1
131128
if max_distance is None:
132129
max_distance = sys.float_info.max
130+
item_size = struct.calcsize('d')
131+
buffer = bytearray(self._tree_sequence.get_num_mutations() * item_size)
133132
with self._instance_lock:
134133
num_values = self._ll_ld_calculator.get_r2_array(
135-
self._buffer, a, direction=direction,
134+
buffer, a, direction=direction,
136135
max_mutations=max_mutations, max_distance=max_distance)
137-
return np.frombuffer(self._buffer, "d", num_values)
136+
return np.frombuffer(buffer, "d", num_values)
138137

139138
def get_r2_matrix(self):
140139
# Deprecated alias for r2_matrix

0 commit comments

Comments
 (0)