Mercurial > hg > ishara
changeset 14:1ec17635de0e
Finished cell function reorganisation, methods moved to function_handle class.
author | samer |
---|---|
date | Wed, 16 Jan 2013 12:14:39 +0000 |
parents | 03694e5c8365 |
children | 19ec801ee487 |
files | general/cellutils/@cell/foldl.m general/cellutils/@cell/foldr.m general/cellutils/@cell/foreach.m general/cellutils/@cell/map.m general/cellutils/@cell/scanl.m general/cellutils/@cell/select.m general/cellutils/@cell/zipwith.m general/funutils/foldr.m general/funutils/map.m |
diffstat | 9 files changed, 0 insertions(+), 104 deletions(-) [+] |
line wrap: on
line diff
--- a/general/cellutils/@cell/foldl.m Wed Jan 16 12:12:34 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -function X=foldl(fn,e,args) -% foldl - Fold fom the left combinator -% -% This function applies an associative operator to cell array, -% starting from the left using the given starting element. -% eg fold(@plus,0,{1,2,3,4}) = ((((0+1)+2)+3)+4). -% -% foldl :: -% (X,Y->X) ~'associative binary operator', -% X ~'initial element', -% {[N]->Y} ~'list (cell array) of arguments (at least 2 elements)' -% -> X. -X=e; for i=1:length(args), X=fn(X,args{i}); end
--- a/general/cellutils/@cell/foldr.m Wed Jan 16 12:12:34 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -function X=foldr(fn,e,args) -% foldr - Fold combinator from functional programming -% -% This function applies an associative operator to a list of arguments, -% starting from the right, eg -% elements, eg foldr(@plus,0,{1,2,3,4}) = (1+(2+(3+(4+0)))). -% -% foldr :: -% (Y,X->X) ~'associative binary operator', -% Y ~'initial element', -% {[N]->Y} ~'list (cell array) of arguments (at least 2 elements)' -% -> Y. -X=e; for i=length(args):-1:1, X=fn(args{i},X); end
--- a/general/cellutils/@cell/foreach.m Wed Jan 16 12:12:34 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -function foreach(f,X,varargin) -% foreach - do an action for each element in a cell array in order -% -% foreach :: (A=>void), {[N]->A} => void. -% - -if nargin>2, error('Options for foreach no longer supported'); end -for i=1:numel(X), f(x{i}); end
--- a/general/cellutils/@cell/map.m Wed Jan 16 12:12:34 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -% map - Map a function over a cell array -% -% map :: (A->B, {[Size]->A}) -> {[Size]->B} -function Y=map(fn,X), Y=cellmap(fn,X); end
--- a/general/cellutils/@cell/scanl.m Wed Jan 16 12:12:34 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -% scanl - scanl for cell arrays -% -% scanl :: -% (S,X->S) ~'scannning function', -% S ~'initial value', -% {[N]->X} ~'data to scan, sequence of length L' -% -> {[N]->S}. - -function Y=scanl(f,y,X,varargin) - Y=cell(size(X)); - if nargin>3 - opts=prefs('draw',0,varargin{:}); - for i=1:size(X,2) - y1=f(y,X{i}); - Y{i}=y1; - if opts.draw, opts.plotfn(i,y,X{i},y1); end - optpause(opts); - y=y1; - end - else - for i=1:size(X,2), y=f(y,X{i}); Y{i}=y; end - end - -
--- a/general/cellutils/@cell/select.m Wed Jan 16 12:12:34 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -% select - Filter cell array with boolean test -% -% select :: (A->bool), {[N]->A} -> {[M]->A}. -% select :: (A->bool), {[1,N]->A} -> {[1,M]->A}. -% -% eg, select(@iseven,{1,2,3,4}) = {2,4} -function Y=select(fn,X), Y=cellfilt(fn,X);
--- a/general/cellutils/@cell/zipwith.m Wed Jan 16 12:12:34 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -function Y=zipwith(fn,varargin) -% zipwith - Zip cell arrays with a function -% -% zipwith :: ( -% (D1,...,Dn)->R ~ function of n arguments, -% {[size]->D1}, ..., {[size]->Dn} ~ n cell arrays of appropriate types -% ) -> {[size]->R} ~ cell array of results - -Y=cellzip(fn,varargin{:}); - -
--- a/general/funutils/foldr.m Wed Jan 16 12:12:34 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -function X=foldr(fn,e,args) -% foldr - Fold combinator from functional programming -% -% This function applies an associative operator to a list of arguments, -% starting from the right, eg -% elements, eg foldr(@plus,0,{1,2,3,4}) = (1+(2+(3+(4+0)))). -% -% foldr :: -% (X,X->X) ~'associative binary operator', -% X ~'initial element', -% {[N]->X} ~'list (cell array) of arguments (at least 2 elements)' -% -> X. -X=e; for i=length(args):-1:1, X=fn(args{i},X); end
--- a/general/funutils/map.m Wed Jan 16 12:12:34 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -function y=map(f,x) -% map - Map function over collection -% -% map :: (A->B), collection(A) -> collection(B). -% -% collection(A) ::= seq(A) | cells(A). - -if isempty(x), y=x; -else - error(sprintf('Cannot map over objects of class %s',class(x))); -end