samer@0: % umgather - Run a processing unit and collect multiple outputs samer@0: % samer@0: % ugather :: samer@27: % unit({}, A@typelist(K), _) ~'live processing unit with K outputs', samer@0: % T:natural ~'number of iterations to run (can be inf)', samer@0: % options { samer@0: % draw :: boolean/false ~'whether or not to call drawnow after each iteration'; samer@0: % quiet :: boolean/false ~'whether or not to suppress progress messages'; samer@0: % chunk :: natural/1 ~'print progress every chunk interations'; samer@0: % } samer@27: % -> B@typelist(K) ~'collected outputs'. samer@0: % samer@0: % This function accepts the live processing unit associated samer@0: % with an arrow (as created by with_arrow). The arrow must samer@0: % have zero inputs and one output. The requested number of outputs samer@0: % are collected into an array and returned. If inf outputs are samer@0: % requested, the system is run until an EOF exception is caught. samer@0: samer@0: function varargout=umgather(u,its,varargin) samer@37: opts=options('draw',0,varargin{:}); samer@0: nout=length(u.sizes_out); samer@0: gatherers=map(@(sz)gatherer(sz,opts),u.sizes_out); samer@0: if opts.draw, dfn=@drawnow; else dfn=@nop; end samer@0: uiter(u,its,@gatherxx,[],'label','umgather',opts); samer@0: varargout=map(@(g)g.collect(),gatherers); samer@0: samer@0: function s=gatherxx(i,s), samer@0: [outs{1:nout}]=u.process(); samer@0: for i=1:nout, gatherers{i}.append(outs{i}); end samer@0: dfn(); samer@0: end samer@0: end samer@0: samer@0: