Mercurial > hg > ishara
comparison arrows/@erate/construct.m @ 0:672052bd81f8
Initial partial import.
author | samer |
---|---|
date | Wed, 19 Dec 2012 22:38:28 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:672052bd81f8 |
---|---|
1 function u=construct(s,sizes_in) | |
2 | |
3 nin=nargin(s.base); | |
4 | |
5 u=construct(s.base,s.sizes_in(1:nin)); | |
6 u.sizes_out = [u.sizes_out]; % !!! this is wrong. need better type system | |
7 u.process = mkproc(u.process,nin,nargout(s.base)); | |
8 end | |
9 | |
10 function f=mkproc(g,nin,nout) | |
11 empty={{}}; | |
12 f=@proc; | |
13 if nin==1 && nout==1, f=@proc_11; | |
14 elseif nin==1 && nout==0, f=@proc_10; | |
15 else, f=@proc_nn; end | |
16 | |
17 function proc_10(x1), | |
18 if ~isempty(x1), g(x1{1}); end; | |
19 end | |
20 function y1=proc_11(x1,x), if isempty(x1), y1={}; else y1={g(x1{1})}; end; end | |
21 | |
22 function varargout=proc_nn(varargin) | |
23 if any(cellfun(@isempty,varargin)), varargout=repmat(empty,1,nout); | |
24 else | |
25 ins=cellfun(@unbox,varargin(1:nin)); | |
26 [outs{1:nout}]=g(ins{:}); | |
27 varargout=cellfun(@box,outs); | |
28 end | |
29 end | |
30 function x=unbox(y), x=y{1}; end | |
31 function y=box(x), y={x}; end | |
32 end | |
33 |