diff --git a/equationcollection/simplificationstrategy.py b/equationcollection/simplificationstrategy.py index 8f2078ba49ea302f08ad0bceb8ce9613634b2de1..3162b9937de8e29c69eeec1fdedbbe6650a1067d 100644 --- a/equationcollection/simplificationstrategy.py +++ b/equationcollection/simplificationstrategy.py @@ -41,7 +41,7 @@ class SimplificationStrategy: with the run-time the simplification took. """ - ReportElement = namedtuple('ReportElement', ['simplificationName', 'adds', 'muls', 'divs', 'runtime']) + ReportElement = namedtuple('ReportElement', ['simplificationName', 'runtime', 'adds', 'muls', 'divs', 'total']) class Report: def __init__(self): @@ -53,7 +53,7 @@ class SimplificationStrategy: def __str__(self): try: import tabulate - return tabulate(self.elements, headers=['Name', 'Adds', 'Muls', 'Divs', 'Runtime']) + return tabulate(self.elements, headers=['Name', 'Runtime', 'Adds', 'Muls', 'Divs', 'Total']) except ImportError: result = "Name, Adds, Muls, Divs, Runtime\n" for e in self.elements: @@ -62,9 +62,9 @@ class SimplificationStrategy: def _repr_html_(self): htmlTable = '<table style="border:none">' - htmlTable += "<tr> <th>Name</th> <th>Adds</th> <th>Muls</th> <th>Divs</th> <th>Runtime</th></tr>" + htmlTable += "<tr><th>Name</th><th>Runtime</th><th>Adds</th><th>Muls</th><th>Divs</th><th>Total</th></tr>" line = "<tr><td>{simplificationName}</td>" \ - "<td>{adds}</td> <td>{muls}</td> <td>{divs}</td> <td>{runtime}</td> </tr>" + "<td>{runtime}</td> <td>{adds}</td> <td>{muls}</td> <td>{divs}</td> <td>{total}</td> </tr>" for e in self.elements: htmlTable += line.format(**e._asdict()) @@ -74,14 +74,16 @@ class SimplificationStrategy: import time report = Report() op = equationCollection.operationCount - report.add(ReportElement("OriginalTerm", op['adds'], op['muls'], op['divs'], '-')) + total = op['adds'] + op['muls'] + op['divs'] + report.add(ReportElement("OriginalTerm", '-', op['adds'], op['muls'], op['divs'], total)) for t in self._rules: startTime = time.perf_counter() equationCollection = t(equationCollection) endTime = time.perf_counter() op = equationCollection.operationCount timeStr = "%.2f ms" % ((endTime - startTime) * 1000,) - report.add(ReportElement(t.__name__, op['adds'], op['muls'], op['divs'], timeStr)) + total = op['adds'] + op['muls'] + op['divs'] + report.add(ReportElement(t.__name__, timeStr, op['adds'], op['muls'], op['divs'], total)) return report def showIntermediateResults(self, equationCollection, symbols=None): diff --git a/field.py b/field.py index f4424465fbf16f9e46429c9e5507040f59249746..28272f4cdcbcfc5cccace1a2f03f8501facade88 100644 --- a/field.py +++ b/field.py @@ -287,20 +287,23 @@ def extractCommonSubexpressions(equations): return equations -def getLayoutFromNumpyArray(arr): +def getLayoutFromNumpyArray(arr, indexDimensionIds=[]): """ Returns a list indicating the memory layout (linearization order) of the numpy array. Example: >>> getLayoutFromNumpyArray(np.zeros([3,3,3])) - [0, 1, 2] + (0, 1, 2) In this example the loop over the zeroth coordinate should be the outermost loop, followed by the first and second. Elements arr[x,y,0] and arr[x,y,1] are adjacent in memory. Normally constructed numpy arrays have this order, however by stride tricks or other frameworks, arrays with different memory layout can be created. + + The indexDimensionIds parameter leaves specifies which coordinates should not be """ coordinates = list(range(len(arr.shape))) - return [x for (y, x) in sorted(zip(arr.strides, coordinates), key=lambda pair: pair[0], reverse=True)] + relevantStrides = [stride for i, stride in enumerate(arr.strides) if i not in indexDimensionIds] + return tuple(x for (y, x) in sorted(zip(relevantStrides, coordinates), key=lambda pair: pair[0], reverse=True)) def numpyDataTypeToC(dtype):