Fix(compute): clean typing multiply
This commit is contained in:
parent
b24069a72d
commit
1266a2331b
@ -15,8 +15,6 @@ from ..tree import Tree
|
|||||||
from ..MO.mo import MO, MOnumber, MOstr
|
from ..MO.mo import MO, MOnumber, MOstr
|
||||||
from ..MO.fraction import MOFraction
|
from ..MO.fraction import MOFraction
|
||||||
from ..MO.monomial import MOstrPower, MOMonomial
|
from ..MO.monomial import MOstrPower, MOMonomial
|
||||||
from .exceptions import MultiplyError
|
|
||||||
from .filters import special_case
|
|
||||||
|
|
||||||
multiply_doc = """ Multiply MOs
|
multiply_doc = """ Multiply MOs
|
||||||
|
|
||||||
@ -28,48 +26,7 @@ multiply_doc = """ Multiply MOs
|
|||||||
|
|
||||||
multiply = Dispatcher("multiply", doc=multiply_doc)
|
multiply = Dispatcher("multiply", doc=multiply_doc)
|
||||||
|
|
||||||
def multiply_filter(left, right):
|
|
||||||
""" Automatic multiply on MO
|
|
||||||
|
|
||||||
:param left: MO
|
|
||||||
:param right: MO
|
|
||||||
:returns: MO if it is a special case, nothing other wise
|
|
||||||
|
|
||||||
>>> a = MOnumber(1)
|
|
||||||
>>> b = MOFraction(1, 2)
|
|
||||||
>>> multiply(a, b)
|
|
||||||
<MOFraction 1 / 2>
|
|
||||||
>>> multiply(b, a)
|
|
||||||
<MOFraction 1 / 2>
|
|
||||||
>>> a = MOnumber(0)
|
|
||||||
>>> b = MOFraction(1, 2)
|
|
||||||
>>> multiply(a, b)
|
|
||||||
<MOnumber 0>
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
if left == 0:
|
|
||||||
return left
|
|
||||||
except TypeError:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
if right == 0:
|
|
||||||
return right
|
|
||||||
except TypeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
if left == 1:
|
|
||||||
return right
|
|
||||||
except TypeError:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
if right == 1:
|
|
||||||
return left
|
|
||||||
except TypeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@multiply.register((MOnumber, MOFraction), MOstr)
|
@multiply.register((MOnumber, MOFraction), MOstr)
|
||||||
@special_case(multiply_filter)
|
|
||||||
def moscalar_mostr(left, right):
|
def moscalar_mostr(left, right):
|
||||||
""" Multiply a scalar with a letter to create a MOMonomial
|
""" Multiply a scalar with a letter to create a MOMonomial
|
||||||
|
|
||||||
@ -84,7 +41,6 @@ def moscalar_mostr(left, right):
|
|||||||
return MOMonomial(left, right)
|
return MOMonomial(left, right)
|
||||||
|
|
||||||
@multiply.register(MOstr, (MOnumber, MOFraction))
|
@multiply.register(MOstr, (MOnumber, MOFraction))
|
||||||
@special_case(multiply_filter)
|
|
||||||
def mostr_moscalar(left, right):
|
def mostr_moscalar(left, right):
|
||||||
""" Multiply a scalar with a letter to create a MOMonomial
|
""" Multiply a scalar with a letter to create a MOMonomial
|
||||||
|
|
||||||
@ -99,7 +55,6 @@ def mostr_moscalar(left, right):
|
|||||||
return MOMonomial(right, left)
|
return MOMonomial(right, left)
|
||||||
|
|
||||||
@multiply.register((MOnumber, MOFraction), MOstrPower)
|
@multiply.register((MOnumber, MOFraction), MOstrPower)
|
||||||
@special_case(multiply_filter)
|
|
||||||
def moscalar_mostrpower(left, right):
|
def moscalar_mostrpower(left, right):
|
||||||
""" Multiply a scalar with a MOstrPower
|
""" Multiply a scalar with a MOstrPower
|
||||||
|
|
||||||
@ -116,7 +71,6 @@ def moscalar_mostrpower(left, right):
|
|||||||
return MOMonomial(left, right)
|
return MOMonomial(left, right)
|
||||||
|
|
||||||
@multiply.register(MOstrPower, (MOnumber, MOFraction))
|
@multiply.register(MOstrPower, (MOnumber, MOFraction))
|
||||||
@special_case(multiply_filter)
|
|
||||||
def mostrpower_moscalar(left, right):
|
def mostrpower_moscalar(left, right):
|
||||||
""" Multiply a MOstrPower with a scalar
|
""" Multiply a MOstrPower with a scalar
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user