Ejemplo n.º 1
0
def test_csv():
    tab = Tabular()
    tab.add_row([TabularColumn('test1'), TabularColumn('test2'), TabularColumn('test3', fmt="^d")])
    tab.add_row(["1", "2", 3])
    output = io.StringIO()
    tab.render(CSVRenderer(output))
    output = output.getvalue()
    assert output == 'test1,test2,test3\r\n1,2,3\r\n'
Ejemplo n.º 2
0
def test_excel():
    tab = Tabular()
    tab.add_row([
        TabularColumn('test1 is very long'),
        TabularColumnGroup('group',
                           [TabularColumn('test2'),
                            TabularColumn('test3', fmt="^d")])
    ])
    tab.add_row(["1", "2", 3])
    renderer = ExcelRenderer("/tmp/test.xls")
    tab.render(renderer)
Ejemplo n.º 3
0
def test_textable():
    tab = Tabular()
    tab.add_row([TabularColumn('test1'), TabularColumn('test2'), TabularColumn('test3', fmt="^d")])
    tab.add_row(["1", "2", 3])
    renderer = TextTableRenderer(maxwidth=80)
    tab.render(renderer)
    output = renderer.get_output()
    assert output == ('+-------+-------+-------+\n'
                      '| test1 | test2 | test3 |\n'
                      '+=======+=======+=======+\n'
                      '| 1     | 2     |   3   |\n'
                      '+-------+-------+-------+')
Ejemplo n.º 4
0
    def report(self, G, stats):
        table = Tabular()
        table.add_row([
            TabularColumn("Step", fmt="^d"),
            TabularColumn("Name"),
            TabularColumn("In"),
            TabularColumn("Out"),
            TabularColumn("Weights"),
            TabularColumn("Bias"),
            TabularColumn("Calc"),
            TabularColumn("Acc"),
        ])

        for key, qrec in stats.items():
            if not isinstance(key, NodeId):
                continue
            node = G.node(key.node_name)
            if self._step is not None and self._step != node.step_idx:
                continue
            fnode = node.get_contained_node(
                key.fnode_name) if key.fnode_name else None
            step_idx = node.step_idx
            node = fnode or node
            row = [
                step_idx, node.name,
                emit_qs(qrec.in_qs),
                emit_qs(qrec.out_qs)
            ]
            if isinstance(node, FilterParameters):
                for i in ["weights", "biases", "calc", "acc"]:
                    row.append(emit_q(getattr(qrec, i + '_q')))
            else:
                row += ["", "", "", ""]
            table.add_row(row)
        return table
Ejemplo n.º 5
0
 def do_dheader(table):
     header = [
         TabularColumn("name"),
         TabularColumn("step", fmt=">d"),
         TabularColumn("min I range", fmt=">.3f"),
         TabularColumn("max I range", fmt=">.3f"),
         TabularColumn("min O range", fmt=">.3f"),
         TabularColumn("max O range", fmt=">.3f"),
         TabularColumn("min I prec", fmt=">.3f"),
         TabularColumn("avg I prec", fmt=">.3f"),
         TabularColumn("min O prec", fmt=">.3f"),
         TabularColumn("avg O prec", fmt=">.3f"),
     ]
     table.add_row(header)
Ejemplo n.º 6
0
    def report(self, G, stats):
        table = Tabular()
        header = [
            TabularColumn("name"),
            TabularColumn("creating node"),
            TabularColumn("type"),
            TabularColumn("dimensions", fmt="^"),
            TabularColumn("size", fmt=">d"),
            TabularColumn("count", fmt=">d"),
        ]
        is_quantized = stats and 'qtype' in stats[0]
        if is_quantized:
            header.append(TabularColumn("Q"))

        table.add_row(header)
        total = 0
        for stat in stats:
            row = [str(stat[k]) for k in ['name', 'creating_node', 'type']]
            row.append(str(stat['dims']))
            row.append(stat['dims'].size())
            row.append(stat['count'])
            if is_quantized:
                row.append(str(stat['qtype']))

            table.add_row(row)
            total += stat['dims'].size()
        if self._do_totals:
            row = ["Total", "", "", "", total, ""]
            if is_quantized:
                row.append("")
            table.add_row(row)
        return table
