~ubuntu-branches/ubuntu/natty/ffc/natty

« back to all changes in this revision

Viewing changes to bench/utils.py

  • Committer: Bazaar Package Importer
  • Author(s): Johannes Ring
  • Date: 2010-07-01 19:54:32 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100701195432-xz3gw5nprdj79jcb
Tags: 0.9.3-1
* New upstream release.
* debian/control:
  - Minor fix in Vcs fields.
  - Bump Standards-Version to 3.9.0 (no changes needed).
  - Update version for python-ufc, python-fiat, and python-ufl in
    Depends field.
* Switch to dpkg-source 3.0 (quilt) format.
* Update debian/copyright and debian/copyright_hints.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
__author__ = "Anders Logg"
 
2
__date__ = "2010-05-11"
 
3
__copyright__ = "Copyright (C) 2010 " + __author__
 
4
__license__  = "GNU GPL version 3 or any later version"
 
5
 
 
6
def print_table(values, title):
 
7
    "Print nicely formatted table."
 
8
 
 
9
    m = max([key[0] for key in values]) + 2
 
10
    n = max([key[1] for key in values]) + 2
 
11
 
 
12
    table = []
 
13
    for i in range(m):
 
14
        table.append(["" for j in range(n)])
 
15
 
 
16
    for i in range(m - 1):
 
17
        table[i + 1][0] = str(values[(i, 0)][0])
 
18
 
 
19
    for j in range(n - 1):
 
20
        table[0][j + 1] = str(values[(0, j)][1])
 
21
 
 
22
    for i in range(m - 1):
 
23
        for j in range(n - 1):
 
24
            value = values[(i, j)][2]
 
25
            if isinstance(value, float):
 
26
                value = "%.5g" % value
 
27
            table[i + 1][j + 1] = value
 
28
 
 
29
    table[0][0] = title
 
30
 
 
31
    column_sizes = [max([len(table[i][j]) for i in range(m)]) for j in range(n)]
 
32
    row_size = sum(column_sizes) + 3*(len(column_sizes) - 1) + 2
 
33
 
 
34
    print ""
 
35
    for i in range(m):
 
36
        print " " + "-"*row_size
 
37
        print "|",
 
38
        for j in range(n):
 
39
            print table[i][j] + " "*(column_sizes[j] - len(table[i][j])),
 
40
            print "|",
 
41
        print ""
 
42
    print " " + "-"*row_size
 
43
    print ""