Skip to content
Snippets Groups Projects
Commit 6e7e2fc5 authored by Martin Bauer's avatar Martin Bauer
Browse files

Tests: Memory Bugfix for ipynb-runner

- shortened the longest running tests, moved some configurations
  to longrun
parent 04cd0614
Branches
Tags
No related merge requests found
import sympy as sp import sympy as sp
from copy import deepcopy from copy import copy
from pystencils.sympyextensions import fastSubs, countNumberOfOperations, sortEquationsTopologically from pystencils.sympyextensions import fastSubs, countNumberOfOperations, sortEquationsTopologically
...@@ -40,11 +40,20 @@ class EquationCollection(object): ...@@ -40,11 +40,20 @@ class EquationCollection(object):
return [] return []
def copy(self, mainEquations=None, subexpressions=None): def copy(self, mainEquations=None, subexpressions=None):
res = deepcopy(self) res = copy(self)
res.simplificationHints = self.simplificationHints.copy()
res.subexpressionSymbolNameGenerator = copy(self.subexpressionSymbolNameGenerator)
if mainEquations is not None: if mainEquations is not None:
res.mainEquations = mainEquations res.mainEquations = mainEquations
else:
res.mainEquations = self.mainEquations.copy()
if subexpressions is not None: if subexpressions is not None:
res.subexpressions = subexpressions res.subexpressions = subexpressions
else:
res.subexpressions = self.subexpressions.copy()
return res return res
def copyWithSubstitutionsApplied(self, substitutionDict, addSubstitutionsAsSubexpressions=False, def copyWithSubstitutionsApplied(self, substitutionDict, addSubstitutionsAsSubexpressions=False,
...@@ -103,7 +112,7 @@ class EquationCollection(object): ...@@ -103,7 +112,7 @@ class EquationCollection(object):
@property @property
def operationCount(self): def operationCount(self):
"""See :func:`countNumberOfOperations` """ """See :func:`countNumberOfOperations` """
return countNumberOfOperations(self.allEquations) return countNumberOfOperations(self.allEquations, onlyType=None)
def get(self, symbols, fromMainEquationsOnly=False): def get(self, symbols, fromMainEquationsOnly=False):
"""Return the equations which have symbols as left hand sides""" """Return the equations which have symbols as left hand sides"""
......
...@@ -420,13 +420,14 @@ def countNumberOfOperations(term, onlyType='real'): ...@@ -420,13 +420,14 @@ def countNumberOfOperations(term, onlyType='real'):
""" """
Counts the number of additions, multiplications and division Counts the number of additions, multiplications and division
:param term: a sympy term, equation or sequence of terms/equations :param term: a sympy term, equation or sequence of terms/equations
:param onlyType: 'real' or 'int' to count only operations on these types, or None for all
:return: a dictionary with 'adds', 'muls' and 'divs' keys :return: a dictionary with 'adds', 'muls' and 'divs' keys
""" """
result = {'adds': 0, 'muls': 0, 'divs': 0} result = {'adds': 0, 'muls': 0, 'divs': 0}
if isinstance(term, Sequence): if isinstance(term, Sequence):
for element in term: for element in term:
r = countNumberOfOperations(element) r = countNumberOfOperations(element, onlyType)
for operationName in result.keys(): for operationName in result.keys():
result[operationName] += r[operationName] result[operationName] += r[operationName]
return result return result
...@@ -469,7 +470,7 @@ def countNumberOfOperations(term, onlyType='real'): ...@@ -469,7 +470,7 @@ def countNumberOfOperations(term, onlyType='real'):
elif t.is_integer: elif t.is_integer:
pass pass
elif t.func is sp.Pow: elif t.func is sp.Pow:
if checkType(t): if checkType(t.args[0]):
visitChildren = False visitChildren = False
if t.exp.is_integer and t.exp.is_number: if t.exp.is_integer and t.exp.is_number:
if t.exp >= 0: if t.exp >= 0:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment