diff --git a/pystencils/simp/assignment_collection.py b/pystencils/simp/assignment_collection.py index 49fc06e2ddf6217f3425dacd33f1b913f6cd8c18..b0c09cec9ae2066d2db9fcb11d2c03e239d0e091 100644 --- a/pystencils/simp/assignment_collection.py +++ b/pystencils/simp/assignment_collection.py @@ -61,8 +61,11 @@ class AssignmentCollection: self.simplification_hints = simplification_hints + ctrs = [int(n.name[3:])for n in self.rhs_symbols if "xi_" in n.name] + max_ctr = max(ctrs) + 1 if len(ctrs) > 0 else 0 + if subexpression_symbol_generator is None: - self.subexpression_symbol_generator = SymbolGen() + self.subexpression_symbol_generator = SymbolGen(ctr=max_ctr) else: self.subexpression_symbol_generator = subexpression_symbol_generator @@ -453,8 +456,8 @@ class AssignmentCollection: class SymbolGen: """Default symbol generator producing number symbols ζ_0, ζ_1, ...""" - def __init__(self, symbol="xi", dtype=None): - self._ctr = 0 + def __init__(self, symbol="xi", dtype=None, ctr=0): + self._ctr = ctr self._symbol = symbol self._dtype = dtype diff --git a/pystencils/typing/types.py b/pystencils/typing/types.py index 531a8e2902fe5f44db911ff5fe4ee6eb4f11737b..f0f9744a558ed42bfebe08e6430da3aa21d8131a 100644 --- a/pystencils/typing/types.py +++ b/pystencils/typing/types.py @@ -70,7 +70,7 @@ class BasicType(AbstractType): BasicType is defined with a const qualifier and a np.dtype. """ - def __init__(self, dtype: Union[np.dtype, 'BasicType', str], const: bool = False): + def __init__(self, dtype: Union[type, 'BasicType', str], const: bool = False): if isinstance(dtype, BasicType): self.numpy_dtype = dtype.numpy_dtype self.const = dtype.const @@ -291,7 +291,7 @@ class StructType(AbstractType): return hash((self.numpy_dtype, self.const)) -def create_type(specification: Union[np.dtype, AbstractType, str]) -> AbstractType: +def create_type(specification: Union[type, AbstractType, str]) -> AbstractType: # TODO: Deprecated Use the constructor of BasicType or StructType instead """Creates a subclass of Type according to a string or an object of subclass Type.