Skip to content

Commit c597b63

Browse files
committed
Remove __div__ and alias it to __truediv__
These performed the same operation with different spellings anyway. Changes a ValueError to a TypeError too
1 parent 932f3c1 commit c597b63

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

galgebra/mv.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numbers
77
import operator
88
from functools import reduce, cmp_to_key
9+
import sys
910

1011
from sympy import (
1112
Symbol, Function, S, expand, Add,
@@ -577,18 +578,15 @@ def __mul__(self, A):
577578
def __rmul__(self, A):
578579
return Mv(expand(A * self.obj), ga=self.Ga)
579580

580-
def __div__(self, A):
581-
if isinstance(A,Mv):
582-
return self * A.inv()
583-
else:
584-
return self * (S(1)/A)
585-
586581
def __truediv__(self, A):
587582
if isinstance(A,Mv):
588583
return self * A.inv()
589584
else:
590585
return self * (S(1)/A)
591586

587+
if sys.version_info.major < 3:
588+
__div__ = __truediv__
589+
592590
def __str__(self):
593591
if printer.GaLatexPrinter.latex_flg:
594592
Printer = printer.GaLatexPrinter
@@ -2199,23 +2197,19 @@ def TSimplify(self):
21992197
new_terms.append((metric.Simp.apply(coef), pdiff))
22002198
return Dop(new_terms, ga=self.Ga)
22012199

2202-
def __div__(self, a):
2203-
if isinstance(a, (Mv, Dop)):
2204-
raise TypeError('!!!!Can only divide Dop by sympy scalar expression!!!!')
2205-
else:
2206-
return (1/a) * self
2200+
def __truediv__(self, dopr):
2201+
if isinstance(dopr, (Dop, Mv)):
2202+
raise TypeError('In Dop.__truediv__ dopr must be a sympy scalar.')
2203+
return Dop([
2204+
(coef / dopr, pdiff) for (coef, pdiff) in self.terms
2205+
], ga=self.Ga)
2206+
2207+
if sys.version_info.major < 3:
2208+
__div__ = __truediv__
22072209

22082210
def __mul__(self, dopr): # * geometric product
22092211
return Dop.Mul(self, dopr, op='*')
22102212

2211-
def __truediv__(self, dopr):
2212-
if isinstance(dopr, (Dop, Mv)):
2213-
raise ValueError('In Dop.__truediv__ dopr must be a sympy scalar.')
2214-
terms = []
2215-
for term in self.terms:
2216-
terms.append((term[0]/dopr,term[1]))
2217-
return Dop(terms, ga= self.Ga)
2218-
22192213
def __rmul__(self, dopl): # * geometric product
22202214
return Dop.Mul(dopl, self, op='*')
22212215

0 commit comments

Comments
 (0)