Check Boost version in include/utilities/property-maps.h + minor changes to cocycle.py
3 from cvxopt import spmatrix, matrix
4 from cvxopt.blas import copy
6 from sys import argv, exit
9 def smooth(boundary_list, cocycle_list):
10 dimension = max((max(d[1], d[2]) for d in boundary_list))
13 # NB: D is a coboundary matrix; 1 and 2 below are transposed
14 D = spmatrix([d[0] for d in boundary_list],
15 [d[2] for d in boundary_list],
16 [d[1] for d in boundary_list], (dimension, dimension))
19 z = spmatrix([zz[0] for zz in cocycle_list],
20 [zz[1] for zz in cocycle_list],
21 [0 for zz in cocycle_list], (dimension, 1))
24 # print "D^2 is zero:", not bool(D*D)
25 # print "D*z is zero:", not bool(v1)
28 def Dfun(x,y,trans = 'N'):
34 assert False, "Unexpected trans parameter"
39 solution = lsqr(Dfun, matrix(z), show = show, atol = tol, btol = tol, itnlim = maxit)
44 # assert sum((D*v)**2) < tol and sum((D.T*v)**2) < tol, "Expected a harmonic cocycle"
45 if not (sum((D*v)**2) < tol and sum((D.T*v)**2) < tol):
46 print "Expected a harmonic cocycle:", sum((D*v)**2), sum((D.T*v)**2)
51 def vertex_values(solution, vertices):
52 values = [None]*len(vertices)
54 values[v] = solution[i]
58 def read_list_file(filename):
60 with open(filename) as fp:
61 for line in fp.xreadlines():
62 if line.startswith('#'): continue 63 list.append(map(int, line.split()))
67 if __name__ == '__main__':
69 print "Usage: %s BOUNDARY COCYCLE VERTEXMAP" % argv[0]
72 boundary_filename = argv[1]
73 cocycle_filename = argv[2]
74 vertexmap_filename = argv[3]
76 boundary_list = read_list_file(boundary_filename)
77 cocycle_list = read_list_file(cocycle_filename)
78 vertexmap_list = read_list_file(vertexmap_filename)
80 solution = smooth(boundary_list, cocycle_list)
81 values = vertex_values(solution, vertexmap_list)
83 outfn = os.path.splitext(cocycle_filename)[0] + '.val'
84 with open(outfn, 'w') as f:
85 for i,v in enumerate(values):
86 f.write('%d %f\n' % (i,v))