for x in chart:
print x
for idx, row in chart[x].data.items():
- print '%-30s := %s' % (pretty((x,idx)), row[-1])
+ print '%s: %-30s := %s' % (idx, pretty((x,idx)), row[-1])
print
update_dispatcher(item, now)
+agg = {}
+
def aggregate(item):
- print ' aggregate:', pretty(item), aggregator[item],
- val = 0.0 # need identity element or do a "fold1"
- for k, multiplicity in aggregator[item].iteritems():
- assert multiplicity >= 0, "negative multiplicity: this should never happen."
- val += k*multiplicity # val*multiplicity; TODO: use correct aggregator
- print 'result:', val
- return val
+ (fn, _) = item
+ return aggr[agg[fn]](item)
def max_equals(item):
- raise NotImplementedError
+ return max(k for k, m in aggregator[item].iteritems() if m > 0)
+
def min_equals(item):
- raise NotImplementedError
+ return min(k for k, m in aggregator[item].iteritems() if m > 0)
+
def plus_equals(item):
- raise NotImplementedError
+ return reduce(operator.add,
+ [k*m for k, m in aggregator[item].iteritems()])
+
def times_equals(item):
- raise NotImplementedError
+ return reduce(operator.mul,
+ [k**m for k, m in aggregator[item].iteritems()])
+
def and_equals(item):
- raise NotImplementedError
+ return reduce(operator.and_,
+ [k for k, m in aggregator[item].iteritems() if m > 0])
+
def or_equals(item):
- raise NotImplementedError
+ return reduce(operator.or_,
+ [k for k, m in aggregator[item].iteritems() if m > 0])
aggr = {
_delete = False
+# Example of reactivity
+# >>> emit(('rewrite/3', 5), -1000)
+# >>> run_agenda()
+
[dyna] = sys.argv[1:]
cmd = """ghc -isrc Dyna.Backend.Python -e 'processFile "%s"' """ % dyna
phrase(X,I,K,t(X,TY)) += phrase(Y,I,K,TY) * rewrite(X,Y).
phrase(X,I,K,t(X,TY,TZ)) += phrase(Y,I,J,TY) * phrase(Z,J,K,TZ) * rewrite(X,Y,Z).
-goal(P) = phrase("S",0,*length,P).
+goal(P) += phrase("S", 0, *length, P).
-length max= word(_, I), I.
+length max= word(_, I), I+1.
% grammar rules
rewrite( "S", "S", ".") += 1.
Left e -> throw $ TLEAggPlan e
Right x -> return x
- forM (M.toList aggm) $ \(k,v) -> do {
- hPutStrLn fh $ "# " ++ (show k) ++ "->" ++ show v
+ hPutStrLn fh $ "agg = {}"
+ forM (M.toList aggm) $ \((f,a),v) -> do {
+ hPutStrLn fh $ show $ "agg" <> brackets (dquotes $ pretty f <> "/" <> pretty a)
+ <+> equals <+> (dquotes $ pretty v)
}
cPlans <- return $! combinePlans -- crux plans