Skip to content

Commit 33ea37a

Browse files
committed
Fix the behavior of Dop with no arguments
This fixes the `TestDop.test_empty_dop` test.
1 parent b2e4fc4 commit 33ea37a

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

galgebra/mv.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,16 +1964,20 @@ def __init__(self, *args, **kwargs):
19641964
self.title = None
19651965

19661966
if len(args) == 2:
1967-
if len(args[0]) != len(args[1]):
1967+
coefs, pdiffs = args
1968+
if len(coefs) != len(pdiffs):
19681969
raise ValueError('In Dop.__init__ coefficent list and Pdop list must be same length.')
1969-
self.terms = tuple(zip(args[0], args[1]))
1970+
self.terms = tuple(zip(coefs, pdiffs))
19701971
elif len(args) == 1:
1971-
if isinstance(args[0][0][0], Mv): # Mv expansion [(Mv, Pdop)]
1972-
self.terms = tuple(args[0])
1973-
elif isinstance(args[0][0][0], Sdop): # Sdop expansion [(Sdop, Mv)]
1972+
arg, = args
1973+
if len(arg) == 0:
1974+
self.terms = ()
1975+
elif isinstance(arg[0][0], Mv): # Mv expansion [(Mv, Pdop)]
1976+
self.terms = tuple(arg)
1977+
elif isinstance(arg[0][0], Sdop): # Sdop expansion [(Sdop, Mv)]
19741978
coefs = []
19751979
pdiffs = []
1976-
for (sdop, mv) in args[0]:
1980+
for (sdop, mv) in arg:
19771981
for (coef, pdiff) in sdop.terms:
19781982
if pdiff in pdiffs:
19791983
index = pdiffs.index(pdiff)
@@ -2037,23 +2041,18 @@ def Add(dop1, dop2):
20372041
if dop1.cmpflg != dop2.cmpflg:
20382042
raise ValueError('In Dop.Add complement flags have different values: %s vs. %s' % (dop1.cmpflg, dop2.cmpflg))
20392043

2040-
coefs1, pdiffs1 = list(zip(*dop1.terms))
2041-
coefs2, pdiffs2 = list(zip(*dop2.terms))
2042-
2043-
pdiffs1 = list(pdiffs1)
2044-
pdiffs2 = list(pdiffs2)
2044+
pdiffs1 = [pdiff for _, pdiff in dop1.terms]
2045+
pdiffs2 = [pdiff for _, pdiff in dop2.terms]
20452046

20462047
pdiffs = pdiffs1 + [x for x in pdiffs2 if x not in pdiffs1]
20472048
coefs = len(pdiffs) * [S(0)]
20482049

2049-
for pdiff in pdiffs1:
2050+
for coef, pdiff in dop1.terms:
20502051
index = pdiffs.index(pdiff)
2051-
coef = coefs1[pdiffs1.index(pdiff)]
20522052
coefs[index] += coef
20532053

2054-
for pdiff in pdiffs2:
2054+
for coef, pdiff in dop2.terms:
20552055
index = pdiffs.index(pdiff)
2056-
coef = coefs2[pdiffs2.index(pdiff)]
20572056
coefs[index] += coef
20582057

20592058
return Dop(coefs, pdiffs, cmpflg=dop1.cmpflg, ga=dop1.Ga)

test/test_differential_ops.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def test_associativity_and_distributivity(self):
3232
assert v ^ (ga.rgrad ^ ex) == (v ^ ga.rgrad) ^ ex != 0
3333
assert v ^ (ga.rgrad ^ 20) == (v ^ ga.rgrad) ^ 20 != 0
3434

35-
@pytest.mark.xfail(raises=IndexError)
3635
def test_empty_dop(self):
3736
""" Test that dop with zero terms is equivalent to multiplying by zero """
3837
coords = x, y, z = symbols('x y z', real=True)

0 commit comments

Comments
 (0)