samer@0
|
1 % umgather - Run a processing unit and collect multiple outputs
|
samer@0
|
2 %
|
samer@0
|
3 % ugather ::
|
samer@27
|
4 % unit({}, A@typelist(K), _) ~'live processing unit with K outputs',
|
samer@0
|
5 % T:natural ~'number of iterations to run (can be inf)',
|
samer@0
|
6 % options {
|
samer@0
|
7 % draw :: boolean/false ~'whether or not to call drawnow after each iteration';
|
samer@0
|
8 % quiet :: boolean/false ~'whether or not to suppress progress messages';
|
samer@0
|
9 % chunk :: natural/1 ~'print progress every chunk interations';
|
samer@0
|
10 % }
|
samer@27
|
11 % -> B@typelist(K) ~'collected outputs'.
|
samer@0
|
12 %
|
samer@0
|
13 % This function accepts the live processing unit associated
|
samer@0
|
14 % with an arrow (as created by with_arrow). The arrow must
|
samer@0
|
15 % have zero inputs and one output. The requested number of outputs
|
samer@0
|
16 % are collected into an array and returned. If inf outputs are
|
samer@0
|
17 % requested, the system is run until an EOF exception is caught.
|
samer@0
|
18
|
samer@0
|
19 function varargout=umgather(u,its,varargin)
|
samer@37
|
20 opts=options('draw',0,varargin{:});
|
samer@0
|
21 nout=length(u.sizes_out);
|
samer@0
|
22 gatherers=map(@(sz)gatherer(sz,opts),u.sizes_out);
|
samer@0
|
23 if opts.draw, dfn=@drawnow; else dfn=@nop; end
|
samer@0
|
24 uiter(u,its,@gatherxx,[],'label','umgather',opts);
|
samer@0
|
25 varargout=map(@(g)g.collect(),gatherers);
|
samer@0
|
26
|
samer@0
|
27 function s=gatherxx(i,s),
|
samer@0
|
28 [outs{1:nout}]=u.process();
|
samer@0
|
29 for i=1:nout, gatherers{i}.append(outs{i}); end
|
samer@0
|
30 dfn();
|
samer@0
|
31 end
|
samer@0
|
32 end
|
samer@0
|
33
|
samer@0
|
34
|