示例#1
0
def extract(sequence, elements):
    """Given a sequence (possibly with nested sequences), extract
    the element identifed by the elements sequence.

    Args:
        sequence: A sequence of elements which may be other sequences
        elements: Sequence of nested element indicies (in sequence parameter)
            to extract

    Returns:
        The target element

    Example:
        >>> inputs = [1, (2, 3, (4, 5)), 6]
        >>> extract(inputs, [0])
        >>> 1
        >>> extract(inputs, [1])
        >>> (2, 3, (4, 5))
        >>> extract(inputs, [1, 0])
        >>> 2
        >>> extract(inputs, [1, 1])
        >>> 3
        >>> extract(inputs, [1, 2])
        >>> (4, 5)
        >>> extract(inputs, [1, 2, 0])
        >>> 4
    ...
    """

    e = tuple(elements)
    if len(e) == 0 or not getattr(sequence, '__iter__', False):
        return sequence
    else:
        seq = sequence[first(e)]
        return extract(seq, drop(1, e))
示例#2
0
def test_deduplicate():
    inputs = [{
        'x': 1,
        'y': 2,
        'acquired': '1980-01-01',
        'ubid': 'a/b/c/d'
    }, {
        'x': 1,
        'y': 2,
        'acquired': '1980-01-01',
        'ubid': 'a/b/c/d'
    }, {
        'x': 2,
        'y': 2,
        'acquired': '1980-01-01',
        'ubid': 'a/b/c/d'
    }, {
        'x': 1,
        'y': 3,
        'acquired': '1980-01-01',
        'ubid': 'a/b/c/d'
    }, {
        'x': 1,
        'y': 2,
        'acquired': '1980-01-02',
        'ubid': 'a/b/c/d'
    }, {
        'x': 1,
        'y': 2,
        'acquired': '1980-01-01',
        'ubid': 'a/b/c'
    }]

    assert chips.deduplicate(inputs) == tuple(drop(1, inputs))
示例#3
0
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
示例#4
0
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
示例#5
0
 def drop(self, n):
     """Drop the first `n` items."""
     return self._construct(cytoolz.drop(n, self))
示例#6
0
 def drop(self, n):
     """Drop the first `n` items."""
     return self._construct(cytoolz.drop(n, self))
示例#7
0
 def __call__(self, iterator):
     return cytoolz.drop(self.n, iterator)
示例#8
0
 def drop(self, n):
     return self.__class__(cytoolz.drop(n, self))
示例#9
0
    def drop(self, n):
        """Drop the first `n` blocks.

        .. note:: If you want to drop `n` samples, use `s.samples().drop(n)`.
        """
        return self._construct(cytoolz.drop(n, self))
def read_student_title():
    with open("../student_title.csv") as f:
        return tlz.drop(1, [line for line in csv.reader(f)])