From 6e7e2fc532f72442ac685dea3b67b26dba2e7b0c Mon Sep 17 00:00:00 2001 From: Martin Bauer <martin.bauer@fau.de> Date: Wed, 28 Mar 2018 17:35:40 +0200 Subject: [PATCH] Tests: Memory Bugfix for ipynb-runner - shortened the longest running tests, moved some configurations to longrun --- equationcollection/equationcollection.py | 15 ++++++++++++--- sympyextensions.py | 5 +++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/equationcollection/equationcollection.py b/equationcollection/equationcollection.py index 66146ad0c..1609c95d6 100644 --- a/equationcollection/equationcollection.py +++ b/equationcollection/equationcollection.py @@ -1,5 +1,5 @@ import sympy as sp -from copy import deepcopy +from copy import copy from pystencils.sympyextensions import fastSubs, countNumberOfOperations, sortEquationsTopologically @@ -40,11 +40,20 @@ class EquationCollection(object): return [] 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: res.mainEquations = mainEquations + else: + res.mainEquations = self.mainEquations.copy() + if subexpressions is not None: res.subexpressions = subexpressions + else: + res.subexpressions = self.subexpressions.copy() + return res def copyWithSubstitutionsApplied(self, substitutionDict, addSubstitutionsAsSubexpressions=False, @@ -103,7 +112,7 @@ class EquationCollection(object): @property def operationCount(self): """See :func:`countNumberOfOperations` """ - return countNumberOfOperations(self.allEquations) + return countNumberOfOperations(self.allEquations, onlyType=None) def get(self, symbols, fromMainEquationsOnly=False): """Return the equations which have symbols as left hand sides""" diff --git a/sympyextensions.py b/sympyextensions.py index 566cc7441..6e29cabf9 100644 --- a/sympyextensions.py +++ b/sympyextensions.py @@ -420,13 +420,14 @@ def countNumberOfOperations(term, onlyType='real'): """ Counts the number of additions, multiplications and division :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 """ result = {'adds': 0, 'muls': 0, 'divs': 0} if isinstance(term, Sequence): for element in term: - r = countNumberOfOperations(element) + r = countNumberOfOperations(element, onlyType) for operationName in result.keys(): result[operationName] += r[operationName] return result @@ -469,7 +470,7 @@ def countNumberOfOperations(term, onlyType='real'): elif t.is_integer: pass elif t.func is sp.Pow: - if checkType(t): + if checkType(t.args[0]): visitChildren = False if t.exp.is_integer and t.exp.is_number: if t.exp >= 0: -- GitLab