def compute_boundary_operators(self): """Compute and return matrix form of boundary operators. Return list of sparse `SimpleMatrix` instances. Matrix form of boundary operators operates on column vectors: the `i`-th differential `D[i]` is `dim C[i-1]` rows (range) by `dim C[i]` columns (domain). """ D = DifferentialComplex() D.append(NullMatrix, 0, self.module[0].dimension) for i in xrange(1, self.length): d = SimpleMatrix(self.module[i-1].dimension, self.module[i].dimension) for j in xrange(self.module[i].dimension): for (k, c) in self.module[i-1].coordinates( self.differential[i]( self.module[i].base[j])).iteritems(): d.addToEntry(k, j, c) D.append(d, self.module[i-1].dimension, self.module[i].dimension) logging.info(" Computed %dx%d matrix D[%d]", len(self.module[i-1].base), len(self.module[i].base), i) return D
def compute_boundary_operators(self): #: Matrix form of boundary operators; the `i`-th differential #: `D[i]` is `dim C[i-1]` rows (range) by `dim C[i]` columns #: (domain). m = self.module # micro-optimization D = DifferentialComplex() D.append(NullMatrix, 0, len(m[0])) for i in xrange(1, len(self)): timing.start("D[%d]" % i) p = len(m[i - 1]) # == dim C[i-1] q = len(m[i]) # == dim C[i] try: checkpoint = os.path.join(runtime.options.checkpoint_dir, ('M%d,%d-D%d.sms' % (runtime.g, runtime.n, i))) except AttributeError: checkpoint = None # maybe load `D[i]` from persistent storage if checkpoint and p > 0 and q > 0 and runtime.options.restart: d = SimpleMatrix(p, q) if d.load(checkpoint): D.append(d, p, q) logging.info(" Loaded %dx%d matrix D[%d] from file '%s'", p, q, i, checkpoint) continue # with next `i` # compute `D[i]` d = SimpleMatrix(p, q) j0 = 0 for pool1 in m[i].iterblocks(): k0 = 0 for pool2 in m[i - 1].iterblocks(): for edgeno in xrange(pool1.graph.num_edges): if pool1.graph.is_loop(edgeno): continue # with next `edgeno` for (j, k, s) in NumberedFatgraphPool.facets( pool1, edgeno, pool2): assert k < len(pool2) assert j < len(pool1) assert k + k0 < p assert j + j0 < q d.addToEntry(k + k0, j + j0, s) k0 += len(pool2) # # `pool2` will never be used again, so clear it from the cache. # # XXX: using implementation detail! # pool2.graph._cache_isomorphisms.clear() j0 += len(pool1) # `pool1` will never be used again, so clear it from the cache. # XXX: using implementation detail! pool1.graph._cache_isomorphisms.clear() timing.stop("D[%d]" % i) if checkpoint: d.save(checkpoint) D.append(d, p, q) logging.info(" Computed %dx%d matrix D[%d] (elapsed: %.3fs)", p, q, i, timing.get("D[%d]" % i)) return D
def compute_boundary_operators(self): #: Matrix form of boundary operators; the `i`-th differential #: `D[i]` is `dim C[i-1]` rows (range) by `dim C[i]` columns #: (domain). m = self.module # micro-optimization D = DifferentialComplex() D.append(NullMatrix, 0, len(m[0])) for i in xrange(1, len(self)): timing.start("D[%d]" % i) p = len(m[i-1]) # == dim C[i-1] q = len(m[i]) # == dim C[i] try: checkpoint = os.path.join(runtime.options.checkpoint_dir, ('M%d,%d-D%d.sms' % (runtime.g, runtime.n, i))) except AttributeError: checkpoint = None # maybe load `D[i]` from persistent storage if checkpoint and p>0 and q>0 and runtime.options.restart: d = SimpleMatrix(p, q) if d.load(checkpoint): D.append(d, p, q) logging.info(" Loaded %dx%d matrix D[%d] from file '%s'", p, q, i, checkpoint) continue # with next `i` # compute `D[i]` d = SimpleMatrix(p, q) j0 = 0 for pool1 in m[i].iterblocks(): k0 = 0 for pool2 in m[i-1].iterblocks(): for edgeno in xrange(pool1.graph.num_edges): if pool1.graph.is_loop(edgeno): continue # with next `edgeno` for (j, k, s) in NumberedFatgraphPool.facets(pool1, edgeno, pool2): assert k < len(pool2) assert j < len(pool1) assert k+k0 < p assert j+j0 < q d.addToEntry(k+k0, j+j0, s) k0 += len(pool2) # # `pool2` will never be used again, so clear it from the cache. # # XXX: using implementation detail! # pool2.graph._cache_isomorphisms.clear() j0 += len(pool1) # `pool1` will never be used again, so clear it from the cache. # XXX: using implementation detail! pool1.graph._cache_isomorphisms.clear() timing.stop("D[%d]" % i) if checkpoint: d.save(checkpoint) D.append(d, p, q) logging.info(" Computed %dx%d matrix D[%d] (elapsed: %.3fs)", p, q, i, timing.get("D[%d]" % i)) return D
def compute_boundary_operators(self): """Compute and return matrix form of boundary operators. Return list of sparse `SimpleMatrix` instances. Matrix form of boundary operators operates on column vectors: the `i`-th differential `D[i]` is `dim C[i-1]` rows (range) by `dim C[i]` columns (domain). """ D = DifferentialComplex() D.append(NullMatrix, 0, self.module[0].dimension) for i in xrange(1, self.length): d = SimpleMatrix(self.module[i - 1].dimension, self.module[i].dimension) for j in xrange(self.module[i].dimension): for (k, c) in self.module[i - 1].coordinates(self.differential[i]( self.module[i].base[j])).iteritems(): d.addToEntry(k, j, c) D.append(d, self.module[i - 1].dimension, self.module[i].dimension) logging.info(" Computed %dx%d matrix D[%d]", len(self.module[i - 1].base), len(self.module[i].base), i) return D
from collections import defaultdict import logging import os.path import numbers ## application-local imports from fatghol.loadsave import load, save from fatghol.runtime import runtime from fatghol.simplematrix import SimpleMatrix, is_null_product import fatghol.timing as timing ## main NullMatrix = SimpleMatrix(0, 0) #@cython.cclass class VectorSpace(object): """Represent the vector space generated by the given `base` vectors. After construction, you can retrieve the base vectors set and the dimension from instance attributes `base` and `dimension`. The `base` elements are assumed to be *linearly independent*, so the `dimension` of the generated vector space equals the number of elements in the base set. """ def __init__(self, base): """Constructor, taking list of base vectors.
return (0, 0) i0 = 0 while thresholds[i0] < i: i0 += 1 i0 -= 1 return (i0, i-i0) def labelfn(D, i): i0, i1 = matrix_index_to_G(i) return ("G_{%d,%d}^{(%d)}" % (num_edges-1, i0, i)) p = len(all_graphs[num_edges-1]) if (num_edges-1 in all_graphs) else 0 q = len(all_graphs[num_edges]) if (num_edges in all_graphs) else 0 r = num_edges - min_num_edges + 1 matrix_file = os.path.join(dir, ("M%d,%d-D%d.sms" % (g,n,r))) if os.path.exists(matrix_file): d = SimpleMatrix(p, q) d.load(matrix_file) k0 = 0 for j, G in enumerate(graphs): pool = pools[j] name = ("G_{%d,%d}" % (num_edges, j)) orientable = G.is_oriented() outfile.start_graph(name, G, pool) # print automorphisms Aut = list(G.automorphisms()) if len(Aut) > 1: outfile.add_automorphisms(Aut) if pool[0].is_oriented(): # print markings if n > 1: