def from_sympy(self, a): """Convert SymPy's expression to `dtype`. """ p, q = a.as_numer_denom() num, _ = dict_from_basic(p, gens=self.gens) den, _ = dict_from_basic(q, gens=self.gens) for k, v in num.items(): num[k] = self.dom.from_sympy(v) for k, v in den.items(): den[k] = self.dom.from_sympy(v) return self((num, den)).cancel()
def from_sympy(self, a): """Convert SymPy's expression to `dtype`. """ p, q = a.as_numer_denom() num, _ = dict_from_basic(p, gens=self.gens) den, _ = dict_from_basic(q, gens=self.gens) for k, v in num.iteritems(): num[k] = self.dom.from_sympy(v) for k, v in den.iteritems(): den[k] = self.dom.from_sympy(v) return self((num, den)).cancel()
def from_sympy(self, a): """Convert SymPy's expression to `dtype`. """ try: rep, _ = dict_from_basic(a, gens=self.gens) except PolynomialError: raise CoercionFailed("can't convert %s to type %s" % (a, self)) for k, v in rep.items(): rep[k] = self.dom.from_sympy(v) return self(rep)
def from_sympy(self, a): """Convert SymPy's expression to `dtype`. """ try: rep, _ = dict_from_basic(a, gens=self.gens) except PolynomialError: raise CoercionFailed("can't convert %s to type %s" % (a, self)) for k, v in rep.iteritems(): rep[k] = self.dom.from_sympy(v) return self(rep)