Style: apply black

This commit is contained in:
2019-05-14 06:55:56 +02:00
parent 7097801306
commit 09b04d2703
35 changed files with 533 additions and 354 deletions

View File

@@ -29,6 +29,7 @@ add_doc = """ Adding MOs
add = Dispatcher("add", doc=add_doc)
def add_filter(left, right):
""" Automatic add on MO
@@ -59,6 +60,7 @@ def add_filter(left, right):
except AttributeError:
pass
@add.register(MOnumber, MOnumber)
@special_case(add_filter)
def monumber_monumber(left, right):
@@ -72,6 +74,7 @@ def monumber_monumber(left, right):
"""
return MO.factory(left.value + right.value)
@add.register(MOnumber, MOFraction)
@special_case(add_filter)
def monumber_mofraction(left, right):
@@ -87,6 +90,7 @@ def monumber_mofraction(left, right):
left_fraction = MOFraction(left, MOnumber(1))
return Tree("+", left_fraction, right)
@add.register(MOFraction, MOnumber)
@special_case(add_filter)
def mofraction_monumber(left, right):
@@ -103,6 +107,7 @@ def mofraction_monumber(left, right):
right_fraction = MOFraction(right, MOnumber(1))
return Tree("+", left, right_fraction)
@add.register(MOFraction, MOFraction)
@special_case(add_filter)
def mofraction_mofraction(left, right):
@@ -200,6 +205,7 @@ def mofraction_mofraction(left, right):
return Tree("+", left_frac, right_frac)
@add.register(MOstr, MOstr)
@special_case(add_filter)
def mostr_mostr(left, right):
@@ -215,6 +221,7 @@ def mostr_mostr(left, right):
raise NotImplementedError("Can't add 2 MOstr with not same letter")
return MOMonomial(2, left)
@add.register(MOstrPower, MOstrPower)
@special_case(add_filter)
def mostrpower_mostrpower(left, right):
@@ -230,6 +237,7 @@ def mostrpower_mostrpower(left, right):
raise NotImplementedError("Can't add 2 MOstrPower with not same power")
return MOMonomial(2, left.variable, left.power)
@add.register((MOnumber, MOFraction), MOpolynomial)
@special_case(add_filter)
def moscalar_mopolynomial(left, right):
@@ -254,7 +262,8 @@ def moscalar_mopolynomial(left, right):
right_top = [mo for deg, mo in right.monomials.items() if deg > 0][::-1]
adds = right_top + [Tree("+", left, right_const)]
return Tree.from_list('+', adds)
return Tree.from_list("+", adds)
@add.register(MOpolynomial, (MOnumber, MOFraction))
@special_case(add_filter)
@@ -280,7 +289,8 @@ def mopolynomial_moscalar(left, right):
left_top = [mo for deg, mo in left.monomials.items() if deg > 0][::-1]
adds = left_top + [Tree("+", left_const, right)]
return Tree.from_list('+', adds)
return Tree.from_list("+", adds)
@add.register(MOstr, MOpolynomial)
@special_case(add_filter)
@@ -313,6 +323,7 @@ def mostr_mopolynomial(left, right):
return Tree.from_list("+", adds)
@add.register(MOpolynomial, MOstr)
@special_case(add_filter)
def mopolynomial_mostr(left, right):
@@ -344,6 +355,7 @@ def mopolynomial_mostr(left, right):
return Tree.from_list("+", adds)
@add.register(MOstrPower, MOpolynomial)
@special_case(add_filter)
def mostrpower_mopolynomial(left, right):
@@ -387,6 +399,7 @@ def mostrpower_mopolynomial(left, right):
return Tree.from_list("+", adds)
@add.register(MOpolynomial, MOstrPower)
@special_case(add_filter)
def mopolynomial_mostrpower(left, right):
@@ -431,6 +444,7 @@ def mopolynomial_mostrpower(left, right):
return Tree.from_list("+", adds)
@add.register(MOMonomial, MOpolynomial)
@special_case(add_filter)
def momonomial_mopolynomial(left, right):
@@ -474,6 +488,7 @@ def momonomial_mopolynomial(left, right):
return Tree.from_list("+", adds)
@add.register(MOpolynomial, MOMonomial)
@special_case(add_filter)
def mopolynomial_momonomial(left, right):
@@ -517,6 +532,7 @@ def mopolynomial_momonomial(left, right):
return Tree.from_list("+", adds)
@add.register(MOpolynomial, MOpolynomial)
@special_case(add_filter)
def mopolynomial_mopolynomial(left, right):
@@ -563,7 +579,7 @@ def mopolynomial_mopolynomial(left, right):
| > 2
"""
common_degree = set(left.monomials.keys()).intersection(right.monomials.keys())
common_degree = set(left.monomials.keys()).intersection(right.monomials.keys())
if not common_degree:
raise NotImplementedError("No degree in common, no calculus to do")
@@ -573,6 +589,7 @@ def mopolynomial_mopolynomial(left, right):
return Tree.from_list("+", list(merge_monomials.values())[::-1])
@add.register(MOstr, MOMonomial)
@special_case(add_filter)
def mostr_momonomial(left, right):
@@ -593,6 +610,7 @@ def mostr_momonomial(left, right):
add_scal = Tree("+", 1, right.coefficient)
return Tree("*", add_scal, left)
@add.register(MOMonomial, MOstr)
@special_case(add_filter)
def momonomial_mostr(left, right):
@@ -613,6 +631,7 @@ def momonomial_mostr(left, right):
add_scal = Tree("+", left.coefficient, 1)
return Tree("*", add_scal, right)
@add.register(MOstrPower, MOMonomial)
@special_case(add_filter)
def mostrpower_momonomial(left, right):
@@ -633,6 +652,7 @@ def mostrpower_momonomial(left, right):
add_scal = Tree("+", 1, right.coefficient)
return Tree("*", add_scal, left)
@add.register(MOMonomial, MOstrPower)
@special_case(add_filter)
def momonomial_mostrpower(left, right):
@@ -653,6 +673,7 @@ def momonomial_mostrpower(left, right):
add_scal = Tree("+", left.coefficient, 1)
return Tree("*", add_scal, right)
@add.register(MOMonomial, MOMonomial)
@special_case(add_filter)
def momonomial_momonomial(left, right):