diff options
author | Nao Pross <np@0hm.ch> | 2024-05-08 12:44:32 +0200 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-05-08 13:40:57 +0200 |
commit | a8738f49ae09a8c368f4ed1887aa6e12bad953fd (patch) | |
tree | e79c14a33032d4baf109ad5c058c482e28155807 | |
parent | Fix bug in PolyMatrixAsAffineExpr.affine_coefficient (diff) | |
download | polymatrix-a8738f49ae09a8c368f4ed1887aa6e12bad953fd.tar.gz polymatrix-a8738f49ae09a8c368f4ed1887aa6e12bad953fd.zip |
Create singular polymatrix.from_name to remove ambiguous return type
-rw-r--r-- | polymatrix/__init__.py | 3 | ||||
-rw-r--r-- | polymatrix/expression/from_.py | 14 |
2 files changed, 8 insertions, 9 deletions
diff --git a/polymatrix/__init__.py b/polymatrix/__init__.py index a808d92..f68f364 100644 --- a/polymatrix/__init__.py +++ b/polymatrix/__init__.py @@ -3,7 +3,7 @@ from polymatrix.expressionstate.init import ( init_expression_state as internal_init_expression_state, ) from polymatrix.expression.expression import Expression as internal_Expression -from polymatrix.expression.from_ import from_ as internal_from, from_names as internal_from_names +from polymatrix.expression.from_ import from_ as internal_from, from_names as internal_from_names, from_name as internal_from_name from polymatrix.expression import v_stack as internal_v_stack from polymatrix.expression import h_stack as internal_h_stack from polymatrix.expression import product as internal_product @@ -30,3 +30,4 @@ to_matrix_repr = from_polymatrix to_dense = from_polymatrix to_affine = to_affine_expression from_names = internal_from_names +from_name = internal_from_name diff --git a/polymatrix/expression/from_.py b/polymatrix/expression/from_.py index a1303a3..1e50c40 100644 --- a/polymatrix/expression/from_.py +++ b/polymatrix/expression/from_.py @@ -33,14 +33,12 @@ def from_( ) -def from_names(names: str, shape: tuple[int, int] = (1,1)) -> tuple[VariableExpression] | VariableExpression: +def from_names(names: str, shape: tuple[int, int] = (1,1)) -> Iterable[VariableExpression]: """ Construct one or multiple variables from comma separated a list of names. """ - variables = tuple(init_variable_expression( - underlying=polymatrix.expression.init.init_variable_expr(name.strip(), shape)) - for name in names.split(",")) + for name in names.split(","): + yield from_name(name.strip(), shape) - if len(variables) == 1: - return variables[0] - - return variables +def from_name(name: str, shape: tuple[int, int] = (1,1)) -> VariableExpression: + """ Construct a variable from its names """ + return init_variable_expression(polymatrix.expression.init.init_variable_expr(name, shape)) |