annotate arrows/uiterate.m @ 61:eff6bddf82e3 tip

Finally implemented perceptual brightness thing.
author samer
date Sun, 11 Oct 2015 10:20:42 +0100
parents beb8a3f4a345
children
rev   line source
samer@0 1 % uiterate - Run a processing unit for some number of iterations
samer@0 2 %
samer@0 3 % uiterate ::
samer@0 4 % unit({}, _, _) ~'live processing unit',
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@0 11 % -> action ().
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. Outputs are ignored. If inf iterations are
samer@0 16 % requested, the system is run until an EOF exception is caught.
samer@0 17
samer@0 18 function uiterate(u,its,varargin)
samer@0 19 uiter1(u,its,u.process,'label','uiterate',varargin{:});
samer@0 20 end
samer@0 21
samer@0 22 function itsdone=uiter1(u,its,itfn,varargin)
samer@37 23 opts=options('draw',1,'quiet',0,'chunk',1,varargin{:});
samer@0 24 quiet=opts.quiet; draw=opts.draw;
samer@0 25 chunk=opts.chunk;
samer@0 26 u.starting();
samer@0 27 try
samer@0 28 i=1;
samer@0 29 while i<=its,
samer@0 30 if ~quiet && mod(i,chunk)==0, fprintf(' %s: %d \r',opts.label,i); end
samer@0 31 itfn();
samer@0 32 if draw, drawnow; end
samer@0 33 i=i+1;
samer@0 34 end
samer@0 35 catch ex
samer@0 36 if ~iseof(ex)
samer@0 37 if ~quiet, fprintf('exception at %d iterations.\n',i); end
samer@0 38 u.stopping();
samer@0 39 rethrow(ex);
samer@0 40 end
samer@0 41 end
samer@0 42 itsdone=i-1;
samer@0 43 if ~quiet, fprintf('done %d iterations.\n',itsdone); end
samer@0 44 u.stopping();
samer@0 45 end