Fix(Compute/Typing): Add MOpolynomial to MOS list
This commit is contained in:
parent
298093d97d
commit
eae88d6c4c
@ -20,11 +20,12 @@ from .power import power
|
|||||||
from ..MO.mo import MOnumber, MOstr
|
from ..MO.mo import 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 ..MO.polynomial import MOpolynomial
|
||||||
|
|
||||||
from itertools import product
|
from itertools import product
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
|
||||||
MOS = [ MOnumber, MOstr, MOFraction, MOstrPower, MOMonomial ]
|
MOS = [ MOnumber, MOstr, MOFraction, MOstrPower, MOMonomial, MOpolynomial]
|
||||||
|
|
||||||
OPERATIONS = {
|
OPERATIONS = {
|
||||||
"+": add,
|
"+": add,
|
||||||
@ -67,7 +68,7 @@ def compute_capacities(node):
|
|||||||
|
|
||||||
:example:
|
:example:
|
||||||
>>> compute_capacities("+")
|
>>> compute_capacities("+")
|
||||||
[['+', 'MOnumber', 'MOstr', 'MOFraction', 'MOstrPower', 'MOMonomial'], ['MOnumber', True, False, True, False, False], ['MOstr', False, True, False, False, True], ['MOFraction', True, False, True, False, False], ['MOstrPower', False, False, False, True, True], ['MOMonomial', False, True, False, True, True]]
|
[['+', 'MOnumber', 'MOstr', 'MOFraction', 'MOstrPower', 'MOMonomial', 'MOpolynomial'], ['MOnumber', True, False, True, False, False, True], ['MOstr', False, True, False, False, True, True], ['MOFraction', True, False, True, False, False, True], ['MOstrPower', False, False, False, True, True, True], ['MOMonomial', False, True, False, True, True, True], ['MOpolynomial', True, True, True, True, True, True]]
|
||||||
|
|
||||||
"""
|
"""
|
||||||
op = OPERATIONS[node]
|
op = OPERATIONS[node]
|
||||||
|
@ -13,23 +13,24 @@ Computing with MO
|
|||||||
from .exceptions import TypingError
|
from .exceptions import TypingError
|
||||||
from .add import add
|
from .add import add
|
||||||
# from .minus import minus
|
# from .minus import minus
|
||||||
# from .multiply import multiply
|
from .multiply import multiply
|
||||||
from .divide import divide
|
from .divide import divide
|
||||||
from .power import power
|
from .power import power
|
||||||
|
|
||||||
from ..MO.mo import MOnumber, MOstr
|
from ..MO.mo import 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 ..MO.polynomial import MOpolynomial
|
||||||
|
|
||||||
from itertools import product
|
from itertools import product
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
|
||||||
MOS = [ MOnumber, MOstr, MOFraction, MOstrPower, MOMonomial ]
|
MOS = [ MOnumber, MOstr, MOFraction, MOstrPower, MOMonomial, MOpolynomial]
|
||||||
|
|
||||||
OPERATIONS = {
|
OPERATIONS = {
|
||||||
"+": add,
|
"+": add,
|
||||||
# "-": minus,
|
# "-": minus,
|
||||||
# "*": multiply,
|
"*": multiply,
|
||||||
"/": divide,
|
"/": divide,
|
||||||
"^": power,
|
"^": power,
|
||||||
}
|
}
|
||||||
@ -46,7 +47,10 @@ def typing(node, left_v, right_v):
|
|||||||
operation = OPERATIONS[node]
|
operation = OPERATIONS[node]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise TypingError(f"Unknown operation ({node}) in typing")
|
raise TypingError(f"Unknown operation ({node}) in typing")
|
||||||
|
try:
|
||||||
return operation(left_v, right_v)
|
return operation(left_v, right_v)
|
||||||
|
except NotImplementedError:
|
||||||
|
raise TypingError(f"Can't create new MO with {node}, {type(left_v)} and {type(right_v)}")
|
||||||
|
|
||||||
def typing_capacities(node):
|
def typing_capacities(node):
|
||||||
""" Test an operation through all MOs
|
""" Test an operation through all MOs
|
||||||
@ -54,6 +58,10 @@ def typing_capacities(node):
|
|||||||
:param operation: string which represent an (mo, mo) -> mo
|
:param operation: string which represent an (mo, mo) -> mo
|
||||||
:returns: { (motype, motype): True/False } when it's implemented
|
:returns: { (motype, motype): True/False } when it's implemented
|
||||||
|
|
||||||
|
:example:
|
||||||
|
>>> typing_capacities("*")
|
||||||
|
[['*', 'MOnumber', 'MOstr', 'MOFraction', 'MOstrPower', 'MOMonomial', 'MOpolynomial'], ['MOnumber', False, True, False, True, False, False], ['MOstr', True, False, True, False, False, False], ['MOFraction', False, True, False, True, False, False], ['MOstrPower', True, False, True, False, False, False], ['MOMonomial', False, False, False, False, False, False], ['MOpolynomial', False, False, False, False, False, False]]
|
||||||
|
|
||||||
"""
|
"""
|
||||||
op = OPERATIONS[node]
|
op = OPERATIONS[node]
|
||||||
lines = [[node] + [mo.__name__ for mo in MOS]]
|
lines = [[node] + [mo.__name__ for mo in MOS]]
|
||||||
|
Loading…
Reference in New Issue
Block a user