From: <cde...@us...> - 2010-12-08 11:30:22
|
Revision: 7996 http://octave.svn.sourceforge.net/octave/?rev=7996&view=rev Author: cdemills Date: 2010-12-08 11:30:15 +0000 (Wed, 08 Dec 2010) Log Message: ----------- Fixed a few issues when the dataframe was initialised from a 3D array Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/find.m trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_mapper2.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_pad.m trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/find.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/find.m 2010-12-08 09:24:23 UTC (rev 7995) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/find.m 2010-12-08 11:30:15 UTC (rev 7996) @@ -29,8 +29,9 @@ resu = []; mz = max(cellfun(@length, df._rep)); for indc = 1:df._cnt(2), [indr, inds] = feval(@find, df._data{indc}(:, df._rep{indc})); - resu = [resu; sub2ind([df._cnt(1:2) mz], indr, \ - repmat(indc, [length(indr) 1]), inds)]; + %# 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); case 2 Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m 2010-12-08 09:24:23 UTC (rev 7995) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m 2010-12-08 11:30:15 UTC (rev 7996) @@ -24,6 +24,8 @@ %# $Id$ %# - resu = df_mapper2(@permute, df, varargin{:}); + %# resu = df_mapper2(@permute, df, varargin{:}); + resu = permute(df_whole(df), varargin{:}); + endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_mapper2.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_mapper2.m 2010-12-08 09:24:23 UTC (rev 7995) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_mapper2.m 2010-12-08 11:30:15 UTC (rev 7996) @@ -30,10 +30,19 @@ dim = 1; resu = []; vout = varargin; - if (!isempty(varargin) && isnumeric(varargin{1})), - dim = varargin{1}; - %# the "third" dim is the second on stored data - if 3 == dim, vout(1) = 2; endif + %# 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 + endif + break; + endwhile endif switch(dim) Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_pad.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_pad.m 2010-12-08 09:24:23 UTC (rev 7995) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_pad.m 2010-12-08 11:30:15 UTC (rev 7996) @@ -146,9 +146,13 @@ 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(horizcat(df._data{indi}(:, df._rep{indi}), \ - repmat(NA, df._cnt(1), 1)), \ + dummy = cast(horzcat(df._data{indi}(:, df._rep{indi}), \ + repmat(NA, df._cnt(1), 1)), \ df._type{indi}); endswitch df._data{indi} = dummy; Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m 2010-12-08 09:24:23 UTC (rev 7995) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m 2010-12-08 11:30:15 UTC (rev 7996) @@ -219,7 +219,17 @@ [indc, ncol, S(1).subs{2}] = \ df_name2idx(df._name{2}, S(1).subs{2}, df._cnt(2), 'column'); if (max(indc) > df._cnt(2)), - error("Accessing dataframe past end of columns"); + %# is it a two index access of a 3D structure ? + if (length(df._cnt) > 2), + [fullindc, fullinds] = ind2sub(df._cnt(2:3), indc); + if (fullindc <= df._cnt(2)), + indc = fullindc; inds = fullinds; + endif + endif + %# retest + if (max(indc) > df._cnt(2)), + error("Accessing dataframe past end of columns"); + endif endif else %# one single dim -- probably something like df(:), df(A), ... This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cde...@us...> - 2010-12-08 14:49:19
|
Revision: 7997 http://octave.svn.sourceforge.net/octave/?rev=7997&view=rev Author: cdemills Date: 2010-12-08 14:49:12 +0000 (Wed, 08 Dec 2010) Log Message: ----------- Implemented the permute() operation Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_pad.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m 2010-12-08 11:30:15 UTC (rev 7996) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m 2010-12-08 14:49:12 UTC (rev 7997) @@ -117,9 +117,10 @@ resu = []; if (!isempty(df._ridx)), for ind1 = 1:size(df._ridx, 2), - if (1 == size(df._ridx, 3)) && (any(!isna(df._ridx(:, ind1)))), + if (1 == size(df._ridx, 3)) && \ + (any(!isna(df._ridx(1:df._cnt(1), ind1)))), dummy{2, 1} = [sprintf("_%d", ind1) ; "Nr"]; - dummy{3, 1} = disp(df._ridx(:, ind1)); + dummy{3, 1} = disp(df._ridx(1:df._cnt(1), ind1)); indi = regexp(dummy{3, 1}, '\b.*\b', 'match', 'dotexceptnewline'); if isempty(resu), resu = strjust(char(dummy{2, 1}, indi), 'right'); @@ -129,9 +130,9 @@ endif else for ind2 = 1:size(df._ridx, 3), - if (any(!isna(df._ridx(:, 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(:, ind1, ind2)); + dummy{3, 1} = disp(df._ridx(1:df._cnt(1), ind1, ind2)); indi = regexp(dummy{3, 1}, '\b.*\b', 'match', 'dotexceptnewline'); if isempty(resu), resu = strjust(char(dummy{2, 1}, indi), 'right'); Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m 2010-12-08 11:30:15 UTC (rev 7996) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m 2010-12-08 14:49:12 UTC (rev 7997) @@ -1,4 +1,4 @@ -function resu = permute(df, varargin) +function resu = permute(df, perm) %% Copyright (C) 2009-2010 Pascal Dupuis <Pas...@uc...> %% @@ -26,6 +26,85 @@ %# resu = df_mapper2(@permute, df, varargin{:}); - resu = permute(df_whole(df), varargin{:}); + resu = dataframe([]); + resu._cnt = df._cnt(perm); + if (ndims(df._ridx) < 3), + resu._ridx = permute(df._ridx, [min(perm(1), 2) min(perm(2:3))]); + else + resu._ridx = permute(df._ridx, perm); + endif + + if (perm(1) > 1), + resu._name{1} = df._name{2}; + resu._over{1} = df._over{2}; + else + resu._name{1} = df._name{1}; + resu._over{1} = df._over{1}; + endif + + if (isempty(resu._name{1})), + indc = 0; + else + indc = length(resu._name{1}); + endif + indi = resu._cnt(1) - indc; + 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); + resu._over{1}(1, indc + (1:indi)) = true; + endif + + if (perm(2) > 1), + resu._name{2} = df._name{2}; + resu._over{2} = df._over{2}; + else + resu._name{2} = df._name{1}; + resu._over{2} = df._over{1}; + endif + + if (isempty(resu._name{2})), + indc = 0; + else + indc = length(resu._name{2}); + endif + indi = resu._cnt(2) - indc; + 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); + resu._over{2}(1, indc + (1:indi)) = true; + endif + + 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); + endfor + else %# 2 == perm(2) + 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}; + endfor + endif + endif + + resu.src = df._src; + resu.cmt = df._cmt; + endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_pad.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_pad.m 2010-12-08 11:30:15 UTC (rev 7996) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_pad.m 2010-12-08 14:49:12 UTC (rev 7997) @@ -32,15 +32,15 @@ switch dim case 1 - if !isempty(df._name{1}), - if length(df._name{1}) < df._cnt(1)+n, + 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), + if (isempty(df._ridx)), dummy = (1:n)(:); else dummy = vertcat(df._ridx, repmat(size(df._ridx, 1)+(1:n)(:), ... @@ -50,7 +50,7 @@ %# 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, + if (neff > 0), m = size(df._data{indi}, 2); switch df._type{indi} case {'char'} @@ -69,12 +69,12 @@ case 2 %# create new columns - if isempty(coltype) + if (isempty(coltype)) error("df_pad: dim equals 2, and coltype undefined"); endif - if length(n) > 1, %#second value is an offset + if (length(n) > 1), %#second value is an offset indc = n(2); n = n(1); - if indc < df._cnt(2), + 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); @@ -93,8 +93,8 @@ %# 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, + if (!isa(coltype, 'cell')), coltype = {coltype}; endif + if (isscalar(coltype) && n > 1), coltype = repmat(coltype, 1, n); endif for indi = (1:n), @@ -114,10 +114,10 @@ df._type{indc+indi} = coltype{indi}; endfor - if size(df._data, 2) > df._cnt(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), + 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')); @@ -131,13 +131,13 @@ coltype = 1:df._cnt(2); endif dummy = max(n+cellfun(@length, df._rep(coltype))); - if size(df._ridx, 2) < dummy, + 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'), + if (isa(df._data{indi}, 'char')), dummy = horzcat(df._data{indi}(:, df._rep{indi}), \ {repmat(NA, df._cnt(1), 1)}); else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cde...@us...> - 2010-12-08 17:45:37
|
Revision: 8000 http://octave.svn.sourceforge.net/octave/?rev=8000&view=rev Author: cdemills Date: 2010-12-08 17:45:30 +0000 (Wed, 08 Dec 2010) Log Message: ----------- WIP Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m trunk/octave-forge/extra/dataframe/inst/@dataframe/subsindex.m trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m 2010-12-08 17:08:30 UTC (rev 7999) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m 2010-12-08 17:45:30 UTC (rev 8000) @@ -143,8 +143,10 @@ df._cnt(2), 'column'); else mz = max(cellfun(@length, df._rep)); - [indr, indc, inds] = ind2sub([df._cnt(1:2) mz], indr); - ncol = length(unique(indc)); + [fullindr, fullindc, fullinds] = ind2sub([df._cnt(1:2) mz], indr); + indr = unique(fullindr); indc = unique(fullindc); + inds = unique(fullinds); + ncol = length(indc); S(1).subs{1} = indr; S(1).subs{2} = indc; if (any(inds > 1)), S(1).subs{3} = inds; @@ -481,10 +483,19 @@ %# skip second dim and copy data S.subs(2) = []; Sorig = S; for indi = 1:length(indc), - [df, S] = df_cow(df, S, indc(indi)); + %try + [df, S] = df_cow(df, S, indc(indi)); + # catch + # keyboard + # error(lasterr()); + # end_try_catch if (strcmp(df._type(indc(indi)), RHS._type(indi))), + try df._data{indc(indi)} = feval(@subsasgn, df._data{indc(indi)}, S, \ RHS._data{indi}(:, RHS._rep{indi})); + catch + keyboard + end_try_catch else df._data{indc(indi)} = feval(@subsasgn, df._data{indc(indi)}, S, \ cast(RHS._data{indi}(:, RHS._rep{indi}),\ Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/subsindex.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsindex.m 2010-12-08 17:08:30 UTC (rev 7999) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/subsindex.m 2010-12-08 17:45:30 UTC (rev 8000) @@ -37,6 +37,7 @@ dummy = df_whole(df); if isa(dummy, 'logical'), resu = sort(find(dummy)-base); + %# resu = dummy - base; else resu = dummy - base; endif Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m 2010-12-08 17:08:30 UTC (rev 7999) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m 2010-12-08 17:45:30 UTC (rev 8000) @@ -233,11 +233,11 @@ endif else %# one single dim -- probably something like df(:), df(A), ... - fullindr = 1; + fullindr = 1; onedimidx = S(1).subs{1}; switch class(S(1).subs{1}) case {'char'} %# one dimensional access, disallow it if not ':' if (strcmp(S(1).subs{1}, ':')), - fullindr = []; fullindc = []; + fullindr = []; fullindc = []; asked_output_type = "array"; else error(["Accessing through single dimension and name " \ S(1).subs{1} " not allowed\n-- use variable(:, 'name') instead"]); @@ -259,12 +259,9 @@ ([df._cnt dummy], S(1).subs{1}); endif - onedimidx = S(1).subs{1}; - 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), %# verify that the extracted values form a square matrix dummy = zeros(indr(end), indc(end)); @@ -279,7 +276,6 @@ fullindr = []; fullindc = []; endif endif - endif endif %# at this point, S is either empty, either contains further dereferencing @@ -319,22 +315,24 @@ output_type = "array"; endif endif - + if (any(strcmp({asked_output_type}, class(df)))), %# was (any(strcmp({output_type, asked_output_type}, class(df)))) - if (!isempty(S) && 1 == length(S(1).subs)), - if (ncol > 1), + if (!isempty(S) && (1 == length(S(1).subs))), + if (ncol > 1), if (false & isempty(asked_output_type) \ || strcmp(asked_output_type, class(df))), error("Vector-like access not implemented for 'dataframe' output format"); else [asked_output_type, output_type] = deal("array"); endif -%# error("Selected columns not compatible with cat() -- use 'cell' as output format"); + %# error("Selected columns not compatible with cat() -- use 'cell' as output format"); + elseif ((isnumeric(S(1).subs) && isvector(S(1).subs)) \ + && isempty(asked_output_type)), + %# in the case of vector input, favor array output + [asked_output_type, output_type] = deal("array"); endif endif - elseif (isempty(asked_output_type) && 1 == length(S(1).subs)), - [asked_output_type, output_type] = deal("array"); endif indt = {}; %# in case we have to mix matrix of different width @@ -492,7 +490,7 @@ %# * x(:, :) returns a horzcat of the third dimension %# * x(:, n:m) select only the first sequence %# * x(:) returns a vertcat of the columns of x(:, :) - %# disp('line 403 '); keyboard + 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}))), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cde...@us...> - 2010-12-10 10:01:09
|
Revision: 8010 http://octave.svn.sourceforge.net/octave/?rev=8010&view=rev Author: cdemills Date: 2010-12-10 10:01:02 +0000 (Fri, 10 Dec 2010) Log Message: ----------- When using dynamic allocation, access _over{2} as a vector Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2010-12-10 09:24:16 UTC (rev 8009) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2010-12-10 10:01:02 UTC (rev 8010) @@ -167,8 +167,9 @@ if !strcmp(dummy, UTF8_BOM), frewind(fid); endif - in = fread(fid); %# slurps everything - in = char(in.'); %# convert doubles to char + %# slurp everything and convert doubles to char, avoiding + %# problems with char > 127 + in = char(fread(fid).'); else in = []; endif Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m 2010-12-10 09:24:16 UTC (rev 8009) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m 2010-12-10 10:01:02 UTC (rev 8010) @@ -113,7 +113,7 @@ indc = df._cnt(2); ncol = 1; df._name{2}(end) = S(1).subs; df._name{2} = genvarname(df._name{2}); - df._over{2} = false; + df._over{2}(end) = false; endif if (length(S) > 1), if (1 == length(S(2).subs)), %# add column reference This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cde...@us...> - 2010-12-10 14:17:05
|
Revision: 8014 http://octave.svn.sourceforge.net/octave/?rev=8014&view=rev Author: cdemills Date: 2010-12-10 14:16:57 +0000 (Fri, 10 Dec 2010) Log Message: ----------- dataframe.m now calls directly df_matassign, which was extracted from subsasgn. This way, empty assignements are handled the right way, i.e. without modifying the df Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_name2idx.m trunk/octave-forge/extra/dataframe/inst/@dataframe/reshape.m trunk/octave-forge/extra/dataframe/inst/@dataframe/sort.m trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m Added Paths: ----------- trunk/octave-forge/extra/dataframe/inst/@dataframe/kron.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2010-12-10 14:02:02 UTC (rev 8013) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2010-12-10 14:16:57 UTC (rev 8014) @@ -323,7 +323,8 @@ idx.subs = {'', indj}; %# use direct assignement if (ndims(x) > 2), idx.subs{3} = 1:size(x, 3); endif - df = subsasgn(df, idx, x); + %# df = subsasgn(df, idx, x); <= call directly lower level + df = df_matassign(df, idx, indj, length(indj), x); if (!isempty(cmt_lines)), df._cmt{end+1, 1} = cmt_lines; cmt_lines = []; Added: trunk/octave-forge/extra/dataframe/inst/@dataframe/kron.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/kron.m (rev 0) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/kron.m 2010-12-10 14:16:57 UTC (rev 8014) @@ -0,0 +1,36 @@ +function resu = kron(A, B) + + %% Copyright (C) 2009-2010 Pascal Dupuis <Pas...@uc...> + %% + %% This file is part of Octave. + %% + %% Octave is free software; you can redistribute it and/or + %% modify it under the terms of the GNU General Public + %% License as published by the Free Software Foundation; + %% either version 2, or (at your option) any later version. + %% + %% Octave is distributed in the hope that it will be useful, + %% but WITHOUT ANY WARRANTY; without even the implied + %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + %% PURPOSE. See the GNU General Public License for more + %% details. + %% + %% You should have received a copy of the GNU General Public + %% License along with Octave; see the file COPYING. If not, + %% write to the Free Software Foundation, 59 Temple Place - + %% Suite 330, Boston, MA 02111-1307, USA. + + %# + %# $Id$ + %# + + if (isa(A, 'dataframe')), + A = df_whole(A); + endif + if (isa(B, 'dataframe')), + B = df_whole(B); + endif + + resu = kron(A, B); + +endfunction Property changes on: trunk/octave-forge/extra/dataframe/inst/@dataframe/kron.m ___________________________________________________________________ Added: svn:keywords + Id Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m 2010-12-10 14:02:02 UTC (rev 8013) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m 2010-12-10 14:16:57 UTC (rev 8014) @@ -24,13 +24,12 @@ %# $Id$ %# - %# resu = df_mapper2(@permute, df, varargin{:}); - resu = dataframe([]); resu._cnt = df._cnt(perm); + if (ndims(df._ridx) < 3), - resu._ridx = permute(df._ridx, [min(perm(1), 2) min(perm(2:3))]); + resu._ridx = permute(df._ridx, [min(perm(1), 2) min(perm(2:end))]); else resu._ridx = permute(df._ridx, perm); endif @@ -104,7 +103,7 @@ endif endif - resu.src = df._src; - resu.cmt = df._cmt; + resu._src = df._src; + resu._cmt = df._cmt; endfunction Added: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m (rev 0) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m 2010-12-10 14:16:57 UTC (rev 8014) @@ -0,0 +1,475 @@ +function df = df_matassign(df, S, indc, ncol, RHS) + %# auxiliary function: assign the dataframe as if it was a matrix + + %% Copyright (C) 2009-2010 Pascal Dupuis <Pas...@uc...> + %% + %% This file is part of Octave. + %% + %% Octave is free software; you can redistribute it and/or + %% modify it under the terms of the GNU General Public + %% License as published by the Free Software Foundation; + %% either version 2, or (at your option) any later version. + %% + %% Octave is distributed in the hope that it will be useful, + %% but WITHOUT ANY WARRANTY; without even the implied + %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + %% PURPOSE. See the GNU General Public License for more + %% details. + %% + %% You should have received a copy of the GNU General Public + %% License along with Octave; see the file COPYING. If not, + %% write to the Free Software Foundation, 59 Temple Place - + %% Suite 330, Boston, MA 02111-1307, USA. + + %# + %# $Id$ + %# + + if (isnull(RHS)), + if (1 == ncol), + if (sum(~strcmp(S.subs, ':')) > 2), + error("A null assignment can only have one non-colon index."); + endif + elseif (sum(~strcmp(S.subs, ':')) > 1), + error("A null assignment can only have one non-colon index."); + endif + + if (strcmp(S.subs(1), ':')), %# removing column/matrix + RHS = S; RHS.subs(2) = []; + for indi = indc, + unfolded = df._data{indi}(:, df._rep{indi}); + unfolded = feval(@subsasgn, unfolded, RHS, []); + df._data{indi} = unfolded; + if (!isempty(unfolded)), + df._rep(indi) = 1:size(unfolded, 2); + endif + endfor + %# remove empty elements + indi = cellfun('isempty', df._data); + if (any(indi)), %# nothing left, remove this column + df._cnt(2) = df._cnt(2) - sum(indi); + indi = ~indi; %# vector of kept data + df._name{2} = df._name{2}(indi); + df._over{2} = df._over{2}(indi); + df._type = df._type(indi); + df._data = df._data(indi); + df._rep = df._rep(indi); + endif + if (size(df._ridx, 3) > 1), + df._ridx(:, indc, :) = []; + endif + elseif (strcmp(S.subs(2), ':')), %# removing rows + indr = S.subs{1}; + if !isempty(df._name{1}), + df._name{1}(indr, :) = []; + df._over{1}(indr) = []; + endif + df._ridx(indr, :, :) = []; + %# to remove a line, iterate on each column + df._data = cellfun(@(x) feval(@subsasgn, x, S, []), \ + df._data, "UniformOutPut", false); + if (isa(indr, 'char')), + df._cnt(1) = 0; + else + df._cnt(1) = df._cnt(1) - length(indr); + endif + endif + df = df_thirddim(df); + return; + endif + + indc_was_set = ~isempty(indc); + if (~indc_was_set), %# initial dataframe was empty + ncol = size(RHS, 2); indc = 1:ncol; + endif + + indr = S.subs{1, 1}; + indr_was_set = ~isempty(indr); + %# initial dataframe was empty ? + if (~indr_was_set || strcmp(indr, ':')), + if (iscell(RHS)), + nrow = max(sum(cellfun('size', RHS, 1))); + else + if (isvector(RHS)), + if (0 == df._cnt(1)), + nrow = size(RHS, 1); + else + nrow = df._cnt(1); %# limit to df numbner of rows + endif + else + %# deduce limit from RHS + nrow = size(RHS, 1); + endif + endif + indr = 1:nrow; + elseif (!isempty(indr) && isnumeric(indr)), + nrow = length(indr); + endif + if (length(S.subs) > 2), + inds = S.subs{1, 3}; + else + inds = []; + endif + + rname = cell(0, 0); rname_width = max(1, size(df._name{2}, 2)); + ridx = []; cname = rname; ctype = rname; + + if (iscell(RHS)), + if (length(indc) == df._cnt(2) && size(RHS, 2) >= df._cnt(2)) \ + || 0 == df._cnt(2) || isempty(S.subs{1}), + %# providing too much information -- remove extra content + if (size(RHS, 1) > 1), + %# at this stage, verify that the first line doesn't contain + %# chars only; use them for column names + dummy = cellfun('class', \ + RHS(1, ~cellfun('isempty', RHS(1, :))), \ + 'UniformOutput', false); + dummy = strcmp(dummy, 'char'); + if (all(dummy)), + if (length(df._over{2}) >= max(indc) \ + && !all(df._over{2}(indc))), + keyboard + warning("Trying to overwrite colum names"); + endif + cname = RHS(1, :).'; RHS = RHS(2:end, :); + if (~indr_was_set), + nrow = nrow - 1; indr = 1:nrow; + endif + endif + %# at this stage, verify that the first line doesn't contain + %# chars only; use them for column types + dummy = cellfun('class', \ + RHS(1, ~cellfun('isempty', RHS(1, :))), \ + 'UniformOutput', false); + dummy = strcmp(dummy, 'char'); + if (all(dummy)), + if (length(df._over{2}) >= max(indc) \ + && !all(df._over{2}(indc))), + warning("Trying to overwrite colum names"); + endif + ctype = RHS(1, :); RHS = RHS(2:end, :); + if (~indr_was_set), + nrow = nrow - 1; indr = 1:nrow; + endif + endif + endif + + %# more elements than df width -- try to use the first two as + %# row index and/or row name + if (size(RHS, 1) > 1), + dummy = all(cellfun('isnumeric', \ + RHS(~cellfun('isempty', RHS(:, 1)), 1))); + else + dummy = isnumeric(RHS{1, 1}); + endif + dummy = dummy && (!isempty(cname) && size(cname{1}, 2) < 1); + if (dummy), + ridx = cell2mat(RHS(:, 1)); + %# can it be converted to a list of unique numbers ? + if (length(unique(ridx)) == length(ridx)), + ridx = RHS(:, 1); RHS = RHS(:, 2:end); + if (length(df._name{2}) == df._cnt(2) + ncol), + %# columns name were pre-filled with too much values + df._name{2}(end) = []; + df._over{2}(end) = []; + if (size(RHS, 2) < ncol), + ncol = size(RHS, 2); indc = 1:ncol; + endif + elseif (!indc_was_set), + ncol = ncol - 1; indc = 1:ncol; + endif + if (!isempty(cname)), cname = cname(2:end); endif + if (!isempty(ctype)), ctype = ctype(2:end); endif + else + ridx = []; + endif + endif + + if (size(RHS, 2) > df._cnt(2)), + %# verify the the first row doesn't contain chars only, use them + %# for row names + dummy = cellfun('class', \ + RHS(~cellfun('isempty', RHS(:, 1)), 1), \ + 'UniformOutput', false); + dummy = strcmp(dummy, 'char') \ + && (!isempty(cname) && size(cname{1}, 2) < 1); + if (all(dummy)), + if (length(df._over{1}) >= max(indr) \ + && !all(df._over{1}(indr))), + warning("Trying to overwrite row names"); + else + rname = RHS(:, 1); + endif + rname_width = max([1; cellfun('size', rname, 2)]); + RHS = RHS(:, 2:end); + if (length(df._name{2}) == df._cnt(2) + ncol), + %# columns name were pre-filled with too much values + df._name{2}(end) = []; + df._over{2}(end) = []; + if (size(RHS, 2) < ncol), + ncol = size(RHS, 2); indc = 1:ncol; + endif + elseif (!indc_was_set), + ncol = ncol - 1; indc = 1:ncol; + endif + if (!isempty(cname)), cname = cname(2:end); endif + if (!isempty(ctype)), ctype = ctype(2:end); endif + endif + endif + endif + endif + + %# perform row resizing if columns are already filled + if (!isempty(indr) && isnumeric(indr)), + if (max(indr) > df._cnt(1) && size(df._data, 2) == df._cnt(2)), + df = df_pad(df, 1, max(indr)-df._cnt(1), rname_width); + endif + endif + + if (iscell(RHS)), %# we must pad on a column-by-column basis + %# verify that each cell contains a non-empty vector, and that sizes + %# are compatible + %# dummy = cellfun('size', RHS(:), 2); + %# if any(dummy < 1), + %# error("cells content may not be empty"); + %# endif + + %# dummy = cellfun('size', RHS, 1); + %# if any(dummy < 1), + %# error("cells content may not be empty"); + %# endif + %# if any(diff(dummy) > 0), + %# error("cells content with unequal length"); + %# endif + %# if 1 < size(RHS, 1) && any(dummy > 1), + %# error("cells may only contain scalar"); + %# endif + + %# the real assignement + if (1 == size(RHS, 1)), %# each cell contains one vector + fillfunc = @(x) RHS{x}; + idxOK = logical(indr); + else %# use cell2mat to pad on a column-by-column basis + fillfunc = @(x) cell2mat(RHS(:, x)); + endif + + indj = 1; + for indi = 1:ncol, + if (indc(indi) > df._cnt(2)), + %# perform dynamic resizing one-by-one, to get type right + if (isempty(ctype) || length(ctype) < indc(indi)), + df = df_pad(df, 2, indc(indi)-df._cnt(2), class(RHS{1, indj})); + else + df = df_pad(df, 2, indc(indi)-df._cnt(2), ctype{indj}); + endif + endif + if (nrow == df._cnt(1)), + %# whole assignement + try + if (size(RHS, 1) <= 1), + switch df._type{indc(indi)} + case {'char' } %# use a cell array to hold strings + dummy = RHS(:, indj); + case {'double' } + dummy = fillfunc(indj); + otherwise + dummy = cast(fillfunc(indj), df._type{indc(indi)}); + endswitch + else + %# keeps indexes in sync as cell elements may be empty + idxOK = ~cellfun('isempty', RHS(:, indj)); + %# intialise dummy so that it can receive "anything" + dummy = []; + switch df._type{indc(indi)} + case {'char' } %# use a cell array to hold strings + dummy = RHS(:, indj); + case {'double' } + dummy(idxOK, :) = fillfunc(indj); dummy(~idxOK, :) = NA; + otherwise + dummy(idxOK, :) = fillfunc(indj); dummy(~idxOK, :) = NA; + dummy = cast(dummy, df._type{indc(indi)}); + 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); + end_try_catch + if (size(dummy, 1) < df._cnt(1)), + dummy(end+1:df._cnt(1), :) = NA; + endif + else + %# partial assignement -- extract actual data and update + dummy = df._data{indc(indi)}; + try + switch df._type{indc(indi)} + case {'char' } %# use a cell array to hold strings + dummy(indr, 1) = RHS(:, indj); + case {'double' } + dummy(indr, :) = fillfunc(indj); + otherwise + dummy(indr, :) = cast(fillfunc(indj), df._type{indc(indi)}); + endswitch + 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); + end_try_catch + endif + df._data{indc(indi)} = dummy; df._rep{indc(indi)} = 1:size(dummy, 2); + indj = indj + 1; + endfor + + else + %# RHS is either a numeric, either a df + if (any(indc > min(size(df._data, 2), df._cnt(2)))), + df = df_pad(df, 2, max(indc-min(size(df._data, 2), df._cnt(2))),\ + class(RHS)); + endif + if (!isempty(inds) && any(inds > 1)), + for indi=1:length(indc), + if (max(inds) > length(df._rep{indc(indi)})), + df = df_pad(df, 3, max(inds)-length(df._rep{indc(indi)}), \ + indc(indi)); + endif + endfor + endif + + if (isa(RHS, 'dataframe')), + %# block-copy index + S.subs(2) = 1; + if (any(!isna(RHS._ridx))), + df._ridx = feval(@subsasgn, df._ridx, S, RHS._ridx); + endif + %# skip second dim and copy data + S.subs(2) = []; Sorig = S; + for indi = 1:length(indc), + [df, S] = df_cow(df, S, indc(indi)); + if (strcmp(df._type(indc(indi)), RHS._type(indi))), + try + df._data{indc(indi)} = feval(@subsasgn, df._data{indc(indi)}, S, \ + RHS._data{indi}(:, RHS._rep{indi})); + catch + disp(lasterr()); disp('line 516 ???'); keyboard + end_try_catch + else + df._data{indc(indi)} = feval(@subsasgn, df._data{indc(indi)}, S, \ + cast(RHS._data{indi}(:, RHS._rep{indi}),\ + df._type(indc(indi)))); + endif + S = Sorig; + endfor + if (!isempty(RHS._name{1})), + df._name{1}(indr) = genvarname(RHS._name{1}(indr)); + df._over{1}(indr) = RHS._over{1}(indr); + endif + if (!isempty(RHS._src)), + if (!any(strcmp(cellstr(df._src), cellstr(RHS._src)))), + df._src = vertcat(df._src, RHS._src); + endif + endif + if (!isempty(RHS._cmt)), + if (!any(strcmp(cellstr(df._cmt), cellstr(RHS._cmt)))), + df._cmt = vertcat(df._cmt, RHS._cmt); + endif + endif + + else + %# RHS is homogenous, pad at once + if (isvector(RHS)), %# scalar - vector + if (isempty(S.subs)), + fillfunc = @(x, y) RHS; + else + %# ignore 'column' dimension -- force colum vectors -- use a + %# third dim just in case + if (isempty(S.subs{1})), S.subs{1} = ':'; endif + S.subs(2) = []; + if (length(S.subs) < 2), + S.subs{2} = 1; + endif + if (length(indc) > 1 && length(RHS) > 1), + %# set a row from a vector + fillfunc = @(x, S, y) feval(@subsasgn, x, S, RHS(y)); + else + fillfunc = @(x, S, y) feval(@subsasgn, x, S, RHS); + endif + endif + Sorig = S; + for indi = 1:length(indc), + try + [df, S] = df_cow(df, S, indc(indi)); + df._data{indc(indi)} = fillfunc(df._data{indc(indi)}, S, indi); + S = Sorig; + catch + disp(lasterr) + disp('line 470 '); keyboard + end_try_catch + # catch + # if ndims(df._data{indc(indi)}) > 2, + # %# upstream forgot to give the third dim + # dummy = S; dummy.subs(3) = 1; + # df._data{indc(indi)} = fillfunc(df._data{indc(indi)}, \ + # dummy, indi); + # else + # rethrow(lasterr()); + # endif + # end_try_catch + endfor + else %# 2D - 3D matrix + S.subs(2) = []; %# ignore 'column' dimension + if (isempty(S.subs{1})), + S.subs{1} = indr; + endif + %# 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), + [df, S] = df_cow(df, S, indc(indi)); + df._data{indc(indi)} = fillfunc(df._data{indc(indi)}, S, indi); + S = Sorig; + endfor + endif + if indi < size(RHS, 2) && !isa(RHS, 'char'), + warning(' not all columns of RHS used'); + endif + endif + endif + + %# delayed row padding -- column padding occured before + if !isempty(indr) && isnumeric(indr), + if max(indr) > df._cnt(1) && size(df._data, 2) < df._cnt(2), + df = df_pad(df, 1, max(indr)-df._cnt(1), rname_width); + endif + endif + + %# adjust ridx and rnames, if required + if !isempty(ridx), + dummy = df._ridx; + if 1 == size(RHS, 1), + dummy(indr) = ridx{1}; + else + dummy(indr) = vertcat(ridx{indr}); + endif + if length(unique(dummy)) != length(dummy), %# || \ + %# any(diff(dummy) <= 0), + error("row indexes are not unique or not ordered"); + endif + df._ridx = dummy; + endif + + if !isempty(rname) && (length(df._over{1}) < max(indr) || \ + all(df._over{1}(indr))), + df._name{1}(indr, 1) = genvarname(rname); + df._over{1}(1, indr) = false; + endif + if !isempty(cname) && (length(df._over{2}) < max(indc) || \ + all(df._over{2}(indc))), + df._name{2}(indc, 1) = genvarname(cname); + df._over{2}(1, indc) = false; + endif + + df = df_thirddim(df); + +endfunction Property changes on: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m ___________________________________________________________________ Added: svn:keywords + Id Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_name2idx.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_name2idx.m 2010-12-10 14:02:02 UTC (rev 8013) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_name2idx.m 2010-12-10 14:16:57 UTC (rev 8014) @@ -117,7 +117,7 @@ error(dummy); endif elseif (isa(subs, 'logical')), - idx = 1:length(subs); + idx = 1:length(subs(:)); idx = reshape(idx, size(subs)); idx(~subs) = []; elseif (isa(subs, 'dataframe')), idx = subsindex(subs, 1); Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/reshape.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/reshape.m 2010-12-10 14:02:02 UTC (rev 8013) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/reshape.m 2010-12-10 14:16:57 UTC (rev 8014) @@ -25,6 +25,11 @@ %# $Id$ %# - 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 endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/sort.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/sort.m 2010-12-10 14:02:02 UTC (rev 8013) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/sort.m 2010-12-10 14:16:57 UTC (rev 8014) @@ -136,7 +136,12 @@ otherwise error("Invalid dimension %d", dim); endswitch + + dummy = dbstack(); + if (any(strmatch('quantile', {dummy.name}))), + resu = df_whole(resu); + else + resu = dataframe(resu); + endif - resu = dataframe(resu); - endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m 2010-12-10 14:02:02 UTC (rev 8013) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m 2010-12-10 14:16:57 UTC (rev 8014) @@ -147,9 +147,18 @@ case '()' [indr, nrow, S(1).subs{1}] = df_name2idx(df._name{1}, S(1).subs{1}, \ df._cnt(1), 'row'); + if (isempty(indr) && df._cnt(1) > 0), + %# this is not an initial assignment + resu = df; return; + endif + if (length(S(1).subs) > 1), [indc, ncol, S(1).subs{2}] = df_name2idx(df._name{2}, S(1).subs{2}, \ df._cnt(2), 'column'); + if (isempty(indc) && df._cnt(2) > 0), + %# this is not an initial assignment + resu = df; return; + endif else mz = max(cellfun(@length, df._rep)); [fullindr, fullindc, fullinds] = ind2sub([df._cnt(1:2) mz], indr); @@ -161,479 +170,11 @@ S(1).subs{3} = inds; endif endif + resu = df_matassign(df, S, indc, ncol, RHS); - + endswitch %# disp("end of subasgn"); keyboard endfunction - -function df = df_matassign(df, S, indc, ncol, RHS) - %# auxiliary function: assign the dataframe as if it was a matrix - - if (isnull(RHS)), - if (1 == ncol), - if (sum(~strcmp(S.subs, ':')) > 2), - error("A null assignment can only have one non-colon index."); - endif - elseif (sum(~strcmp(S.subs, ':')) > 1), - error("A null assignment can only have one non-colon index."); - endif - - if (strcmp(S.subs(1), ':')), %# removing column/matrix - RHS = S; RHS.subs(2) = []; - for indi = indc, - unfolded = df._data{indi}(:, df._rep{indi}); - unfolded = feval(@subsasgn, unfolded, RHS, []); - df._data{indi} = unfolded; - if (!isempty(unfolded)), - df._rep(indi) = 1:size(unfolded, 2); - endif - endfor - %# remove empty elements - indi = cellfun('isempty', df._data); - if (any(indi)), %# nothing left, remove this column - df._cnt(2) = df._cnt(2) - sum(indi); - indi = ~indi; %# vector of kept data - df._name{2} = df._name{2}(indi); - df._over{2} = df._over{2}(indi); - df._type = df._type(indi); - df._data = df._data(indi); - df._rep = df._rep(indi); - endif - if (size(df._ridx, 3) > 1), - df._ridx(:, indc, :) = []; - endif - elseif (strcmp(S.subs(2), ':')), %# removing rows - indr = S.subs{1}; - if !isempty(df._name{1}), - df._name{1}(indr, :) = []; - df._over{1}(indr) = []; - endif - df._ridx(indr, :, :) = []; - %# to remove a line, iterate on each column - df._data = cellfun(@(x) feval(@subsasgn, x, S, []), \ - df._data, "UniformOutPut", false); - if (isa(indr, 'char')), - df._cnt(1) = 0; - else - df._cnt(1) = df._cnt(1) - length(indr); - endif - endif - df = df_thirddim(df); - return; - endif - - indc_was_set = ~isempty(indc); - if (~indc_was_set), %# initial dataframe was empty - ncol = size(RHS, 2); indc = 1:ncol; - endif - - indr = S.subs{1, 1}; - indr_was_set = ~isempty(indr); - %# initial dataframe was empty ? - if (~indr_was_set || strcmp(indr, ':')), - if (iscell(RHS)), - nrow = max(sum(cellfun('size', RHS, 1))); - else - if (isvector(RHS)), - if (0 == df._cnt(1)), - nrow = size(RHS, 1); - else - nrow = df._cnt(1); %# limit to df numbner of rows - endif - else - %# deduce limit from RHS - nrow = size(RHS, 1); - endif - endif - indr = 1:nrow; - elseif (!isempty(indr) && isnumeric(indr)), - nrow = length(indr); - endif - if (length(S.subs) > 2), - inds = S.subs{1, 3}; - else - inds = []; - endif - - rname = cell(0, 0); rname_width = max(1, size(df._name{2}, 2)); - ridx = []; cname = rname; ctype = rname; - - if (iscell(RHS)), - if (length(indc) == df._cnt(2) && size(RHS, 2) >= df._cnt(2)) \ - || 0 == df._cnt(2) || isempty(S.subs{1}), - %# providing too much information -- remove extra content - if (size(RHS, 1) > 1), - %# at this stage, verify that the first line doesn't contain - %# chars only; use them for column names - dummy = cellfun('class', \ - RHS(1, ~cellfun('isempty', RHS(1, :))), \ - 'UniformOutput', false); - dummy = strcmp(dummy, 'char'); - if (all(dummy)), - if (length(df._over{2}) >= max(indc) \ - && !all(df._over{2}(indc))), - warning("Trying to overwrite colum names"); - endif - cname = RHS(1, :).'; RHS = RHS(2:end, :); - if (~indr_was_set), - nrow = nrow - 1; indr = 1:nrow; - endif - endif - %# at this stage, verify that the first line doesn't contain - %# chars only; use them for column types - dummy = cellfun('class', \ - RHS(1, ~cellfun('isempty', RHS(1, :))), \ - 'UniformOutput', false); - dummy = strcmp(dummy, 'char'); - if (all(dummy)), - if (length(df._over{2}) >= max(indc) \ - && !all(df._over{2}(indc))), - warning("Trying to overwrite colum names"); - endif - ctype = RHS(1, :); RHS = RHS(2:end, :); - if (~indr_was_set), - nrow = nrow - 1; indr = 1:nrow; - endif - endif - endif - - %# more elements than df width -- try to use the first two as - %# row index and/or row name - if (size(RHS, 1) > 1), - dummy = all(cellfun('isnumeric', \ - RHS(~cellfun('isempty', RHS(:, 1)), 1))); - else - dummy = isnumeric(RHS{1, 1}); - endif - dummy = dummy && (!isempty(cname) && size(cname{1}, 2) < 1); - if (dummy), - ridx = cell2mat(RHS(:, 1)); - %# can it be converted to a list of unique numbers ? - if (length(unique(ridx)) == length(ridx)), - ridx = RHS(:, 1); RHS = RHS(:, 2:end); - if (length(df._name{2}) == df._cnt(2) + ncol), - %# columns name were pre-filled with too much values - df._name{2}(end) = []; - df._over{2}(end) = []; - if (size(RHS, 2) < ncol), - ncol = size(RHS, 2); indc = 1:ncol; - endif - elseif (!indc_was_set), - ncol = ncol - 1; indc = 1:ncol; - endif - if (!isempty(cname)), cname = cname(2:end); endif - if (!isempty(ctype)), ctype = ctype(2:end); endif - else - ridx = []; - endif - endif - - if (size(RHS, 2) > df._cnt(2)), - %# verify the the first row doesn't contain chars only, use them - %# for row names - dummy = cellfun('class', \ - RHS(~cellfun('isempty', RHS(:, 1)), 1), \ - 'UniformOutput', false); - dummy = strcmp(dummy, 'char') \ - && (!isempty(cname) && size(cname{1}, 2) < 1); - if (all(dummy)), - if (length(df._over{1}) >= max(indr) \ - && !all(df._over{1}(indr))), - warning("Trying to overwrite row names"); - else - rname = RHS(:, 1); - endif - rname_width = max([1; cellfun('size', rname, 2)]); - RHS = RHS(:, 2:end); - if (length(df._name{2}) == df._cnt(2) + ncol), - %# columns name were pre-filled with too much values - df._name{2}(end) = []; - df._over{2}(end) = []; - if (size(RHS, 2) < ncol), - ncol = size(RHS, 2); indc = 1:ncol; - endif - elseif (!indc_was_set), - ncol = ncol - 1; indc = 1:ncol; - endif - if (!isempty(cname)), cname = cname(2:end); endif - if (!isempty(ctype)), ctype = ctype(2:end); endif - endif - endif - endif - endif - - %# perform row resizing if columns are already filled - if (!isempty(indr) && isnumeric(indr)), - if (max(indr) > df._cnt(1) && size(df._data, 2) == df._cnt(2)), - df = df_pad(df, 1, max(indr)-df._cnt(1), rname_width); - endif - endif - - if (iscell(RHS)), %# we must pad on a column-by-column basis - %# verify that each cell contains a non-empty vector, and that sizes - %# are compatible - %# dummy = cellfun('size', RHS(:), 2); - %# if any(dummy < 1), - %# error("cells content may not be empty"); - %# endif - - %# dummy = cellfun('size', RHS, 1); - %# if any(dummy < 1), - %# error("cells content may not be empty"); - %# endif - %# if any(diff(dummy) > 0), - %# error("cells content with unequal length"); - %# endif - %# if 1 < size(RHS, 1) && any(dummy > 1), - %# error("cells may only contain scalar"); - %# endif - - %# the real assignement - if (1 == size(RHS, 1)), %# each cell contains one vector - fillfunc = @(x) RHS{x}; - idxOK = logical(indr); - else %# use cell2mat to pad on a column-by-column basis - fillfunc = @(x) cell2mat(RHS(:, x)); - endif - - indj = 1; - for indi = 1:ncol, - if (indc(indi) > df._cnt(2)), - %# perform dynamic resizing one-by-one, to get type right - if (isempty(ctype) || length(ctype) < indc(indi)), - df = df_pad(df, 2, indc(indi)-df._cnt(2), class(RHS{1, indj})); - else - df = df_pad(df, 2, indc(indi)-df._cnt(2), ctype{indj}); - endif - endif - if (nrow == df._cnt(1)), - %# whole assignement - try - if (size(RHS, 1) <= 1), - switch df._type{indc(indi)} - case {'char' } %# use a cell array to hold strings - dummy = RHS(:, indj); - case {'double' } - dummy = fillfunc(indj); - otherwise - dummy = cast(fillfunc(indj), df._type{indc(indi)}); - endswitch - else - %# keeps indexes in sync as cell elements may be empty - idxOK = ~cellfun('isempty', RHS(:, indj)); - %# intialise dummy so that it can receive "anything" - dummy = []; - switch df._type{indc(indi)} - case {'char' } %# use a cell array to hold strings - dummy = RHS(:, indj); - case {'double' } - dummy(idxOK, :) = fillfunc(indj); dummy(~idxOK, :) = NA; - otherwise - dummy(idxOK, :) = fillfunc(indj); dummy(~idxOK, :) = NA; - dummy = cast(dummy, df._type{indc(indi)}); - 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); - end_try_catch - if (size(dummy, 1) < df._cnt(1)), - dummy(end+1:df._cnt(1), :) = NA; - endif - else - %# partial assignement -- extract actual data and update - dummy = df._data{indc(indi)}; - try - switch df._type{indc(indi)} - case {'char' } %# use a cell array to hold strings - dummy(indr, 1) = RHS(:, indj); - case {'double' } - dummy(indr, :) = fillfunc(indj); - otherwise - dummy(indr, :) = cast(fillfunc(indj), df._type{indc(indi)}); - endswitch - 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); - end_try_catch - endif - df._data{indc(indi)} = dummy; df._rep{indc(indi)} = 1:size(dummy, 2); - indj = indj + 1; - endfor - - else - %# RHS is either a numeric, either a df - if (any(indc > min(size(df._data, 2), df._cnt(2)))), - df = df_pad(df, 2, max(indc-min(size(df._data, 2), df._cnt(2))),\ - class(RHS)); - endif - if (!isempty(inds) && any(inds > 1)), - for indi=1:length(indc), - if (max(inds) > length(df._rep{indc(indi)})), - df = df_pad(df, 3, max(inds)-length(df._rep{indc(indi)}), \ - indc(indi)); - endif - endfor - endif - - if (isa(RHS, 'dataframe')), - %# block-copy index - S.subs(2) = 1; - if (any(!isna(RHS._ridx))), - df._ridx = feval(@subsasgn, df._ridx, S, RHS._ridx); - endif - %# skip second dim and copy data - S.subs(2) = []; Sorig = S; - for indi = 1:length(indc), - %try - [df, S] = df_cow(df, S, indc(indi)); - # catch - # keyboard - # error(lasterr()); - # end_try_catch - if (strcmp(df._type(indc(indi)), RHS._type(indi))), - try - df._data{indc(indi)} = feval(@subsasgn, df._data{indc(indi)}, S, \ - RHS._data{indi}(:, RHS._rep{indi})); - catch - keyboard - end_try_catch - else - df._data{indc(indi)} = feval(@subsasgn, df._data{indc(indi)}, S, \ - cast(RHS._data{indi}(:, RHS._rep{indi}),\ - df._type(indc(indi)))); - endif - S = Sorig; - endfor - if (!isempty(RHS._name{1})), - df._name{1}(indr) = genvarname(RHS._name{1}(indr)); - df._over{1}(indr) = RHS._over{1}(indr); - endif - if (!isempty(RHS._src)), - if (!any(strcmp(cellstr(df._src), cellstr(RHS._src)))), - df._src = vertcat(df._src, RHS._src); - endif - endif - if (!isempty(RHS._cmt)), - if (!any(strcmp(cellstr(df._cmt), cellstr(RHS._cmt)))), - df._cmt = vertcat(df._cmt, RHS._cmt); - endif - endif - - else - %# RHS is homogenous, pad at once - if (isvector(RHS)), %# scalar - vector - if (isempty(S.subs)), - fillfunc = @(x, y) RHS; - else - %# ignore 'column' dimension -- force colum vectors -- use a - %# third dim just in case - if (isempty(S.subs{1})), S.subs{1} = ':'; endif - S.subs(2) = []; - if (length(S.subs) < 2), - S.subs{2} = 1; - endif - if (length(indc) > 1 && length(RHS) > 1), - %# set a row from a vector - fillfunc = @(x, S, y) feval(@subsasgn, x, S, RHS(y)); - else - fillfunc = @(x, S, y) feval(@subsasgn, x, S, RHS); - endif - endif - Sorig = S; - for indi = 1:length(indc), - try - [df, S] = df_cow(df, S, indc(indi)); - df._data{indc(indi)} = fillfunc(df._data{indc(indi)}, S, indi); - S = Sorig; - catch - disp(lasterr) - disp('line 470 '); keyboard - end_try_catch - # catch - # if ndims(df._data{indc(indi)}) > 2, - # %# upstream forgot to give the third dim - # dummy = S; dummy.subs(3) = 1; - # df._data{indc(indi)} = fillfunc(df._data{indc(indi)}, \ - # dummy, indi); - # else - # rethrow(lasterr()); - # endif - # end_try_catch - endfor - else %# 2D - 3D matrix - S.subs(2) = []; %# ignore 'column' dimension - if (isempty(S.subs{1})), - S.subs{1} = indr; - endif - %# 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), - [df, S] = df_cow(df, S, indc(indi)); - df._data{indc(indi)} = fillfunc(df._data{indc(indi)}, S, indi); - S = Sorig; - endfor - endif - if indi < size(RHS, 2) && !isa(RHS, 'char'), - warning(' not all columns of RHS used'); - endif - endif - endif - - %# delayed row padding -- column padding occured before - if !isempty(indr) && isnumeric(indr), - if max(indr) > df._cnt(1) && size(df._data, 2) < df._cnt(2), - df = df_pad(df, 1, max(indr)-df._cnt(1), rname_width); - endif - endif - - %# adjust ridx and rnames, if required - if !isempty(ridx), - dummy = df._ridx; - if 1 == size(RHS, 1), - dummy(indr) = ridx{1}; - else - dummy(indr) = vertcat(ridx{indr}); - endif - if length(unique(dummy)) != length(dummy), %# || \ - %# any(diff(dummy) <= 0), - error("row indexes are not unique or not ordered"); - endif - df._ridx = dummy; - endif - - if !isempty(rname) && (length(df._over{1}) < max(indr) || \ - all(df._over{1}(indr))), - df._name{1}(indr, 1) = genvarname(rname); - df._over{1}(1, indr) = false; - endif - if !isempty(cname) && (length(df._over{2}) < max(indc) || \ - all(df._over{2}(indc))), - df._name{2}(indc, 1) = genvarname(cname); - df._over{2}(1, indc) = false; - endif - - df = df_thirddim(df); - - %# catch - %# dummy = lasterr(); - %# if isempty(dummy), - %# error("Not enough values in RHS"); - %# else - %# error(dummy); - %# endif - %# end_try_catch - %# else - %# keyboard - %# error("either row, either column index empty - should not happen"); - %# endif - -endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m 2010-12-10 14:02:02 UTC (rev 8013) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m 2010-12-10 14:16:57 UTC (rev 8014) @@ -319,8 +319,8 @@ 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})) \ - && isempty(asked_output_type)), + 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"); endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cde...@us...> - 2010-12-13 17:13:35
|
Revision: 8019 http://octave.svn.sourceforge.net/octave/?rev=8019&view=rev Author: cdemills Date: 2010-12-13 17:13:29 +0000 (Mon, 13 Dec 2010) Log Message: ----------- Add the target name of assignment in display(); make comments a cellstr in dataframe Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2010-12-12 10:05:45 UTC (rev 8018) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2010-12-13 17:13:29 UTC (rev 8019) @@ -326,7 +326,7 @@ %# df = subsasgn(df, idx, x); <= call directly lower level df = df_matassign(df, idx, indj, length(indj), x); if (!isempty(cmt_lines)), - df._cmt{end+1, 1} = cmt_lines; + df._cmt = vertcat(df._cmt, cellstr(cmt_lines)); cmt_lines = []; endif else Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m 2010-12-12 10:05:45 UTC (rev 8018) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m 2010-12-13 17:13:29 UTC (rev 8019) @@ -28,21 +28,28 @@ %# %# generate header name - if 2 == length(df._cnt), - head = sprintf("Dataframe with %d rows and %d columns", df._cnt); + dummy = inputname(1); + if (isempty(dummy)), + dummy = "ans"; + endif + + if (2 == length(df._cnt)), + head = sprintf("%s = dataframe with %d rows and %d columns", \ + dummy, df._cnt); else - head = sprintf("Dataframe with %d rows and %d columns on %d pages", ... - df._cnt); + head = sprintf("%s = dataframe with %d rows and %d columns on %d pages", \ + 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)\ df._src{indi, 1}]); 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)\ @@ -50,13 +57,13 @@ endfor endif - if all(df._cnt > 0), %# stop for empty df + if (all(df._cnt > 0)), %# stop for empty df 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)), %# emit column names and type - if 1 == length(df._rep{indc}), + if (1 == length(df._rep{indc})), dummy{1, 2+indi} = deblank(disp(df._name{2}{indc})); dummy{2, 2+indi} = deblank(df._type{indc}); else @@ -79,8 +86,8 @@ indj = cellfun('isprint', tmp_str, 'UniformOutput', false); indj = ~cellfun('all', indj); for indr = 1:length(indj), - if indj(indr), - if isna(tmp_str{indr}), + if (indj(indr)), + if (isna(tmp_str{indr})), tmp_str{indr} = "NA"; else tmp_str{indr} = undo_string_escapes(tmp_str{indr}); @@ -122,7 +129,7 @@ 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'); - if isempty(resu), + if (isempty(resu)), resu = strjust(char(dummy{2, 1}, indi), 'right'); else resu = horzcat(resu, vspace, strjust(char(dummy{2, 1}, indi), \ @@ -134,7 +141,7 @@ 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'); - if isempty(resu), + if (isempty(resu)), resu = strjust(char(dummy{2, 1}, indi), 'right'); else resu = horzcat(resu, vspace, strjust(char(dummy{2, 1}, indi), \ @@ -147,7 +154,7 @@ endif %# emit row names - if isempty(df._name{1}), + if (isempty(df._name{1})), dummy{2, 2} = []; dummy{3, 2} = []; else dummy{2, 2} = [" ";" "]; @@ -155,9 +162,9 @@ endif %# insert a vertical space - if !isempty(dummy{3, 2}), + if (!isempty(dummy{3, 2})), indi = ~cellfun('isempty', dummy{3, 2}); - if any(indi), + if (any(indi)), resu = horzcat(resu, vspace, strjust(char(dummy{2, 2}, dummy{3, 2}),\ 'right')); endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cde...@us...> - 2010-12-13 22:18:06
|
Revision: 8020 http://octave.svn.sourceforge.net/octave/?rev=8020&view=rev Author: cdemills Date: 2010-12-13 22:17:59 +0000 (Mon, 13 Dec 2010) Log Message: ----------- Fixed a few oddities occurring when the target structure is empty Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m trunk/octave-forge/extra/dataframe/inst/@dataframe/sort.m trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m 2010-12-13 17:13:29 UTC (rev 8019) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m 2010-12-13 22:17:59 UTC (rev 8020) @@ -165,8 +165,12 @@ if (!isempty(dummy{3, 2})), indi = ~cellfun('isempty', dummy{3, 2}); if (any(indi)), - resu = horzcat(resu, vspace, strjust(char(dummy{2, 2}, dummy{3, 2}),\ - 'right')); + try + resu = horzcat(resu, vspace, strjust(char(dummy{2, 2}, dummy{3, 2}),\ + 'right')); + catch + disp('line 172 '); keyboard + end_try_catch endif endif Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m 2010-12-13 17:13:29 UTC (rev 8019) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m 2010-12-13 22:17:59 UTC (rev 8020) @@ -26,7 +26,11 @@ resu = dataframe([]); - resu._cnt = df._cnt(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))]); @@ -34,7 +38,7 @@ resu._ridx = permute(df._ridx, perm); endif - if (perm(1) > 1), + if (2 == perm(1)), resu._name{1} = df._name{2}; resu._over{1} = df._over{2}; else @@ -56,7 +60,7 @@ resu._over{1}(1, indc + (1:indi)) = true; endif - if (perm(2) > 1), + if (2 == perm(2)), resu._name{2} = df._name{2}; resu._over{2} = df._over{2}; else Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/sort.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/sort.m 2010-12-13 17:13:29 UTC (rev 8019) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/sort.m 2010-12-13 22:17:59 UTC (rev 8020) @@ -117,10 +117,12 @@ 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)]), - resu._ridx = resu._ridx(idx, :); - resu._name{1, 1} = resu._name{1, 1}(idx); - resu._over{1, 1} = resu._over{1, 1}(idx); + if (all([1 == size(idx, 2) 1 == size(idx, 3)])), + resu._ridx = resu._ridx(idx, :); + 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; Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m 2010-12-13 17:13:29 UTC (rev 8019) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m 2010-12-13 22:17:59 UTC (rev 8020) @@ -247,7 +247,12 @@ case {'dataframe'} S(1).subs{1} = subsindex(S(1).subs{1}, 1); endswitch - + + if (isempty(S(1).subs{1})), + resu = df_colmeta(df); + return; + endif + if (!isempty(fullindr)), %# convert linear index to subscripts if (length(df._cnt) <= 2), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cde...@us...> - 2010-12-23 15:27:57
|
Revision: 8038 http://octave.svn.sourceforge.net/octave/?rev=8038&view=rev Author: cdemills Date: 2010-12-23 15:27:50 +0000 (Thu, 23 Dec 2010) Log Message: ----------- Added a new() operator, which can also works recursivelly Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2010-12-22 23:07:32 UTC (rev 8037) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2010-12-23 15:27:50 UTC (rev 8038) @@ -60,6 +60,7 @@ if 0 == nargin disp('FIXME -- should create a dataframe from the whole workspace') + df = dataframe([]); return endif Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m 2010-12-22 23:07:32 UTC (rev 8037) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m 2010-12-23 15:27:50 UTC (rev 8038) @@ -127,6 +127,19 @@ case "comment" S(1).subs = "_cmt"; further_deref = true; + case "new" + if (isempty(dummy)), + resu = dataframe([]); + else + if (!strcmp(dummy(1).type, "()")), + error("Bogus constructor call"); + endif + resu = dataframe(dummy(1).subs{:}); + endif + if (length(dummy) > 1), + resu = subsref(resu, dummy(2:end)); + endif + return; otherwise error("Unknown column name: %s", S(1).subs); endswitch This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cde...@us...> - 2011-01-12 16:16:38
|
Revision: 8053 http://octave.svn.sourceforge.net/octave/?rev=8053&view=rev Author: cdemills Date: 2011-01-12 16:16:31 +0000 (Wed, 12 Jan 2011) Log Message: ----------- Removed some bugs, and added bsxfun in anticipation of Octave 3.4 Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/bsxfun.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_cow.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m Property Changed: ---------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/bsxfun.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/bsxfun.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/bsxfun.m 2011-01-12 14:49:26 UTC (rev 8052) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/bsxfun.m 2011-01-12 16:16:31 UTC (rev 8053) @@ -1,65 +1,65 @@ function resu = bsxfun(func, A, B) + %# function resu = bsxfun(func, A, B) + %# Implements a wrapper around internal bsxfun + + %% Copyright (C) 2009-2010 Pascal Dupuis <Pas...@uc...> + %% + %% This file is part of Octave. + %% + %% Octave is free software; you can redistribute it and/or + %% modify it under the terms of the GNU General Public + %% License as published by the Free Software Foundation; + %% either version 2, or (at your option) any later version. + %% + %% Octave is distributed in the hope that it will be useful, + %% but WITHOUT ANY WARRANTY; without even the implied + %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + %% PURPOSE. See the GNU General Public License for more + %% details. + %% + %% You should have received a copy of the GNU General Public + %% License along with Octave; see the file COPYING. If not, + %% write to the Free Software Foundation, 59 Temple Place - + %% Suite 330, Boston, MA 02111-1307, USA. + + %# + %# $Id$ + %# + resu = []; - singletondim = find(B._cnt < 2); - if !isempty(singletomdim), singletondim = singletondim(1); endif + try + singletondim = find(B._cnt < 2); + if !isempty(singletondim), singletondim = singletondim(1); endif - - if !isempty(singletondim), %# was isvector(B) - Bisscal = isscalar(B); - if (!Bisscal), - if (B._cnt(1) > 1), - error('bsxfun on dataframes: only column iterations permitted'); - endif - if (A._cnt(2) != max(B._cnt)), - error('bsxfun: dimension mismatch'); - endif - endif - %# prepare to call to subsref / subsasgn - SA.type = '()'; SA.subs={':', 1, ':'}; - SB.type = '()'; SB.subs = { 1 }; - - if (Bisscal), - for indi = 1:A._cnt(2), - SA.subs{2} = indi; - resu = subsasgn(resu, SA, @bsxfun(func, subsref(A, SA), B)); + if !isempty(singletondim), + resu = A; + %# prepare the call to subsref / subsasgn + SA.type = '()'; SA.subs = repmat({':'}, [1 length(A._cnt)]); + for indi = A._cnt(singletondim):-1:1, + SA.subs{singletondim} = indi; + resu = subsasgn(resu, SA, @bsxfun(func, subsref(A, SA), B)); endfor else - for indi = 1:A._cnt(2), - [SA.subs{2}, SB.subs{1}] = deal(indi); - resu = subsasgn(resu, SA, @bsxfun(func, subsref(A, SA), subsref(B, SB))); - endfor - endif - elseif isvector(A), - resu = B; Aisscal = isscalar(A); - if (!Aisscal), - if (A._cnt(1) > 1), - error('bsxfun on dataframes: only column iterations permitted'); + singletondim = find(A._cnt < 2); + if !isempty(singletondim), singletondim = singletondim(1); endif + + if !isempty(singletondim), %# was isvector(B) + resu = B; + %# prepare the call to subsref / subsasgn + SB.type = '()'; SB.subs = repmat({':'}, [1 length(B._cnt)]); + for indi = B._cnt(singletondim):-1:1, + SB.subs{singletondim} = indi; + resu = subsasgn(resu, SB, @bsxfun(func, A, subsref(B, SB))); + endfor + else + %# standard approach + resu = df_func(func, A, B); endif - if (B._cnt(2) != max(A.cnt)), - error('bsxfun: dimension mismatch'); - endif endif - - %# prepare to call to subsref / subsasgn - SA.type = '()'; SA.subs = { 1 }; - SB.type = '()'; SB.subs = {':', 1, ':'}; - - if (Aisscal), - for indi = 1:max(A._cnt), - SB.subs{2} = indi; - resu = subsasgn(resu, SB, @bsxfun(func, A, subsref(B, SB))); - endfor - else - for indi = 1:max(B._cnt), - [SA.subs{1}, SB.subs{2}] = deal(indi); - resu = subsasgn(resu, SB, @bsxfun(func, subsref(A, SA), subsref(B, SB))); - endfor - endif - else - %# standard approach - resu = df_func(func, A, B); - endif + catch + error('bsxfun: non-compatible dimensions') + end_try_catch endfunction Property changes on: trunk/octave-forge/extra/dataframe/inst/@dataframe/bsxfun.m ___________________________________________________________________ Added: svn:keywords + Id Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_cow.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_cow.m 2011-01-12 14:49:26 UTC (rev 8052) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_cow.m 2011-01-12 16:16:31 UTC (rev 8053) @@ -39,6 +39,13 @@ inds = S.subs{2}; endif + if (!isnumeric(inds)), + if !strcmp(inds, ':'), + error("Unknown sheet selector %s", inds); + endif + inds = 1:length(df._rep(col)); + endif + for indi = inds(:).', dummy = df._rep{col}; dummy(indi) = 0; [t1, t2] = ismember(df._rep{col}(indi)(:), dummy); Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m 2011-01-12 14:49:26 UTC (rev 8052) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m 2011-01-12 16:16:31 UTC (rev 8053) @@ -328,8 +328,8 @@ df = df_pad(df, 2, max(indc-min(size(df._data, 2), df._cnt(2))),\ class(RHS)); endif - if (!isempty(inds) && any(inds > 1)), - for indi=1:length(indc), + if (!isempty(inds) && isnumeric(inds) && any(inds > 1)), + for indi = 1:length(indc), if (max(inds) > length(df._rep{indc(indi)})), df = df_pad(df, 3, max(inds)-length(df._rep{indc(indi)}), \ indc(indi)); @@ -344,13 +344,13 @@ df._ridx = feval(@subsasgn, df._ridx, S, RHS._ridx); endif %# skip second dim and copy data - S.subs(2) = []; Sorig = S; + S.subs(2) = []; Sorig = S; for indi = 1:length(indc), [df, S] = df_cow(df, S, indc(indi)); if (strcmp(df._type(indc(indi)), RHS._type(indi))), try - df._data{indc(indi)} = feval(@subsasgn, df._data{indc(indi)}, S, \ - RHS._data{indi}(:, RHS._rep{indi})); + df._data{indc(indi)} = feval(@subsasgn, df._data{indc(indi)}, S, \ + RHS._data{indi}(:, RHS._rep{indi})); catch disp(lasterr()); disp('line 516 ???'); keyboard end_try_catch Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m 2011-01-12 14:49:26 UTC (rev 8052) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m 2011-01-12 16:16:31 UTC (rev 8053) @@ -27,6 +27,10 @@ %# $Id$ %# + if isempty(df), + error('dataframe subsasgn: first argument may not be empty'); + endif + switch(S(1).type) case '{}' error('Invalid dataframe as cell assignement'); @@ -165,11 +169,15 @@ indr = unique(fullindr); indc = unique(fullindc); inds = unique(fullinds); ncol = length(indc); - S(1).subs{1} = indr; S(1).subs{2} = indc; if (any(inds > 1)), S(1).subs{3} = inds; endif endif + + %# avoid passing ':' as selector on the two first dims + if (!isnull(RHS)), + S(1).subs{1} = indr; S(1).subs{2} = indc; + endif resu = df_matassign(df, S, indc, ncol, RHS); Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m 2011-01-12 14:49:26 UTC (rev 8052) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m 2011-01-12 16:16:31 UTC (rev 8053) @@ -422,7 +422,11 @@ resu._ridx = df._ridx; endif if (!isempty(resu._ridx)), - resu._ridx = resu._ridx(onedimidx); + if (size(resu._ridx, 2) > 1), + resu._ridx = resu._ridx(indr, indc); + else + resu._ridx = resu._ridx(indr); + endif endif endif %# to be verified : keyboard This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cde...@us...> - 2011-10-06 16:46:38
|
Revision: 8688 http://octave.svn.sourceforge.net/octave/?rev=8688&view=rev Author: cdemills Date: 2011-10-06 16:46:26 +0000 (Thu, 06 Oct 2011) Log Message: ----------- Fixed a few annoyances; started switching to Octave internal .m files style Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2011-10-06 14:32:51 UTC (rev 8687) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2011-10-06 16:46:26 UTC (rev 8688) @@ -25,7 +25,8 @@ %# Recognised options are: @itemize %# @item rownames : take the values as initialiser for row names %# @item colnames : take the values as initialiser for column names - %# @item seeked : a filed value which triggers start of processing. + %# @item seeked : a (kept) field value which triggers start of processing. + %# @item trigger : a (unkept) field value which triggers start of processing. %# Each preceeding line is silently skipped. Default: none %# @item unquot: a logical switch telling wheter or not strings should %# be unquoted before storage, default = true; @@ -58,283 +59,305 @@ %# $Id$ %# -if 0 == nargin - disp('FIXME -- should create a dataframe from the whole workspace') - df = dataframe([]); +if (0 == nargin) + disp ('FIXME -- should create a dataframe from the whole workspace') + df = dataframe ([]); return endif -if isempty(x) && 1 == nargin, +if (isempty (x) && 1 == nargin) %# default constructor: initialise the fields in the right order df._cnt = [0 0]; df._name = {cell(0, 1), cell(1, 0)}; %# rows - cols - df._over = cell(1, 2); + df._over = cell (1, 2); df._ridx = []; - df._data = cell(0, 0); - df._rep = cell(0, 0); %# a repetition index - df._type = cell(0, 0); %# the type of each column - df._src = cell(0, 0); - df._cmt = cell(0, 0); %# to put comments - df = class(df, 'dataframe'); + df._data = cell (0, 0); + df._rep = cell (0, 0); %# a repetition index + df._type = cell (0, 0); %# the type of each column + df._src = cell (0, 0); + df._cmt = cell (0, 0); %# to put comments + df = class (df, 'dataframe'); return endif -if isa(x, 'dataframe') +if (isa (x, 'dataframe')) df = x; -elseif isa(x, 'struct'), - df = class(x, 'dataframe'); return +elseif (isa (x, 'struct')) + df = class (x, 'dataframe'); return else - df = dataframe([]); %# get the right fields + df = dataframe ([]); %# get the right fields endif -seeked = []; unquot = true; sep = "\t,"; cmt_lines = []; +%# default values +seeked = []; trigger =[]; unquot = true; sep = "\t,"; cmt_lines = []; -if length(varargin) > 0, +if (length(varargin) > 0) indi = 1; %# loop over possible arguments - while indi <= size(varargin, 2), - if isa(varargin{indi}, 'char'), + while (indi <= size (varargin, 2)) + if (isa (varargin{indi}, 'char')) switch(varargin{indi}) - case 'rownames' - switch class(varargin{indi+1}) - case {'cell'} - df._name{1} = varargin{indi+1}; - case {'char'} - df._name{1} = cellstr(varargin{indi+1}); - otherwise - df._name{1} = cellstr(num2str(varargin{indi+1})); - endswitch - df._name{1} = genvarname(df._name{1}); - df._over{1}(1, 1:length(df._name{1})) = false; - df._cnt(1) = size(df._name{1}, 1); - df._ridx = (1:df._cnt(1))'; - varargin(indi:indi+1) = []; - case 'colnames' - switch class(varargin{indi+1}) - case {'cell'} - df._name{2} = varargin{indi+1}; - case {'char'} - df._name{2} = cellstr(varargin{indi+1}); - otherwise - df._name{2} = cellstr(num2str(varargin{indi+1})); - endswitch - %# detect assignment - functions calls - ranges - dummy = cellfun('size', cellfun(@(x) strsplit(x, ":=("), df._name{2}, \ - "UniformOutput", false), 2); - if any(dummy > 1), - warning('dataframe colnames taken literally and not interpreted'); - endif - df._name{2} = genvarname(df._name{2}); - df._over{2}(1, 1:length(df._name{2})) = false; - varargin(indi:indi+1) = []; - case 'seeked', - seeked = varargin{indi + 1}; - varargin(indi:indi+1) = []; - case 'unquot', - unquot = varargin{indi + 1}; - varargin(indi:indi+1) = []; - case 'sep', - sep = varargin{indi + 1}; - varargin(indi:indi+1) = []; - otherwise %# FIXME: just skip it for now - disp(sprintf("Ignoring unkown argument %s", varargin{indi})); - indi = indi + 1; + case 'rownames' + switch class (varargin{indi+1}) + case {'cell'} + df._name{1} = varargin{indi+1}; + case {'char'} + df._name{1} = cellstr (varargin{indi+1}); + otherwise + df._name{1} = cellstr (num2str (varargin{indi+1})); + endswitch + df._name{1} = genvarname (df._name{1}); + df._over{1}(1, 1:length (df._name{1})) = false; + df._cnt(1) = size (df._name{1}, 1); + df._ridx = (1:df._cnt(1))'; + varargin(indi:indi+1) = []; + case 'colnames' + switch class(varargin{indi+1}) + case {'cell'} + df._name{2} = varargin{indi+1}; + case {'char'} + df._name{2} = cellstr (varargin{indi+1}); + otherwise + df._name{2} = cellstr (num2str (varargin{indi+1})); + endswitch + %# detect assignment - functions calls - ranges + dummy = cellfun ('size', cellfun (@(x) strsplit (x, ":=("), df._name{2}, \ + "UniformOutput", false), 2); + if (any(dummy > 1)) + warning('dataframe colnames taken literally and not interpreted'); + endif + df._name{2} = genvarname (df._name{2}); + df._over{2}(1, 1:length (df._name{2})) = false; + varargin(indi:indi+1) = []; + case 'seeked', + seeked = varargin{indi + 1}; + varargin(indi:indi+1) = []; + case 'trigger', + trigger = varargin{indi + 1}; + varargin(indi:indi+1) = []; + case 'unquot', + unquot = varargin{indi + 1}; + varargin(indi:indi+1) = []; + case 'sep', + sep = varargin{indi + 1}; + varargin(indi:indi+1) = []; + otherwise %# FIXME: just skip it for now + disp (sprintf ("Ignoring unkown argument %s", varargin{indi})); + indi = indi + 1; endswitch else indi = indi + 1; %# skip it - endif + endif endwhile endif +if (!isempty (seeked) && !isempty (trigger)) + error ('seeked and trigger are mutuallly incompatible arguments'); +endif + indi = 0; -while indi <= size(varargin, 2), +while (indi <= size(varargin, 2)) indi = indi + 1; - if ~isa(x, 'dataframe') - if isa(x, 'char') && size(x, 1) < 2, + if (~isa (x, 'dataframe')) + if (isa(x, 'char') && size(x, 1) < 2) %# read the data frame from a file try - dummy = tilde_expand(x); - x = load(dummy); - df._src{end+1, 1} = dummy; + dummy = tilde_expand (x); + x = load (dummy); + df._src{end+1, 1} = dummy; catch %# try our own method - UTF8_BOM = char([0xEF 0xBB 0xBF]); - unwind_protect - dummy = tilde_expand(x); - fid = fopen(dummy); - if fid != -1, - df._src{end+1, 1} = dummy; - dummy = fgetl(fid); - if !strcmp(dummy, UTF8_BOM), - frewind(fid); - endif - %# slurp everything and convert doubles to char, avoiding - %# problems with char > 127 - in = char(fread(fid).'); - else - in = []; - endif - unwind_protect_cleanup - if fid != -1, fclose(fid); endif - end_unwind_protect + UTF8_BOM = char([0xEF 0xBB 0xBF]); + unwind_protect + dummy = tilde_expand (x); + fid = fopen (dummy); + if (fid != -1) + df._src{end+1, 1} = dummy; + dummy = fgetl (fid); + if (!strcmp (dummy, UTF8_BOM)) + frewind (fid); + endif + %# slurp everything and convert doubles to char, avoiding + %# problems with char > 127 + in = char (fread (fid).'); + else + in = []; + endif + unwind_protect_cleanup + if (fid != -1) fclose (fid); endif + end_unwind_protect - 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. - eol = '(\r\n|\n|\v|\f|\r|\x85)'; - %# cut into lines -- include the EOL to have a one-to-one - %# matching between line numbers. Use a non-greedy match. - lines = regexp(in, ['.*?' eol], 'match'); - dummy = cellfun(@(x) regexp(x, eol), lines); - %# remove the EOL character(s) - lines(1==dummy) = {""}; - %# use a positive lookahead -- eol is not part of the match - lines(dummy > 1) = cellfun(@(x) regexp(x, ['.*?(?=' eol ')'], \ - 'match'), lines(dummy > 1)); - %# a field either starts at a word boundary, either by + - . for - %# a numeric data, either by ' for a string. - - %# content = cellfun(@(x) regexp(x, '(\b|[-+\.''])[^,]*(''|\b)', 'match'),\ - %# lines, 'UniformOutput', false); %# extract fields - content = cellfun(@(x) strsplit(x, sep), lines, \ - 'UniformOutput', false); %# extract fields - indl = 1; indj = 1; %# disp('line 151 '); keyboard - if ~isempty(seeked), - while indl <= length(lines), - dummy = content{indl}; - if strcmp(dummy{1}, seeked) - break; - endif - indl = indl + 1; - endwhile - %# else - %# dummy = content{indl}; - endif - x = cell(1+length(lines)-indl, size(dummy, 2)); - empty_lines = []; cmt_lines = []; - while indl <= length(lines), - dummy = content{indl}; - if all(cellfun('size', dummy, 2) == 0), - empty_lines = [empty_lines indj]; - indl = indl + 1; indj = indj + 1; - continue; - endif - %# does it looks like a comment line ? - if regexp(dummy{1}, ['^\s*' char(35)]), - empty_lines = [empty_lines indj]; - cmt_lines = strvcat(cmt_lines, horzcat(dummy{:})); - indl = indl + 1; indj = indj + 1; - continue; - endif - %# try to convert to float - the_line = cellfun(@(x) sscanf(x, "%f"), dummy, \ - 'UniformOutput', false); - for indk = 1: size(the_line, 2), - if isempty(the_line{indk}) || any(size(the_line{indk}) > 1), - %#if indi > 1 && indk > 1, disp('line 117 '); keyboard; %#endif - if unquot, - try - %# remove quotes and leading space(s) - x(indj, indk) = regexp(dummy{indk}, '[^'' ].*[^'']', 'match'){1}; - catch - %# if the previous test fails, try a simpler one - in = regexp(dummy{indk}, '[^'' ]+', 'match'); - if !isempty(in), - x(indj, indk) = in{1}; - %# else - %# x(indj, indk) = []; - endif - end_try_catch - else - %# no conversion possible, store and remove leading space(s) - x(indj, indk) = regexp(dummy{indk}, '[^ ].*', 'match'); - endif - else - x(indj, indk) = the_line{indk}; - endif - endfor - indl = indl + 1; indj = indj + 1; - endwhile - if !isempty(empty_lines), - x(empty_lines, :) = []; - endif - %# detect empty columns - empty_lines = find(0 == sum(cellfun('size', x, 2))); - if !isempty(empty_lines), - x(:, empty_lines) = []; - endif - clear UTF8_BOM fid in lines indl the_line content empty_lines - endif + 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. + eol = '(\r\n|\n|\v|\f|\r|\x85)'; + %# cut into lines -- include the EOL to have a one-to-one + %# matching between line numbers. Use a non-greedy match. + lines = regexp (in, ['.*?' eol], 'match'); + dummy = cellfun (@(x) regexp (x, eol), lines); + %# remove the EOL character(s) + lines(1 == dummy) = {""}; + %# use a positive lookahead -- eol is not part of the match + lines(dummy > 1) = cellfun (@(x) regexp (x, ['.*?(?=' eol ')'], \ + 'match'), lines(dummy > 1)); + %# a field either starts at a word boundary, either by + - . for + %# a numeric data, either by ' for a string. + + %# content = cellfun(@(x) regexp(x, '(\b|[-+\.''])[^,]*(''|\b)', 'match'),\ + %# lines, 'UniformOutput', false); %# extract fields + content = cellfun (@(x) strsplit (x, sep), lines, \ + 'UniformOutput', false); %# extract fields + indl = 1; indj = 1; %# disp('line 151 '); keyboard + if (~isempty (seeked)) + while (indl <= length (lines)) + dummy = content{indl}; + if (all (cellfun ('size', dummy, 2) == 0)) + indl = indl + 1; + continue; + endif + dummy = content{indl}; + if (strcmp (dummy{1}, seeked)) + break; + endif + indl = indl + 1; + endwhile + elseif (~isempty (trigger)) + while (indl <= length (lines)) + dummy = content{indl}; + indl = indl + 1; + if (all (cellfun ('size', dummy, 2) == 0)) + continue; + endif + if (strcmp (dummy{1}, trigger)) + break; + endif + endwhile + endif + x = cell (1+length (lines)-indl, size(dummy, 2)); + empty_lines = []; cmt_lines = []; + while (indl <= length(lines)) + dummy = content{indl}; + if (all (cellfun ('size', dummy, 2) == 0)) + empty_lines = [empty_lines indj]; + indl = indl + 1; indj = indj + 1; + continue; + endif + %# does it looks like a comment line ? + if (regexp (dummy{1}, ['^\s*' char(35)])) + empty_lines = [empty_lines indj]; + cmt_lines = strvcat (cmt_lines, horzcat (dummy{:})); + indl = indl + 1; indj = indj + 1; + continue; + endif + %# try to convert to float + the_line = cellfun (@(x) sscanf (x, "%f", ""), dummy, \ + 'UniformOutput', false); + for indk = (1:size (the_line, 2)) + if (isempty (the_line{indk}) || any (size (the_line{indk}) > 1)) + %#if indi > 1 && indk > 1, disp('line 117 '); keyboard; %#endif + if (unquot) + try + %# remove quotes and leading space(s) + x(indj, indk) = regexp (dummy{indk}, '[^'' ].*[^'']', 'match'){1}; + catch + %# if the previous test fails, try a simpler one + in = regexp (dummy{indk}, '[^'' ]+', 'match'); + if (!isempty(in)) + x(indj, indk) = in{1}; + %# else + %# x(indj, indk) = []; + endif + end_try_catch + else + %# no conversion possible, store and remove leading space(s) + x(indj, indk) = regexp (dummy{indk}, '[^ ].*', 'match'); + endif + else + x(indj, indk) = the_line{indk}; + endif + endfor + indl = indl + 1; indj = indj + 1; + endwhile + if (!isempty(empty_lines)) + x(empty_lines, :) = []; + endif + %# detect empty columns + empty_lines = find (0 == sum (cellfun ('size', x, 2))); + if (!isempty(empty_lines)) + x(:, empty_lines) = []; + endif + clear UTF8_BOM fid in lines indl the_line content empty_lines + endif end_try_catch endif %# fallback, avoiding a recursive call idx.type = '()'; - if !isa(x, 'char'), - indj = df._cnt(2)+(1:size(x, 2)); + if (!isa (x, 'char')) + indj = df._cnt(2)+(1:size (x, 2)); else %# at this point, reading some filename failed error("dataframe: can't open '%s' for reading data", x); endif; - - if iscell(x), - 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, - error(["With two-elements cell, the first should resolve " ... - "to a single column"]); - endif - try - dummy = cellfun('class', x{2}(2, :), 'UniformOutput', false); - catch - dummy = cellfun('class', x{2}(1, :), 'UniformOutput', false); - end_try_catch - df = df_pad(df, 2, [length(dummy) indc], dummy); - x = x{2}; - indj = indc + (1:size(x, 2)); %# redefine target range + + if (iscell(x)) + 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) + error (["With two-elements cell, the first should resolve " ... + "to a single column"]); + endif + try + dummy = cellfun ('class', x{2}(2, :), 'UniformOutput', false); + catch + dummy = cellfun ('class', x{2}(1, :), 'UniformOutput', false); + end_try_catch + df = df_pad (df, 2, [length(dummy) indc], dummy); + x = x{2}; + indj = indc + (1:size(x, 2)); %# redefine target range else - if isa(x{1}, 'cell'), - x = x{1}; %# remove one cell level - endif + if (isa (x{1}, 'cell')) + x = x{1}; %# remove one cell level + endif endif - if length(df._name{2}) < indj(1) || isempty(df._name{2}(indj)), - [df._name{2}(indj, 1), df._over{2}(1, indj)] ... - = df_colnames(inputname(indi), indj); - df._name{2} = genvarname(df._name{2}); + if (length (df._name{2}) < indj(1) || isempty (df._name{2}(indj))) + [df._name{2}(indj, 1), df._over{2}(1, indj)] ... + = df_colnames (inputname(indi), indj); + df._name{2} = genvarname (df._name{2}); endif %# allow overwriting of column names df._over{2}(1, indj) = true; else - 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)] ... - = df_colnames(char(df._name{2}), indj); - elseif (length(df._name{2}) < indj(1) || isempty(df._name{2}(indj))), - [df._name{2}(indj, 1), df._over{2}(1, indj)] ... - = df_colnames(inputname(indi), indj); - endif - df._name{2} = genvarname(df._name{2}); + 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)] ... + = df_colnames (char(df._name{2}), indj); + elseif (length (df._name{2}) < indj(1) || isempty (df._name{2}(indj))) + [df._name{2}(indj, 1), df._over{2}(1, indj)] ... + = df_colnames (inputname(indi), indj); + endif + 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)); - cmt_lines = []; + 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)); + cmt_lines = []; endif else - df._cnt(2) = length(df._name{2}); + df._cnt(2) = length (df._name{2}); endif - elseif (indi > 1), - error('Concatenating dataframes: use cat instead'); + elseif (indi > 1) + error ('Concatenating dataframes: use cat instead'); endif try @@ -351,35 +374,35 @@ function [x, y] = df_colnames(base, num) %# small auxiliary function to generate column names. This is required %# here, as only the constructor can use inputname() - if (any([index(base, "=")])), + if (any ([index(base, "=")])) %# takes the left part as base - x = strsplit(base, "="); - x = deblank(x{1}); - if (isvarname(x)), + x = strsplit (base, "="); + x = deblank (x{1}); + if (isvarname (x)) y = false; else x = 'X'; y = true; endif else %# is base most probably a filename ? - x = regexp(base, '''[^''].*[^'']''', 'match'); - if (isempty(x)), - if (isvarname(base)), - x = base; y = false; + x = regexp (base, '''[^''].*[^'']''', 'match'); + if (isempty (x)) + if (isvarname (base)) + x = base; y = false; else - x = 'X'; y = true; %# this is a default value, may be changed + x = 'X'; y = true; %# this is a default value, may be changed endif else x = x{1}; y = true; endif endif - if (numel(num) > 1), - x = repmat(x, numel(num), 1); - x = cstrcat(x, strjust(num2str(num(:)), 'left')); - y = repmat(y, 1, numel(num)); + if (numel (num) > 1) + x = repmat (x, numel (num), 1); + x = cstrcat (x, strjust (num2str (num(:)), 'left')); + y = repmat (y, 1, numel (num)); endif - x = cellstr(x); + x = cellstr (x); endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m 2011-10-06 14:32:51 UTC (rev 8687) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m 2011-10-06 16:46:26 UTC (rev 8688) @@ -28,93 +28,97 @@ %# %# generate header name - dummy = inputname(1); - if (isempty(dummy)), + dummy = inputname (1); + if (isempty(dummy)) dummy = "ans"; endif - if (2 == length(df._cnt)), - head = sprintf("%s = dataframe with %d rows and %d columns", \ - dummy, df._cnt); + if (2 == length (df._cnt)) + head = sprintf ("%s = dataframe with %d rows and %d columns", \ + dummy, df._cnt); else - head = sprintf("%s = dataframe with %d rows and %d columns on %d pages", \ - dummy, df._cnt); + head = sprintf ("%s = dataframe with %d rows and %d columns on %d pages", \ + dummy, df._cnt); endif - if (!isempty(df._src)), - for indi = 1:size(df._src, 1), + if (!isempty (df._src)) + for indi = (1:size (df._src, 1)) head = strvcat\ - (head, [repmat("Src: ", size(df._src{indi, 1}, 1), 1)\ - df._src{indi, 1}]); + (head, [repmat("Src: ", size (df._src{indi, 1}, 1), 1)\ + df._src{indi, 1}]); endfor endif - if (!isempty(df._cmt)), - for indi = 1:size(df._cmt, 1), + if (!isempty (df._cmt)) + for indi = (1:size(df._cmt, 1)) head = strvcat\ - (head, [repmat("Comment: ", size(df._cmt{indi, 1}, 1), 1)\ - df._cmt{indi, 1}]); + (head, [repmat("Comment: ", size (df._cmt{indi, 1}, 1), 1)\ + df._cmt{indi, 1}]); endfor endif - if (all(df._cnt > 0)), %# stop for empty df - dummy=[]; vspace = repmat(' ', df._cnt(1), 1); + if (all (df._cnt > 0)) %# stop for empty df + 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)), + for indc = (1:min (df._cnt(2), size (df._data, 2))) %# emit column names and type - if (1 == length(df._rep{indc})), - dummy{1, 2+indi} = deblank(disp(df._name{2}{indc})); - dummy{2, 2+indi} = deblank(df._type{indc}); + if (1 == length (df._rep{indc})) + dummy{1, 2+indi} = deblank (disp (df._name{2}{indc})); + dummy{2, 2+indi} = deblank (df._type{indc}); else - %# append a dot and the third-dimension index to column name - tmp_str = [deblank(disp(df._name{2}{indc})) "."]; - tmp_str = arrayfun(@(x) horzcat(tmp_str, num2str(x)), ... - (1:length(df._rep{indc})), 'UniformOutput', false); - dummy{1, 2+indi} = tmp_str{1}; - dummy{2, 2+indi} = deblank(df._type{indc}); - for indk = 2:length(tmp_str), - dummy{1, 1+indi+indk} = tmp_str{indk}; - dummy{2, 1+indi+indk} = dummy{2, 2+indi}; - endfor + %# append a dot and the third-dimension index to column name + tmp_str = [deblank(disp (df._name{2}{indc})) "."]; + tmp_str = arrayfun (@(x) horzcat (tmp_str, num2str(x)), ... + (1:length (df._rep{indc})), 'UniformOutput', false); + dummy{1, 2+indi} = tmp_str{1}; + dummy{2, 2+indi} = deblank (df._type{indc}); + for indk = (2:length (tmp_str)) + dummy{1, 1+indi+indk} = tmp_str{indk}; + dummy{2, 1+indi+indk} = dummy{2, 2+indi}; + endfor endif %# "print" each column switch df._type{indc} - case {'char'} - indk = 1; while indk <= size(df._data{indc}, 2), - 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), - if (indj(indr)), - if (isna(tmp_str{indr})), - tmp_str{indr} = "NA"; - else - tmp_str{indr} = undo_string_escapes(tmp_str{indr}); - endif - endif - endfor - %# keep the whole thing, and add a vertical space - dummy{3, 2+indi} = disp(char(tmp_str)); - dummy{3, 2+indi} = horzcat... - (vspace, char(regexp(dummy{3, 2+indi}, '.*', ... - 'match', 'dotexceptnewline'))); - indi = indi + 1; indk = indk + 1; - endwhile - otherwise - %# keep only one horizontal space per line - unfolded = df._data{indc}(:, df._rep{indc}); - indk = 1; while indk <= size(unfolded, 2), - dummy{3, 2+indi} = disp(unfolded(:, indk)); - tmp_str = char(regexp(dummy{3, 2+indi}, \ - '[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?(\s??[-+]\s??[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?i)?', \ - 'match', 'dotexceptnewline')); - tmp_str = horzcat... - (vspace, char(regexp(dummy{3, 2+indi}, '\S.*', ... - 'match', 'dotexceptnewline'))); - dummy{3, 2+indi} = tmp_str; - indi = indi + 1; indk = indk + 1; - endwhile + case {'char'} + indk = 1; while (indk <= size (df._data{indc}, 2)) + 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)) + if (indj(indr)), + if (isna (tmp_str{indr})), + tmp_str{indr} = "NA"; + else + try + tmp_str{indr} = undo_string_escapes (tmp_str{indr}); + catch + disp('line 93 '); keyboard + end + endif + endif + endfor + %# keep the whole thing, and add a vertical space + dummy{3, 2+indi} = disp (char (tmp_str)); + dummy{3, 2+indi} = horzcat... + (vspace, char (regexp (dummy{3, 2+indi}, '.*', ... + 'match', 'dotexceptnewline'))); + indi = indi + 1; indk = indk + 1; + endwhile + otherwise + %# keep only one horizontal space per line + unfolded = df._data{indc}(:, df._rep{indc}); + indk = 1; while (indk <= size (unfolded, 2)) + dummy{3, 2+indi} = disp (unfolded(:, indk)); + tmp_str = char (regexp (dummy{3, 2+indi}, \ + '[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?(\s??[-+]\s??[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?i)?', \ + 'match', 'dotexceptnewline')); + tmp_str = horzcat... + (vspace, char (regexp (dummy{3, 2+indi}, '\S.*', ... + 'match', 'dotexceptnewline'))); + dummy{3, 2+indi} = tmp_str; + indi = indi + 1; indk = indk + 1; + endwhile endswitch endfor @@ -122,39 +126,39 @@ vspace = [' '; ' '; vspace]; %# second line content resu = []; - 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)))), - 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'); - if (isempty(resu)), - resu = strjust(char(dummy{2, 1}, indi), 'right'); - else - resu = horzcat(resu, vspace, strjust(char(dummy{2, 1}, indi), \ - 'right'), vspace); - endif - else - for ind2 = 1:size(df._ridx, 3), - 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'); - if (isempty(resu)), - resu = strjust(char(dummy{2, 1}, indi), 'right'); - else - resu = horzcat(resu, vspace, strjust(char(dummy{2, 1}, indi), \ - 'right'), vspace); - endif - endif - endfor - endif + 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))))) + 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'); + if (isempty (resu)) + resu = strjust (char (dummy{2, 1}, indi), 'right'); + else + resu = horzcat(resu, vspace, strjust (char (dummy{2, 1}, indi), \ + 'right'), vspace); + endif + else + for ind2 = (1:size (df._ridx, 3)) + 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'); + if (isempty (resu)) + resu = strjust (char (dummy{2, 1}, indi), 'right'); + else + resu = horzcat (resu, vspace, strjust (char(dummy{2, 1}, indi), \ + 'right'), vspace); + endif + endif + endfor + endif endfor endif %# emit row names - if (isempty(df._name{1})), + if (isempty (df._name{1})), dummy{2, 2} = []; dummy{3, 2} = []; else dummy{2, 2} = [" ";" "]; @@ -162,39 +166,39 @@ endif %# insert a vertical space - if (!isempty(dummy{3, 2})), - indi = ~cellfun('isempty', dummy{3, 2}); - if (any(indi)), - try - resu = horzcat(resu, vspace, strjust(char(dummy{2, 2}, dummy{3, 2}),\ - 'right')); - catch - disp('line 172 '); keyboard - end_try_catch + if (!isempty(dummy{3, 2})) + indi = ~cellfun ('isempty', dummy{3, 2}); + if (any (indi)) + try + resu = horzcat (resu, vspace, strjust (char(dummy{2, 2}, dummy{3, 2}),\ + 'right')); + catch + disp ('line 172 '); keyboard + end_try_catch endif endif %# emit each colum - for indi = 1:size(dummy, 2) - 2, + for indi = (1:size (dummy, 2) - 2) %# was max(df._cnt(2:end)), try - %# avoid this column touching the previous one - if any(cellfun('size', dummy(1:2, 2+indi), 2) >= \ - size(dummy{3, 2+indi}, 2)), - resu = horzcat(resu, vspace); - endif - resu = horzcat(resu, strjust(char(dummy{:, 2+indi}), 'right')); + %# avoid this column touching the previous one + if (any (cellfun ('size', dummy(1:2, 2+indi), 2) >= \ + size (dummy{3, 2+indi}, 2))) + resu = horzcat (resu, vspace); + endif + resu = horzcat (resu, strjust (char (dummy{:, 2+indi}), 'right')); catch - tmp_str = sprintf("Emitting %d lines, expecting %d", ... - size(dummy{3, 2+indi}, 1), df._cnt(1)); - keyboard - error(tmp_str); + tmp_str = sprintf ("Emitting %d lines, expecting %d", ... + size (dummy{3, 2+indi}, 1), df._cnt(1)); + keyboard + error (tmp_str); end_try_catch endfor else resu = ''; endif - resu = char(head, resu); disp(resu) + resu = char (head, resu); disp (resu) endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m 2011-10-06 14:32:51 UTC (rev 8687) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m 2011-10-06 16:46:26 UTC (rev 8688) @@ -25,451 +25,455 @@ %# $Id$ %# - if (isnull(RHS)), - if (1 == ncol), - if (sum(~strcmp(S.subs, ':')) > 2), - error("A null assignment can only have one non-colon index."); + if (isnull (RHS)) + if (1 == ncol) + if (sum (~strcmp (S.subs, ':')) > 2) + error("A null assignment can only have one non-colon index."); endif - elseif (sum(~strcmp(S.subs, ':')) > 1), + elseif (sum (~strcmp (S.subs, ':')) > 1) error("A null assignment can only have one non-colon index."); endif - if (strcmp(S.subs(1), ':')), %# removing column/matrix + if (strcmp (S.subs(1), ':')) %# removing column/matrix RHS = S; RHS.subs(2) = []; - for indi = indc, - unfolded = df._data{indi}(:, df._rep{indi}); - unfolded = feval(@subsasgn, unfolded, RHS, []); - df._data{indi} = unfolded; - if (!isempty(unfolded)), - df._rep(indi) = 1:size(unfolded, 2); - endif + for indi = indc + unfolded = df._data{indi}(:, df._rep{indi}); + unfolded = feval (@subsasgn, unfolded, RHS, []); + df._data{indi} = unfolded; + if (!isempty (unfolded)) + df._rep(indi) = 1:size (unfolded, 2); + endif endfor %# remove empty elements - indi = cellfun('isempty', df._data); - if (any(indi)), %# nothing left, remove this column - df._cnt(2) = df._cnt(2) - sum(indi); - indi = ~indi; %# vector of kept data - df._name{2} = df._name{2}(indi); - df._over{2} = df._over{2}(indi); - df._type = df._type(indi); - df._data = df._data(indi); - df._rep = df._rep(indi); + indi = cellfun ('isempty', df._data); + if (any (indi)) %# nothing left, remove this column + df._cnt(2) = df._cnt(2) - sum (indi); + indi = ~indi; %# vector of kept data + df._name{2} = df._name{2}(indi); + df._over{2} = df._over{2}(indi); + df._type = df._type(indi); + df._data = df._data(indi); + df._rep = df._rep(indi); endif - if (size(df._ridx, 3) > 1), - df._ridx(:, indc, :) = []; + if (size (df._ridx, 3) > 1) + df._ridx(:, indc, :) = []; endif - elseif (strcmp(S.subs(2), ':')), %# removing rows + elseif (strcmp (S.subs(2), ':')) %# removing rows indr = S.subs{1}; - if !isempty(df._name{1}), - df._name{1}(indr, :) = []; - df._over{1}(indr) = []; - endif + if (!isempty (df._name{1})) + df._name{1}(indr, :) = []; + df._over{1}(indr) = []; + endif df._ridx(indr, :, :) = []; %# to remove a line, iterate on each column - df._data = cellfun(@(x) feval(@subsasgn, x, S, []), \ - df._data, "UniformOutPut", false); - if (isa(indr, 'char')), - df._cnt(1) = 0; + df._data = cellfun (@(x) feval(@subsasgn, x, S, []), \ + df._data, "UniformOutPut", false); + if (isa (indr, 'char')) + df._cnt(1) = 0; else - df._cnt(1) = df._cnt(1) - length(indr); + df._cnt(1) = df._cnt(1) - length (indr); endif endif df = df_thirddim(df); return; endif - indc_was_set = ~isempty(indc); - if (~indc_was_set), %# initial dataframe was empty - ncol = size(RHS, 2); indc = 1:ncol; + indc_was_set = ~isempty (indc); + if (~indc_was_set) %# initial dataframe was empty + ncol = size (RHS, 2); indc = 1:ncol; endif indr = S.subs{1, 1}; - indr_was_set = ~isempty(indr); + indr_was_set = ~isempty (indr); %# initial dataframe was empty ? - if (~indr_was_set || strcmp(indr, ':')), - if (iscell(RHS)), - nrow = max(sum(cellfun('size', RHS, 1))); + if (~indr_was_set || strcmp (indr, ':')) + if (iscell (RHS)) + nrow = max (sum (cellfun ('size', RHS, 1))); else - if (isvector(RHS)), - if (0 == df._cnt(1)), - nrow = size(RHS, 1); - else - nrow = df._cnt(1); %# limit to df numbner of rows - endif + if (isvector (RHS)) + if (0 == df._cnt(1)) + nrow = size (RHS, 1); + else + nrow = df._cnt(1); %# limit to df numbner of rows + endif else - %# deduce limit from RHS - nrow = size(RHS, 1); + %# deduce limit from RHS + nrow = size (RHS, 1); endif endif indr = 1:nrow; - elseif (!isempty(indr) && isnumeric(indr)), - nrow = length(indr); + elseif (!isempty (indr) && isnumeric (indr)) + nrow = length (indr); endif - if (length(S.subs) > 2), + if (length (S.subs) > 2) inds = S.subs{1, 3}; else inds = []; endif - - rname = cell(0, 0); rname_width = max(1, size(df._name{2}, 2)); + + rname = cell(0, 0); rname_width = max (1, size (df._name{2}, 2)); ridx = []; cname = rname; ctype = rname; - if (iscell(RHS)), - if (length(indc) == df._cnt(2) && size(RHS, 2) >= df._cnt(2)) \ - || 0 == df._cnt(2) || isempty(S.subs{1}), + if (iscell (RHS)) + if (length (indc) == df._cnt(2) && size (RHS, 2) >= df._cnt(2)) \ + || 0 == df._cnt(2) || isempty (S.subs{1}) %# providing too much information -- remove extra content - if (size(RHS, 1) > 1), - %# at this stage, verify that the first line doesn't contain - %# chars only; use them for column names - dummy = cellfun('class', \ - RHS(1, ~cellfun('isempty', RHS(1, :))), \ - 'UniformOutput', false); - dummy = strcmp(dummy, 'char'); - if (all(dummy)), - if (length(df._over{2}) >= max(indc) \ - && !all(df._over{2}(indc))), - keyboard - warning("Trying to overwrite colum names"); - endif - cname = RHS(1, :).'; RHS = RHS(2:end, :); - if (~indr_was_set), - nrow = nrow - 1; indr = 1:nrow; - endif - endif - %# at this stage, verify that the first line doesn't contain - %# chars only; use them for column types - dummy = cellfun('class', \ - RHS(1, ~cellfun('isempty', RHS(1, :))), \ - 'UniformOutput', false); - dummy = strcmp(dummy, 'char'); - if (all(dummy)), - if (length(df._over{2}) >= max(indc) \ - && !all(df._over{2}(indc))), - warning("Trying to overwrite colum names"); - endif - ctype = RHS(1, :); RHS = RHS(2:end, :); - if (~indr_was_set), - nrow = nrow - 1; indr = 1:nrow; - endif - endif + if (size (RHS, 1) > 1) + %# at this stage, verify that the first line doesn't contain + %# chars only; use them for column names + dummy = cellfun ('class', \ + RHS(1, ~cellfun ('isempty', RHS(1, :))), \ + 'UniformOutput', false); + dummy = strcmp (dummy, 'char'); + if (all (dummy)) + if (length (df._over{2}) >= max (indc) \ + && !all (df._over{2}(indc))) + keyboard + warning("Trying to overwrite colum names"); + endif + cname = RHS(1, :).'; RHS = RHS(2:end, :); + if (~indr_was_set) + nrow = nrow - 1; indr = 1:nrow; + endif + endif + %# at this stage, verify that the first line doesn't contain + %# chars only; use them for column types + dummy = cellfun ('class', \ + RHS(1, ~cellfun ('isempty', RHS(1, :))), \ + 'UniformOutput', false); + dummy = strcmp (dummy, 'char'); + if (all (dummy)) + if (length (df._over{2}) >= max (indc) \ + && !all (df._over{2}(indc))) + warning("Trying to overwrite colum names"); + endif + ctype = RHS(1, :); RHS = RHS(2:end, :); + if (~indr_was_set) + nrow = nrow - 1; indr = 1:nrow; + endif + endif endif %# more elements than df width -- try to use the first two as %# row index and/or row name - if (size(RHS, 1) > 1), - dummy = all(cellfun('isnumeric', \ - RHS(~cellfun('isempty', RHS(:, 1)), 1))); + if (size (RHS, 1) > 1) + dummy = all (cellfun ('isnumeric', \ + RHS(~cellfun ('isempty', RHS(:, 1)), 1))); else - dummy = isnumeric(RHS{1, 1}); + dummy = isnumeric(RHS{1, 1}); endif - dummy = dummy && (!isempty(cname) && size(cname{1}, 2) < 1); - if (dummy), - ridx = cell2mat(RHS(:, 1)); - %# can it be converted to a list of unique numbers ? - if (length(unique(ridx)) == length(ridx)), - ridx = RHS(:, 1); RHS = RHS(:, 2:end); - if (length(df._name{2}) == df._cnt(2) + ncol), - %# columns name were pre-filled with too much values - df._name{2}(end) = []; - df._over{2}(end) = []; - if (size(RHS, 2) < ncol), - ncol = size(RHS, 2); indc = 1:ncol; - endif - elseif (!indc_was_set), - ncol = ncol - 1; indc = 1:ncol; - endif - if (!isempty(cname)), cname = cname(2:end); endif - if (!isempty(ctype)), ctype = ctype(2:end); endif - else - ridx = []; - endif + dummy = dummy && (!isempty (cname) && size (cname{1}, 2) < 1); + if (dummy) + ridx = cell2mat(RHS(:, 1)); + %# can it be converted to a list of unique numbers ? + if (length (unique (ridx)) == length (ridx)) + ridx = RHS(:, 1); RHS = RHS(:, 2:end); + if (length (df._name{2}) == df._cnt(2) + ncol) + %# columns name were pre-filled with too much values + df._name{2}(end) = []; + df._over{2}(end) = []; + if (size (RHS, 2) < ncol) + ncol = size (RHS, 2); indc = 1:ncol; + endif + elseif (!indc_was_set) + ncol = ncol - 1; indc = 1:ncol; + endif + if (!isempty (cname)) cname = cname(2:end); endif + if (!isempty (ctype)) ctype = ctype(2:end); endif + else + ridx = []; + endif endif - if (size(RHS, 2) > df._cnt(2)), - %# verify the the first row doesn't contain chars only, use them - %# for row names - dummy = cellfun('class', \ - RHS(~cellfun('isempty', RHS(:, 1)), 1), \ - 'UniformOutput', false); - dummy = strcmp(dummy, 'char') \ - && (!isempty(cname) && size(cname{1}, 2) < 1); - if (all(dummy)), - if (length(df._over{1}) >= max(indr) \ - && !all(df._over{1}(indr))), - warning("Trying to overwrite row names"); - else - rname = RHS(:, 1); - endif - rname_width = max([1; cellfun('size', rname, 2)]); - RHS = RHS(:, 2:end); - if (length(df._name{2}) == df._cnt(2) + ncol), - %# columns name were pre-filled with too much values - df._name{2}(end) = []; - df._over{2}(end) = []; - if (size(RHS, 2) < ncol), - ncol = size(RHS, 2); indc = 1:ncol; - endif - elseif (!indc_was_set), - ncol = ncol - 1; indc = 1:ncol; - endif - if (!isempty(cname)), cname = cname(2:end); endif - if (!isempty(ctype)), ctype = ctype(2:end); endif - endif + if (size (RHS, 2) > df._cnt(2)) + %# verify the the first row doesn't contain chars only, use them + %# for row names + dummy = cellfun ('class', \ + RHS(~cellfun ('isempty', RHS(:, 1)), 1), \ + 'UniformOutput', false); + dummy = strcmp (dummy, 'char') \ + && (!isempty (cname) && size (cname{1}, 2) < 1); + if (all (dummy)) + if (length (df._over{1}) >= max (indr) \ + && !all (df._over{1}(indr))) + warning("Trying to overwrite row names"); + else + rname = RHS(:, 1); + endif + rname_width = max ([1; cellfun('size', rname, 2)]); + RHS = RHS(:, 2:end); + if (length (df._name{2}) == df._cnt(2) + ncol) + %# columns name were pre-filled with too much values + df._name{2}(end) = []; + df._over{2}(end) = []; + if (size (RHS, 2) < ncol) + ncol = size (RHS, 2); indc = 1:ncol; + endif + elseif (!indc_was_set) + ncol = ncol - 1; indc = 1:ncol; + endif + if (!isempty (cname)) cname = cname(2:end); endif + if (!isempty (ctype)) ctype = ctype(2:end); endif + endif endif endif endif %# perform row resizing if columns are already filled - if (!isempty(indr) && isnumeric(indr)), - if (max(indr) > df._cnt(1) && size(df._data, 2) == df._cnt(2)), - df = df_pad(df, 1, max(indr)-df._cnt(1), rname_width); + if (!isempty (indr) && isnumeric(indr)) + if (max (indr) > df._cnt(1) && size (df._data, 2) == df._cnt(2)) + df = df_pad(df, 1, max (indr)-df._cnt(1), rname_width); endif endif - if (iscell(RHS)), %# we must pad on a column-by-column basis + if (iscell(RHS)) %# we must pad on a column-by-column basis %# verify that each cell contains a non-empty vector, and that sizes %# are compatible - %# dummy = cellfun('size', RHS(:), 2); - %# if any(dummy < 1), + %# dummy = cellfun ('size', RHS(:), 2); + %# if any (dummy < 1), %# error("cells content may not be empty"); %# endif - %# dummy = cellfun('size', RHS, 1); - %# if any(dummy < 1), + %# dummy = cellfun ('size', RHS, 1); + %# if any (dummy < 1), %# error("cells content may not be empty"); %# endif - %# if any(diff(dummy) > 0), + %# if any (diff(dummy) > 0), %# error("cells content with unequal length"); %# endif - %# if 1 < size(RHS, 1) && any(dummy > 1), + %# if 1 < size (RHS, 1) && any (dummy > 1), %# error("cells may only contain scalar"); %# endif %# the real assignement - if (1 == size(RHS, 1)), %# each cell contains one vector + if (1 == size (RHS, 1)) %# each cell contains one vector fillfunc = @(x) RHS{x}; idxOK = logical(indr); else %# use cell2mat to pad on a column-by-column basis - fillfunc = @(x) cell2mat(RHS(:, x)); + fillfunc = @(x) cell2mat (RHS(:, x)); endif indj = 1; for indi = 1:ncol, - if (indc(indi) > df._cnt(2)), - %# perform dynamic resizing one-by-one, to get type right - if (isempty(ctype) || length(ctype) < indc(indi)), - df = df_pad(df, 2, indc(indi)-df._cnt(2), class(RHS{1, indj})); - else - df = df_pad(df, 2, indc(indi)-df._cnt(2), ctype{indj}); - endif + if (indc(indi) > df._cnt(2)) + %# perform dynamic resizing one-by-one, to get type right + if (isempty (ctype) || length (ctype) < indc(indi)) + df = df_pad(df, 2, indc(indi)-df._cnt(2), class(RHS{1, indj})); + else + df = df_pad(df, 2, indc(indi)-df._cnt(2), ctype{indj}); + endif endif - if (nrow == df._cnt(1)), - %# whole assignement - try - if (size(RHS, 1) <= 1), - switch df._type{indc(indi)} - case {'char' } %# use a cell array to hold strings - dummy = RHS(:, indj); - case {'double' } - dummy = fillfunc(indj); - otherwise - dummy = cast(fillfunc(indj), df._type{indc(indi)}); - endswitch - else - %# keeps indexes in sync as cell elements may be empty - idxOK = ~cellfun('isempty', RHS(:, indj)); - %# intialise dummy so that it can receive "anything" - dummy = []; - switch df._type{indc(indi)} - case {'char' } %# use a cell array to hold strings - dummy = RHS(:, indj); - case {'double' } - dummy(idxOK, :) = fillfunc(indj); dummy(~idxOK, :) = NA; - otherwise - dummy(idxOK, :) = fillfunc(indj); dummy(~idxOK, :) = NA; - dummy = cast(dummy, df._type{indc(indi)}); - 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); - end_try_catch - if (size(dummy, 1) < df._cnt(1)), - dummy(end+1:df._cnt(1), :) = NA; - endif + if (nrow == df._cnt(1)) + %# whole assignement + try + if (size (RHS, 1) <= 1) + switch df._type{indc(indi)} + case {'char' } %# use a cell array to hold strings + dummy = RHS(:, indj); + case {'double' } + dummy = fillfunc (indj); + otherwise + dummy = cast(fillfunc (indj), df._type{indc(indi)}); + endswitch + else + %# keeps indexes in sync as cell elements may be empty + idxOK = ~cellfun ('isempty', RHS(:, indj)); + %# intialise dummy so that it can receive "anything" + dummy = []; + switch df._type{indc(indi)} + case {'char' } %# use a cell array to hold strings + dummy = RHS(:, indj); + case {'double' } + dummy(idxOK, :) = fillfunc (indj); dummy(~idxOK, :) = NA; + otherwise + dummy(idxOK, :) = fillfunc (indj); dummy(~idxOK, :) = NA; + dummy = cast(dummy, df._type{indc(indi)}); + 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); + end_try_catch + if (size (dummy, 1) < df._cnt(1)) + dummy(end+1:df._cnt(1), :) = NA; + endif else - %# partial assignement -- extract actual data and update - dummy = df._data{indc(indi)}; - try - switch df._type{indc(indi)} - case {'char' } %# use a cell array to hold strings - dummy(indr, 1) = RHS(:, indj); - case {'double' } - dummy(indr, :) = fillfunc(indj); - otherwise - dummy(indr, :) = cast(fillfunc(indj), df._type{indc(indi)}); - endswitch - 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); - end_try_catch + %# partial assignement -- extract actual data and update + dummy = df._data{indc(indi)}; + try + switch df._type{indc(indi)} + case {'char' } %# use a cell array to hold strings + dummy(indr, 1) = RHS(:, indj); + case {'double' } + dummy(indr, :) = fillfunc (indj); + otherwise + dummy(indr, :) = cast(fillfunc (indj), df._type{indc(indi)}); + endswitch + 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); + end_try_catch endif - df._data{indc(indi)} = dummy; df._rep{indc(indi)} = 1:size(dummy, 2); + df._data{indc(indi)} = dummy; df._rep{indc(indi)} = 1:size (dummy, 2); indj = indj + 1; endfor else %# RHS is either a numeric, either a df - if (any(indc > min(size(df._data, 2), df._cnt(2)))), - df = df_pad(df, 2, max(indc-min(size(df._data, 2), df._cnt(2))),\ - class(RHS)); + if (any (indc > min (size (df._data, 2), df._cnt(2)))) + df = df_pad(df, 2, max (indc-min (size (df._data, 2), df._cnt(2))),\ + class(RHS)); endif - if (!isempty(inds) && isnumeric(inds) && any(inds > 1)), - for indi = 1:length(indc), - if (max(inds) > length(df._rep{indc(indi)})), - df = df_pad(df, 3, max(inds)-length(df._rep{indc(indi)}), \ - indc(indi)); - endif + if (!isempty (inds) && isnumeric(inds) && any (inds > 1)) + for indi = 1:length (indc) + if (max (inds) > length (df._rep{indc(indi)})) + df = df_pad(df, 3, max (inds)-length (df._rep{indc(indi)}), \ + indc(indi)); + endif endfor endif - if (isa(RHS, 'dataframe')), + if (isa (RHS, 'dataframe')) %# block-copy index S.subs(2) = 1; - if (any(!isna(RHS._ridx))), - df._ridx = feval(@subsasgn, df._ridx, S, RHS._ridx); + if (any (!isna(RHS._ridx))) + df._ridx = feval(@subsasgn, df._ridx, S, RHS._ridx); endif %# skip second dim and copy data S.subs(2) = []; Sorig = S; - for indi = 1:length(indc), - [df, S] = df_cow(df, S, indc(indi)); - if (strcmp(df._type(indc(indi)), RHS._type(indi))), - try - df._data{indc(indi)} = feval(@subsasgn, df._data{indc(indi)}, S, \ - RHS._data{indi}(:, RHS._rep{indi})); - catch - disp(lasterr()); disp('line 516 ???'); keyboard - end_try_catch - else - df._data{indc(indi)} = feval(@subsasgn, df._data{indc(indi)}, S, \ - cast(RHS._data{indi}(:, RHS._rep{indi}),\ - df._type(indc(indi)))); - endif - S = Sorig; + for indi = 1:length (indc) + [df, S] = df_cow(df, S, indc(indi)); + if (strcmp (df._type(indc(indi)), RHS._type(indi))) + try + df._data{indc(indi)} = feval(@subsasgn, df._data{indc(indi)}, S, \ + RHS._data{indi}(:, RHS._rep{indi})); + catch + disp(lasterr()); disp('line 516 ???'); keyboard + end_try_catch + else + df._data{indc(indi)} = feval(@subsasgn, df._data{indc(indi)}, S, \ + cast(RHS._data{indi}(:, RHS._rep{indi}),\ + df._type(indc(indi)))); + endif + S = Sorig; endfor - if (!isempty(RHS._name{1})), - df._name{1}(indr) = genvarname(RHS._name{1}(indr)); - df._over{1}(indr) = RHS._over{1}(indr); + if (!isempty (RHS._name{1})) + df._name{1}(indr) = genvarname(RHS._name{1}(indr)); + df._over{1}(indr) = RHS._over{1}(indr); endif - if (!isempty(RHS._src)), - if (!any(strcmp(cellstr(df._src), cellstr(RHS._src)))), - df._src = vertcat(df._src, RHS._src); - endif + if (!isempty (RHS._src)) + if (!any (strcmp (cellstr(df._src), cellstr(RHS._src)))) + df._src = vertcat(df._src, RHS._src); + endif endif - if (!isempty(RHS._cmt)), - if (!any(strcmp(cellstr(df._cmt), cellstr(RHS._cmt)))), - df._cmt = vertcat(df._cmt, RHS._cmt); - endif + if (!isempty (RHS._cmt)) + if (!any (strcmp (cellstr(df._cmt), cellstr(RHS._cmt)))) + df._cmt = vertcat(df._cmt, RHS._cmt); + endif endif else %# RHS is homogenous, pad at once - if (isvector(RHS)), %# scalar - vector - if (isempty(S.subs)), - fillfunc = @(x, y) RHS; - else - %# ignore 'column' dimension -- force colum vectors -- use a - %# third dim just in case - if (isempty(S.subs{1})), S.subs{1} = ':'; endif - S.subs(2) = []; - if (length(S.subs) < 2), - S.subs{2} = 1; - endif - if (length(indc) > 1 && length(RHS) > 1), - %# set a row from a vector - fillfunc = @(x, S, y) feval(@subsasgn, x, S, RHS(y)); - else - fillfunc = @(x, S, y) feval(@subsasgn, x, S, RHS); - endif - endif - Sorig = S; - for indi = 1:length(indc), - try - [df, S] = df_cow(df, S, indc(indi)); - df._data{indc(indi)} = fillfunc(df._data{indc(indi)}, S, indi); - S = Sorig; - catch - disp(lasterr) - disp('line 470 '); keyboard - end_try_catch - # catch - # if ndims(df._data{indc(indi)}) > 2, - # %# upstream forgot to give the third dim - # dummy = S; dummy.subs(3) = 1; - # df._data{indc(indi)} = fillfunc(df._data{indc(indi)}, \ - # dummy, indi); - # else - # rethrow(lasterr()); - # endif - # end_try_catch - endfor + if (isvector (RHS)) %# scalar - vector + if (isempty (S.subs)) + fillfunc = @(x, y) RHS; + else + %# ignore 'column' dimension -- force colum vectors -- use a + %# third dim just in case + if (isempty (S.subs{1})) S.subs{1} = ':'; endif + S.subs(2) = []; + if (length (S.subs) < 2) + S.subs{2} = 1; + endif + if (length (indc) > 1 && length (RHS) > 1) + %# set a row from a vector + fillfunc = @(x, S, y) feval (@subsasgn, x, S, RHS(y)); + else + fillfunc = @(x, S, y) feval (@subsasgn, x, S, RHS); + endif + endif + Sorig = S; + for indi = 1:length (indc) + try + [df, S] = df_cow(df, S, indc(indi)); + df._data{indc(indi)} = fillfunc (df._data{indc(indi)}, S, indi); + S = Sorig; + catch + disp(lasterr) + disp('line 470 '); keyboard + end_try_catch + # catch + # if ndims(df._data{indc(indi)}) > 2, + # %# upstream forgot to give the third dim + # dummy = S; dummy.subs(3) = 1; + # df._data{indc(indi)} = fillfunc(df._data{indc(indi)}, \ + # dummy, indi); + # else + # rethrow(lasterr()); + # endif + # end_try_catch + endfor else %# 2D - 3D matrix - S.subs(2) = []; %# ignore 'column' dimension - if (isempty(S.subs{1})), - S.subs{1} = indr; - endif - %# 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), - [df, S] = df_cow(df, S, indc(indi)); - df._data{indc(indi)} = fillfunc(df._data{indc(indi)}, S, indi); - S = Sorig; - endfor + S.subs(2) = []; %# ignore 'column' dimension + if (isempty (S.subs{1})) + S.subs{1} = indr; + endif + %# 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) + [df, S] = df_cow(df, S, indc(indi)); + df._data{indc(indi)} = fillfunc (df._data{indc(indi)}, S, indi); + S = Sorig; + endfor endif - if indi < size(RHS, 2) && !isa(RHS, 'char'), - warning(' not all columns of RHS used'); + if (indi < size (RHS, 2) && !isa (RHS, 'char')) + warning(' not all columns of RHS used'); endif endif endif %# delayed row padding -- column padding occured before - if !isempty(indr) && isnumeric(indr), - if max(indr) > df._cnt(1) && size(df._data, 2) < df._cnt(2), - df = df_pad(df, 1, max(indr)-df._cnt(1), rname_width); + if (!isempty (indr) && isnumeric (indr)) + if (max (indr) > df._cnt(1) && size (df._data, 2) < df._cnt(2)) + df = df_pad(df, 1, max (indr)-df._cnt(1), rname_width); endif endif %# adjust ridx and rnames, if required - if !isempty(ridx), + if !isempty (ridx) dummy = df._ridx; - ... [truncated message content] |
From: <cde...@us...> - 2012-03-11 20:53:40
|
Revision: 9817 http://octave.svn.sourceforge.net/octave/?rev=9817&view=rev Author: cdemills Date: 2012-03-11 20:53:31 +0000 (Sun, 11 Mar 2012) Log Message: ----------- apply the emptiness test in dataframe.m only if more than one row Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/cat.m trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m trunk/octave-forge/extra/dataframe/inst/@dataframe/find.m trunk/octave-forge/extra/dataframe/inst/@dataframe/fold.m trunk/octave-forge/extra/dataframe/inst/@dataframe/horzcat.m trunk/octave-forge/extra/dataframe/inst/@dataframe/inv.m trunk/octave-forge/extra/dataframe/inst/@dataframe/isfield.m trunk/octave-forge/extra/dataframe/inst/@dataframe/isscalar.m trunk/octave-forge/extra/dataframe/inst/@dataframe/isvector.m trunk/octave-forge/extra/dataframe/inst/@dataframe/ne.m trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_allmeta.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_basecomp.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_check_char_array.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_colmeta.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_cow.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_mapper2.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_name2idx.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_pad.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_strjust.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_strset.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_thirddim.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_whole.m trunk/octave-forge/extra/dataframe/inst/@dataframe/prod.m trunk/octave-forge/extra/dataframe/inst/@dataframe/repmat.m trunk/octave-forge/extra/dataframe/inst/@dataframe/reshape.m trunk/octave-forge/extra/dataframe/inst/@dataframe/size.m trunk/octave-forge/extra/dataframe/inst/@dataframe/sort.m trunk/octave-forge/extra/dataframe/inst/@dataframe/subsasgn.m trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m trunk/octave-forge/extra/dataframe/inst/@dataframe/sum.m trunk/octave-forge/extra/dataframe/inst/@dataframe/summary.m trunk/octave-forge/extra/dataframe/inst/@dataframe/sumsq.m trunk/octave-forge/extra/dataframe/inst/@dataframe/vertcat.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/cat.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/cat.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/cat.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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 Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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 Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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 Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/find.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/find.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/find.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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 Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/fold.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/fold.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/fold.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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 Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/horzcat.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/horzcat.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/horzcat.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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 Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/inv.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/inv.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/inv.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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 Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/isfield.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/isfield.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/isfield.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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 Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/isscalar.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/isscalar.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/isscalar.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -26,6 +26,6 @@ %# $Id$ %# - resu = ismatrix(df) & (length(find(df._cnt > 1)) < 1); + resu = ismatrix (df) & (length (find (df._cnt > 1)) < 1); endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/isvector.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/isvector.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/isvector.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -26,6 +26,6 @@ %# $Id$ %# - resu = ismatrix(df) & (length(find(df._cnt > 1)) <= 1); + resu = ismatrix (df) & (length (find (df._cnt > 1)) <= 1); endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/ne.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/ne.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/ne.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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 <Pas...@uc...> %% @@ -27,6 +27,6 @@ %# $Id$ %# - resu = df_func(@ne, A, B); + resu = df_func (@ne, A, B); endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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 Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_allmeta.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_allmeta.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_allmeta.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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; Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_basecomp.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_basecomp.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_basecomp.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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 Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_check_char_array.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_check_char_array.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_check_char_array.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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 Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_colmeta.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_colmeta.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_colmeta.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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; Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_cow.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_cow.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_cow.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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 Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m 2012-03-11 20:34:47 UTC (rev 9816) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m 2012-03-11 20:53:31 UTC (rev 9817) @@ -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} = sq... [truncated message content] |
From: <cde...@us...> - 2012-05-08 10:47:34
|
Revision: 10379 http://octave.svn.sourceforge.net/octave/?rev=10379&view=rev Author: cdemills Date: 2012-05-08 10:47:23 +0000 (Tue, 08 May 2012) Log Message: ----------- Removes single and double quotes Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2012-05-08 09:18:11 UTC (rev 10378) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/dataframe.m 2012-05-08 10:47:23 UTC (rev 10379) @@ -303,7 +303,7 @@ if (unquot) try %# remove quotes and leading space(s) - x(indj, indm) = regexp (dummy{indk}, '[^'' ].*[^'']', 'match'){1}; + x(indj, indm) = regexp (dummy{indk}, '[^''" ].*[^''"]', 'match'){1}; catch %# if the previous test fails, try a simpler one in = regexp (dummy{indk}, '[^'' ]+', 'match'); Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m 2012-05-08 09:18:11 UTC (rev 10378) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_matassign.m 2012-05-08 10:47:23 UTC (rev 10379) @@ -67,17 +67,17 @@ df._ridx(indr, :, :) = []; %# to remove a line, iterate on each column df._data = cellfun (@(x) feval(@subsasgn, x, S, []), \ - df._data, "UniformOutPut", false); + df._data, "UniformOutPut", false); if (isa (indr, 'char')) - df._cnt(1) = 0; - else - df._cnt(1) = df._cnt(1) - length (indr); - endif + df._cnt(1) = 0; + else + df._cnt(1) = df._cnt(1) - length (indr); + endif endif df = df_thirddim (df); return; endif - + indc_was_set = ~isempty (indc); if (~indc_was_set) %# initial dataframe was empty ncol = size (RHS, 2); indc = 1:ncol; @@ -116,10 +116,10 @@ else inds = []; endif - + rname = cell(0, 0); rname_width = max (1, size (df._name{2}, 2)); ridx = []; cname = rname; ctype = rname; - + if (iscell (RHS)) if ((length (indc) == df._cnt(2) && size (RHS, 2) >= df._cnt(2)) \ || 0 == df._cnt(2) || isempty (S.subs{1}) || isempty (S.subs{2})) @@ -133,10 +133,10 @@ dummy = strcmp (dummy, 'char'); if (all (dummy)) if (length (df._over{2}) >= max (indc) \ - && ~all (df._over{2}(indc)) && ~isempty (S.subs{2})) + && ~all (df._over{2}(indc)) && ~isempty (S.subs{2})) warning("Trying to overwrite colum names"); endif - + cname = RHS(1, :).'; RHS = RHS(2:end, :); if (~indr_was_set) nrow = nrow - 1; indr = 1:nrow; @@ -157,19 +157,19 @@ %# at this stage, verify that the first line doesn't contain %# chars only; use them for column types dummy = cellfun ('class', \ - RHS(1, ~cellfun ('isempty', RHS(1, :))), \ - 'UniformOutput', false); + RHS(1, ~cellfun ('isempty', RHS(1, :))), \ + 'UniformOutput', false); dummy = strcmp (dummy, 'char'); if (all (dummy)) if (length (df._over{2}) >= max (indc) \ - && ~all (df._over{2}(indc))) + && ~all (df._over{2}(indc))) warning ("Trying to overwrite colum names"); endif if (sum (~cellfun ('isempty', RHS(1, indc))) == ncol) ctype = RHS(1, :); endif - + RHS = RHS(2:end, :); if (~indr_was_set) nrow = nrow - 1; indr = 1:nrow; @@ -181,7 +181,7 @@ %# row index and/or row name if (size (RHS, 1) > 1) dummy = all (cellfun ('isnumeric', \ - RHS(~cellfun ('isempty', RHS(:, 1)), 1))); + RHS(~cellfun ('isempty', RHS(:, 1)), 1))); else dummy = isnumeric(RHS{1, 1}); endif @@ -207,18 +207,18 @@ ridx = []; endif endif - + if (size (RHS, 2) > df._cnt(2)) %# verify the the first row doesn't contain chars only, use them %# for row names dummy = cellfun ('class', \ - RHS(~cellfun ('isempty', RHS(:, 1)), 1), \ - 'UniformOutput', false); + RHS(~cellfun ('isempty', RHS(:, 1)), 1), \ + 'UniformOutput', false); dummy = strcmp (dummy, 'char') \ && (~isempty (cname) && size (cname{1}, 2) < 1); if (all (dummy)) if (length (df._over{1}) >= max (indr) \ - && ~all (df._over{1}(indr))) + && ~all (df._over{1}(indr))) warning("Trying to overwrite row names"); else rname = RHS(:, 1); @@ -241,14 +241,14 @@ endif endif endif - + %# perform row resizing if columns are already filled if (~isempty (indr) && isnumeric(indr)) if (max (indr) > df._cnt(1) && size (df._data, 2) == df._cnt(2)) df = df_pad (df, 1, max (indr)-df._cnt(1), rname_width); endif endif - + if (iscell(RHS)) %# we must pad on a column-by-column basis %# verify that each cell contains a non-empty vector, and that sizes %# are compatible @@ -267,11 +267,15 @@ %# if 1 < size (RHS, 1) && any (dummy > 1), %# error("cells may only contain scalar"); %# endif - + if (size (RHS, 2) > indc) - keyboard + if (size (cname, 1) > indc) + ncol = size (RHS, 2); indc = 1:ncol; + else + keyboard + endif endif - + %# try to detect and remove bottom garbage eff_len = zeros (nrow, 1); if (size (RHS, 1) > 1) @@ -295,7 +299,7 @@ endwhile clear eff_len; endif - + %# the real assignement if (1 == size (RHS, 1)) %# each cell contains one vector fillfunc = @(x) RHS{x}; @@ -304,7 +308,7 @@ fillfunc = @(x) cell2mat (RHS(:, x)); endif - indj = 1; + indj = 1; for indi = (1:ncol) if (indc(indi) > df._cnt(2)) %# perform dynamic resizing one-by-one, to get type right This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cde...@us...> - 2012-09-06 20:29:37
|
Revision: 10967 http://octave.svn.sourceforge.net/octave/?rev=10967&view=rev Author: cdemills Date: 2012-09-06 20:29:31 +0000 (Thu, 06 Sep 2012) Log Message: ----------- A few cleanups Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/isempty.m trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/isempty.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/isempty.m 2012-09-05 20:02:40 UTC (rev 10966) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/isempty.m 2012-09-06 20:29:31 UTC (rev 10967) @@ -5,6 +5,6 @@ %# the number of columns, or both are zero). Otherwise, return 0. %# @end deftypefn - resu = any(0 == size(df)); + resu = any (0 == size (df)); endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m 2012-09-05 20:02:40 UTC (rev 10966) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/permute.m 2012-09-06 20:29:31 UTC (rev 10967) @@ -109,6 +109,7 @@ endif resu._src = df._src; + resu._header = df._header; resu._cmt = df._cmt; endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |