Exemple #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
Exemple #2
0
class LocalMemoryFactory(Factory):
    """
    Factory that stores parameters in memory.
    """

    def get_connection(self):
        self.params = Message()
        self.computed_metrics = defaultdict(Message)

    def read(self):
        return self.params, self.computed_metrics

    def write(self, params, metrics_dict):
        self.params = self.params.append(params)
        for key in metrics_dict:
            self.computed_metrics[key] = self.computed_metrics[key].append(metrics_dict[key])