Ejemplo n.º 7
0
def do_dheader(table, one_input):
    header = [
        TabularColumn("name"),
        TabularColumn("op type"),
        TabularColumn("step", fmt=">d"),
        TabularColumn("avg error", fmt=">.3f"),
        TabularColumn("max error", fmt=">.3f"),
        TabularColumn("min error", fmt=">.3f")
    ]
    if one_input:
        header.extend([TabularColumn("QSNR", fmt=">.0f")])
    else:
        header.extend([
            TabularColumn("av QSNR", fmt=">.0f"),
            TabularColumn("max QSNR", fmt=">.0f"),
            TabularColumn("min QSNR", fmt=">.0f"),
        ])

    header.extend([
        TabularColumn("OverF dot", fmt=">d"),
        TabularColumn("OverF acc", fmt=">d"),
    ])
    table.add_row(header)
Ejemplo n.º 8
0
    def do_headers(self, active_order, tab):
        headers = [
            TabularColumn("Step", fmt="^d"),
            TabularColumn("Step name"),
            TabularColumn("Operation"),
        ]
        if self._split_dims:
            headers.append(
                TabularColumnGroup("Input Dims",
                                   [TabularColumn("C", fmt="^s"),
                                    TabularColumn("H", fmt="^s"),
                                    TabularColumn("W", fmt="^s")]))
            headers.append(
                TabularColumnGroup("Output Dims",
                                   [TabularColumn("C", fmt="^s"),
                                    TabularColumn("H", fmt="^s"),
                                    TabularColumn("W", fmt="^s")]))
        else:
            headers.append(
                TabularColumn("Input Dims\n({})".format(active_order), fmt="^s")
            )
            headers.append(
                TabularColumn("Output Dims\n({})".format(active_order), fmt="^s")
            )
        headers.extend([
            TabularColumn("Inputs", fmt="^s"),
            TabularColumn("Active\nsize", fmt="^d"),
            TabularColumn("Params\nsize", fmt="^d"),
            TabularColumn("Ops", fmt=">s"),
            TabularColumn("Params"),
            TabularColumn("Hints")
        ])

        tab.add_row(headers)
Ejemplo n.º 9
0
def do_header(table):
    header = [
        TabularColumn("step"),
        TabularColumn("name"),
        TabularColumn("mean", fmt=">.3f"),
        TabularColumn("std dev", fmt=">.3f"),
        TabularColumn("min", fmt=">.3f"),
        TabularColumn("max", fmt=">.3f"),
        TabularColumn("min acc", fmt=">.3f"),
        TabularColumn("max acc", fmt=">.3f"),
        TabularColumn("weak\nOLs", fmt=">d"),
        TabularColumn("strong\nOLs", fmt=">d"),
        TabularColumn("min\nOL", fmt=">.3f"),
        TabularColumn("max\nOL", fmt=">.3f"),
        TabularColumn("int\nbits", fmt=">d"),
    ]

    for bit_size in STATS_BITS:
        header.append(TabularColumn("{}-bits\nformat".format(bit_size), fmt="^s"))
        header.append(TabularColumn("{}-bits\nQSNR".format(bit_size), fmt=">.0f"))

    header.append(TabularColumn("size\n(bytes)", fmt=">d"))

    table.add_row(header)
