def of_tab(self, tabfile):
     """
         Initialize `stats_by_config` table from the spreadsheet `tabfile`
     """
     util.fold_file(
         tabfile, None, lambda acc, row: self.set_stats(row[0], util.stats_of_row([int(v) for v in row[1:]]))
     )
def all_cells_matching(tabfile, config_pred):
    """
        Return a list of all data cells in rows whose titles
        match `config_pred`.
    """
    def process_row(row):
        title = row[0]
        if config_pred(title):
            return [int(x) for x in row[1::]]
        else:
            return []
    return util.fold_file(tabfile, [], lambda acc,row: acc + process_row(row))
def bucketize(fname, get_bkt, num_buckets, pred=None):
    """
        Group the rows in `fname` into buckets,
        using `get_bkt` to assign a row of the file to a bucket.
        Return the collected list of lists
        (todo? optionally allow 'edit_row' function,
          instead of mushing all values into a list)
    """
    init = [[] for _ in range(1+num_buckets)]
    def add_row(acc, row):
        # TODO don't graph all points because ... (I had a reason at some point)
        if (pred is None) or (pred(row[0])):
            acc[get_bkt(row[0])].extend([int(x) for x in row[1::]])
        return acc
    return util.fold_file(fname, init, add_row)
def best_rows(tabfile, limit, metric, val_of_row, init=None):
    """ (->* (Path-String (-> A A Boolean) (-> (Listof Nat) A)) (A) A)
        Return the "value" of the best row, according to `metric`.
        i.e. the row R such that for any other row r: metric(val_of_row(r), val_of_row(R)) = True
        - `tabfile` filename, a tab-separated file
        - `metric`  a < judgment on rows
        - `val_of_row` a pre-processing transformation on rows (used to filter, take mean, etc)
        - `init` optionally, a first value to compare to
    """
    cache = [None] * limit
    cache[0] = init
    def process_row(acc, row):
        # Get value from row.
        # Insert into the list `acc`
        if config.is_untyped(row[0]) or config.is_typed(row[0]):
            # Ignore fully typed / untyped configs
            return acc
        val = val_of_row(row)
        return sorted_buffer.insert(acc, val, metric, 0)
    return util.fold_file(tabfile, cache, process_row)
 def results_of_config(self, config):
     return util.fold_file(
         self.source,
         None,
         lambda acc, row: acc or (util.stats_of_row([int(x) for x in row[1:]]) if row[0] == config else None),
     )