Really hacky python performance scripts!
[ipdf/code.git] / tools / gpubounds_error.py
1 #!/usr/bin/python
2 import sys
3 import os
4 import math
5
6 # Calculates the total error in coordinates of GPU bounds rectangles of objects
7
8 def ComputeError(reference, other):
9         reference = open(reference, "r")
10         other = open(other, "r")
11         total = 0.0
12         while True:
13                 a = reference.readline()
14                 b = other.readline()
15                 if a == "" and b == "":
16                         reference.close()
17                         other.close()
18                         return total
19                 if a[0] == '#' and b[0] == '#':
20                         continue
21                 a = map(float, a.strip(" \r\n").split("\t"))
22                 b = map(float, b.strip(" \r\n").split("\t"))
23                 deltaArea = abs(b[3]*b[4] - a[3]*a[4])
24                 
25                 deltaCoord = b[1] - a[1] + b[2] - a[2]
26                 total += math.sqrt(deltaArea) + abs(deltaCoord)
27
28 # Counts the number of unique bounds
29 def UniqueBounds(other):
30         other = open(other, "r")
31         store = {}
32         for l in other.readlines():
33                 if l[0] == "#":
34                         continue
35                 #print "L is " + str(l)
36                 l = map(float, l.strip(" \r\n").split("\t"))
37                 l = tuple(l[1:])
38                 if not l in store.keys():
39                         store[l] = 1
40                 else:
41                         store[l] += 1
42         other.close()
43         return len(store.keys())
44         
45 def main(argv):
46         print str(ComputeError(argv[1], argv[2])) + "\t" + str(UniqueBounds(argv[1])) + "\t" + str(UniqueBounds(argv[2]))
47         return 0
48         
49         
50 if __name__ == "__main__":
51         sys.exit(main(sys.argv))

UCC git Repository :: git.ucc.asn.au