Exemplo n.º 1
0
    def __getitem__(self, index):
        """
        Retreives items in index by looping through inputs as many times as needed.
        """

        # TODO: Check if index exceeds length, either explicitly or implicitly.

        # Sort index
        index = sorted(index_to_list(index))
        above = [i for i in index
                 if i >= self.position]  # Go forward to reach these
        below = [i for i in index if i < self.position
                 ]  # Will have to reset the loop to reach these
        if len(above) > 0:
            above_values = fireworks.cat(
                [self.step_forward(i + 1) for i in above])
        else:
            above_values = Message()
        if len(below) > 0:
            self.reset()  # Position will now be reset to 0
            below_values = fireworks.cat(
                [self.step_forward(i + 1) for i in below])
        else:
            below_values = Message()
        return below_values.append(
            above_values
        )  # TODO: Resort this message so values are in the order requested by index
Exemplo n.º 2
0
    def __getitem__(self, index):

        index = index_to_list(index)

        if index == []:
            return None
        elif max(index) < self.length and min(index) >= 0:
            return Message({'values': np.array(index)})
        else:
            raise IndexError("Out of bounds for dummy pipe with length {0}.".format(self.length))
Exemplo n.º 3
0
    def __getitem__(self, index):

        index = index_to_list(index)
        if self.length and len(
                index):  # Implicit length check if length is known
            if max(index) >= self.length:
                raise IndexError(
                    "Requested index is out of bounds for inputs with length {0}."
                    .format(self.length))

        # Identify what is in the cache and what isn't.
        in_cache = [i for i in index if i in self.cache.pointers
                    ]  # Elements of index corresponding to in_cache elements
        in_cache_indices = [
            j for i, j in zip(index, count()) if i in self.cache.pointers
        ]  # Indices in index corresponding to in_cache elements
        not_in_cache = [
            i for i in index if i not in self.cache.pointers
        ]  # Elements of index corresponding to not_in_cache elements
        not_in_cache_indices = [
            j for i, j in zip(index, count()) if i not in self.cache.pointers
        ]  # Indices in index corresponding to not_in_cache elements
        # Retrieve from cache existing elements
        in_cache_elements = self.cache[
            in_cache]  # elements in cache corresponding to indices in cache
        # Update cache to have other elements
        not_in_cache_elements = self.input[not_in_cache]
        self.cache[not_in_cache] = not_in_cache_elements
        # Reorder and merge requested elements
        message = in_cache_elements.append(not_in_cache_elements)
        indices = in_cache_indices
        indices.extend(not_in_cache_indices)
        # Elements must be reordered based on their order in index
        permutation = indices.copy()
        for i, j in zip(indices, count()):
            permutation[i] = j
        message = message.permute(permutation)
        # Implicit update of internal knowledge of length
        if len(index) and self.length is None and not self.infinite:
            l = max(index)
            if l > self.lower_bound:
                self.lower_bound = l

        return message
Exemplo n.º 4
0
    def __getitem__(self, index):

        index = index_to_list(index)

        return self.input[self.pointers[index]['output'].values.tolist()]