def __add__(self, other): if other == 0: return self if not isinstance(other, Tensor): raise TypeError(messages.type_err(Tensor, other)) if (self.dom, self.cod) != (other.dom, other.cod): raise AxiomError(messages.cannot_add(self, other)) return Tensor(self.dom, self.cod, self.array + other.array)
def __init__(self, terms, dom=None, cod=None): self.terms = list(terms) if not terms: if dom is None or cod is None: raise ValueError(messages.missing_types_for_empty_sum()) else: dom = terms[0].dom if dom is None else dom cod = terms[0].cod if cod is None else cod if (dom, cod) != (terms[0].dom, terms[0].cod): raise AxiomError( messages.cannot_add(Sum([], dom, cod), terms[0])) for arrow in terms: if (arrow.dom, arrow.cod) != (dom, cod): raise AxiomError(messages.cannot_add(terms[0], arrow)) name = "Sum({})".format(repr(terms)) if terms\ else "Sum([], dom={}, cod={})".format(repr(dom), repr(cod)) super().__init__(name, dom, cod)
def __add__(self, other): if other == 0: return self if (self.dom, self.cod) != (other.dom, other.cod): raise AxiomError(messages.cannot_add(self, other)) return CQMap(self.dom, self.cod, self.array + other.array)