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

Pressure driven channel

parent 8e483da4
No related merge requests found
......@@ -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):
......
......@@ -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):
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment