Skip to content
Browse files

REF ExplainingExecutor

  • Loading branch information...
1 parent be312fd commit 154072ee30ad39ee024982673959eba89e0ecd10 @dagss committed
Showing with 86 additions and 3 deletions.
  1. +1 −0 oomatrix/decompositions.py
  2. +74 −1 oomatrix/formatter.py
  3. +11 −2 oomatrix/matrix.py
View
1 oomatrix/decompositions.py
@@ -28,6 +28,7 @@ class Factor(Decomposition):
def create_computation(kind):
# todo: dispatch on kind
class DecompositionComputation:
+ name='some-factoring-decomposition'
@staticmethod
def compute(matrix_impl):
return matrix_impl.factor()
View
75 oomatrix/formatter.py
@@ -90,8 +90,81 @@ def format(self, expr):
# explain()
#
+class ExplainingExecutor(object):
+ def __init__(self, stream, expression_formatter, margin=''):
+ self.stream = stream
+ self.margin = margin
+ self.num_indents = 0
+ self.num_tasks = 0
+ self.results = {}
+ self.expression_formatter = expression_formatter
+
+ # Implement Executor interface
+
+ def execute_task(self, task, arguments):
+ if task.computation is None:
+ # leaf task
+ return task.value
+ else:
+ task_id = self.num_tasks
+ self.num_tasks += 1
+ arg_strs = []
+ for arg_task, arg_result in zip(task.argument_tasks,
+ arguments):
+ expr = arg_task.descriptive_expression
+ #print expr
+ #arg_str = self.expression_formatter.format(expr)
+ #if arg_result in self.results:
+ # arg_str += ' (computed in task %s)' % arg_result
+ if isinstance(expr, symbolic.LeafNode):
+ arg_str = self.expression_formatter.format(expr)
+ else:
+ arg_str = repr(arg_result)
+ arg_strs.append(arg_str)
+
+ self.describe_operation(task_id, task.computation.name,
+ arg_strs,
+ task.metadata.kind,
+ task.cost)
+ self.results[task] = task_id
+ return task_id
+
+ def get_result(self, task):
+ return self.results[task]
+
+ def is_ready(self, task):
+ return task in self.results
+
+ def release_result(self, task):
+ if task.computation is None:
+ # leaf task
+ return
+ elif task in self.results:
+ self.putln('Release memory of task %d' % self.results[task])
+ del self.results[task]
+
+ def done(self):
+ pass
+
+
+ # Utilities
+ def putln(self, line, *args, **kw):
+ self.stream.write(self.margin + ' ' * self.num_indents +
+ line.format(*args, **kw) + '\n')
+
+ def describe_operation(self, result, computation_name, args,
+ result_kind_name, cost):
+ self.putln('{0} = {1}({2}) [{3} result, cost={4}]',
+ result, computation_name, ', '.join(args),
+ result_kind_name, cost)
+
+
+
class Explainer(object):
- def __init__(self, stream, symbolic_root, computable_root, margin=''):
+ def __init__(self, stream, symbolic_root, task, margin=''):
+ print symbolic_root
+ print task.dump()
+ return
self.stream = stream
self.symbolic_root = symbolic_root
self.computable_root = computable_root
View
13 oomatrix/matrix.py
@@ -120,9 +120,18 @@ def compute(self, compiler=None):
return result
def explain(self, compiler=None):
- computable = self.compile(compiler=compiler)
+ from .task import Scheduler
+ from .formatter import ExplainingExecutor, BasicExpressionFormatter
+
+ task, is_transpose = self.compile(compiler=compiler)
+
stream = StringIO()
- Explainer(stream, self._expr, computable, margin=' ').explain()
+ name_to_matrices = {}
+ expression_formatter = BasicExpressionFormatter(name_to_matrices)
+ stream.write(expression_formatter.format(self._expr))
+ executor = ExplainingExecutor(stream, expression_formatter)
+ Scheduler(task, executor).execute()
+
return stream.getvalue()
def __getitem__(self, index):

0 comments on commit 154072e

Please sign in to comment.
Something went wrong with that request. Please try again.