diff arrows/@aparallel/construct.m @ 0:672052bd81f8

Initial partial import.
author samer
date Wed, 19 Dec 2012 22:38:28 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/arrows/@aparallel/construct.m	Wed Dec 19 22:38:28 2012 +0000
@@ -0,0 +1,57 @@
+function u=construct(s,sizes_in)
+
+	nin1=nargin(s.a1);
+	nin2=nargin(s.a2);
+
+	u1=[]; u2=[];
+	try
+		u1=construct(s.a1,sizes_in(1:nin1));
+		u2=construct(s.a2,sizes_in(nin1+(1:nin2)));
+
+		u.sizes_out = [u1.sizes_out,u2.sizes_out];
+
+		nout1=length(u1.sizes_out);
+		nout2=length(u2.sizes_out);
+
+		ix1 = 1:nin1;  ix2 = nin1+(1:nin2); 
+		ox1 = 1:nout1; ox2 = nout1+(1:nout2);
+
+		nout = length(u.sizes_out);
+		if all([nin1,nin2,nout1,nout2]==[1,1,1,1]),
+			u.process = @proc11;
+		else
+			u.process = @proc;
+		end
+	catch ex
+		if ~isempty(u2), u2.dispose(); end
+		if ~isempty(u1), u1.dispose(); end
+		rethrow(ex);
+	end
+
+	u.dispose = @dispose;
+	u.starting= @starting;
+	u.stopping= @starting;
+	u.dispose = @dispose;
+	u.get_state = @get_state;
+	u.set_state = @set_state;
+	u.viewables = [u1.viewables;u2.viewables];
+
+	function [y1,y2]=proc11(x1,x2)
+		y1=u1.process(x1);
+		y2=u2.process(x2);
+	end
+
+	function varargout=proc(varargin)
+		varargout=cell(1,nout);
+		[varargout{ox1}]=u1.process(varargin{ix1});
+		[varargout{ox2}]=u2.process(varargin{ix2});
+	end
+
+	function dispose, u1.dispose(); u2.dispose(); end
+	function starting, u1.starting(); u2.starting(); end
+	function stopping, u1.stopping(); u2.stopping(); end
+
+	function s=get_state, s = {u1.get_state(),u2.get_state()}; end
+	function set_state(s), u1.set_state(s{1}); u2.set_state(s{2}); end
+end
+