async def stream_read( self: 'streams.Stream', count: int, spin_wait: Union[int, float] = 0) -> Union[Array, None]: if not self.running or self.stopping: exceptions.check_error(pa.STREAM_IS_STOPPED) if not self.is_input: exceptions.check_error(pa.CAN_NOT_READ_FROM_AN_OUTPUT_ONLY_STREAM) buffer = self.buffer[0] parts = [] count *= self.config[0].channels total = 0 while True: # spin until all requested data has been popped, or timeout popped = buffer.pop(count - total) if popped is not None: total += len(popped) parts.append(popped) if total < count: await asyncio.sleep(spin_wait) if not self.running or self.stopping: exceptions.check_error(pa.STREAM_IS_STOPPED) else: break if len(parts) == 1: return parts[0] elif len(parts): return concatenate(*parts) return None
def test_concatenate(): array_size = 10000 num_arrays = 1000 arrays = [ Array(format='i', shape=(array_size, ), itemsize=struct.calcsize('i')) for i in range(num_arrays) ] expected = [ np.linspace(i, i + array_size, num=array_size, dtype='i') for i in range(0, array_size * num_arrays, array_size) ] for i, arr in enumerate(arrays): arr[:] = expected[i] concatenated = concatenate(*arrays) assert np.array_equal( np.array(concatenated, dtype='i'), np.concatenate(expected), )
def test_concatenate_valueerror_empty(): with pytest.raises(ValueError): concatenate(b'')
def test_concatenate_typeerror(invalid): with pytest.raises(TypeError): concatenate(invalid, np.array([1, 2], dtype='i'))
def test_concatenate_valueerror_no_args(): with pytest.raises(ValueError): concatenate()
def test_concatenate_valueerror_ndims(): with pytest.raises(ValueError): concatenate(np.array([[1, 2], [3, 4]]), np.array([[1, 2], [3, 4]]))