Exemple #1
0
    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
Exemple #2
0
 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
Exemple #4
0
    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