Ejemplo n.º 1
0
 def inside(self, o):
     for k, v in self.variables.items():
         if not k in o.variables:
             return False
         ov = o.variables[k]
         if type(v) is tuple:
             v = v[1]
         if type(ov) is tuple:
             ov = ov[1]
         if is_numeric(v) and is_numeric(ov):
             if not get_numeric(v) == get_numeric(ov):
                 return False
         else:
             if not v == ov:
                 return False
     return True
Ejemplo n.º 2
0
    def __cmp__(self, o):
        for k, v in self.variables.items():
            if not k in o.variables: return 1
            ov = o.variables[k]
            if is_numeric(v) and is_numeric(ov):
                return get_numeric(v) - get_numeric(ov)

            if type(v) is str or type(ov) is str:
                if str(v) < str(ov):
                    return -1
                if str(v) > str(ov):
                    return 1
            else:
                if v < ov:
                    return -1
                if v > ov:
                    return 1
        return 0
Ejemplo n.º 3
0
 def __hash__(self):
     n = 0
     for k, v in self.variables.items():
         if type(v) is tuple:
             v = v[1]
         if is_numeric(v):
             n += get_numeric(v).__hash__()
         else:
             n += str(v).__hash__()
         n += k.__hash__()
     return n
Ejemplo n.º 4
0
 def __eq__(self, o):
     if len(self.variables) != len(o.variables):
         return False
     for k, v in self.variables.items():
         if not k in o.variables:
             return False
         ov = o.variables[k]
         if v == ov:
             return True
         if type(v) is tuple:
             v = v[1]
         if type(ov) is tuple:
             ov = ov[1]
         if is_numeric(v) and is_numeric(ov):
             if not get_numeric(v) == get_numeric(ov):
                 return False
         else:
             if not v == ov:
                 return False
     return True
Ejemplo n.º 5
0
def var_divider(testie: 'Testie', key: str, result_type):
    div = testie.config.get_dict_value("var_divider", "result", result_type=result_type, default=1)
    if is_numeric(div):
        return float(div)
    if div.lower() == 'g':
        return 1024 * 1024 * 1024
    elif div.lower() == 'm':
        return 1024 * 1024
    elif div.lower() == 'k':
        return 1024
    return 1
Ejemplo n.º 6
0
def convert_to_xyeb(datasets: List[Tuple['Testie', 'Build', Dataset]],
                    run_list,
                    key,
                    do_x_sort,
                    statics,
                    options,
                    max_series=None,
                    series_sort=None,
                    y_group={},
                    color=[],
                    kind=None) -> AllXYEB:
    write_output(datasets, statics, options, run_list, kind)
    data_types = OrderedDict()
    all_result_types = OrderedSet()

    for testie, build, all_results in datasets:
        for run, run_results in all_results.items():
            for result_type, results in run_results.items():
                all_result_types.add(result_type)

    for testie, build, all_results in datasets:
        x = OrderedDict()
        y = OrderedDict()
        e = OrderedDict()
        for run in run_list:
            if len(run) == 0:
                xval = build.pretty_name()
            else:
                xval = run.print_variable(key, build.pretty_name())

            results_types = all_results.get(run, OrderedDict())
            for result_type in all_result_types:

                #ydiv = var_divider(testie, "result", result_type) results are now divided before
                xdiv = var_divider(testie, key)
                result = results_types.get(result_type, None)

                if xdiv != 1 and is_numeric(xval):
                    x.setdefault(result_type,
                                 []).append(get_numeric(xval) / xdiv)
                else:
                    x.setdefault(result_type, []).append(xval)

                if result is not None:
                    yval = group_val(
                        result,
                        y_group[result_type] if result_type in y_group else
                        (y_group['result'] if 'result' in y_group else 'mean'))
                    y.setdefault(result_type, []).append(yval)

                    std = np.std(result)
                    mean = np.mean(result)
                    e.setdefault(result_type, []).append((mean, std, result))
                else:
                    y.setdefault(result_type, []).append(np.nan)
                    e.setdefault(result_type, []).append(
                        (np.nan, np.nan, [np.nan]))

        for result_type in x.keys():

            try:

                if not do_x_sort:
                    ox = x[result_type]
                    oy = y[result_type]
                    oe = e[result_type]
                else:
                    order = np.argsort(x[result_type])
                    ox = np.array(x[result_type])[order]
                    oy = np.array(y[result_type])[order]
                    oe = [e[result_type][i] for i in order]

                data_types.setdefault(result_type, []).append(
                    (ox, oy, oe, build))
            except Exception as err:
                print("ERROR while transforming data")
                print(err)
                print("x", x[result_type])
                print("y", y[result_type])
                print("e", e[result_type])

    if series_sort is not None and series_sort != "":
        if type(series_sort) is str and series_sort.startswith('-'):
            inverted = True
            series_sort = series_sort[1:]
        else:
            inverted = False

        new_data_types = OrderedDict()
        for result_type, data in data_types.items():
            avg = []
            max = []
            min = []
            for x, y, e, build in data:
                if not np.isnan(np.sum(y)):
                    avg.append(np.sum(y))
                else:
                    avg.append(0)
                max.append(np.max(y))
                min.append(np.min(y))
            if type(series_sort) is list:
                ok = True
                for i, so in enumerate(series_sort):

                    if is_numeric(so):
                        o = so
                        if o >= len(data):
                            print(
                                "ERROR: sorting for %s is invalid, %d is out of range"
                                % (result_type, o))
                            ok = False
                            break
                    elif so in [x for x, y, e, build in data]:
                        o = [x for x, y, e, build in data].index(so)
                    elif so in [
                            build.pretty_name() for x, y, e, build in data
                    ]:
                        o = [build.pretty_name()
                             for x, y, e, build in data].index(so)
                    else:
                        print(
                            "ERROR: sorting for %s is invalid, %s is not in list"
                            % (result_type, so))
                        ok = False
                        break
                    series_sort[i] = o

                if ok:
                    order = series_sort
                else:
                    order = np.argsort(np.asarray(avg))
            elif series_sort == 'avg':
                order = np.argsort(np.asarray(avg))
            elif series_sort == 'max':
                order = np.argsort(-np.asarray(max))
            elif series_sort == 'min':
                order = np.argsort(np.asarray(min))
            elif series_sort == 'natsort':
                order = natsort.index_natsorted(
                    data, key=lambda x: x[3].pretty_name())
            elif series_sort == 'color':
                order = np.argsort(color)
            else:
                raise Exception("Unknown sorting : %s" % series_sort)

            if inverted:
                order = np.flip(order, 0)

            data = [data[i] for i in order]
            new_data_types[result_type] = data
        data_types = new_data_types

    if max_series:
        new_data_types = OrderedDict()
        for i, (result_type, data) in enumerate(data_types.items()):
            new_data_types[result_type] = data[:max_series]
        data_types = new_data_types

    return data_types