Fix: typing filter for multiply
This commit is contained in:
parent
fdf3b088f2
commit
b51ac7880d
@ -15,6 +15,7 @@ from ..tree import Tree
|
||||
from ..MO import MO, MOnumber, MOstr
|
||||
from ..MO.fraction import MOFraction
|
||||
from ..MO.monomial import MOstrPower, MOMonomial
|
||||
from ..compute.filters import special_case
|
||||
|
||||
multiply_doc = """ Multiply MOs
|
||||
|
||||
@ -26,8 +27,26 @@ multiply_doc = """ Multiply MOs
|
||||
|
||||
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
|
||||
"""
|
||||
try:
|
||||
if left == 1:
|
||||
return right
|
||||
except TypeError:
|
||||
pass
|
||||
try:
|
||||
if right == 1:
|
||||
return left
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
@multiply.register((MOnumber, MOFraction), MOstr)
|
||||
@special_case(multiply_filter)
|
||||
def moscalar_mostr(left, right):
|
||||
""" Multiply a scalar with a letter to create a MOMonomial
|
||||
|
||||
@ -43,6 +62,7 @@ def moscalar_mostr(left, right):
|
||||
|
||||
|
||||
@multiply.register(MOstr, (MOnumber, MOFraction))
|
||||
@special_case(multiply_filter)
|
||||
def mostr_moscalar(left, right):
|
||||
""" Multiply a scalar with a letter to create a MOMonomial
|
||||
|
||||
@ -58,6 +78,7 @@ def mostr_moscalar(left, right):
|
||||
|
||||
|
||||
@multiply.register((MOnumber, MOFraction), MOstrPower)
|
||||
@special_case(multiply_filter)
|
||||
def moscalar_mostrpower(left, right):
|
||||
""" Multiply a scalar with a MOstrPower
|
||||
|
||||
@ -65,12 +86,18 @@ def moscalar_mostrpower(left, right):
|
||||
>>> x = MOstrPower('x', 4)
|
||||
>>> multiply(a, x)
|
||||
<MOMonomial 4x^4>
|
||||
|
||||
>>> a = MOnumber(1)
|
||||
>>> x = MOstrPower('x', 4)
|
||||
>>> multiply(a, x)
|
||||
<MOstrPower x^4>
|
||||
"""
|
||||
#if left == 1:
|
||||
# return right
|
||||
return MOMonomial(left, right)
|
||||
|
||||
|
||||
@multiply.register(MOstrPower, (MOnumber, MOFraction))
|
||||
@special_case(multiply_filter)
|
||||
def mostrpower_moscalar(left, right):
|
||||
""" Multiply a MOstrPower with a scalar
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user