samer@0
|
1 % arr - Lift function to processing unit
|
samer@0
|
2 %
|
samer@0
|
3 % arr ::
|
samer@27
|
4 % F:(A@typelist(N)->B@typelist(M)) ~'arbitrary function with N inputs and M outputs',
|
samer@0
|
5 % options {
|
samer@0
|
6 % nargin :: natural / nargin(F);
|
samer@0
|
7 % nargout :: natural / nargout(F);
|
samer@0
|
8 % }
|
samer@27
|
9 % -> arrow(A@typelist(N),B@typelist(M),empty).
|
samer@0
|
10 %
|
samer@0
|
11 % The arr class is a class of arrows which simply apply an ordinary
|
samer@0
|
12 % Matlab function to the inputs to obtain the outputs. In many cases,
|
samer@0
|
13 % the number of inputs and outputs can be determined from the supplied
|
samer@0
|
14 % function handle, but if the number arguments in or out is variable,
|
samer@0
|
15 % then the nargin and nargout options must be used.
|
samer@0
|
16 %
|
samer@0
|
17 % The type empty denotes the type of empty arrays, ie
|
samer@0
|
18 % the state of an arr arrow is always an empty matrix.
|
samer@0
|
19 %
|
samer@0
|
20 % arr(@log) - arrow which supplies the log of its input.
|
samer@0
|
21 % arr(@plus) - sum two inputs to produce output
|
samer@0
|
22 % arr(@(a,b)deal(a+b,a-b),'nargout',2) - computes sum and difference of inputs.
|
samer@0
|
23
|
samer@0
|
24 function o=arr(fn,varargin)
|
samer@0
|
25 if nargin==0, fn=@id; end
|
samer@37
|
26 opts=options('nargin',[],'nargout',[],'sizefn',[],varargin{:});
|
samer@0
|
27 if isempty(opts.nargin), opts.nargin=nargin(fn); end
|
samer@0
|
28 if isempty(opts.nargout), opts.nargout=nargout(fn); end
|
samer@0
|
29 if opts.nargout<0, opts.nargout=1; end % assume 1 if we can't tell
|
samer@0
|
30 o=class(struct('fn',fn,'sizefn',opts.sizefn),'arr',arrow(opts.nargin,opts.nargout));
|
samer@0
|
31 end
|