public Collection <R, T> FixedPoint <K>( Func <Microsoft.Research.Naiad.Dataflow.Iteration.LoopContext <T>, Collection <R, IterationIn <T> >, Collection <R, IterationIn <T> > > f, Expression <Func <R, K> > consolidateFunction, int maxIterations) { if (f == null) { throw new ArgumentNullException("f"); } var compiled = consolidateFunction.ConvertToWeightedFuncAndHashCode(); var fp = new Microsoft.Research.Naiad.Dataflow.Iteration.LoopContext <T>(this.Statistics, "FixedPoint"); var delay = fp.Delay <Weighted <R> >(compiled, maxIterations); var ingress = fp.EnterLoop <Weighted <R> >(this.Output).ToCollection() .PartitionBy(consolidateFunction); // add coordinate and ensure partitioned appropriately. var source = ingress.Concat(delay.Output.ToCollection()); // merge input with feedback data. var iteration = f(fp, source); // apply the body of the logic. var fixedpoint = iteration.Except(ingress) // subtract starting point. .Consolidate(consolidateFunction); // consolidate, to ensure cancellation. delay.Input = fixedpoint.Output; // attach the result to the delayVertex source. return(fp.ExitLoop(iteration.Output).ToCollection()); // return the loop body as output. }
public Collection <R, T> GeneralFixedPoint <K>( Func <Microsoft.Research.Naiad.Dataflow.Iteration.LoopContext <T>, Collection <R, IterationIn <T> >, Collection <R, IterationIn <T> > > f, // (lc, x) => f(x) Func <R, int> priorityFunction, Expression <Func <R, K> > partitionedBy, int maxIterations) { if (priorityFunction == null) { throw new ArgumentNullException("priorityFunction"); } var compiled = partitionedBy.ConvertToWeightedFuncAndHashCode(); var fp = new Microsoft.Research.Naiad.Dataflow.Iteration.LoopContext <T>(this.Statistics, "FixedPointSequence"); // probably doesn't work correctly when max + pri >= 2^31. Fix! var delayVertex = fp.Delay(compiled, maxIterations); // consider partitioning first, to ensure even boring work is distributed var ingress = fp.EnterLoop(this.Output, x => priorityFunction(x.record)) .ToCollection() .PartitionBy(partitionedBy); var source = ingress.Concat(delayVertex.Output.ToCollection()); var iteration = f(fp, source); var fixedpoint = iteration.Except(ingress) .Consolidate(partitionedBy); delayVertex.Input = fixedpoint.Output; var egress = fp.ExitLoop(iteration.Output).ToCollection(); return(egress); }
/// <summary> /// Adds a temporal dimension to each record. /// </summary> /// <param name="context">Loop context</param> /// <param name="initialIteration">initial iteration selector</param> /// <returns></returns> public Collection <R, IterationIn <T> > EnterLoop(Microsoft.Research.Naiad.Dataflow.Iteration.LoopContext <T> context, Func <R, int> initialIteration) { return(context.EnterLoop(this.Output, (Weighted <R> x) => initialIteration(x.record)).ToCollection(this.Immutable)); }
/// <summary> /// Adds a temporal dimension to each record. /// </summary> /// <param name="context">Loop context</param> /// <returns></returns> public Collection <R, IterationIn <T> > EnterLoop(Microsoft.Research.Naiad.Dataflow.Iteration.LoopContext <T> context) { return(context.EnterLoop(this.Output).ToCollection(this.Immutable)); }