def item_type(self): if self.is_countable: return type(self.items[0]) else: first, items = cytoolz.peek(self.items) self.items = items return type(first)
def vdl(signal, times, delay, initial_value=0.0): """Variable delay line which delays `signal` at 'times' with 'delay'. :param signal: Signal to be delayed. :type signal: Iterator :param delay: Delay. :type delay: Iterator :param initial_value: Sample to yield before first actual sample is yielded due to initial delay. .. note:: Times and delay should have the same unit, e.g. both in samples or both in seconds. """ dt0, delay = cytoolz.peek(delay) times, _times = itertools.tee(times) # Yield initial value before interpolation kicks in # Note that this method, using tee, buffers all samples that will be discarded. # Therefore, room for optimization! n = 0 if initial_value is not None: while next(_times) < dt0: n += 1 yield initial_value times1, times2 = itertools.tee(times) interpolated = interpolate_linear(map(operator.add, times2, delay), signal, times1) yield from cytoolz.drop(n, interpolated) # FIXME: move drop before interpolation, saves memory
def vdl(signal, times, delay, initial_value=0.0): """Variable delay line which delays `signal` at 'times' with 'delay'. :param signal: Signal to be delayed. :type signal: Iterator :param delay: Delay. :type delay: Iterator :param initial_value: Sample to yield before first actual sample is yielded due to initial delay. .. note:: Times and delay should have the same unit, e.g. both in samples or both in seconds. """ dt0, delay = cytoolz.peek(delay) times, _times = itertools.tee(times) # Yield initial value before interpolation kicks in # Note that this method, using tee, buffers all samples that will be discarded. # Therefore, room for optimization! n = 0 if initial_value is not None: while next(_times) < dt0: n += 1 yield initial_value times1, times2 = itertools.tee(times) interpolated = interpolate_linear(map(operator.add, times2, delay), signal, times1) yield from cytoolz.drop( n, interpolated) # FIXME: move drop before interpolation, saves memory
def peek(self): """Check the first item in the stream.""" first, self._iterator = cytoolz.peek(self._iterator) return first
def peek(self): first, seq = cytoolz.peek(self) self = self.__class__(seq) return first