def counit(A): assert isinstance(A, Cell1) src = A * A.dual tgt = Cell1.identity(A.tgt) assert tgt.hom == src.hom shape = tgt.shape n = shape[0] assert n == shape[1] rig = A.rig ring = rig.ring linss = [] for i in range(n): lins = [] # row for k in range(n): t, s = tgt[i, k], src[i, k] if i != k: lin = Lin.zero(t, s) else: # argh... why can't we direct_sum the Lin.counit's ? a = elim.zeros(ring, t.n, s.n) idx = 0 for j in range(A.shape[1]): counit = Lin.counit(rig.one, A[i, j]) a[:, idx:idx + counit.shape[1]] = counit.A idx += counit.shape[1] assert idx == s.n lin = Lin(t, s, a) lins.append(lin) linss.append(lins) return Cell2(tgt, src, linss)
def zero(cls, tgt, src): # tgt <---- src assert isinstance(tgt, Cell1) assert isinstance(src, Cell1) assert tgt.rig == src.rig assert tgt.hom == src.hom rig = tgt.rig rows, cols = tgt.shape linss = [[Lin.zero(tgt[i, j], src[i, j]) for j in range(cols)] for i in range(rows)] return Cell2(tgt, src, linss)