Skip to content

Commit 09b6a73

Browse files
eric-wieserutensil
authored andcommitted
Merge the equivalent Sdop.__call__ and Sdop.__mul__ (#191)
The only differences were: * The variable names * A missing consolidation step in `__call__`
1 parent 732a1e3 commit 09b6a73

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

galgebra/mv.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,13 +1590,15 @@ def __init__(self, *args, **kwargs):
15901590
def __call__(self, arg):
15911591
if isinstance(arg, Sdop):
15921592
if self.Ga != arg.Ga:
1593-
raise ValueError('In Sdop.__call__ self.Ga != arg.Ga.')
1593+
raise ValueError(
1594+
'When chaining scalar differential operators, self.Ga != arg.Ga.')
15941595
terms = []
15951596
for (coef, pdiff) in self.terms:
15961597
new_terms = pdiff(arg.terms)
15971598
new_terms = [(coef * c, p) for c, p in new_terms]
15981599
terms += new_terms
1599-
return Sdop(terms, ga=self.Ga)
1600+
product = Sdop(terms, ga=self.Ga)
1601+
return Sdop.consolidate_coefs(product)
16001602
else:
16011603
return sum([coef * pdiff(arg) for coef, pdiff in self.terms], S(0))
16021604

@@ -1651,19 +1653,8 @@ def __rsub__(self, sdop):
16511653
return Sdop.Add(-self, sdop)
16521654

16531655
def __mul__(self, sdopr):
1654-
sdopl = self
1655-
if isinstance(sdopr, Sdop):
1656-
if sdopl.Ga != sdopr.Ga:
1657-
raise ValueError('In Sdop.__mul__ Sdop arguments are not from same geometric algebra')
1658-
terms = []
1659-
for (coef, pdiff) in sdopl.terms:
1660-
Dsdopl = pdiff(sdopr.terms) # list of terms
1661-
Dsdopl = [(coef * c, p) for c, p in Dsdopl]
1662-
terms += Dsdopl
1663-
product = Sdop(terms, ga=sdopl.Ga)
1664-
return Sdop.consolidate_coefs(product)
1665-
else: # sdopr is a scalar or a multivector
1666-
return sum([coef * pdiff(sdopr) for coef, pdiff in sdopl.terms], S(0)) # returns scalar
1656+
# alias for applying the operator
1657+
return self.__call__(sdopr)
16671658

16681659
def __rmul__(self, sdop):
16691660
terms = [(sdop * coef, pdiff) for coef, pdiff in self.terms]

0 commit comments

Comments
 (0)