Ejemplo n.º 10
0
    def report(self, G, stats):
        table = Tabular()
        table.add_row([
            TabularColumn("Step", fmt="^d"),
            TabularColumn("Name"),
            TabularColumn("Type"),
            TabularColumn("In"),
            TabularColumn("Out"),
            TabularColumn("Weights"),
            TabularColumn("Bias"),
            TabularColumn("Mulbias"),
            TabularColumn("Calc"),
            TabularColumn("Acc"),
        ])

        # TODO - Fix report for weights_q

        for key, qrec in stats.sorted_iterator(G):
            if not isinstance(key, NodeId):
                continue
            node = G.node(key.node_name)
            if self._step is not None and self._step != node.step_idx:
                continue
            fnode = node.get_contained_node(
                key.fnode_name) if key.fnode_name else None
            step_idx = node.step_idx
            node = fnode or node
            if qrec:
                if self._step is None or not isinstance(
                        qrec, MultScalableFilterQuantizationRecord) or len(
                            qrec.in_qs[1].scale) == 1:
                    if isinstance(node, ConstantInputParameters):
                        row = [
                            step_idx, node.name, qrec.TYPE, "",
                            self.emit_qs(qrec.out_qs,
                                         limit=self._step is None), "", "", "",
                            "", ""
                        ]
                    else:
                        row = [
                            step_idx, node.name, qrec.TYPE,
                            self.emit_qs(qrec.in_qs, limit=self._step is None),
                            self.emit_qs(qrec.out_qs, limit=self._step is None)
                        ]
                        if isinstance(
                                qrec,
                            (SymmetricScalableFilterQuantizationRecord,
                             MultScalableFilterQuantizationRecord)):
                            for i in [1, 2]:
                                row.append(self.emit_qs([qrec.in_qs[i]]))
                            for i in ["mul_biases", "calc", "acc"]:
                                row.append(
                                    self.emit_qs([getattr(qrec, i + '_q')]))
                        else:
                            row += ["", "", "", "", ""]
                else:
                    first = True
                    for chan in range(len(qrec.in_qs[1].scale)):
                        if first:
                            row = [
                                step_idx,
                                node.name,
                                qrec.TYPE,
                                self.emit_qs(qrec.in_qs,
                                             limit=self._step is None),
                                self.emit_qs(qrec.out_qs,
                                             limit=self._step is None),
                                self.emit_q_chan(qrec.in_qs[1], chan),
                                self.emit_q_chan(qrec.in_qs[2], chan),
                                self.emit_q_chan(qrec.mul_biases_q, chan),
                                str(qrec.calc_q),
                                str(qrec.acc_q),
                            ]
                            first = False
                        else:
                            row = [
                                chan, "", "", "", "",
                                self.emit_q_chan(qrec.in_qs[1], chan),
                                self.emit_q_chan(qrec.in_qs[2], chan),
                                self.emit_q_chan(qrec.mul_biases_q, chan), "",
                                ""
                            ]
                        table.add_row(row)
                    continue
            else:
                row = [
                    step_idx, node.name, "IEEE32", "None", "None", "", "", "",
                    "", ""
                ]
            table.add_row(row)
        return table
