Skip to content

Commit a944957

Browse files
committed
Removed _extend_using_coroutines
1 parent 7fabe9b commit a944957

File tree

2 files changed

+0
-92
lines changed

2 files changed

+0
-92
lines changed

nibabel/streamlines/array_sequence.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -240,67 +240,6 @@ def extend(self, elements):
240240

241241
self.finalize_append()
242242

243-
def _extend_using_coroutine(self, buffer_size=4):
244-
""" Creates a coroutine allowing to append elements.
245-
246-
Parameters
247-
----------
248-
buffer_size : float, optional
249-
Size (in Mb) for memory pre-allocation.
250-
251-
Returns
252-
-------
253-
coroutine
254-
Coroutine object which expects the values to be appended to this
255-
array sequence.
256-
257-
Notes
258-
-----
259-
This method is essential for
260-
:func:`create_arraysequences_from_generator` as it allows for an
261-
efficient way of creating multiple array sequences in a hyperthreaded
262-
fashion and still benefit from the memory buffering. Whitout this
263-
method the alternative would be to use :meth:`append` which does
264-
not have such buffering mechanism and thus is at least one order of
265-
magnitude slower.
266-
"""
267-
offsets = []
268-
lengths = []
269-
270-
offset = self._get_next_offset()
271-
try:
272-
first_element = True
273-
while True:
274-
e = (yield)
275-
e = np.asarray(e)
276-
if first_element:
277-
first_element = False
278-
n_rows_buffer = int(buffer_size * 1024**2 // e.nbytes)
279-
new_shape = (n_rows_buffer,) + e.shape[1:]
280-
if len(self) == 0:
281-
self._data = np.empty(new_shape, dtype=e.dtype)
282-
283-
end = offset + len(e)
284-
if end > len(self._data):
285-
# Resize needed, adding `len(e)` items plus some buffer.
286-
nb_points = len(self._data)
287-
nb_points += len(e) + n_rows_buffer
288-
self._data.resize((nb_points,) + self.common_shape)
289-
290-
offsets.append(offset)
291-
lengths.append(len(e))
292-
self._data[offset:offset + len(e)] = e
293-
offset += len(e)
294-
295-
except GeneratorExit:
296-
pass
297-
298-
self._offsets = np.r_[self._offsets, offsets].astype(np.intp)
299-
self._lengths = np.r_[self._lengths, lengths].astype(np.intp)
300-
301-
# Clear unused memory.
302-
self._data.resize((offset,) + self.common_shape)
303-
304243
def copy(self):
305244
""" Creates a copy of this :class:`ArraySequence` object.
306245

nibabel/streamlines/tests/test_array_sequence.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -204,37 +204,6 @@ def test_arraysequence_extend(self):
204204
seq = SEQ_DATA['seq'].copy() # Copy because of in-place modification.
205205
assert_raises(ValueError, seq.extend, data)
206206

207-
def test_arraysequence_extend_using_coroutine(self):
208-
new_data = generate_data(nb_arrays=10,
209-
common_shape=SEQ_DATA['seq'].common_shape,
210-
rng=SEQ_DATA['rng'])
211-
212-
# Extend with an empty list.
213-
seq = SEQ_DATA['seq'].copy() # Copy because of in-place modification.
214-
coroutine = seq._extend_using_coroutine()
215-
coroutine.send(None)
216-
coroutine.close()
217-
check_arr_seq(seq, SEQ_DATA['data'])
218-
219-
# Extend with a list of ndarrays.
220-
seq = SEQ_DATA['seq'].copy() # Copy because of in-place modification.
221-
coroutine = seq._extend_using_coroutine()
222-
coroutine.send(None)
223-
for e in new_data:
224-
coroutine.send(e)
225-
coroutine.close()
226-
check_arr_seq(seq, SEQ_DATA['data'] + new_data)
227-
228-
# Extend with elements of different shape.
229-
data = generate_data(nb_arrays=10,
230-
common_shape=SEQ_DATA['seq'].common_shape*2,
231-
rng=SEQ_DATA['rng'])
232-
seq = SEQ_DATA['seq'].copy() # Copy because of in-place modification.
233-
234-
coroutine = seq._extend_using_coroutine()
235-
coroutine.send(None)
236-
assert_raises(ValueError, coroutine.send, data[0])
237-
238207
def test_arraysequence_getitem(self):
239208
# Get one item
240209
for i, e in enumerate(SEQ_DATA['seq']):

0 commit comments

Comments
 (0)