Doc(Compute): Add dynamic table for sum up implemented operations
This commit is contained in:
parent
a557fa3981
commit
2bbcfaf482
@ -16,6 +16,15 @@ from .minus import minus
|
|||||||
from .multiply import multiply
|
from .multiply import multiply
|
||||||
from .divide import divide
|
from .divide import divide
|
||||||
|
|
||||||
|
from ..MO.mo import MOnumber, MOstr
|
||||||
|
from ..MO.fraction import MOFraction
|
||||||
|
from ..MO.monomial import MOstrPower, MOMonomial
|
||||||
|
|
||||||
|
from itertools import product
|
||||||
|
from tabulate import tabulate
|
||||||
|
|
||||||
|
MOS = [ MOnumber, MOstr, MOFraction, MOstrPower, MOMonomial ]
|
||||||
|
|
||||||
OPERATIONS = {
|
OPERATIONS = {
|
||||||
"+": add,
|
"+": add,
|
||||||
"-": minus,
|
"-": minus,
|
||||||
@ -48,6 +57,31 @@ def compute(node, left_v, right_v):
|
|||||||
|
|
||||||
return operation(left_v, right_v)
|
return operation(left_v, right_v)
|
||||||
|
|
||||||
|
def compute_capacities(node):
|
||||||
|
""" Test an operation through all MOs
|
||||||
|
|
||||||
|
:param operation: string which represent an (mo, mo) -> mo
|
||||||
|
:returns: { (motype, motype): True/False } when it's implemented
|
||||||
|
|
||||||
|
:example:
|
||||||
|
>>> compute_capacities("+")
|
||||||
|
[['+', 'MOnumber', 'MOstr', 'MOFraction', 'MOstrPower', 'MOMonomial'], ['MOnumber', True, False, True, False, False], ['MOstr', False, False, False, False, False], ['MOFraction', True, False, True, False, False], ['MOstrPower', False, False, False, False, False], ['MOMonomial', False, False, False, False, False]]
|
||||||
|
|
||||||
|
"""
|
||||||
|
op = OPERATIONS[node]
|
||||||
|
lines = [[node] + [mo.__name__ for mo in MOS]]
|
||||||
|
for left_mo in MOS:
|
||||||
|
lines.append(
|
||||||
|
[left_mo.__name__] + \
|
||||||
|
[(left_mo, i) in op.funcs for i in MOS]
|
||||||
|
)
|
||||||
|
return lines
|
||||||
|
|
||||||
|
|
||||||
|
compute.__doc__ += "Implemented compute operations among MOs"
|
||||||
|
for op in OPERATIONS:
|
||||||
|
compute.__doc__ += f"\n{tabulate(compute_capacities(op), tablefmt='grid')} \n"
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
# Reglages pour 'vim'
|
# Reglages pour 'vim'
|
||||||
|
Loading…
Reference in New Issue
Block a user