diff options
Diffstat (limited to '')
-rw-r--r-- | polymatrix/expression/from_.py | 17 | ||||
-rw-r--r-- | polymatrix/expression/mixins/variablemixin.py | 2 |
2 files changed, 17 insertions, 2 deletions
diff --git a/polymatrix/expression/from_.py b/polymatrix/expression/from_.py index 011d5d7..c34e75d 100644 --- a/polymatrix/expression/from_.py +++ b/polymatrix/expression/from_.py @@ -1,9 +1,14 @@ +from typing import Iterable +from typing_extensions import override + from polymatrix.expression.typing import FromDataTypes import polymatrix.expression.init from polymatrix.expression.expression import init_expression, Expression from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin +from polymatrix.expression.mixins.variablemixin import VariableMixin +from polymatrix.expression.init import init_variable_expr from polymatrix.statemonad.abc import StateMonad @@ -30,3 +35,15 @@ def from_( data=data, ), ) + + +def from_names(names: str, shape: tuple[int, int] = (1,1)) -> VariableMixin | tuple[VariableMixin]: + """ Construct one or multiple variables from comma separated a list of names. """ + variables = tuple(init_variable_expr(name.strip(), shape) + for name in names.split(",")) + + if len(variables) == 1: + return variables[0] + + return variables + diff --git a/polymatrix/expression/mixins/variablemixin.py b/polymatrix/expression/mixins/variablemixin.py index c2b0bc1..67ee481 100644 --- a/polymatrix/expression/mixins/variablemixin.py +++ b/polymatrix/expression/mixins/variablemixin.py @@ -26,8 +26,6 @@ class VariableMixin(ExpressionBaseMixin): @override def apply(self, state: ExpressionStateMixin) -> tuple[ExpressionStateMixin, PolyMatrixMixin]: - """ See :py:meth:`ExpressionBaseMixin.apply`. """ - state, indices = state.index(self) p = PolyMatrixDict() |