Feat(Core): Add signature to mos

This commit is contained in:
Bertrand Benjamin 2018-11-23 10:05:36 +01:00
parent 8933359945
commit 8f99d1e71e
2 changed files with 40 additions and 0 deletions

View File

@ -46,6 +46,7 @@ class MO(object):
:attr value: sympy compatible version of the MO
:attr _tree: tree version of the MO
:attr _signature: Name to identify the MO in the API
"""
@ -67,6 +68,7 @@ class MO(object):
self._tree = value
self.is_scalar = True
self._signature = None
@classmethod
def factory(cls, value):
@ -128,6 +130,18 @@ class MO(object):
except AttributeError:
return self._tree == other
@property
def signature(self):
""" Name of the mo in the API
:example:
>>> MOnumber(3).signature
'scalar'
>>> MOstr("x").signature
'monome1'
"""
return self._signature
@total_ordering
class MOnumber(MO):
@ -168,6 +182,7 @@ class MOnumber(MO):
raise MOError("The value of an MOnumber need to be a int, a float or a Decimal")
self.value = self._tree
self._signature = "scalar"
@property
def __txt__(self):
@ -234,6 +249,7 @@ class MOstr(MO):
MO.__init__(self, val)
self.is_scalar = False
self._variable = val
self._signature = "monome1"
@property
def variable(self):

View File

@ -74,6 +74,18 @@ class MOstrPower(MO):
def power(self):
return self._power
@property
def signature(self):
""" Name of the mo in the API
:example:
>>> MOstrPower("x", 3).signature
'monome3'
>>> MOstrPower("x", 2).signature
'monome2'
"""
return f"monome{self.power}"
class MOMonomial(MO):
""" Monomial math object"""
@ -151,6 +163,18 @@ class MOMonomial(MO):
def power(self):
return self._power
@property
def signature(self):
""" Name of the mo in the API
:example:
>>> MOMonomial(2, "x").signature
'monome1'
>>> MOMonomial(4, "x", 2).signature
'monome2'
"""
return f"monome{self.power}"
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4: