Skip to content

Commit

Permalink
modify xthreaded and xreplace to fail gracefully
Browse files Browse the repository at this point in the history
- xreplace leave args that don't implement xreplace alone
- xtrheaded allows objects that don't rebuild to return unchanged
  • Loading branch information
smichr committed Apr 26, 2013
1 parent bb21c8d commit 2ea7594
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 7 additions & 1 deletion sympy/core/basic.py
Expand Up @@ -1050,7 +1050,13 @@ def xreplace(self, rule):
if self in rule:
return rule[self]
elif rule:
args = tuple([arg.xreplace(rule) for arg in self.args])
args = []
for a in self.args:
try:
args.append(a.xreplace(rule))
except AttributeError:
args.append(a)
args = tuple(args)
if not _aresame(args, self.args):
return self.func(*args)
return self
Expand Down
4 changes: 3 additions & 1 deletion sympy/polys/partfrac.py
Expand Up @@ -65,7 +65,9 @@ def apart(f, x=None, full=False, **options):
nc = Mul(*[apart(i, x=x, full=full, **_options) for i in nc])
if c:
c = apart(Mul._from_args(c), x=x, full=full, **_options)
return c*nc
return c*nc
else:
return nc
elif f.is_Add:
c = []
nc = []
Expand Down
5 changes: 4 additions & 1 deletion sympy/utilities/decorator.py
Expand Up @@ -14,7 +14,10 @@ def threaded_func(expr, *args, **kwargs):
if isinstance(expr, Matrix):
return expr.applyfunc(lambda f: func(f, *args, **kwargs))
elif iterable(expr):
return expr.__class__([ func(f, *args, **kwargs) for f in expr ])
try:
return expr.__class__([func(f, *args, **kwargs) for f in expr])
except TypeError:
return expr
else:
expr = sympify(expr)

Expand Down

0 comments on commit 2ea7594

Please sign in to comment.