Mercurial > forge
changeset 9631:e9febb47e864 octave-forge
apply the emptiness test in dataframe.m only if more than one row
line wrap: on
line diff
--- a/extra/dataframe/inst/@dataframe/cat.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/cat.m Sun Mar 11 20:53:31 2012 +0000 @@ -29,172 +29,172 @@ %# $Id$ %# - if (!isa(A, 'dataframe')), - A = dataframe(A); + if (~isa (A, 'dataframe')), + A = dataframe (A); endif switch dim case 1 resu = A; - for indi = 1:length(varargin), - B = varargin{indi}; - if !isa(B, 'dataframe'), - if iscell(B) && 2 == length(B), - B = dataframe(B{2}, 'rownames', B{1}); - else - B = dataframe(B, 'colnames', inputname(2+indi)); - endif - endif - if resu._cnt(2) != B._cnt(2), - error('Different number of columns in dataframes'); - endif - %# do not duplicate empty names - if !isempty(resu._name{1}) || !isempty(B._name{1}), - if length(resu._name{1}) < resu._cnt(1), - resu._name{1}(end+1:resu._cnt(1), 1) = {''}; - endif - if length(B._name{1}) < B._cnt(1), - B._name{1}(end+1:B._cnt(1), 1) = {''}; - endif - resu._name{1} = vertcat(resu._name{1}(:), B._name{1}(:)); - resu._over{1} = [resu._over{1} B._over{1}]; - endif - resu._cnt(1) = resu._cnt(1) + B._cnt(1); - if size(resu._ridx, 2) < size(B._ridx, 2), - resu._ridx(:, end+1:size(B._ridx, 2)) = NA; - elseif size(resu._ridx, 2) > size(B._ridx, 2), - B._ridx(:, end+1:size(resu._ridx, 2)) = NA; - endif - resu._ridx = [resu._ridx; B._ridx]; - %# find data with same column names - dummy = A._over{2} & B._over{2}; - indA = true(1, resu._cnt(2)); - indB = true(1, resu._cnt(2)); - for indj = 1:resu._cnt(2), - if (dummy(indj)), - indk = strmatch(resu._name{2}(indj), B._name{2}, 'exact'); - if (~isempty(indk)), - indk = indk(1); - if ~strcmp(resu._type{indj}, B._type{indk}), - error("Trying to mix columns of different types"); - endif - endif - else - indk = indj; - endif - resu._data{indj} = [resu._data{indj}; B._data{indk}]; - indA(indj) = false; indB(indk) = false; - endfor - if any(indA) || any(indB) - error('Different number/names of columns in dataframe'); - endif - + for indi = (1:length (varargin)) + B = varargin{indi}; + if (~isa (B, 'dataframe')) + if (iscell (B) && 2 == length (B)) + B = dataframe (B{2}, 'rownames', B{1}); + else + B = dataframe (B, 'colnames', inputname(2+indi)); + endif + endif + if (resu._cnt(2) ~= B._cnt(2)) + error ('Different number of columns in dataframes'); + endif + %# do not duplicate empty names + if (~isempty (resu._name{1}) || ~isempty (B._name{1})) + if (length (resu._name{1}) < resu._cnt(1)) + resu._name{1}(end+1:resu._cnt(1), 1) = {''}; + endif + if (length (B._name{1}) < B._cnt(1)) + B._name{1}(end+1:B._cnt(1), 1) = {''}; + endif + resu._name{1} = vertcat (resu._name{1}(:), B._name{1}(:)); + resu._over{1} = [resu._over{1} B._over{1}]; + endif + resu._cnt(1) = resu._cnt(1) + B._cnt(1); + if (size (resu._ridx, 2) < size (B._ridx, 2)) + resu._ridx(:, end+1:size(B._ridx, 2)) = NA; + elseif (size (resu._ridx, 2) > size (B._ridx, 2)) + B._ridx(:, end+1:size(resu._ridx, 2)) = NA; + endif + resu._ridx = [resu._ridx; B._ridx]; + %# find data with same column names + dummy = A._over{2} & B._over{2}; + indA = true (1, resu._cnt(2)); + indB = true (1, resu._cnt(2)); + for indj = (1:resu._cnt(2)) + if (dummy(indj)) + indk = strmatch (resu._name{2}(indj), B._name{2}, 'exact'); + if (~isempty (indk)) + indk = indk(1); + if (~strcmp (resu._type{indj}, B._type{indk})) + error ("Trying to mix columns of different types"); + endif + endif + else + indk = indj; + endif + resu._data{indj} = [resu._data{indj}; B._data{indk}]; + indA(indj) = false; indB(indk) = false; + endfor + if (any (indA) || any (indB)) + error ('Different number/names of columns in dataframe'); + endif + endfor case 2 resu = A; - for indi = 1:length(varargin), - B = varargin{indi}; - if !isa(B, 'dataframe'), - if iscell(B) && 2 == length(B), - B = dataframe(B{2}, 'colnames', B{1}); - else - B = dataframe(B, 'colnames', inputname(2+indi)); - endif - B._ridx = resu._ridx; %# make them compatibles - endif - if resu._cnt(1) != B._cnt(1), - error('Different number of rows in dataframes'); - endif - if any(resu._ridx(:) - B._ridx(:)) - error('dataframes row indexes not matched'); - endif - resu._name{2} = vertcat(resu._name{2}, B._name{2}); - resu._over{2} = [resu._over{2} B._over{2}]; - resu._data(resu._cnt(2)+(1:B._cnt(2))) = B._data; - resu._type(resu._cnt(2)+(1:B._cnt(2))) = B._type; - resu._cnt(2) = resu._cnt(2) + B._cnt(2); + for indi = (1:length (varargin)) + B = varargin{indi}; + if (~isa (B, 'dataframe')) + if (iscell (B) && 2 == length (B)) + B = dataframe (B{2}, 'colnames', B{1}); + else + B = dataframe (B, 'colnames', inputname(2+indi)); + endif + B._ridx = resu._ridx; %# make them compatibles + endif + if (resu._cnt(1) ~= B._cnt(1)) + error ('Different number of rows in dataframes'); + endif + if (any(resu._ridx(:) - B._ridx(:))) + error ('dataframes row indexes not matched'); + endif + resu._name{2} = vertcat (resu._name{2}, B._name{2}); + resu._over{2} = [resu._over{2} B._over{2}]; + resu._data(resu._cnt(2)+(1:B._cnt(2))) = B._data; + resu._type(resu._cnt(2)+(1:B._cnt(2))) = B._type; + resu._cnt(2) = resu._cnt(2) + B._cnt(2); endfor case 3 resu = A; - for indi = 1:length(varargin), - B = varargin{indi}; - if (!isa(B, 'dataframe')), - if (iscell(B) && 2 == length(B)), - B = dataframe(B{2}, 'rownames', B{1}); - else - B = dataframe(B, 'colnames', inputname(indi+2)); - endif - endif - if (resu._cnt(1) != B._cnt(1)), - error('Different number of rows in dataframes'); - endif - if (resu._cnt(2) != B._cnt(2)), - error('Different number of columns in dataframes'); - endif - %# to be merged against 3rd dim, rownames must be equals, if - %# non-empty. Columns are merged based upon their name; columns - %# with identic content are kept. + for indi = (1:length (varargin)) + B = varargin{indi}; + if (~isa (B, 'dataframe')) + if (iscell (B) && 2 == length (B)), + B = dataframe (B{2}, 'rownames', B{1}); + else + B = dataframe (B, 'colnames', inputname(indi+2)); + endif + endif + if (resu._cnt(1) ~= B._cnt(1)) + error ('Different number of rows in dataframes'); + endif + if (resu._cnt(2) ~= B._cnt(2)), + error ('Different number of columns in dataframes'); + endif + %# to be merged against 3rd dim, rownames must be equals, if + %# non-empty. Columns are merged based upon their name; columns + %# with identic content are kept. - if size(resu._ridx, 2) < size(B._ridx, 2), - resu._ridx(:, end+1:size(B._ridx, 2)) = NA; - elseif size(resu._ridx, 2) > size(B._ridx, 2), - B._ridx(:, end+1:size(resu._ridx, 2)) = NA; - endif - resu._ridx = cat(3, resu._ridx, B._ridx); - %# find data with same column names - indA = true(1, resu._cnt(2)); - indB = true(1, resu._cnt(2)); - dummy = A._over{2} & B._over{2}; - for indj = 1:resu._cnt(2), - if (dummy(indj)), - indk = strmatch(resu._name{2}(indj), B._name{2}, 'exact'); - if (~isempty(indk)), - indk = indk(1); - if (~strcmp(resu._type{indj}, B._type{indk})), - error("Trying to mix columns of different types"); - endif - endif - else - indk = indj; - endif - if (all([isnumeric(resu._data{indj}) isnumeric(B._data{indk})])), - %# iterate over the columns of resu and B - op1 = resu._data{indj}; op2 = B._data{indk}; - for ind2=1:columns(op2), - indr = false; - for ind1=1:columns(op1), - if (all(abs(op1(:, ind1) - op2(:, ind2)) <= eps)), - resu._rep{indj} = [resu._rep{indj} ind1]; - indr = true; - break; - endif - endfor - if (!indr), - %# pad in the second dim - resu._data{indj} = [resu._data{indj}, B._data{indk}]; - resu._rep{indj} = [resu._rep{indj} 1+length(resu._rep{indj})]; - endif - endfor - else - resu._data{indj} = [resu._data{indj} B._data{indk}]; - resu._rep{indj} = [resu._rep{indj} 1+length(resu._rep({indj}))]; - endif - indA(indj) = false; indB(indk) = false; - endfor - if (any(indA) || any(indB)), - error('Different number/names of columns in dataframe'); - endif + if (size(resu._ridx, 2) < size(B._ridx, 2)) + resu._ridx(:, end+1:size(B._ridx, 2)) = NA; + elseif (size(resu._ridx, 2) > size(B._ridx, 2)) + B._ridx(:, end+1:size(resu._ridx, 2)) = NA; + endif + resu._ridx = cat (3, resu._ridx, B._ridx); + %# find data with same column names + indA = true (1, resu._cnt(2)); + indB = true (1, resu._cnt(2)); + dummy = A._over{2} & B._over{2}; + for indj = (1:resu._cnt(2)) + if (dummy(indj)) + indk = strmatch (resu._name{2}(indj), B._name{2}, 'exact'); + if (~isempty (indk)), + indk = indk(1); + if (~strcmp (resu._type{indj}, B._type{indk})), + error("Trying to mix columns of different types"); + endif + endif + else + indk = indj; + endif + if (all ([isnumeric(resu._data{indj}) isnumeric(B._data{indk})])), + %# iterate over the columns of resu and B + op1 = resu._data{indj}; op2 = B._data{indk}; + for ind2 = (1:columns (op2)) + indr = false; + for ind1 = (1:columns (op1)) + if (all (abs (op1(:, ind1) - op2(:, ind2)) <= eps)), + resu._rep{indj} = [resu._rep{indj} ind1]; + indr = true; + break; + endif + endfor + if (~indr), + %# pad in the second dim + resu._data{indj} = [resu._data{indj}, B._data{indk}]; + resu._rep{indj} = [resu._rep{indj} 1+length(resu._rep{indj})]; + endif + endfor + else + resu._data{indj} = [resu._data{indj} B._data{indk}]; + resu._rep{indj} = [resu._rep{indj} 1+length(resu._rep({indj}))]; + endif + indA(indj) = false; indB(indk) = false; + endfor + if (any (indA) || any (indB)) + error ('Different number/names of columns in dataframe'); + endif endfor - resu = df_thirddim(resu); + resu = df_thirddim (resu); otherwise - error('Incorrect call to cat'); + error ('Incorrect call to cat'); endswitch %# disp('End of cat'); keyboard
--- a/extra/dataframe/inst/@dataframe/dataframe.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/dataframe.m Sun Mar 11 20:53:31 2012 +0000 @@ -92,7 +92,7 @@ seeked = []; trigger =[]; unquot = true; sep = "\t,"; cmt_lines = []; locales = "C"; -if (length(varargin) > 0) +if (length (varargin) > 0) indi = 1; %# loop over possible arguments while (indi <= size (varargin, 2)) @@ -155,7 +155,7 @@ endwhile endif -if (!isempty (seeked) && !isempty (trigger)) +if (~isempty (seeked) && ~isempty (trigger)) error ('seeked and trigger are mutuallly incompatible arguments'); endif @@ -175,10 +175,10 @@ unwind_protect dummy = tilde_expand (x); fid = fopen (dummy); - if (fid != -1) + if (fid ~= -1) df._src{end+1, 1} = dummy; dummy = fgetl (fid); - if (!strcmp (dummy, UTF8_BOM)) + if (~strcmp (dummy, UTF8_BOM)) frewind (fid); endif %# slurp everything and convert doubles to char, avoiding @@ -188,10 +188,10 @@ in = []; endif unwind_protect_cleanup - if (fid != -1) fclose (fid); endif + if (fid ~= -1) fclose (fid); endif end_unwind_protect - if (!isempty (in)) + if (~isempty (in)) %# explicit list taken from 'man pcrepattern' -- we enclose all %# vertical separators in case the underlying regexp engine %# doesn't have them all. @@ -212,7 +212,7 @@ %# lines, 'UniformOutput', false); %# extract fields content = cellfun (@(x) strsplit (x, sep), lines, \ 'UniformOutput', false); %# extract fields - indl = 1; indj = 1; %# disp('line 151 '); keyboard + indl = 1; indj = 1; %#disp('line 151 '); keyboard if (~isempty (seeked)) while (indl <= length (lines)) dummy = content{indl}; @@ -246,7 +246,7 @@ endif x = cell (1+length (lines)-indl, size(dummy, 2)); empty_lines = []; cmt_lines = []; - while (indl <= length(lines)) + while (indl <= length (lines)) dummy = content{indl}; if (all (cellfun ('size', dummy, 2) == 0)) empty_lines = [empty_lines indj]; @@ -273,7 +273,7 @@ catch %# if the previous test fails, try a simpler one in = regexp (dummy{indk}, '[^'' ]+', 'match'); - if (!isempty(in)) + if (~isempty (in)) x(indj, indk) = in{1}; %# else %# x(indj, indk) = []; @@ -284,7 +284,7 @@ x(indj, indk) = regexp (dummy{indk}, '[^ ].*', 'match'); endif else - if (!isempty (regexp (dummy{indk}, '[/:]'))) + if (~isempty (regexp (dummy{indk}, '[/:]'))) %# try to convert to a date [timeval, nfields] = strptime( dummy{indk}, [char(37) 'd/' char(37) 'm/' char(37) 'Y ' char(37) 'T']); @@ -293,7 +293,7 @@ timeval); %# try to extract the usec field, if any idx = regexp (dummy{indk}, timestr, 'end'); - if (!isempty (idx)) + if (~isempty (idx)) idx = idx + 1; if (ispunct (dummy{indk}(idx))) idx = idx + 1; @@ -310,12 +310,12 @@ endfor indl = indl + 1; indj = indj + 1; endwhile - if (!isempty(empty_lines)) + if (~isempty (empty_lines)) x(empty_lines, :) = []; endif %# detect empty columns empty_lines = find (0 == sum (cellfun ('size', x, 2))); - if (!isempty(empty_lines)) + if (~isempty (empty_lines)) x(:, empty_lines) = []; endif clear UTF8_BOM fid in lines indl the_line content empty_lines @@ -326,7 +326,7 @@ %# fallback, avoiding a recursive call idx.type = '()'; - if (!isa (x, 'char')) + if (~isa (x, 'char')) indj = df._cnt(2)+(1:size (x, 2)); else %# at this point, reading some filename failed @@ -337,7 +337,7 @@ if (2 == length (x)) %# use the intermediate value as destination column [indc, ncol] = df_name2idx (df._name{2}, x{1}, df._cnt(2), "column"); - if (ncol != 1) + if (ncol ~= 1) error (["With two-elements cell, the first should resolve " ... "to a single column"]); endif @@ -362,7 +362,7 @@ %# allow overwriting of column names df._over{2}(1, indj) = true; else - if (!isempty(indj)) + if (~isempty (indj)) if (1 == length (df._name{2}) && length (df._name{2}) < \ length (indj)) [df._name{2}(indj, 1), df._over{2}(1, indj)] ... @@ -374,15 +374,15 @@ df._name{2} = genvarname (df._name{2}); endif endif - if (!isempty (indj)) + if (~isempty (indj)) %# the exact row size will be determined latter idx.subs = {'', indj}; %# use direct assignement if (ndims (x) > 2), idx.subs{3} = 1:size (x, 3); endif %# df = subsasgn(df, idx, x); <= call directly lower level - df = df_matassign (df, idx, indj, length(indj), x); - if (!isempty (cmt_lines)) - df._cmt = vertcat(df._cmt, cellstr(cmt_lines)); + df = df_matassign (df, idx, indj, length (indj), x); + if (~isempty (cmt_lines)) + df._cmt = vertcat (df._cmt, cellstr (cmt_lines)); cmt_lines = []; endif else
--- a/extra/dataframe/inst/@dataframe/display.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/display.m Sun Mar 11 20:53:31 2012 +0000 @@ -29,7 +29,7 @@ %# generate header name dummy = inputname (1); - if (isempty(dummy)) + if (isempty (dummy)) dummy = "ans"; endif @@ -41,7 +41,7 @@ dummy, df._cnt); endif - if (!isempty (df._src)) + if (~isempty (df._src)) for indi = (1:size (df._src, 1)) head = strvcat\ (head, [repmat("Src: ", size (df._src{indi, 1}, 1), 1)\ @@ -49,7 +49,7 @@ endfor endif - if (!isempty (df._cmt)) + if (~isempty (df._cmt)) for indi = (1:size(df._cmt, 1)) head = strvcat\ (head, [repmat("Comment: ", size (df._cmt{indi, 1}, 1), 1)\ @@ -58,7 +58,7 @@ endif if (all (df._cnt > 0)) %# stop for empty df - dummy=[]; vspace = repmat (' ', df._cnt(1), 1); + dummy = []; vspace = repmat (' ', df._cnt(1), 1); indi = 1; %# the real, unfolded index %# loop over columns where the corresponding _data really exists for indc = (1:min (df._cnt(2), size (df._data, 2))) @@ -85,7 +85,7 @@ tmp_str = df._data{indc}(:, indk); %#get the whole column indj = cellfun ('isprint', tmp_str, 'UniformOutput', false); indj = ~cellfun ('all', indj); - for indr = (1:length(indj)) + for indr = (1:length (indj)) if (indj(indr)), if (isna (tmp_str{indr})), tmp_str{indr} = "NA"; @@ -125,10 +125,10 @@ vspace = [' '; ' '; vspace]; %# second line content resu = []; - if (!isempty (df._ridx)) + if (~isempty (df._ridx)) for (ind1 = 1:size (df._ridx, 2)) if ((1 == size(df._ridx, 3)) && \ - (any (!isna (df._ridx(1:df._cnt(1), ind1))))) + (any (~isna (df._ridx(1:df._cnt(1), ind1))))) dummy{2, 1} = [sprintf("_%d", ind1) ; "Nr"]; dummy{3, 1} = disp (df._ridx(1:df._cnt(1), ind1)); indi = regexp (dummy{3, 1}, '\b.*\b', 'match', 'dotexceptnewline'); @@ -140,7 +140,7 @@ endif else for ind2 = (1:size (df._ridx, 3)) - if (any (!isna (df._ridx(1:df._cnt(1), ind1, ind2)))), + if (any (~isna (df._ridx(1:df._cnt(1), ind1, ind2)))), dummy{2, 1} = [sprintf("_%d.%d", ind1, ind2) ; "Nr"]; dummy{3, 1} = disp (df._ridx(1:df._cnt(1), ind1, ind2)); indi = regexp (dummy{3, 1}, '\b.*\b', 'match', 'dotexceptnewline'); @@ -165,7 +165,7 @@ endif %# insert a vertical space - if (!isempty(dummy{3, 2})) + if (~isempty (dummy{3, 2})) indi = ~cellfun ('isempty', dummy{3, 2}); if (any (indi)) try
--- a/extra/dataframe/inst/@dataframe/find.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/find.m Sun Mar 11 20:53:31 2012 +0000 @@ -26,35 +26,35 @@ switch nargout case {0, 1} - resu = []; mz = max(cellfun(@length, df._rep)); - for indc = 1:df._cnt(2), - [indr, inds] = feval(@find, df._data{indc}(:, df._rep{indc})); - %# create a vector the same size as indr - dummy = indr; dummy(:) = indc; - resu = [resu; sub2ind([df._cnt(1:2) mz], indr, dummy, inds)]; + resu = []; mz = max (cellfun (@length, df._rep)); + for indc = (1:df._cnt(2)) + [indr, inds] = feval (@find, df._data{indc}(:, df._rep{indc})); + %# create a vector the same size as indr + dummy = indr; dummy(:) = indc; + resu = [resu; sub2ind([df._cnt(1:2) mz], indr, dummy, inds)]; endfor - varargout{1} = sort(resu); + varargout{1} = sort (resu); case 2 nz = 0; idx_i = []; idx_j = []; - for indc = 1:df._cnt(2), - [dum1, dum2] = feval(@find, df._data{indc}(:, df._rep{indc})); - idx_i = [idx_i; dum1]; - idx_j = [idx_j; nz + dum2]; - nz = nz + df._cnt(1)*length(df._rep{indc}); + for indc = (1:df._cnt(2)) + [dum1, dum2] = feval (@find, df._data{indc}(:, df._rep{indc})); + idx_i = [idx_i; dum1]; + idx_j = [idx_j; nz + dum2]; + nz = nz + df._cnt(1)*length (df._rep{indc}); endfor varargout{1} = idx_i; varargout{2} = idx_j; case 3 nz = 0; idx_i = []; idx_j = []; val = []; - for indc = 1:df._cnt(2), - [dum1, dum2, dum3] = feval(@find, df._data{indc}(:, df._rep{indc})); - idx_i = [idx_i; dum1]; - idx_j = [idx_j; nz + dum2]; - val = [val; dum3]; - nz = nz + df._cnt(1)*length(df._rep{indc}); + for indc = (1:df._cnt(2)) + [dum1, dum2, dum3] = feval (@find, df._data{indc}(:, df._rep{indc})); + idx_i = [idx_i; dum1]; + idx_j = [idx_j; nz + dum2]; + val = [val; dum3]; + nz = nz + df._cnt(1)*length (df._rep{indc}); endfor varargout{1} = idx_i; varargout{2} = idx_j; varargout{3} = val; otherwise - print_usage('find'); + print_usage ('find'); endswitch endfunction
--- a/extra/dataframe/inst/@dataframe/fold.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/fold.m Sun Mar 11 20:53:31 2012 +0000 @@ -32,65 +32,63 @@ %# switch dim case 1 - [indr, nrow] = df_name2idx(df._name{1}, indr, df._cnt(1), 'row'); - [indc, ncol] = df_name2idx(df._name{2}, indc, df._cnt(2), 'column'); + [indr, nrow] = df_name2idx (df._name{1}, indr, df._cnt(1), 'row'); + [indc, ncol] = df_name2idx (df._name{2}, indc, df._cnt(2), 'column'); - if (indr(1) > 1), + if (indr(1) > 1) slice_size = indr(1) - 1; %# we can't use directly resu = df(1:slice_size, :, :) S.type = '()'; S.subs = { 1:slice_size, ':', ':', 'dataframe'}; - resu = subsref(df, S); + resu = subsref (df, S); %# how many columns for each slice - targets = cellfun(@length, df._rep); + targets = cellfun (@length, df._rep); %# a test function to determine if the location is free - for indj = 1:df._cnt(2), - if (any(indj == indc)), - continue; - endif - switch df._type{indj} - case { 'char' } - testfunc{indj} = @(x, indr, indc) ... - !isna(x{indr, indc}); - otherwise - testfunc{indj} = @(x, indr, indc) ... - !isna(x(indr, indc)); - endswitch + for indj = (1:df._cnt(2)) + if (any (indj == indc)) + continue; + endif + switch (df._type{indj}) + case { 'char' } + testfunc{indj} = @(x, indr, indc) ... + ~isna (x{indr, indc}); + otherwise + testfunc{indj} = @(x, indr, indc) ... + ~isna (x(indr, indc)); + endswitch endfor - for indi = indr, - %# where does this line go ? - where = find(df._data{indc}(1:slice_size, 1) ... - == df._data{indc}(indi, 1)); - if (!isempty(where)), - %# transfering one line -- loop over columns - for indj = 1:df._cnt(2), - if any(indj == indc), - continue; - endif - - if (testfunc{indj}(resu._data{indj}, where, targets(indj))), - %# add one more sheet - resu = df_pad(resu, 3, 1, indj); - targets(indj) = targets(indj) + 1; - endif - %# transfer field - stop - resu._data{indj}(where, targets(indj)) = ... - df._data{indj}(indi, 1); - endfor - %# update row index - resu._ridx(where, max(targets)) = df._ridx(indi); - else - disp('line 65: FIXME'); keyboard; - endif + for indi = (indr) + %# where does this line go ? + where = find (df._data{indc}(1:slice_size, 1) ... + == df._data{indc}(indi, 1)); + if (~isempty (where)) + %# transfering one line -- loop over columns + for indj = (1:df._cnt(2)) + if (any (indj == indc)) + continue; + endif + + if (testfunc{indj}(resu._data{indj}, where, targets(indj))) + %# add one more sheet + resu = df_pad(resu, 3, 1, indj); + targets(indj) = targets(indj) + 1; + endif + %# transfer field + stop + resu._data{indj}(where, targets(indj)) = ... + df._data{indj}(indi, 1); + endfor + %# update row index + resu._ridx(where, max(targets)) = df._ridx(indi); + else + disp ('line 65: FIXME'); keyboard; + endif endfor else - - disp('line 70: FIXME '); keyboard + disp ('line 70: FIXME '); keyboard endif - endswitch
--- a/extra/dataframe/inst/@dataframe/horzcat.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/horzcat.m Sun Mar 11 20:53:31 2012 +0000 @@ -24,10 +24,10 @@ %# $Id$ %# - for indi = 1:length(varargin), - varargin{indi} = dataframe(varargin{indi}, 'colnames', inputname(1+indi));, + for indi = (1:length (varargin)) + varargin{indi} = dataframe (varargin{indi}, 'colnames', inputname(1+indi));, endfor - resu = cat(2, df, varargin{:}); + resu = cat (2, df, varargin{:}); endfunction
--- a/extra/dataframe/inst/@dataframe/inv.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/inv.m Sun Mar 11 20:53:31 2012 +0000 @@ -29,24 +29,24 @@ %# $Id$ %# - if (length(df._cnt) > 2 || (df._cnt(1) != df._cnt(2))), - error("Dataframe is not square"); + if (length (df._cnt) > 2 || (df._cnt(1) ~= df._cnt(2))) + error ("Dataframe is not square"); endif %# quick and dirty conversion - [dummy, rcond] = inv(horzcat(df._data{:})); + [dummy, rcond] = inv (horzcat (df._data{:})); resu = df_allmeta(df); - [resu._name{2}, resu._name{1}] = deal(resu._name{1}, resu._name{2}); - [resu._over{2}, resu._over{1}] = deal(resu._over{1}, resu._over{2}); - if (isempty(resu._name{2})), - resu._name{2} = cellstr(repmat('_', resu._cnt(2), 1)); - resu._over{2} = ones(1, resu._cnt(2)); + [resu._name{2}, resu._name{1}] = deal (resu._name{1}, resu._name{2}); + [resu._over{2}, resu._over{1}] = deal (resu._over{1}, resu._over{2}); + if (isempty (resu._name{2})), + resu._name{2} = cellstr (repmat('_', resu._cnt(2), 1)); + resu._over{2} = ones (1, resu._cnt(2)); endif - for indi = resu._cnt(1):-1:1, + for indi = (resu._cnt(1):-1:1) resu._data{indi} = dummy(:, indi); endfor - resu._type(:) = class(dummy); + resu._type(:) = class (dummy); endfunction
--- a/extra/dataframe/inst/@dataframe/isfield.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/isfield.m Sun Mar 11 20:53:31 2012 +0000 @@ -35,57 +35,57 @@ %# $Id$ %# - if !isa(df, 'dataframe'), + if (~isa (df, 'dataframe')) resu = false; return; endif - if nargin <2 || nargin > 3, - print_usage(); + if (nargin < 2 || nargin > 3) + print_usage (); resu = false; return; endif - if 2 == nargin, strict = false; endif + if (2 == nargin) strict = false; endif - if isa(name, 'char'), - if strict, %# use strmatch to get indexes - for indi = size(name, 1):-1:1, - dummy = strmatch(name(indi, :), df._name{2}, "exact"); - resu(indi, 1) = !isempty(dummy); - for indj = 1:length(dummy), - idx(indi, indj) = dummy(indj); - endfor + if (isa (name, 'char')) + if (strict) %# use strmatch to get indexes + for indi = (size (name, 1):-1:1) + dummy = strmatch (name(indi, :), df._name{2}, "exact"); + resu(indi, 1) = ~isempty (dummy); + for indj = (1:length (dummy)) + idx(indi, indj) = dummy(indj); + endfor endfor else - for indi = size(name, 1):-1:1, - try - dummy = df_name2idx(df._name{2}, name(indi, :), \ - df._cnt(2), 'column'); - resu(indi, 1) = !isempty(dummy); - for indj = 1:length(dummy), - idx(indi, indj) = dummy(indj); - endfor - catch - resu(indi, 1) = false; idx(indi, 1) = 0; - end_try_catch + for indi = (size (name, 1):-1:1) + try + dummy = df_name2idx (df._name{2}, name(indi, :), \ + df._cnt(2), 'column'); + resu(indi, 1) = ~isempty (dummy); + for indj = (1:length (dummy)) + idx(indi, indj) = dummy(indj); + endfor + catch + resu(indi, 1) = false; idx(indi, 1) = 0; + end_try_catch endfor endif - elseif isa(name, 'cell'), - if strict, %# use strmatch to get indexes - for indi = size(name, 1):-1:1, - dummy = strmatch(name{indi}, df._name{2}, "exact"); - resu{indi, 1} = !isempty(dummy); - idx{indi, 1} = dummy; + elseif (isa (name, 'cell')) + if (strict) %# use strmatch to get indexes + for indi = (size (name, 1):-1:1) + dummy = strmatch (name{indi}, df._name{2}, "exact"); + resu{indi, 1} = ~isempty (dummy); + idx{indi, 1} = dummy; endfor else - for indi = length(name):-1:1, - try - dummy = df_name2idx(df._name{2}, name{indi}, \ - df._cnt(2), 'column'); - keyboard - resu{indi, 1} = !isempty(dummy); idx{indi, 1} = dummy; - catch - resu{indi, 1} = false; cnt{indi, 1} = 0; - end_try_catch + for indi = (length (name):-1:1) + try + dummy = df_name2idx (df._name{2}, name{indi}, \ + df._cnt(2), 'column'); + keyboard + resu{indi, 1} = ~isempty (dummy); idx{indi, 1} = dummy; + catch + resu{indi, 1} = false; cnt{indi, 1} = 0; + end_try_catch endfor endif endif
--- a/extra/dataframe/inst/@dataframe/isscalar.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/isscalar.m Sun Mar 11 20:53:31 2012 +0000 @@ -26,6 +26,6 @@ %# $Id$ %# - resu = ismatrix(df) & (length(find(df._cnt > 1)) < 1); + resu = ismatrix (df) & (length (find (df._cnt > 1)) < 1); endfunction
--- a/extra/dataframe/inst/@dataframe/isvector.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/isvector.m Sun Mar 11 20:53:31 2012 +0000 @@ -26,6 +26,6 @@ %# $Id$ %# - resu = ismatrix(df) & (length(find(df._cnt > 1)) <= 1); + resu = ismatrix (df) & (length (find (df._cnt > 1)) <= 1); endfunction
--- a/extra/dataframe/inst/@dataframe/ne.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/ne.m Sun Mar 11 20:53:31 2012 +0000 @@ -1,7 +1,7 @@ function resu = ne(A, B); %# function resu = ne(A, B) - %# Implements the '!=' operator when at least one argument is a dataframe. + %# Implements the '~=' operator when at least one argument is a dataframe. %% Copyright (C) 2009-2012 Pascal Dupuis <Pascal.Dupuis@uclouvain.be> %% @@ -27,6 +27,6 @@ %# $Id$ %# - resu = df_func(@ne, A, B); + resu = df_func (@ne, A, B); endfunction
--- a/extra/dataframe/inst/@dataframe/permute.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/permute.m Sun Mar 11 20:53:31 2012 +0000 @@ -24,21 +24,21 @@ %# $Id$ %# - resu = dataframe([]); + resu = dataframe ([]); - if (length(df._cnt) >= length(perm)), + if (length (df._cnt) >= length (perm)) resu._cnt = df._cnt(perm); else resu._cnt = [df._cnt 1](perm); endif - if (ndims(df._ridx) < 3), - resu._ridx = permute(df._ridx, [min(perm(1), 2) min(perm(2:end))]); + if (ndims (df._ridx) < 3) + resu._ridx = permute (df._ridx, [min(perm(1), 2) min(perm(2:end))]); else - resu._ridx = permute(df._ridx, perm); + resu._ridx = permute (df._ridx, perm); endif - if (size(resu._ridx, 1) < resu._cnt(1)), + if (size (resu._ridx, 1) < resu._cnt(1)) %# adjust index size, if required resu._ridx(end+1:resu._cnt(1), :, :) = NA; endif @@ -46,13 +46,13 @@ if (2 == perm(1)), resu._name{1} = df._name{2}; resu._over{1} = df._over{2}; - indc = length(resu._name{1}); + indc = length (resu._name{1}); indi = resu._cnt(1) - indc; - if (indi > 0), + if (indi > 0) %# generate a name for the new row(s) - dummy = cstrcat(repmat('_', indi, 1), ... - strjust(num2str(indc + (1:indi).'), 'left')); - resu._name{1}(indc + (1:indi)) = cellstr(dummy); + dummy = cstrcat (repmat ('_', indi, 1), ... + strjust (num2str (indc + (1:indi).'), 'left')); + resu._name{1}(indc + (1:indi)) = cellstr (dummy); resu._over{1}(1, indc + (1:indi)) = true; endif else @@ -61,7 +61,7 @@ endif - if (2 == perm(2)), + if (2 == perm(2)) resu._name{2} = df._name{2}; resu._over{2} = df._over{2}; else @@ -69,41 +69,41 @@ resu._over{2} = df._over{1}; endif - if (isempty(resu._name{2})), + if (isempty (resu._name{2})), indc = 0; else - indc = length(resu._name{2}); + indc = length (resu._name{2}); endif indi = resu._cnt(2) - indc; - if (indi > 0), + if (indi > 0) %# generate a name for the new column(s) - dummy = cstrcat(repmat('_', indi, 1), ... - strjust(num2str(indc + (1:indi).'), 'left')); - resu._name{2}(indc + (1:indi)) = cellstr(dummy); + dummy = cstrcat (repmat ('_', indi, 1), ... + strjust (num2str (indc + (1:indi).'), 'left')); + resu._name{2}(indc + (1:indi)) = cellstr (dummy); resu._over{2}(1, indc + (1:indi)) = true; endif - if (2 != perm(2)), + if (2 ~= perm(2)), %# recompute the new type - dummy = zeros(0, class(sum(cellfun(@(x) zeros(1, class(x(1))),\ - df._data)))); - resu._type(1:resu._cnt(2)) = class(dummy); - dummy = permute(df_whole(df), perm); - for indi = 1:resu._cnt(2), - resu._data{indi} = squeeze(dummy(:, indi, :)); - resu._rep{indi} = 1:size(resu._data{indi}, 2); + dummy = zeros (0, class (sum (cellfun (@(x) zeros (1, class(x(1))),\ + df._data)))); + resu._type(1:resu._cnt(2)) = class (dummy); + dummy = permute (df_whole(df), perm); + for indi = (1:resu._cnt(2)) + resu._data{indi} = squeeze (dummy(:, indi, :)); + resu._rep{indi} = 1:size (resu._data{indi}, 2); endfor else %# 2 == perm(2) - if (1 == perm(1)), %# blank operation + if (1 == perm(1)) %# blank operation resu._type = df._type; resu._data = df._data; resu._rep = df._rep; else - for indi = 1:resu._cnt(2), - unfolded = df._data{indi}(:, df._rep{indi}); - resu._data{indi} = permute(unfolded, [2 1]); - resu._rep{indi} = 1:size(resu._data{indi}, 2); - resu._type{indi} = df._type{indi}; + for indi = (1:resu._cnt(2)) + unfolded = df._data{indi}(:, df._rep{indi}); + resu._data{indi} = permute (unfolded, [2 1]); + resu._rep{indi} = 1:size (resu._data{indi}, 2); + resu._type{indi} = df._type{indi}; endfor endif endif
--- a/extra/dataframe/inst/@dataframe/private/df_allmeta.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/private/df_allmeta.m Sun Mar 11 20:53:31 2012 +0000 @@ -28,33 +28,33 @@ %# $Id$ %# - resu = dataframe([]); + resu = dataframe ([]); - if (isempty(dim)), + if (isempty (dim)), dim = df._cnt(1:2); else dim = dim(1:2); %# ignore third dim, if any endif - resu._cnt(1:2) = min(dim, df._cnt(1:2)); - if (!isempty(df._name{1})), + resu._cnt(1:2) = min (dim, df._cnt(1:2)); + if (~isempty(df._name{1})) resu._name{1} = df._name{1}(1:resu._cnt(1)); resu._over{1} = df._over{1}(1:resu._cnt(1)); endif - if (!isempty(df._name{2})), + if (~isempty(df._name{2})) resu._name{2} = df._name{2}(1:resu._cnt(2)); resu._over{2} = df._over{2}(1:resu._cnt(2)); endif - if (!isempty(df._ridx)), - if (size(df._ridx, 2) >= resu._cnt(2)), + if (~isempty(df._ridx)) + if (size (df._ridx, 2) >= resu._cnt(2)), resu._ridx = df._ridx(1:resu._cnt(1), :, :); else resu._ridx = df._ridx(1:resu._cnt(1), 1, :); endif endif %# init it with the right orientation - resu._data = cell(size(df._data)); - resu._rep = cell(size(df._rep)); + resu._data = cell (size (df._data)); + resu._rep = cell (size (df._rep)); resu._type = df._type(1:resu._cnt(2)); resu._src = df._src; resu._cmt = df._cmt;
--- a/extra/dataframe/inst/@dataframe/private/df_basecomp.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/private/df_basecomp.m Sun Mar 11 20:53:31 2012 +0000 @@ -30,162 +30,162 @@ %# $Id$ %# - if 1 == length(itercol), + if (1 == length (itercol)) strict = false; else strict = itercol(2); itercol = itercol(1); endif - if (iscell(A)), A = dataframe(A); endif - if (iscell(B)), B = dataframe(B); endif + if (iscell (A)), A = dataframe (A); endif + if (iscell (B)), B = dataframe (B); endif - switch (func2str(func)), + switch (func2str (func)), case 'bsxfun' %# bsxfun compatibility rule: if there is at least one singleton %# dim, the smallest is repeated to reach the size of the %# greatest. Otherwise, all dims must be equal. - if (any(size(A)(1:2) != size(B)(1:2))) - if (!any (1 == [size(A) size(B)])) - error('bsxfun: both arguments must have the same dim, of one of them must have at least one singleton dim'); - else - Csize = max([size(A)(1:2); size(B)(1:2)]); - endif + if (any (size (A)(1:2) ~= size (B)(1:2))) + if (~any (1 == [size(A) size(B)])) + error ('bsxfun: both arguments must have the same dim, of one of them must have at least one singleton dim'); + else + Csize = max ([size(A)(1:2); size(B)(1:2)]); + endif else - Csize = size(A)(1:2); + Csize = size (A)(1:2); endif case 'mldivide' - if (isscalar(A)), - Csize = size(B)(1:2); + if (isscalar (A)), + Csize = size (B)(1:2); else - if (size(A, 1) != size(B, 1)), - error("Non compatible row sizes (op1 is %dx%d, op2 is %dx%d)",\ - size(A), size(B)(1:2)); - endif - Csize = [size(A, 2) size(B, 2)]; + if (size (A, 1) ~= size (B, 1)) + error ("Non compatible row sizes (op1 is %dx%d, op2 is %dx%d)",\ + size (A), size (B)(1:2)); + endif + Csize = [size(A, 2) size(B, 2)]; endif otherwise %# if strict is set, B may not be non-scalar vs scalar - if ((!(isscalar(A) || isscalar(B)))||(strict && isscalar(A))), - if (itercol), %# requires full compatibility - Csize = size(A)(1:2); - if (any(Csize - size(B)(1:2))), - %# disp([size(A) size(B)]) - error("Non compatible row and columns sizes (op1 is %dx%d, op2 is %dx%d)",\ - Csize, size(B)); - endif - else %# compatibility with matrix product - if (size(A, 2) - size(B, 1)), - error("Non compatible columns vs. rows size (op1 is %dx%d, op2 is %dx%d)",\ - size(A)(1:2), size(B)(1:2)); - endif - Csize = [size(A, 1) size(B, 2)]; - endif + if ((~(isscalar (A) || isscalar (B)))||(strict && isscalar (A))) + if (itercol), %# requires full compatibility + Csize = size (A)(1:2); + if (any (Csize - size (B)(1:2))) + %# disp([size(A) size(B)]) + error ("Non compatible row and columns sizes (op1 is %dx%d, op2 is %dx%d)",\ + Csize, size (B)); + endif + else %# compatibility with matrix product + if (size (A, 2) - size (B, 1)), + error ("Non compatible columns vs. rows size (op1 is %dx%d, op2 is %dx%d)",\ + size (A)(1:2), size (B)(1:2)); + endif + Csize = [size(A, 1) size(B, 2)]; + endif endif endswitch - if !(isscalar(A) || isscalar(B)) + if (~(isscalar (A) || isscalar (B))) C = []; - if (isa(A, 'dataframe')) - if (nargout > 2 && all(Csize == size(A)(1:2))), - C = df_allmeta(A, Csize); + if (isa (A, 'dataframe')) + if (nargout > 2 && all (Csize == size (A)(1:2))), + C = df_allmeta (A, Csize); endif - if (isa(B, 'dataframe')) - if (nargout > 2 && isempty(C) && all(Csize == size(B)(1:2))), - C = df_allmeta(B, Csize); - endif - if (strict), - %# compare indexes if both exist - if (!isempty(A._ridx)) - if (!isempty(B._ridx) && itercol), - if (any(A._ridx-B._ridx)), - error("Non compatible indexes"); - endif - endif - else - if (nargout > 2 && itercol), C._ridx = B._ridx; endif - endif - - if (itercol), - idxB = 1; %# row-row comparison - else - idxB = 2; %# row-col comparsion - endif - - if (!isempty(A._name{1})) - if (!isempty(B._name{idxB})) - dummy = !(strcmp(cellstr(A._name{1}), cellstr(B._name{idxB}))\ - | (A._over{1}(:)) | (B._over{idxB}(:))); - if (any(dummy)), - if (itercol), - error("Incompatible row names"); - else - error("Incompatible row vs. column names"); - endif - endif - dummy = A._over{1} > B._over{idxB}; - if (any(dummy)), - C._name{1}(dummy) = B._name{idxB}(dummy); - C._over{1}(dummy) = B._over{idxB}(dummy); - endif - endif - else - if (nargout > 2), - C._name{1} = B._name{idxB}; C._over{1} = B._over{idxB}; - endif - endif - - idxB = 3-idxB; - - if (!isempty(A._name{2})) - if (!isempty(B._name{idxB})) - dummy = !(strcmp(cellstr(A._name{2}), cellstr(B._name{2}))\ - | (A._over{2}(:)) | (B._over{2}(:))); - if (any(dummy)), - if (itercol), - error("Incompatible column vs row names"); - else - error("Incompatible column names"); - endif - endif - dummy = A._over{2} > B._over{idxB}; - if (any(dummy)), - C._name{2}(dummy) = B._name{idxB}(dummy); - C._over{2}(dummy) = B._over{idxB}(dummy); - endif - endif - else - if (nargout > 2 && !isempty(B._name{idxB})), - C._name{2} = B._name{idxB}; C._over{2} = B._over{idxB}; - endif - endif - endif + if (isa (B, 'dataframe')) + if (nargout > 2 && isempty (C) && all (Csize == size (B)(1:2))), + C = df_allmeta (B, Csize); + endif + if (strict) + %# compare indexes if both exist + if (~isempty (A._ridx)) + if (~isempty(B._ridx) && itercol) + if (any (A._ridx-B._ridx)), + error ("Non compatible indexes"); + endif + endif + else + if (nargout > 2 && itercol), C._ridx = B._ridx; endif + endif + + if (itercol), + idxB = 1; %# row-row comparison + else + idxB = 2; %# row-col comparsion + endif + + if (~isempty (A._name{1})) + if (~isempty (B._name{idxB})) + dummy = ~(strcmp (cellstr (A._name{1}), cellstr (B._name{idxB}))\ + | (A._over{1}(:)) | (B._over{idxB}(:))); + if (any (dummy)) + if (itercol), + error ("Incompatible row names"); + else + error ("Incompatible row vs. column names"); + endif + endif + dummy = A._over{1} > B._over{idxB}; + if (any (dummy)), + C._name{1}(dummy) = B._name{idxB}(dummy); + C._over{1}(dummy) = B._over{idxB}(dummy); + endif + endif + else + if (nargout > 2), + C._name{1} = B._name{idxB}; C._over{1} = B._over{idxB}; + endif + endif + + idxB = 3-idxB; + + if (~isempty(A._name{2})) + if (~isempty(B._name{idxB})) + dummy = ~(strcmp (cellstr (A._name{2}), cellstr (B._name{2}))\ + | (A._over{2}(:)) | (B._over{2}(:))); + if (any (dummy)), + if (itercol), + error ("Incompatible column vs row names"); + else + error ("Incompatible column names"); + endif + endif + dummy = A._over{2} > B._over{idxB}; + if (any (dummy)), + C._name{2}(dummy) = B._name{idxB}(dummy); + C._over{2}(dummy) = B._over{idxB}(dummy); + endif + endif + else + if (nargout > 2 && ~isempty (B._name{idxB})), + C._name{2} = B._name{idxB}; C._over{2} = B._over{idxB}; + endif + endif + endif - if (isempty(A._src) && nargout > 2 && !isempty(B._src)), - C._src = B._src; - endif - if (isempty(A._cmt) && nargout > 2 && !isempty(B._cmt)), - C._cmt = B._cmt; - endif + if (isempty (A._src) && nargout > 2 && ~isempty (B._src)), + C._src = B._src; + endif + if (isempty (A._cmt) && nargout > 2 && ~isempty (B._cmt)), + C._cmt = B._cmt; + endif else %# B is not a df - if (nargout > 2 && isempty(C)), - C = df_allmeta(A); - endif + if (nargout > 2 && isempty (C)), + C = df_allmeta (A); + endif endif else %# A is not a df if (nargout > 2), - if (all(Csize==size(B)(1:2))), - C = df_allmeta(B, Csize); - else - C = df_allmeta(B); - endif + if (all (Csize == size (B)(1:2))), + C = df_allmeta (B, Csize); + else + C = df_allmeta (B); + endif endif endif else %# both arg are scalar - if (nargout > 2), - if (isa(A, 'dataframe')) - C = df_allmeta(A); + if (nargout > 2) + if (isa (A, 'dataframe')) + C = df_allmeta (A); else - C = df_allmeta(B); + C = df_allmeta (B); endif endif endif
--- a/extra/dataframe/inst/@dataframe/private/df_check_char_array.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/private/df_check_char_array.m Sun Mar 11 20:53:31 2012 +0000 @@ -26,27 +26,27 @@ %# $Id$ %# - if 2 == nargin, required = [nelem 1]; endif + if (2 == nargin) required = [nelem 1]; endif - if nelem < required(1), - error("Too many elements to assign"); + if (nelem < required(1)) + error ("Too many elements to assign"); endif %# a zero-length element is still considered as a space by char - if isempty(x), x = ' '; endif + if (isempty (x)) x = ' '; endif - if size(x, 1) < max(required(1), nelem) + if (size (x, 1) < max (required(1), nelem)) %# pad vertically - dummy = repmat(' ', nelem-size(x, 1), 1); - resu = char(x, dummy); + dummy = repmat (' ', nelem-size (x, 1), 1); + resu = char (x, dummy); else resu = x; endif - if size(resu, 2) < required(2), + if (size (resu, 2) < required(2)) %# pad horizontally - dummy = repmat(' ', nelem, required(2)-size(resu, 2)); - resu = horzcat(resu, dummy); + dummy = repmat (' ', nelem, required(2)-size (resu, 2)); + resu = horzcat (resu, dummy); endif endfunction
--- a/extra/dataframe/inst/@dataframe/private/df_colmeta.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/private/df_colmeta.m Sun Mar 11 20:53:31 2012 +0000 @@ -28,15 +28,15 @@ %# $Id: df_func.m 7943 2010-11-24 15:33:54Z cdemills $ %# - resu = dataframe([]); + resu = dataframe ([]); resu._cnt(2) = df._cnt(2); resu._name{2} = df._name{2}; resu._over{2} = df._over{2}; resu._type = df._type; %# init it with the right orientation - resu._data = cell(size(df._data)); - resu._rep = cell(size(df._rep)); + resu._data = cell (size (df._data)); + resu._rep = cell (size (df._rep)); resu._src = df._src; resu._cmt = df._cmt;
--- a/extra/dataframe/inst/@dataframe/private/df_cow.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/private/df_cow.m Sun Mar 11 20:53:31 2012 +0000 @@ -29,50 +29,50 @@ %# $Id$ %# - if length(col) > 1, - error("df_cow must work on a column-by-column basis"); + if (length (col) > 1) + error ("df_cow must work on a column-by-column basis"); endif - if (1 == length(S.subs)), + if (1 == length (S.subs)), inds = 1; else inds = S.subs{2}; endif - if (!isnumeric(inds)), - if !strcmp(inds, ':'), - error("Unknown sheet selector %s", inds); + if (~isnumeric(inds)) + if (~strcmp (inds, ':')) + error ("Unknown sheet selector %s", inds); endif - inds = 1:length(df._rep(col)); + inds = 1:length (df._rep(col)); endif - for indi = inds(:).', + for indi = (inds(:).') dummy = df._rep{col}; dummy(indi) = 0; - [t1, t2] = ismember(df._rep{col}(indi)(:), dummy); - for indj = t2(find(t2)), %# Copy-On-Write + [t1, t2] = ismember (df._rep{col}(indi)(:), dummy); + for indj = (t2(find (t2))) %# Copy-On-Write %# determines the index for the next column - t1 = 1+max(df._rep{col}); + t1 = 1 + max (df._rep{col}); %# duplicate the touched column - df._data{col} = horzcat(df._data{col}, \ - df._data{col}(:, df._rep{col}(indj))); - if (indi > 1), + df._data{col} = horzcat (df._data{col}, \ + df._data{col}(:, df._rep{col}(indj))); + if (indi > 1) %# a new column has been created df._rep{col}(indi) = t1; else %# update repetition index aliasing this one - df._rep{col}(find(dummy == indi)) = t1; + df._rep{col}(find (dummy == indi)) = t1; endif endfor endfor %# reorder S - if (length(S.subs) > 1), - if (S.subs{2} != 1 || length(S.subs{2}) > 1), + if (length (S.subs) > 1) + if (S.subs{2} ~= 1 || length (S.subs{2}) > 1), %# adapt sheet index according to df_rep S.subs{2} = df._rep{col}(S.subs{2}); endif endif - df = df_thirddim(df); + df = df_thirddim (df); endfunction
--- a/extra/dataframe/inst/@dataframe/private/df_func.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/private/df_func.m Sun Mar 11 20:53:31 2012 +0000 @@ -32,191 +32,191 @@ %# $Id$ %# - [A, B, resu] = df_basecomp(A, B, itercol, func); + [A, B, resu] = df_basecomp (A, B, itercol, func); itercol = itercol(1); %# drop second value - if (isa(B, 'dataframe')) - if (!isa(A, 'dataframe')), - if (isscalar(A)), - for indi = resu._cnt(2):-1:1, + if (isa (B, 'dataframe')) + if (~isa (A, 'dataframe')), + if (isscalar (A)), + for indi = (resu._cnt(2):-1:1) switch resu._type{indi} case "char" - resu._data{indi} = feval(func, A, char(B._data{indi})); + resu._data{indi} = feval (func, A, char (B._data{indi})); otherwise - resu._data{indi} = feval(func, A, B._data{indi}); + resu._data{indi} = feval (func, A, B._data{indi}); endswitch endfor resu._rep = B._rep; else - if (whole(1) && !whole(2)), - for indi = resu._cnt(2):-1:1, + if (whole(1) && ~whole(2)) + for indi = (resu._cnt(2):-1:1) switch resu._type{indi} case "char" - resu._data{indi} = feval(func, A, \ - char(B._data{indi}(:, B._rep{indi}))); + resu._data{indi} = feval (func, A, \ + char (B._data{indi}(:, B._rep{indi}))); otherwise - resu._data{indi} = feval(func, A, \ - B._data{indi}(:, B._rep{indi})); + resu._data{indi} = feval (func, A, \ + B._data{indi}(:, B._rep{indi})); endswitch - resu._rep{indi} = 1:size(resu._data{indi}, 2); + resu._rep{indi} = 1:size (resu._data{indi}, 2); endfor - elseif (itercol && !whole(2)), - for indi = resu._cnt(2):-1:1, + elseif (itercol && ~whole(2)), + for indi = (resu._cnt(2):-1:1) switch resu._type{indi} case "char" - resu._data{indi} = feval(func, squeeze(A(:, indi, :)), \ - char(B._data{indi}(:, B._rep{indi}))); + resu._data{indi} = feval (func, squeeze (A(:, indi, :)), \ + char (B._data{indi}(:, B._rep{indi}))); otherwise - resu._data{indi} = feval(func, squeeze(A(:, indi, :)), \ - B._data{indi}(:, B._rep{indi})); + resu._data{indi} = feval (func, squeeze (A(:, indi, :)), \ + B._data{indi}(:, B._rep{indi})); endswitch - resu._rep{indi} = 1:size(resu._data{indi}, 2); + resu._rep{indi} = 1:size (resu._data{indi}, 2); endfor - elseif (!whole(2)), - warning("no 3D yet"); - for indi = resu._cnt(2):-1:1, + elseif (~whole(2)), + warning ("no 3D yet"); + for indi = (resu._cnt(2):-1:1) switch resu._type{indi} case "char" - resu._data{indi} = feval(func, A(indi, :), char(B._data{indi})); + resu._data{indi} = feval (func, A(indi, :), char (B._data{indi})); otherwise - resu._data{indi} = feval(func, A(indi, :), B._data{indi}); + resu._data{indi} = feval (func, A(indi, :), B._data{indi}); endswitch endfor else - dummy = feval(func, A, df_whole(B)); - for indi = resu._cnt(2):-1:1, %# store column-wise - resu._data{indi} = squeeze(dummy(:, indi, :)); - resu._rep{indi} = 1:size(resu._data{indi}, 2); - resu._type{indi} = class(dummy); + dummy = feval (func, A, df_whole (B)); + for indi = (resu._cnt(2):-1:1) %# store column-wise + resu._data{indi} = squeeze (dummy(:, indi, :)); + resu._rep{indi} = 1:size (resu._data{indi}, 2); + resu._type{indi} = class (dummy); endfor endif endif else - if (itercol), - for indi = resu._cnt(2):-1:1, + if (itercol) + for indi = (resu._cnt(2):-1:1) switch resu._type{indi} case "char" - resu._data{indi} = feval\ - (func, char(A._data{indi}(:, A._rep{indi})), \ - char(B._data{indi}(B._rep{indi}))); + resu._data{indi} = feval \ + (func, char (A._data{indi}(:, A._rep{indi})), \ + char (B._data{indi}(B._rep{indi}))); otherwise - resu._data{indi} = feval\ + resu._data{indi} = feval \ (func, A._data{indi}(:, A._rep{indi}), \ B._data{indi}(:, B._rep{indi})); endswitch - resu._rep{indi} = 1:size(resu._data{indi}, 2); + resu._rep{indi} = 1:size (resu._data{indi}, 2); endfor else %# itercol is false dummy = df_whole(A); - if whole(1), - for indi = resu._cnt(2):-1:1, + if (whole(1)) + for indi = (resu._cnt(2):-1:1) switch resu._type{indi} case "char" - resu._data{indi} = feval(func, dummy, \ - char(B._data{indi}(:, B._rep{indi}))); + resu._data{indi} = feval (func, dummy, \ + char (B._data{indi}(:, B._rep{indi}))); otherwise - resu._data{indi} = feval(func, dummy, \ - B._data{indi}(:, B._rep{indi})); + resu._data{indi} = feval (func, dummy, \ + B._data{indi}(:, B._rep{indi})); endswitch - resu._rep{indi} = 1:size(resu._data{indi}, 2); + resu._rep{indi} = 1:size (resu._data{indi}, 2); endfor - elseif (!whole(2)), - for indi = resu._cnt(2):-1:1, + elseif (~whole(2)) + for indi = (resu._cnt(2):-1:1) switch resu._type{indi} case "char" - resu._data{indi} = squeeze\ - (feval(func, dummy(indi, :, :),\ - char(B._data{indi}(:, B._rep{indi})))); + resu._data{indi} = squeeze \ + (feval (func, dummy(indi, :, :),\ + char (B._data{indi}(:, B._rep{indi})))); otherwise - resu._data{indi} = squeeze\ - (feval(func, dummy(indi, :, :), \ + resu._data{indi} = squeeze \ + (feval (func, dummy(indi, :, :), \ B._data{indi}(:, B._rep{indi}))); endswitch - resu._rep{indi} = 1:size(resu._data{indi}, 2); + resu._rep{indi} = 1:size (resu._data{indi}, 2); endfor else - dummy = feval(func, dummy, df_whole(B)); - for indi = resu._cnt(2):-1:1, %# store column-wise - resu._data{indi} = squeeze(dummy(:, indi, :)); - resu._rep{indi} = 1:size(resu._data{indi}, 2); - resu._type{indi} = class(dummy); + dummy = feval (func, dummy, df_whole(B)); + for indi = (resu._cnt(2):-1:1) %# store column-wise + resu._data{indi} = squeeze (dummy(:, indi, :)); + resu._rep{indi} = 1:size (resu._data{indi}, 2); + resu._type{indi} = class (dummy); endfor endif endif endif else %# B is not a dataframe - if (isscalar(B)), - for indi = resu._cnt(2):-1:1, + if (isscalar (B)) + for indi = (resu._cnt(2):-1:1) switch resu._type{indi} case "char" - resu._data{indi} = feval(func, char(A._data{indi}), B); + resu._data{indi} = feval (func, char (A._data{indi}), B); otherwise - resu._data{indi} = feval(func, A._data{indi}, B); + resu._data{indi} = feval (func, A._data{indi}, B); endswitch endfor resu._rep = A._rep; else - if (itercol), - if (whole(2)), - for indi = resu._cnt(2):-1:1, + if (itercol) + if (whole(2)) + for indi = (resu._cnt(2):-1:1) switch resu._type{indi} case "char" - unfolded = char(A._data{indi}(:, A._rep{indi})); + unfolded = char (A._data{indi}(:, A._rep{indi})); otherwise unfolded = A._data{indi}(:, A._rep{indi}); endswitch - resu._data{indi} = squeeze(feval(func, unfolded, B)); - resu._rep{indi} = 1:size(resu._data{indi}, 2); + resu._data{indi} = squeeze (feval (func, unfolded, B)); + resu._rep{indi} = 1:size (resu._data{indi}, 2); endfor else - for indi = resu._cnt(2):-1:1, + for indi = (resu._cnt(2):-1:1) switch resu._type{indi} case "char" - unfolded = char(A._data{indi}(:, A._rep{indi})); + unfolded = char (A._data{indi}(:, A._rep{indi})); otherwise unfolded = A._data{indi}(:, A._rep{indi}); endswitch - resu._data{indi} = feval(func, unfolded, \ - squeeze(B(:, indi, :))); - resu._rep{indi} = 1:size(resu._data{indi}, 2); + resu._data{indi} = feval (func, unfolded, \ + squeeze (B(:, indi, :))); + resu._rep{indi} = 1:size (resu._data{indi}, 2); endfor endif else dummy = df_whole(A); - if whole(1), - for indi = columns(B):-1:1, - resu._data{indi} = squeeze(feval(func, dummy, B(:, indi, :))); - resu._rep{indi} = 1:size(resu._data{indi}, 2); + if (whole(1)) + for indi = (columns (B):-1:1) + resu._data{indi} = squeeze (feval(func, dummy, B(:, indi, :))); + resu._rep{indi} = 1:size (resu._data{indi}, 2); endfor else - if !whole(2), - for indi = resu._cnt(1):-1:1, - resu._data{indi} = squeeze(feval(func, dummy(indi, :, :), \ - B(:, indi, :))); - resu._rep{indi} = 1:size(resu._data{indi}, 2); + if (~whole(2)) + for indi = (resu._cnt(1):-1:1) + resu._data{indi} = squeeze (feval (func, dummy(indi, :, :), \ + B(:, indi, :))); + resu._rep{indi} = 1:size (resu._data{indi}, 2); endfor else - for indi = resu._cnt(1):-1:1, %# in place computation - dummy(indi, :, :) = feval(func, dummy(indi, :, :), B); + for indi = (resu._cnt(1):-1:1) %# in place computation + dummy(indi, :, :) = feval (func, dummy(indi, :, :), B); endfor - for indi = resu._cnt(2):-1:1, %# store column-wise - resu._data{indi} = squeeze(dummy(:, indi, :)); - resu._rep{indi} = 1:size(resu._data{indi}, 2); + for indi = (resu._cnt(2):-1:1) %# store column-wise + resu._data{indi} = squeeze (dummy(:, indi, :)); + resu._rep{indi} = 1:size (resu._data{indi}, 2); endfor endif endif %# verify that sizes match, this is required for "\" - resu._cnt(2) = length(resu._data); - resu._cnt(1) = max(cellfun('size', resu._data, 1)); - if (length(resu._ridx) < resu._cnt(1)), - if (1 == length(resu._ridx)), + resu._cnt(2) = length (resu._data); + resu._cnt(1) = max (cellfun ('size', resu._data, 1)); + if (length (resu._ridx) < resu._cnt(1)), + if (1 == length (resu._ridx)) resu._ridx(end+1:resu._cnt(1), 1) = resu._ridx(1); else resu._ridx(end+1:resu._cnt(1), 1) = NA; endif endif - if (length(resu._name{2}) < resu._cnt(2)), - if (1 == length(resu._name{2})), + if (length (resu._name{2}) < resu._cnt(2)), + if (1 == length (resu._name{2})), resu._name{2}(end+1:resu._cnt(2), 1) = resu._name{2}; resu._over{2}(end+1:resu._cnt(2), 1) = resu._over{2}; else @@ -228,8 +228,8 @@ endif endif - resu._type = cellfun(@class, resu._data, "UniformOutput", false); + resu._type = cellfun (@class, resu._data, "UniformOutput", false); - resu = df_thirddim(resu); + resu = df_thirddim (resu); endfunction
--- a/extra/dataframe/inst/@dataframe/private/df_mapper2.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/private/df_mapper2.m Sun Mar 11 20:53:31 2012 +0000 @@ -31,47 +31,47 @@ dim = 1; resu = []; vout = varargin; %# take care of constructs as min(x, [], dim) - if (!isempty(varargin)), - indk = 1; while indk <= length(varargin), - if (isnumeric(varargin{indk})), - if (isempty(varargin{indk})), - indk = indk + 1; continue; - endif - dim = varargin{indk}; - %# the "third" dim is the second on stored data - if 3 == dim, vout(indk) = 2; endif + if (~isempty(varargin)) + indk = 1; while (indk <= length (varargin)) + if (isnumeric (varargin{indk})) + if (isempty (varargin{indk})) + indk = indk + 1; continue; + endif + dim = varargin{indk}; + %# the "third" dim is the second on stored data + if (3 == dim) vout(indk) = 2; endif endif break; endwhile endif - switch(dim) - case {1}, - resu = df_colmeta(df); - for indi = 1:df._cnt(2), - resu._data{indi} = feval(func, df._data{indi}(:, df._rep{indi}), \ - vout{:}); - resu._rep{indi} = 1:size(resu._data{indi}, 2); + switch (dim) + case {1} + resu = df_colmeta (df); + for indi = (1:df._cnt(2)) + resu._data{indi} = feval (func, df._data{indi}(:, df._rep{indi}), \ + vout{:}); + resu._rep{indi} = 1:size (resu._data{indi}, 2); endfor - resu._cnt(1) = max(cellfun('size', resu._data, 1)); - if (resu._cnt(1) == df._cnt(1)), - %# the func was not contracting - resu._ridx = df._ridx; - resu._name{1} = resu._name{1}; resu._over{1} = resu._over{1}; + resu._cnt(1) = max (cellfun ('size', resu._data, 1)); + if (resu._cnt(1) == df._cnt(1)) + %# the func was not contracting + resu._ridx = df._ridx; + resu._name{1} = resu._name{1}; resu._over{1} = resu._over{1}; endif - case {2}, - error('Operation not implemented'); - case {3}, + case {2} + error ('Operation not implemented'); + case {3} resu = df_allmeta(df); - for indi = 1:df._cnt(2), - resu._data{indi} = feval(func, df._data{indi}(:, df._rep{indi}), \ - vout{:}); - resu._rep{indi} = 1:size(resu._data{indi}, 2); + for indi = (1:df._cnt(2)) + resu._data{indi} = feval (func, df._data{indi}(:, df._rep{indi}), \ + vout{:}); + resu._rep{indi} = 1:size (resu._data{indi}, 2); endfor otherwise - error("Invalid dimension %d", dim); + error ("Invalid dimension %d", dim); endswitch - resu = df_thirddim(resu); + resu = df_thirddim (resu); endfunction
--- a/extra/dataframe/inst/@dataframe/private/df_matassign.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/private/df_matassign.m Sun Mar 11 20:53:31 2012 +0000 @@ -268,32 +268,34 @@ %# error("cells may only contain scalar"); %# endif - if (size(RHS, 2) > indc) + if (size (RHS, 2) > indc) keyboard endif %# try to detect and remove bottom garbage - eff_len = zeros(nrow, 1); - for indi = (indr) - eff_len(indi, 1) = sum (~cellfun ('isempty', RHS(indi, :))); - endfor - indi = nrow; - while (indi > 0) - if (1 == eff_len(indi)) - nrow = nrow - 1; - indr(end) = []; - RHS(end, :) = []; - indi = indi - 1; - if (~indr_was_set && isempty (df._name{1, 1})) - df._cnt(1) = nrow; - df._ridx(end) = []; + eff_len = zeros (nrow, 1); + if (size (RHS, 1) > 1) + for indi = (indr) + eff_len(indi, 1) = sum (~cellfun ('isempty', RHS(indi, :))); + endfor + indi = nrow; + while (indi > 0) + if (1 == eff_len(indi)) + nrow = nrow - 1; + indr(end) = []; + RHS(end, :) = []; + indi = indi - 1; + if (~indr_was_set && isempty (df._name{1, 1})) + df._cnt(1) = nrow; + df._ridx(end) = []; + endif + else + break; endif - else - break; - endif - endwhile - clear eff_len; - + endwhile + clear eff_len; + endif + %# the real assignement if (1 == size (RHS, 1)) %# each cell contains one vector fillfunc = @(x) RHS{x}; @@ -340,10 +342,33 @@ endswitch endif catch - dummy = \ - sprintf ("Assignement failed for colum %d, of type %s and length %d,\nwith new content\n%s", \ - indj, df._type{indc(indi)}, length (indr), disp (RHS(:, indj))); - error (dummy); + dummy = unique(cellfun(@class, RHS(:, indj), ... + 'UniformOutput', false)); + if (any (strmatch ("char", dummy, "exact"))) + %# replace the actual column, of type numeric, by a char + df._type{indc(indi)} = 'char'; + dummy = RHS(:, indj); + for indk = (size (dummy, 1):-1:1) + if (~isa ("char", dummy{indk})) + if (isinteger (dummy{indk})) + dummy(indk) = mat2str (dummy{indk}); + elseif (isa ("logical", dummy{indk})) + if (dummy{indk}) + dummy(indk) = "true"; + else + dummy{indk} = "false"; + endif + elseif (isnumeric (dummy{indk})) + dummy(indk) = mat2str (dummy{indk}, 6); + endif + endif + endfor + else + dummy = \ + sprintf ("Assignement failed for colum %d, of type %s and length %d,\nwith new content\n%s", \ + indj, df._type{indc(indi)}, length (indr), disp (RHS(:, indj))); + error (dummy); + endif end_try_catch if (size (dummy, 1) < df._cnt(1)) dummy(end+1:df._cnt(1), :) = NA; @@ -378,7 +403,7 @@ class(RHS)); endif if (~isempty (inds) && isnumeric(inds) && any (inds > 1)) - for indi = (1:length (indc)) + for indi = (1:ncol) if (max (inds) > length (df._rep{indc(indi)})) df = df_pad(df, 3, max (inds)-length (df._rep{indc(indi)}), \ indc(indi)); @@ -394,7 +419,7 @@ endif %# skip second dim and copy data S.subs(2) = []; Sorig = S; - for indi = (1:length (indc)) + for indi = (1:ncol) [df, S] = df_cow(df, S, indc(indi)); if (strcmp (df._type(indc(indi)), RHS._type(indi))) try @@ -438,7 +463,7 @@ if (length (S.subs) < 2) S.subs{2} = 1; endif - if (length (indc) > 1 && length (RHS) > 1) + if (ncol > 1 && length (RHS) > 1) %# set a row from a vector fillfunc = @(x, S, y) feval (@subsasgn, x, S, RHS(y)); else @@ -446,7 +471,7 @@ endif endif Sorig = S; - for indi = (1:length (indc)) + for indi = (1:ncol) try [df, S] = df_cow(df, S, indc(indi)); df._data{indc(indi)} = fillfunc (df._data{indc(indi)}, S, indi); @@ -474,7 +499,7 @@ %# rotate slices in dim 1-3 to slices in dim 1-2 fillfunc = @(x, S, y) feval(@subsasgn, x, S, squeeze(RHS(:, y, :))); Sorig = S; - for indi = (1:length (indc)) + for indi = (1:ncol) [df, S] = df_cow(df, S, indc(indi)); df._data{indc(indi)} = fillfunc (df._data{indc(indi)}, S, indi); S = Sorig; @@ -515,6 +540,10 @@ endif if (~isempty (cname) && (length (df._over{2}) < max (indc) || \ all (df._over{2}(indc)))) + if (length (cname) < ncol) + cname(end+1:ncol) = {'_'}; + endif + cname(cellfun (@isempty, cname)) = 'unnamed'; try df._name{2}(indc, 1) = genvarname (cname); catch
--- a/extra/dataframe/inst/@dataframe/private/df_name2idx.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/private/df_name2idx.m Sun Mar 11 20:53:31 2012 +0000 @@ -62,7 +62,7 @@ if (isa (subs, 'cell')) subs = subs(:); idx = []; mask = logical (zeros (size (subs, 1), 1)); %# translate list of variables to list of indices - for indi = (1:size(subs, 1)) + for indi = (1:size (subs, 1)) %# regexp doesn't like empty patterns if (isempty (subs{indi})) continue; endif %# convert from standard pattern to regexp pattern @@ -82,7 +82,7 @@ else dummy = strsplit (subs{indi}, ':'); ind_start = 1; - if (!isempty (dummy{1})) + if (~isempty (dummy{1})) ind_start = sscanf (dummy{1}, "%d"); if (isempty (ind_start)) ind_start = 1;
--- a/extra/dataframe/inst/@dataframe/private/df_pad.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/private/df_pad.m Sun Mar 11 20:53:31 2012 +0000 @@ -32,135 +32,135 @@ switch dim case 1 - if (!isempty(df._name{1})), - if (length(df._name{1}) < df._cnt(1)+n), - %# generate a name for the new row(s) - df._name{1}(df._cnt(1)+(1:n), 1) = {'_'}; - df._over{1}(1, df._cnt(1)+(1:n), 1) = true; - endif + if (~isempty (df._name{1})), + if (length (df._name{1}) < df._cnt(1)+n) + %# generate a name for the new row(s) + df._name{1}(df._cnt(1)+(1:n), 1) = {'_'}; + df._over{1}(1, df._cnt(1)+(1:n), 1) = true; + endif endif %# complete row indexes: by default, row number. - if (isempty(df._ridx)), - dummy = (1:n)(:); + if (isempty (df._ridx)) + dummy = (1:n)(:); else - dummy = vertcat(df._ridx, repmat(size(df._ridx, 1)+(1:n)(:), ... - 1, size(df._ridx, 2))); + dummy = vertcat (df._ridx, repmat (size (df._ridx, 1)+(1:n)(:), ... + 1, size (df._ridx, 2))); endif df._ridx = dummy; %# pad every line - for indi = 1:min(size(df._data, 2), df._cnt(2)), - neff = n + df._cnt(1) - size(df._data{indi}, 1); - if (neff > 0), - m = size(df._data{indi}, 2); - switch df._type{indi} - case {'char'} - dummy = {}; dummy(1:neff, 1:m) = NA; - dummy = vertcat(df._data{indi}, dummy); - case { 'double' } - dummy = vertcat(df._data{indi}, repmat(NA, neff, m)); - otherwise - dummy = cast(vertcat(df._data{indi}, repmat(NA, neff, m)), ... - df._type{indi}); - endswitch - df._data{indi} = dummy; - endif + for indi = (1:min (size (df._data, 2), df._cnt(2))) + neff = n + df._cnt(1) - size (df._data{indi}, 1); + if (neff > 0) + m = size (df._data{indi}, 2); + switch df._type{indi} + case {'char'} + dummy = {}; dummy(1:neff, 1:m) = NA; + dummy = vertcat (df._data{indi}, dummy); + case { 'double' } + dummy = vertcat (df._data{indi}, repmat (NA, neff, m)); + otherwise + dummy = cast (vertcat (df._data{indi}, repmat (NA, neff, m)), ... + df._type{indi}); + endswitch + df._data{indi} = dummy; + endif endfor df._cnt(1) = df._cnt(1) + n; case 2 %# create new columns - if (isempty(coltype)) - error("df_pad: dim equals 2, and coltype undefined"); + if (isempty (coltype)) + error ("df_pad: dim equals 2, and coltype undefined"); endif - if (length(n) > 1), %#second value is an offset - indc = n(2); n = n(1); - if (indc < df._cnt(2)), - %# shift to the right - df._name{2}(n + (indc+1:end)) = df._name{2}(indc+1:end); - df._over{2}(n + (indc+1:end)) = df._over{2}(indc+1:end); - dummy = cstrcat(repmat('_', n, 1), ... - strjust(num2str(indc + (1:n).'), 'left')); - df._name{2}(indc + (1:n)) = cellstr(dummy); - df._over{2}(indc + (1:n)) = true; - df._type(n+(indc+1:end)) = df._type(indc+1:end); - df._type(indc + (1:n)) = NA; - df._data(n + (indc+1:end)) = df._data(indc+1:end); - df._rep(n + (indc+1:end)) = df._rep(indc+1:end); - df._data(indc + (1:n)) = NA; - df._rep(indc + (1:n)) = 1; - endif + if (length (n) > 1) %#second value is an offset + indc = n(2); n = n(1); + if (indc < df._cnt(2)), + %# shift to the right + df._name{2}(n + (indc+1:end)) = df._name{2}(indc+1:end); + df._over{2}(n + (indc+1:end)) = df._over{2}(indc+1:end); + dummy = cstrcat (repmat ('_', n, 1), ... + strjust (num2str(indc + (1:n).'), 'left')); + df._name{2}(indc + (1:n)) = cellstr (dummy); + df._over{2}(indc + (1:n)) = true; + df._type(n+(indc+1:end)) = df._type(indc+1:end); + df._type(indc + (1:n)) = NA; + df._data(n + (indc+1:end)) = df._data(indc+1:end); + df._rep(n + (indc+1:end)) = df._rep(indc+1:end); + df._data(indc + (1:n)) = NA; + df._rep(indc + (1:n)) = 1; + endif else - %# add new values after the last column - indc = min(size(df._data, 2), df._cnt(2)); + %# add new values after the last column + indc = min (size (df._data, 2), df._cnt(2)); endif - if (!isa(coltype, 'cell')), coltype = {coltype}; endif - if (isscalar(coltype) && n > 1), - coltype = repmat(coltype, 1, n); + if (~isa (coltype, 'cell')) coltype = {coltype}; endif + if (isscalar (coltype) && n > 1) + coltype = repmat (coltype, 1, n); endif - for indi = (1:n), - switch coltype{indi} - case {'char'} - dummy = {repmat(NA, df._cnt(1), 1) }; - dummy(:, 1) = '_'; - case { 'double'} - dummy = repmat(NA, df._cnt(1), 1); - case {'logical'} %# there is no NA in logical type - dummy = repmat(false, df._cnt(1), 1); - otherwise - dummy = cast(repmat(NA, df._cnt(1), 1), coltype{indi}); - endswitch - df._data{indc+indi} = dummy; - df._rep{indc+indi} = 1; - df._type{indc+indi} = coltype{indi}; + for indi = (1:n) + switch coltype{indi} + case {'char'} + dummy = {repmat(NA, df._cnt(1), 1) }; + dummy(:, 1) = '_'; + case { 'double'} + dummy = repmat (NA, df._cnt(1), 1); + case {'logical'} %# there is no NA in logical type + dummy = repmat (false, df._cnt(1), 1); + otherwise + dummy = cast (repmat (NA, df._cnt(1), 1), coltype{indi}); + endswitch + df._data{indc+indi} = dummy; + df._rep{indc+indi} = 1; + df._type{indc+indi} = coltype{indi}; endfor - if (size(df._data, 2) > df._cnt(2)), - df._cnt(2) = size(df._data, 2); + if (size (df._data, 2) > df._cnt(2)), + df._cnt(2) = size (df._data, 2); endif - if (length(df._name{2}) < df._cnt(2)), - %# generate a name for the new column(s) - dummy = cstrcat(repmat('_', n, 1), ... - strjust(num2str(indc + (1:n).'), 'left')); - df._name{2}(indc + (1:n)) = cellstr(dummy); - df._over{2}(1, indc + (1:n)) = true; + if (length (df._name{2}) < df._cnt(2)), + %# generate a name for the new column(s) + dummy = cstrcat (repmat ('_', n, 1), ... + strjust (num2str (indc + (1:n).'), 'left')); + df._name{2}(indc + (1:n)) = cellstr (dummy); + df._over{2}(1, indc + (1:n)) = true; endif case 3 - if (n <= 0), return; endif - if (isempty(coltype)), - coltype = 1:df._cnt(2); + if (n <= 0) return; endif + if (isempty (coltype)), + coltype = 1:df._cnt(2); endif - dummy = max(n+cellfun(@length, df._rep(coltype))); - if (size(df._ridx, 2) < dummy), - df._ridx(:, end+1:dummy) = NA; + dummy = max (n+cellfun (@length, df._rep(coltype))); + if (size (df._ridx, 2) < dummy), + df._ridx(:, end+1:dummy) = NA; endif - for indi = coltype, - switch df._type{indi} - case {'char'} - if (isa(df._data{indi}, 'char')), - dummy = horzcat(df._data{indi}(:, df._rep{indi}), \ - {repmat(NA, df._cnt(1), 1)}); - else - dummy = df._data{indi}; - endif - case { 'double' } - dummy = horzcat(df._data{indi}(:, df._rep{indi}), \ - repmat(NA, df._cnt(1), 1)); - case { 'logical' } - %# there is no logical 'NA' -- fill empty elems with false - dummy = horzcat(df._data{indi}(:, df._rep{indi}), \ - repmat(false, df._cnt(1), 1)); - otherwise - dummy = cast(horzcat(df._data{indi}(:, df._rep{indi}), \ - repmat(NA, df._cnt(1), 1)), \ - df._type{indi}); - endswitch - df._data{indi} = dummy; - df._rep{indi} = [df._rep{indi} length(df._rep{indi})+ones(1, n)]; + for indi = (coltype) + switch df._type{indi} + case {'char'} + if (isa (df._data{indi}, 'char')), + dummy = horzcat (df._data{indi}(:, df._rep{indi}), \ + {repmat(NA, df._cnt(1), 1)}); + else + dummy = df._data{indi}; + endif + case {'double'} + dummy = horzcat (df._data{indi}(:, df._rep{indi}), \ + repmat (NA, df._cnt(1), 1)); + case {'logical'} + %# there is no logical 'NA' -- fill empty elems with false + dummy = horzcat (df._data{indi}(:, df._rep{indi}), \ + repmat (false, df._cnt(1), 1)); + otherwise + dummy = cast (horzcat (df._data{indi}(:, df._rep{indi}), \ + repmat (NA, df._cnt(1), 1)), \ + df._type{indi}); + endswitch + df._data{indi} = dummy; + df._rep{indi} = [df._rep{indi} length(df._rep{indi})+ones(1, n)]; endfor - df = df_thirddim(df); + df = df_thirddim (df); otherwise - error('Invalid dimension in df_pad'); + error ('Invalid dimension in df_pad'); endswitch -endfunction +endfunction
--- a/extra/dataframe/inst/@dataframe/private/df_strjust.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/private/df_strjust.m Sun Mar 11 20:53:31 2012 +0000 @@ -26,11 +26,11 @@ %# $Id$ %# - indi = size(a, 2) - size(b, 2); - if indi < 0 - a = horzcat(repmat(' ', size(a, 1), -indi), a); + indi = size (a, 2) - size (b, 2); + if (indi < 0) + a = horzcat (repmat (' ', size (a, 1), -indi), a); elseif indi > 0, - b = horzcat(repmat(' ', size(b, 1), indi), b); + b = horzcat (repmat (' ', size (b, 1), indi), b); endif endfunction
--- a/extra/dataframe/inst/@dataframe/private/df_strset.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/private/df_strset.m Sun Mar 11 20:53:31 2012 +0000 @@ -29,52 +29,52 @@ %# %# adjust x size, if required - if isnull(RHS), + if (isnull (RHS)) %# clearing - if isempty(S), - x = cell(0, 1); over = zeros(1, 0); + if (isempty (S)) + x = cell (0, 1); over = zeros (1, 0); return endif dummy = S; dummy(1).subs(2:end) = []; - over = builtin('subsasgn', over, dummy, true); + over = builtin ('subsasgn', over, dummy, true); else - if isempty(S), %# complete overwrite - if ischar(RHS), RHS = cellstr(RHS); endif - nrow = length(RHS); - if any(~over(nrow)), - warning('going to overwrite names'); + if (isempty (S)) %# complete overwrite + if (ischar (RHS)) RHS = cellstr (RHS); endif + nrow = length (RHS); + if (any(~over(nrow))) + warning ('going to overwrite names'); endif x(1:nrow) = RHS; over(1:nrow) = false; - if nrow < length(x), - x(nrow+1:end) = {pad}; + if (nrow < length (x)) + x(nrow+1:end) = {pad}; endif return else dummy = S(1); dummy.subs(2:end) = []; % keep first dim only - if any(~(builtin('subsref', over, dummy))); - warning('going to overwrite names'); + if (any (~builtin ('subsref', over, dummy))) + warning ('going to overwrite names'); endif - over = builtin('subsasgn', over, dummy, false); + over = builtin ('subsasgn', over, dummy, false); endif endif %# common part - if ischar(RHS) && length(S(1).subs) > 1, + if (ischar (RHS) && length (S(1).subs) > 1) %# partial accesses to a char array - dummy = char(x); - dummy = builtin('subsasgn', dummy, S, RHS); - if isempty(dummy), - x = cell(0, 1); over = zeros(1, 0); + dummy = char (x); + dummy = builtin ('subsasgn', dummy, S, RHS); + if (isempty(dummy)) + x = cell (0, 1); over = zeros (1, 0); return endif - if size(dummy, 1) == length(x), - x = cellstr(dummy); + if (size (dummy, 1) == length (x)) + x = cellstr (dummy); return endif %# partial clearing gone wrong ? retry RHS = { RHS }; endif - x = builtin('subsasgn', x, S, RHS); + x = builtin ('subsasgn', x, S, RHS); endfunction
--- a/extra/dataframe/inst/@dataframe/private/df_thirddim.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/private/df_thirddim.m Sun Mar 11 20:53:31 2012 +0000 @@ -29,10 +29,10 @@ %# %# sanity check - dummy = max(cellfun(@length, df._rep)); - if (dummy != 1), + dummy = max (cellfun (@length, df._rep)); + if (dummy ~= 1), df._cnt(3) = dummy; - elseif (length(df._cnt) > 2), + elseif (length (df._cnt) > 2), df._cnt = df._cnt(1:2); endif
--- a/extra/dataframe/inst/@dataframe/private/df_whole.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/private/df_whole.m Sun Mar 11 20:53:31 2012 +0000 @@ -27,25 +27,25 @@ %# $Id$ %# - inds = max(cellfun(@length, df._rep)); + inds = max (cellfun (@length, df._rep)); resu = df._data{1}(:, df._rep{1}); - if (inds > 1), - resu = reshape(resu, df._cnt(1), 1, []); - if (1 == size(resu, 3)), - resu = repmat(resu, [1 1 inds]); + if (inds > 1) + resu = reshape (resu, df._cnt(1), 1, []); + if (1 == size (resu, 3)) + resu = repmat (resu, [1 1 inds]); endif endif - if df._cnt(2) > 1, - resu = repmat(resu, [1 df._cnt(2)]); - for indi = 2:df._cnt(2), + if (df._cnt(2) > 1) + resu = repmat (resu, [1 df._cnt(2)]); + for indi = (2:df._cnt(2)) dummy = df._data{indi}(:, df._rep{indi}); - if (inds > 1), - dummy = reshape(dummy, df._cnt(1), 1, []); - if (1 == size(dummy, 3)), - dummy = repmat(dummy, [1 1 inds]); - endif + if (inds > 1) + dummy = reshape (dummy, df._cnt(1), 1, []); + if (1 == size (dummy, 3)), + dummy = repmat (dummy, [1 1 inds]); + endif endif resu(:, indi, :) = dummy; endfor
--- a/extra/dataframe/inst/@dataframe/prod.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/prod.m Sun Mar 11 20:53:31 2012 +0000 @@ -24,10 +24,10 @@ %# $Id$ %# - if !isa(df, 'dataframe'), + if (~isa (df, 'dataframe')) resu = []; return; endif - resu = df_mapper2(@prod, df, varargin{:}); + resu = df_mapper2 (@prod, df, varargin{:}); endfunction
--- a/extra/dataframe/inst/@dataframe/repmat.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/repmat.m Sun Mar 11 20:53:31 2012 +0000 @@ -24,42 +24,42 @@ %# $Id$ %# - resu = df; idx = horzcat(varargin{:}); + resu = df; idx = horzcat (varargin{:}); %# for the second dim, use either 1 either the 3rd one dummy = idx; - if (length(dummy) > 2), + if (length (dummy) > 2) dummy(2) = []; else dummy(2) = 1; endif %# operate on first dim - if (idx(1) > 1), - resu = df_mapper(@repmat, df, [idx(1) 1]); - if (!isempty(df._name{1})), - resu._name{1} = feval(@repmat, df._name{1}, [idx(1) 1]); - resu._over{1} = feval(@repmat, df._over{1}, [idx(1) 1]); + if (idx(1) > 1) + resu = df_mapper (@repmat, df, [idx(1) 1]); + if (~isempty (df._name{1})), + resu._name{1} = feval (@repmat, df._name{1}, [idx(1) 1]); + resu._over{1} = feval (@repmat, df._over{1}, [idx(1) 1]); endif resu._cnt(1) = resu._cnt(1) * idx(1); endif - if (dummy(2) > 1), - for indi = 1:resu._cnt(2), - resu._rep{indi} = feval(@repmat, resu._rep{indi}, [1 dummy(2)]); + if (dummy(2) > 1) + for indi = (1:resu._cnt(2)) + resu._rep{indi} = feval (@repmat, resu._rep{indi}, [1 dummy(2)]); endfor endif %# operate on ridx - resu._ridx = feval(@repmat, resu._ridx, idx); + resu._ridx = feval (@repmat, resu._ridx, idx); %# operate on second dim - if (length(idx) > 1 && idx(2) > 1), - resu._data = feval(@repmat, resu._data, [1 idx(2)]); - resu._name{2} = feval(@repmat, df._name{2}, [idx(2) 1]); - resu._over{2} = feval(@repmat, df._over{2}, [1 idx(2)]); - resu._type = feval(@repmat, df._type, [1 idx(2)]); + if (length (idx) > 1 && idx(2) > 1) + resu._data = feval (@repmat, resu._data, [1 idx(2)]); + resu._name{2} = feval (@repmat, df._name{2}, [idx(2) 1]); + resu._over{2} = feval (@repmat, df._over{2}, [1 idx(2)]); + resu._type = feval (@repmat, df._type, [1 idx(2)]); resu._cnt(2) = resu._cnt(2) * idx(2); endif - resu = df_thirddim(resu); + resu = df_thirddim (resu); endfunction
--- a/extra/dataframe/inst/@dataframe/reshape.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/reshape.m Sun Mar 11 20:53:31 2012 +0000 @@ -25,9 +25,9 @@ %# $Id$ %# - dummy = horzcat(varargin{:}); - if (any(dummy != df._cnt)), - error('Function not yet implemented on dataframe'); + dummy = horzcat (varargin{:}); + if (any (dummy ~= df._cnt)), + error ('Function not yet implemented on dataframe'); else resu = df; %# blank operation endif
--- a/extra/dataframe/inst/@dataframe/size.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/size.m Sun Mar 11 20:53:31 2012 +0000 @@ -29,60 +29,60 @@ switch nargin case 1 switch nargout - case {0, 1} - varargout{1} = df._cnt; - case {2} - varargout{1} = df._cnt(1); - if (1 == df._cnt(2) && length(df._cnt) > 2), - varargout{2} = df._cnt(3); - else - varargout{2} = df._cnt(2); - endif - case {3} - varargout{1:2} = df._cnt(1:2); - if 2==length(df._cnt), - varargout{3} = 1; - else - varargout{3} = df._cnt(3); - endif - otherwise - error(print_usage()); + case {0, 1} + varargout{1} = df._cnt; + case {2} + varargout{1} = df._cnt(1); + if (1 == df._cnt(2) && length (df._cnt) > 2) + varargout{2} = df._cnt(3); + else + varargout{2} = df._cnt(2); + endif + case {3} + varargout{1:2} = df._cnt(1:2); + if (2 == length (df._cnt)) + varargout{3} = 1; + else + varargout{3} = df._cnt(3); + endif + otherwise + error (print_usage ()); endswitch case 2 switch nargout - case {0 1} - varargout{1} = df._cnt; - try - varargout{1} = varargout{1}(varargin{1}); - catch - error(print_usage()); - end_try_catch - otherwise - error(print_usage()); + case {0 1} + varargout{1} = df._cnt; + try + varargout{1} = varargout{1}(varargin{1}); + catch + error (print_usage ()); + end_try_catch + otherwise + error (print_usage ()); endswitch case 3 switch nargout - case {0 1} - if (length(df._cnt) < 3), - varargout{1} = 1; - else - varargout{1} = df._cnt; - endif - try - varargout{1} = varargout{1}(varargin{1}); - catch - error(print_usage()); - end_try_catch - otherwise - error(print_usage()); + case {0 1} + if (length (df._cnt) < 3), + varargout{1} = 1; + else + varargout{1} = df._cnt; + endif + try + varargout{1} = varargout{1}(varargin{1}); + catch + error (print_usage ()); + end_try_catch + otherwise + error (print_usage ()); endswitch otherwise - error(print_usage()); + error (print_usage ()); endswitch endfunction function usage = print_usage() - usage = strcat('Invalid call to size. Correct usage is: ', ' ', ... - '-- Overloaded Function: size (A, N)'); + usage = strcat ('Invalid call to size. Correct usage is: ', ' ', ... + '-- Overloaded Function: size (A, N)'); endfunction
--- a/extra/dataframe/inst/@dataframe/sort.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/sort.m Sun Mar 11 20:53:31 2012 +0000 @@ -75,77 +75,77 @@ %# $Id$ %# - if !isa(df, 'dataframe'), + if (~isa (df, 'dataframe')) resu = []; return; endif dim = []; mode = []; vout= varargin; - indi = 1; while indi <= length(varargin) - if isnumeric(varargin{indi}), - if !isempty(dim), - print_usage('@dataframe/sort'); - resu = []; - return + indi = 1; while (indi <= length (varargin)) + if (isnumeric (varargin{indi})) + if (~isempty (dim)) + print_usage ('@dataframe/sort'); + resu = []; + return else - dim = varargin{indi}; - if 3 == dim, vout(indi) = 2; endif + dim = varargin{indi}; + if (3 == dim) vout(indi) = 2; endif endif else - if !isempty(mode), - print_usage('@dataframe/sort'); - resu = []; - return + if (~isempty (mode)) + print_usage ('@dataframe/sort'); + resu = []; + return else - sort = varargin{indi}; + sort = varargin{indi}; endif endif indi = indi + 1; endwhile; - if isempty(dim), dim = 1; endif; + if (isempty (dim)) dim = 1; endif; %# pre-assignation - resu = struct(df); + resu = struct (df); switch(dim) - case {1}, - for indi = 1:resu._cnt(2), - [resu._data{indi}, idx(:, indi, :)] = sort\ - (resu._data{indi}(:, resu._rep{indi}), varargin{:}); - resu._data{indi} = squeeze(resu._data{indi}); - resu._rep{indi} = 1:size(resu._data{indi}, 2); + case {1} + for indi = (1:resu._cnt(2)) + [resu._data{indi}, idx(:, indi, :)] = sort \ + (resu._data{indi}(:, resu._rep{indi}), varargin{:}); + resu._data{indi} = squeeze (resu._data{indi}); + resu._rep{indi} = 1:size(resu._data{indi}, 2); endfor - if (all([1 == size(idx, 2) 1 == size(idx, 3)])), - if (size(resu._ridx, 1) == resu._cnt(1)), - resu._ridx = resu._ridx(idx, :); - endif - if (!isempty(resu._name{1, 1})), - resu._name{1, 1} = resu._name{1, 1}(idx); - resu._over{1, 1} = resu._over{1, 1}(idx); - endif + if (all ([1 == size(idx, 2) 1 == size(idx, 3)])) + if (size (resu._ridx, 1) == resu._cnt(1)) + resu._ridx = resu._ridx(idx, :); + endif + if (~isempty (resu._name{1, 1})) + resu._name{1, 1} = resu._name{1, 1}(idx); + resu._over{1, 1} = resu._over{1, 1}(idx); + endif else - %# data where mixed - resu._ridx = idx; - resu._name{1, 1} = []; resu._over{1, 1} = []; + %# data where mixed + resu._ridx = idx; + resu._name{1, 1} = []; resu._over{1, 1} = []; endif - case {2}, - error('Operation not implemented'); - case {3}, - for indi = 1:resu._cnt(2), - [resu._data{1, indi}, idx(:, indi)] = sort(resu._data{1, indi}, vout(:)); + case {2} + error ('Operation not implemented'); + case {3} + for indi = (1:resu._cnt(2)) + [resu._data{1, indi}, idx(:, indi)] = sort (resu._data{1, indi}, vout(:)); endfor otherwise - error("Invalid dimension %d", dim); + error ("Invalid dimension %d", dim); endswitch - dummy = dbstack(); - if (any(strmatch('quantile', {dummy.name}))), - resu = df_whole(resu); + dummy = dbstack (); + if (any (strmatch ('quantile', {dummy.name}))) + resu = df_whole (resu); else - resu = dataframe(resu); + resu = dataframe (resu); endif endfunction
--- a/extra/dataframe/inst/@dataframe/subsasgn.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/subsasgn.m Sun Mar 11 20:53:31 2012 +0000 @@ -47,7 +47,7 @@ return case "rowidx" - if (1 == length(S)) + if (1 == length (S)) df._ridx = RHS; else df._ridx = feval (@subsasgn, df._ridx, S(2:end), RHS); @@ -88,7 +88,7 @@ return case "source" - if (length(S) > 1) + if (length (S) > 1) df._src = feval (@subsasgn, df._src, S(2:end), RHS); else df._src = RHS; @@ -96,7 +96,7 @@ return case "comment" - if (length(S) > 1) + if (length (S) > 1) df._cmt = feval (@subsasgn, df._cmt, S(2:end), RHS); else df._cmt = RHS; @@ -110,7 +110,7 @@ %# translate the name to column [indc, ncol] = df_name2idx (df._name{2}, S(1).subs, \ df._cnt(2), 'column', true); - if (isempty(indc)) + if (isempty (indc)) %# dynamic allocation df = df_pad (df, 2, 1, class (RHS)); indc = df._cnt(2); ncol = 1; @@ -119,7 +119,7 @@ df._over{2}(end) = false; endif - if (length(S) > 1) + if (length (S) > 1) if (1 == length (S(2).subs)), %# add column reference S(2).subs{2} = indc; else
--- a/extra/dataframe/inst/@dataframe/subsref.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/subsref.m Sun Mar 11 20:53:31 2012 +0000 @@ -47,7 +47,7 @@ asked_output_type = "array"; asked_output_format = S(2).subs; S = S(3:end); else - indi = strmatch(S(1).subs, 'array'); + indi = strmatch (S(1).subs, 'array'); if (~isempty (indi)) asked_output_type = "array"; S = S(2:end); @@ -65,20 +65,20 @@ resu = df; return; endif else - indi = strmatch(S(1).subs, 'cell'); + indi = strmatch (S(1).subs, 'cell'); if (~isempty (indi)) asked_output_type = S(1).subs; S = S(2:end); else %# access as a pseudo-struct - resu = struct(df); %# avoid recursive calls - if (1 == strfind(S(1).subs, '_')) %# its an internal field name + resu = struct (df); %# avoid recursive calls + if (1 == strfind (S(1).subs, '_')) %# its an internal field name %# FIXME: this should only be called from class members and friends %# FIXME -- in case many columns are asked, horzcat them resu = horzcat (feval (@subsref, resu, S)); else %# direct access through the exact column name - indi = strmatch(S(1).subs, resu._name{2}, "exact"); + indi = strmatch (S(1).subs, resu._name{2}, "exact"); if (~isempty (indi)) resu = df._data{indi}; %# extract colum; if (strcmp (df._type{indi}, 'char') \ @@ -89,7 +89,7 @@ dummy = S(2:end); S = S(1); switch dummy(1).type case '()' - if (isa(dummy(1).subs{1}, "char")) + if (isa (dummy(1).subs{1}, "char")) [indr, nrow, dummy(1).subs{1}] = \ df_name2idx(df._name{1}, dummy(1).subs{1}, df._cnt(1), 'row'); endif @@ -131,32 +131,32 @@ if (isempty (dummy)) resu = dataframe([]); else - if (!strcmp (dummy(1).type, "()")) + if (~strcmp (dummy(1).type, "()")) error ("Bogus constructor call"); endif - resu = dataframe(dummy(1).subs{:}); + resu = dataframe (dummy(1).subs{:}); endif if (length (dummy) > 1) - resu = subsref(resu, dummy(2:end)); + resu = subsref (resu, dummy(2:end)); endif return; otherwise error ("Unknown column name: %s", S(1).subs); endswitch - if (!isempty (dummy)) - if ~further_deref, + if (~isempty (dummy)) + if (~further_deref) error ("Invalid sub-dereferencing"); endif - if (isa(dummy(1).subs{1}, "char")) + if (isa (dummy(1).subs{1}, "char")) [indc, ncol, dummy(1).subs{1}] = \ - df_name2idx(df._name{2}, dummy(1).subs{1}, \ - df._cnt(2), 'column'); + df_name2idx (df._name{2}, dummy(1).subs{1}, \ + df._cnt(2), 'column'); if (isempty (indc)) %# should be already catched inside df_name2idx error ("Unknown column name: %s", dummy(1).subs{1}); endif endif - if (!strcmp (dummy(1).type, '()')) + if (~strcmp (dummy(1).type, '()')) error ("Invalid internal field name sub-access, use () instead"); endif endif @@ -165,7 +165,7 @@ S = [S dummy]; %# endif resu = feval(@subsref, resu, S); - if (!isempty (postop)) + if (~isempty (postop)) resu = postop(resu); endif endif @@ -180,22 +180,22 @@ %# disp('line 103 '); keyboard IsFirst = true; - while 1, %# avoid recursive calls on dataframe sub-accesses + while (1) %# avoid recursive calls on dataframe sub-accesses %# a priori, performs whole accesses nrow = df._cnt(1); indr = 1:nrow; ncol = df._cnt(2); indc = 1:ncol; %# linear indexes - [fullindr, fullindc, fullinds, onedimidx] = deal([]); + [fullindr, fullindc, fullinds, onedimidx] = deal ([]); %# iterate over S, sort out strange constructs as x()()(1:10, 1:4) - while length (S) > 0, + while (length (S) > 0) if (strcmp (S(1).type, '{}')) - if (!IsFirst || !isempty (asked_output_format)) + if (~IsFirst || ~isempty (asked_output_format)) error ("Illegal dataframe dereferencing"); endif - [asked_output_type, asked_output_format] = deal('cell'); - elseif (!strcmp (S(1).type, '()')) + [asked_output_type, asked_output_format] = deal ('cell'); + elseif (~strcmp (S(1).type, '()')) %# disp(S); keyboard error ("Illegal dataframe dereferencing"); endif @@ -225,12 +225,12 @@ error ('subsref: second dimension empty ???'); endif [indr, nrow, S(1).subs{1}] = \ - df_name2idx(df._name{1}, S(1).subs{1}, df._cnt(1), 'row'); - if (!isa(indr, 'char') && max (indr) > df._cnt(1)) + df_name2idx (df._name{1}, S(1).subs{1}, df._cnt(1), 'row'); + if (~isa(indr, 'char') && max (indr) > df._cnt(1)) error ("Accessing dataframe past end of lines"); endif [indc, ncol, S(1).subs{2}] = \ - df_name2idx(df._name{2}, S(1).subs{2}, df._cnt(2), 'column'); + df_name2idx (df._name{2}, S(1).subs{2}, df._cnt(2), 'column'); if (max (indc) > df._cnt(2)) %# is it a two index access of a 3D structure ? if (length (df._cnt) > 2) @@ -266,7 +266,7 @@ return; endif - if (!isempty (fullindr)) + if (~isempty (fullindr)) %# convert linear index to subscripts if (length (df._cnt) <= 2) [fullindr, fullindc] = ind2sub (df._cnt, S(1).subs{1}); @@ -280,15 +280,15 @@ indr = unique (fullindr); nrow = length (indr); %# determine on which columns we'll iterate indc = unique (fullindc)(:).'; ncol = length (indc); - if (!isempty (asked_output_type) && ncol > 1) + if (~isempty (asked_output_type) && ncol > 1) %# verify that the extracted values form a square matrix - dummy = zeros(indr(end), indc(end)); + dummy = zeros (indr(end), indc(end)); for indi = (1:ncol) indj = find (fullindc == indc(indi)); dummy(fullindr(indj), indc(indi)) = 1; endfor dummy = dummy(indr(1):indr(end), indc(1):indc(end)); - if (any (any (dummy!= 1))) + if (any (any (dummy~= 1))) error ("Vector-like selection is not rectangular for the asked output type"); else fullindr = []; fullindc = []; @@ -306,14 +306,14 @@ if (isempty (asked_output_type)) output_type = class (df); %# force df output else - if (!strcmp (asked_output_type, "array") \ - || !isempty (asked_output_format)) + if (~strcmp (asked_output_type, "array") \ + || ~isempty (asked_output_format)) %# override the class of the return value output_type = asked_output_type; else %# can the data be merged ? output_type = df._data{indc(1)}(1); - dummy = isnumeric(df._data{indc(1)}); + dummy = isnumeric (df._data{indc(1)}); for indi = (2:ncol) dummy = dummy & isnumeric (df._data{indc(indi)}); if (~strcmp (class (output_type), df._type{indc(indi)})) @@ -334,37 +334,37 @@ endif endif - if (any(strcmp ({output_type, asked_output_type}, class (df)))) - if (!isempty (S) && (1 == length (S(1).subs))) + if (any (strcmp ({output_type, asked_output_type}, class (df)))) + if (~isempty (S) && (1 == length (S(1).subs))) %# is the selection index vector-like ? - if ((isnumeric(S(1).subs{1}) && isvector(S(1).subs{1}) && + if ((isnumeric(S(1).subs{1}) && isvector (S(1).subs{1}) && df._cnt(1) > 1) && isempty (asked_output_type)) %# in the case of vector input, favor array output - [asked_output_type, output_type] = deal("array"); + [asked_output_type, output_type] = deal ("array"); endif endif endif indt = {}; %# in case we have to mix matrix of different width - if (!isempty (fullinds)) + if (~isempty (fullinds)) inds = unique (fullinds); nseq = length (inds); indt(1, 1:df._cnt(2)) = inds; else inds = 1; indt(1, 1:df._cnt(2)) = inds; nseq = 1; - if (isempty (S) || all(cellfun('isclass', S(1).subs, 'char'))) + if (isempty (S) || all (cellfun ('isclass', S(1).subs, 'char'))) inds = ':'; indt(1, 1:df._cnt(2)) = inds; - nseq = max (cellfun(@length, df._rep(indc))); + nseq = max (cellfun (@length, df._rep(indc))); else if (length (S(1).subs) > 1) %# access-as-matrix if (length (S(1).subs) > 2) inds = S(1).subs{3}; if (isa(inds, 'char')) - nseq = max (cellfun(@length, df._rep(indc))); + nseq = max (cellfun (@length, df._rep(indc))); indt(1, 1:df._cnt(2)) = inds; else %# generate a specific index for each column nseq = length (inds); - dummy = cellfun(@length, df._rep(indc)); + dummy = cellfun (@length, df._rep(indc)); indt(1, 1:df._cnt(2)) = inds; indt(1==dummy) = 1; endif @@ -387,7 +387,7 @@ resu._over{2}(1, indi) = df._over{2}(indc(indi)); resu._type{indi} = df._type{indc(indi)}; endfor - if (!isempty (df._ridx) && size (df._ridx, 2) >= inds) + if (~isempty (df._ridx) && size (df._ridx, 2) >= inds) resu._ridx = df._ridx(indr, inds); endif if (length (df._name{1}) >= max (indr)) @@ -411,7 +411,7 @@ else resu._name{2}(indi)= ["X" num2str(indi)]; resu._over{2}(indi)= true; - resu._data{indi} = squeeze(dummy(:, indi, :)); + resu._data{indi} = squeeze (dummy(:, indi, :)); resu._type{indi} = class (dummy(1, indi, 1)); resu._rep{indi} = 1:size (resu._data{indi}, 2); endif @@ -421,7 +421,7 @@ else resu._ridx = df._ridx; endif - if (!isempty (resu._ridx)) + if (~isempty (resu._ridx)) if (size (resu._ridx, 2) > 1) resu._ridx = resu._ridx(indr, indc); else @@ -432,7 +432,7 @@ %# to be verified : keyboard resu._src = df._src; resu._cmt = df._cmt; - resu = df_thirddim(resu); + resu = df_thirddim (resu); if (length (S) > 1) %# perform further access, if required df = resu; S = S(2:end); %# avoid recursive calls @@ -478,14 +478,14 @@ if (~strcmp (S(2).type, '()')) error ("Illegal dataframe-as-cell sub-dereferencing"); endif - if (!isempty (asked_output_format)) - resu = feval(@subsref, resu, S(2:end)); + if (~isempty (asked_output_format)) + resu = feval (@subsref, resu, S(2:end)); else - if (length (S(2).subs) != 1) + if (length (S(2).subs) ~= 1) %# normal, two-dimensionnal access apply the selection on the %# zone containing the data dummy = S; - if (!isempty (dummy(2).subs)) + if (~isempty (dummy(2).subs)) dummy(2).subs{2} = ':'; endif resuf = cat (2, \ @@ -500,7 +500,7 @@ \ ); dummy = S; - if (!isempty (dummy(2).subs)) + if (~isempty (dummy(2).subs)) dummy(2).subs{1} = [1 2]; endif resuf = cat(1, \ @@ -514,8 +514,8 @@ else %# one dimensionnal access of the whole 2D cell array -- you %# asked it, you got it - resu = feval(@subsref, resu(:), S(2:end)); - if (!isa(S(2).subs{1}, 'char') \ + resu = feval (@subsref, resu(:), S(2:end)); + if (~isa (S(2).subs{1}, 'char') \ && size (S(2).subs{1}, 2) > 1) resu = resu.'; endif @@ -523,7 +523,7 @@ endif elseif (1 == length (S(1).subs)) resu = resu(:); - if (!isa(S(1).subs{1}, 'char') \ + if (~isa(S(1).subs{1}, 'char') \ && size (S(1).subs{1}, 2) > 1) resu = resu.'; endif @@ -540,12 +540,12 @@ %# disp('line 403 '); keyboard if (isempty (S) || isempty (S(1).subs) || \ length (S(1).subs) > 1 || \ - (isnumeric(S(1).subs{1}) && !isvector(S(1).subs{1}))) + (isnumeric (S(1).subs{1}) && ~isvector(S(1).subs{1}))) %# access-as-matrix - df = struct(df); %# remove the magic, avoid recursive calls + df = struct (df); %# remove the magic, avoid recursive calls if (isempty (fullindr)) %# two index access if (~isempty (asked_output_format)) %# force a conversion - if (strmatch(asked_output_format, 'cell')) + if (strmatch (asked_output_format, 'cell')) extractfunc = @(x) mat2cell\ (df._data{indc(x)}(indr, df._rep{indc(x)}(inds)), \ ones (nrow, 1)); @@ -596,8 +596,8 @@ resu = dummy; endif endif - if (!isempty (S) && 2 == length (S(1).subs) \ - && all(cellfun('isclass', S(1).subs, 'char'))) + if (~isempty (S) && 2 == length (S(1).subs) \ + && all (cellfun ('isclass', S(1).subs, 'char'))) resu = reshape (resu, nrow, ncol*nseq); endif else %# one index access @@ -632,7 +632,7 @@ endif else %# access-as-vector %# disp('line 548 '); keyboard - if (!isempty (fullindr)) + if (~isempty (fullindr)) switch df._type{indc(1)} case {'char'} resu = df._data{indc(1)}(fullindr(1), \ @@ -659,7 +659,7 @@ else %# using the (:) operator resu = df_whole(df)(:); endif - if (!isa(S(1).subs{1}, 'char') \ + if (~isa (S(1).subs{1}, 'char') \ && size (S(1).subs{1}, 2) > 1) resu = resu.'; endif
--- a/extra/dataframe/inst/@dataframe/sum.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/sum.m Sun Mar 11 20:53:31 2012 +0000 @@ -24,10 +24,10 @@ %# $Id$ %# - if !isa(df, 'dataframe'), + if (~isa (df, 'dataframe')) resu = []; return; endif - resu = df_mapper2(@sum, df, varargin{:}); + resu = df_mapper2 (@sum, df, varargin{:}); endfunction
--- a/extra/dataframe/inst/@dataframe/summary.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/summary.m Sun Mar 11 20:53:31 2012 +0000 @@ -31,38 +31,38 @@ dummy = df._type; resu = []; - for indi = 1:length(dummy), + for indi = (1:length (dummy)) switch dummy{indi} case {'char' 'factor'} - [sval, sidxi, sidxj] = unique(df._data{:, indi}); - %# compute their occurences - sidxj = hist(sidxj, min(sidxj):max(sidxj)); - %# generate a column with unique values - resuR = strjust(char(regexp(disp(sval), '\S.*', 'match', ... - 'dotexceptnewline')), 'right'); - resuR = horzcat(resuR, repmat(':', size(resuR, 1), 1), - strjust(char(regexp(disp(sidxj.'), '\b.*', 'match', ... - 'dotexceptnewline')), ... - 'right')); - %# now put the name above all - resuR = strjust([deblank(df._name{1, 2}(indi, :)); resuR], 'right'); - resuR = horzcat(resuR, repmat(' ', size(resuR, 1), 1)); - resu = horzcat_pad(resu, resuR); - + [sval, sidxi, sidxj] = unique (df._data{:, indi}); + %# compute their occurences + sidxj = hist (sidxj, min(sidxj):max(sidxj)); + %# generate a column with unique values + resuR = strjust (char (regexp (disp (sval), '\S.*', 'match', ... + 'dotexceptnewline')), 'right'); + resuR = horzcat (resuR, repmat (':', size(resuR, 1), 1), + strjust (char (regexp (disp (sidxj.'), '\b.*', 'match', ... + 'dotexceptnewline')), ... + 'right')); + %# now put the name above all + resuR = strjust ([deblank(df._name{1, 2}(indi, :)); resuR], 'right'); + resuR = horzcat (resuR, repmat (' ', size (resuR, 1), 1)); + resu = horzcat_pad (resu, resuR); + otherwise - s = statistics(df._data{:, indi}); - s = s([1:3 6 4:5]); - %# generate a column with name and fields name - resuR = strjust([deblank(df._name{1, 2}{indi, :}); - "Min. :"; "1st Qu.:"; - "Median :"; "Mean :"; - "3rd Qu.:"; "Max. :"], 'right'); - %# generate a column with a blank line and the values - resuR = horzcat(resuR, repmat(' ', size(resuR, 1), 1), - strjust(char(' ', regexp(disp(s), '\S.*', 'match', ... - 'dotexceptnewline')), 'right'),... - repmat(' ', size(resuR, 1), 1)); - resu = horzcat_pad(resu, resuR); + s = statistics (df._data{:, indi}); + s = s([1:3 6 4:5]); + %# generate a column with name and fields name + resuR = strjust ([deblank(df._name{1, 2}{indi, :}); + "Min. :"; "1st Qu.:"; + "Median :"; "Mean :"; + "3rd Qu.:"; "Max. :"], 'right'); + %# generate a column with a blank line and the values + resuR = horzcat (resuR, repmat (' ', size(resuR, 1), 1), + strjust (char (' ', regexp (disp(s), '\S.*', 'match', ... + 'dotexceptnewline')), 'right'),... + repmat (' ', size(resuR, 1), 1)); + resu = horzcat_pad (resu, resuR); endswitch endfor @@ -72,15 +72,15 @@ function resu = horzcat_pad(A, B) %# small auxiliary function to cat horizontally tables of different height - dx = size(A, 1) - size(B, 1); + dx = size (A, 1) - size (B, 1); - if dx < 0, + if (dx < 0) %# pad A - A = strvcat(A, repmat(' ', -dx, size(A, 2))); - elseif dx > 0 - B = strvcat(B, repmat(' ', dx, size(B, 2))); + A = strvcat (A, repmat (' ', -dx, size(A, 2))); + elseif (dx > 0) + B = strvcat (B, repmat (' ', dx, size(B, 2))); endif - resu = horzcat(A, B); + resu = horzcat (A, B); endfunction
--- a/extra/dataframe/inst/@dataframe/sumsq.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/sumsq.m Sun Mar 11 20:53:31 2012 +0000 @@ -24,7 +24,7 @@ %# $Id$ %# - if !isa(df, 'dataframe'), + if (~isa (df, 'dataframe')) resu = []; return; endif
--- a/extra/dataframe/inst/@dataframe/vertcat.m Sun Mar 11 20:34:47 2012 +0000 +++ b/extra/dataframe/inst/@dataframe/vertcat.m Sun Mar 11 20:53:31 2012 +0000 @@ -25,10 +25,10 @@ %# %# do the conversion now, in order not to loose inputnames - for indi = 1:length(varargin), - varargin{indi} = dataframe(varargin{indi}, 'colnames', inputname(1+indi));, + for indi = (1:length (varargin)) + varargin{indi} = dataframe (varargin{indi}, 'colnames', inputname(1+indi));, endfor - resu = cat(1, df, varargin{:}); + resu = cat (1, df, varargin{:}); endfunction