Ejemplo n.º 11
0
    def report(self, G, stats, nodes=None):
        if nodes is None:
            nodes = G.nodes()
        nodes = sorted(nodes, key=lambda x: x.step_idx)
        table = Tabular()
        table.add_row([
            TabularColumn("Step", fmt="^d"),
            TabularColumn("Name"),
            TabularColumn("Type"),
            TabularColumn("In"),
            TabularColumn("Out"),
            TabularColumn("Weights"),
            TabularColumn("Bias"),
            TabularColumn("Mulbias"),
            TabularColumn("Calc"),
            TabularColumn("Acc"),
        ])

        # TODO - Fix report for weights_q
        single = nodes[0].step_idx == nodes[-1].step_idx
        for key, qrec in stats.sorted_iterator(G):
            if not isinstance(key, NodeId):
                continue
            node = G.node(key.node_name)
            if node.step_idx < nodes[0].step_idx or node.step_idx > nodes[
                    -1].step_idx:
                continue
            fnode = node.get_contained_node(
                key.fnode_name) if key.fnode_name else None
            step_idx = node.step_idx
            node = fnode or node
            if qrec:
                if (not single or not qrec.ktype == 'scaled'
                        or not isinstance(node, FilterParameters)
                        or len(qrec.in_qs[1].scale) == 1):
                    if isinstance(node, ConstantInputParameters):
                        row = [
                            step_idx, node.name, qrec.ktype, "",
                            self.emit_qs(qrec.out_qs,
                                         limit=self._step is None), "", "", "",
                            "", ""
                        ]
                    else:
                        row = [
                            step_idx, node.name, qrec.ktype +
                            (" NE16" if qrec.cache.get('ne16') else ""),
                            self.emit_qs(qrec.in_qs, limit=self._step is None),
                            self.emit_qs(qrec.out_qs, limit=self._step is None)
                        ]
                        if isinstance(node, FilterParameters):
                            for i in [1, 2]:
                                row.append(self.emit_qs([qrec.in_qs[i]]))
                            for i in ["mul_biases", "calc", "acc"]:
                                key = f'{i}_q'
                                if key in qrec.cache:
                                    row.append(self.emit_qs([qrec.cache[key]]))
                                else:
                                    row.append("")
                        else:
                            row += ["", "", "", "", ""]
                else:
                    first = True
                    for chan in range(len(qrec.in_qs[1].scale)):
                        if first:
                            row = [
                                step_idx,
                                node.name,
                                qrec.ktype,
                                self.emit_qs(qrec.in_qs,
                                             limit=self._step is None),
                                self.emit_qs(qrec.out_qs,
                                             limit=self._step is None),
                                self.emit_q_chan(qrec.in_qs[1], chan),
                                self.emit_q_chan(qrec.in_qs[2], chan),
                                self.emit_q_chan(qrec.cache['mul_biases_q'],
                                                 chan),
                                str(qrec.cache['calc_q']),
                                str(qrec.cache['acc_q']),
                            ]
                            first = False
                        else:
                            row = [
                                chan, "", "", "", "",
                                self.emit_q_chan(qrec.in_qs[1], chan),
                                self.emit_q_chan(qrec.in_qs[2], chan),
                                self.emit_q_chan(qrec.cache['mul_biases_q'],
                                                 chan), "", ""
                            ]
                        table.add_row(row)
                    continue
            else:
                row = [
                    step_idx, node.name, "IEEE32", "None", "None", "", "", "",
                    "", ""
                ]
            table.add_row(row)
        return table
Ejemplo n.º 12
0
def do_dheader(table, one_input, with_chan):
    header = [
        TabularColumn("name"),
        TabularColumn("op type"),
        TabularColumn("step", fmt=">"),
        TabularColumn("avg error", fmt=">.3f"),
        TabularColumn("max error", fmt=">.3f"),
        TabularColumn("min error", fmt=">.3f")
    ]
    if with_chan:
        header.append(TabularColumn("max ch error", fmt=">.3f"))
    if one_input:
        header.extend([
            TabularColumn("QSNR", fmt=">.0f")
        ])
    else:
        header.extend([
            TabularColumn("av QSNR", fmt=">.0f"),
            TabularColumn("max QSNR", fmt=">.0f"),
            TabularColumn("min QSNR", fmt=">.0f"),
        ])

    table.add_row(header)
Ejemplo n.º 13
0
    def do_header(self, table):
        header = [
            TabularColumn("step"),
            TabularColumn("name")
            if self._step_idx is None else TabularColumn('channel'),
            TabularColumn("mean", fmt=">.3f"),
            TabularColumn("std dev", fmt=">.3f"),
            TabularColumn("min", fmt=">.3f"),
            TabularColumn("max", fmt=">.3f"),
            TabularColumn("weak\nOLs", fmt=">d"),
            TabularColumn("strong\nOLs", fmt=">d"),
            TabularColumn("min\nOL", fmt=">.3f"),
            TabularColumn("max\nOL", fmt=">.3f"),
            TabularColumn("int\nbits", fmt=">d"),
            TabularColumn("avg\nprec", fmt=">.3f"),
        ]

        for bit_size in STATS_BITS:
            header.append(
                TabularColumn("{}-bits\nformat".format(bit_size), fmt="^s"))
            header.append(
                TabularColumn("{}-bits\nQSNR".format(bit_size), fmt=">.1f"))

        header.append(TabularColumn("size\n(bytes)", fmt=">d"))

        table.add_row(header)