From: <cde...@us...> - 2010-11-24 15:34:01
|
Revision: 7943 http://octave.svn.sourceforge.net/octave/?rev=7943&view=rev Author: cdemills Date: 2010-11-24 15:33:54 +0000 (Wed, 24 Nov 2010) Log Message: ----------- A few new functions and corrections Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m trunk/octave-forge/extra/dataframe/inst/@dataframe/numel.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_basecomp.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_mapper2.m Added Paths: ----------- trunk/octave-forge/extra/dataframe/inst/@dataframe/columns.m trunk/octave-forge/extra/dataframe/inst/@dataframe/ismatrix.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/power.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/rows.m Added: trunk/octave-forge/extra/dataframe/inst/@dataframe/columns.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/columns.m (rev 0) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/columns.m 2010-11-24 15:33:54 UTC (rev 7943) @@ -0,0 +1,31 @@ +function resu = columns(df) + %# function resu = columns(df) + %# returns the number of columns of a dataframe + + %% 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 = df._cnt(end); + +endfunction Property changes on: trunk/octave-forge/extra/dataframe/inst/@dataframe/columns.m ___________________________________________________________________ Added: svn:keywords + Id Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m 2010-11-23 17:35:27 UTC (rev 7942) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/display.m 2010-11-24 15:33:54 UTC (rev 7943) @@ -27,111 +27,115 @@ %# $Id$ %# -%# generate header name -if 2 == length(df._cnt), - head = sprintf("Dataframe with %d rows and %d columns", df._cnt); -else - head = sprintf("Dataframe with %d rows and %d columns (%d unfolded)", ... - df._cnt); -endif -if !isempty(df._src), - for indi = 1:size(df._src, 1), - head = char(head, ["Src: " df._src{indi, 1}]); - endfor -endif + %# generate header name + if 2 == length(df._cnt), + head = sprintf("Dataframe with %d rows and %d columns", df._cnt); + else + head = sprintf("Dataframe with %d rows and %d columns (%d unfolded)", ... + df._cnt); + endif -if all(df._cnt > 0), %# stop for empty df - 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 == size(df._data{indc}, 2), - dummy{1, 2+indi} = deblank(disp(df._name{2}{indc})); - dummy{2, 2+indi} = deblank(df._type{indc}); + if !isempty(df._src), + for indi = 1:size(df._src, 1), + head = char(head, ["Src: " df._src{indi, 1}]); + endfor + endif + + if all(df._cnt > 0), %# stop for empty df + 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 == size(df._data{indc}, 2), + 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:size(df._data{indc}, 2)), 'UniformOutput', false); + dummy{1, 2+indi} = tmp_str{1}; + dummy{2, 2+indi} = deblank(df._type{indc}); + indk = 1; while indk < size(df._data{indc}, 2), + dummy{1, 2+indi+indk} = tmp_str{1+indk}; + dummy{2, 2+indi+indk} = dummy{2, 2+indi}; + indk = indk + 1; + endwhile + 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 + indk = 1; while indk <= size(df._data{indc}, 2), + dummy{3, 2+indi} = disp(df._data{indc}(:, 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 + + %# put everything together + vspace = [' '; ' '; vspace]; + %# second line content + if !isempty(df._ridx), + if 1 == size(df._ridx, 2), + dummy{2, 1} = ["_"; "Nr"]; + dummy{3, 1} = disp(df._ridx(:)); + indi = regexp(dummy{3, 1}, '\b.*\b', 'match', 'dotexceptnewline'); + resu = strjust(char(dummy{2, 1}, indi), 'right'); + else + resu = []; + for indi = 1:size(df._ridx, 2)-1, + dummy{2, 1} = [["_." num2str(indi)]; "Nr"]; + dummy{3, 1} = disp(df._ridx(:, indi)); + indj = regexp(dummy{3, 1}, '\b.*\b', 'match', 'dotexceptnewline'); + resu = horzcat(resu, strjust(char(dummy{2, 1}, indj), 'right'), vspace); + endfor + dummy{2, 1} = [["_." num2str(indi+1)]; "Nr"]; + dummy{3, 1} = disp(df._ridx(:, end)); + indj = regexp(dummy{3, 1}, '\b.*\b', 'match', 'dotexceptnewline'); + resu = horzcat(resu, strjust(char(dummy{2, 1}, indj), 'right')); + endif 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:size(df._data{indc}, 2)), 'UniformOutput', false); - dummy{1, 2+indi} = tmp_str{1}; - dummy{2, 2+indi} = deblank(df._type{indc}); - indk = 1; while indk < size(df._data{indc}, 2), - dummy{1, 2+indi+indk} = tmp_str{1+indk}; - dummy{2, 2+indi+indk} = dummy{2, 2+indi}; - indk = indk + 1; - endwhile + resu = []; 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 - indk = 1; while indk <= size(df._data{indc}, 2), - dummy{3, 2+indi} = disp(df._data{indc}(:, 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 - vspace = [' '; ' '; vspace]; - %# second line content - if 1 == size(df._ridx, 2), - dummy{2, 1} = ["_"; "Nr"]; - dummy{3, 1} = disp(df._ridx(:)); - indi = regexp(dummy{3, 1}, '\b.*\b', 'match', 'dotexceptnewline'); - resu = strjust(char(dummy{2, 1}, indi), 'right'); - else - resu = []; - for indi = 1:size(df._ridx, 2)-1, - dummy{2, 1} = [["_." num2str(indi)]; "Nr"]; - dummy{3, 1} = disp(df._ridx(:, indi)); - indj = regexp(dummy{3, 1}, '\b.*\b', 'match', 'dotexceptnewline'); - resu = horzcat(resu, strjust(char(dummy{2, 1}, indj), 'right'), vspace); - endfor - dummy{2, 1} = [["_." num2str(indi+1)]; "Nr"]; - dummy{3, 1} = disp(df._ridx(:, end)); - indj = regexp(dummy{3, 1}, '\b.*\b', 'match', 'dotexceptnewline'); - resu = horzcat(resu, strjust(char(dummy{2, 1}, indj), 'right')); - endif - %# emit row names - if isempty(df._name{1}), - dummy{2, 2} = []; dummy{3, 2} = []; - else - dummy{2, 2} = [" ";" "]; - dummy{3, 2} = df._name{1}; - endif - - if size(dummy, 2) > 1, - %# resu contains the ridx - + %# emit row names + if isempty(df._name{1}), + dummy{2, 2} = []; dummy{3, 2} = []; + else + dummy{2, 2} = [" ";" "]; + dummy{3, 2} = df._name{1}; + endif + %# insert a vertical space if !isempty(dummy{3, 2}), indi = ~cellfun('isempty', dummy{3, 2}); @@ -160,10 +164,7 @@ else resu = ''; endif -else - resu = ''; -endif + + resu = char(head, resu); disp(resu) -resu = char(head, resu); disp(resu) - - +endfunction Added: trunk/octave-forge/extra/dataframe/inst/@dataframe/ismatrix.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/ismatrix.m (rev 0) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/ismatrix.m 2010-11-24 15:33:54 UTC (rev 7943) @@ -0,0 +1,38 @@ +function resu = ismatrix(df) + %# function resu = ismatrix(df) + %# returns true if the dataframe can be converted to 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$ + %# + + df_is_num = isnumeric(df._data{1}); + df_is_char = ischar(df._data{1}); + for indi = df._cnt(2):-1:2, + df_is_num = df_is_num & isnumeric(df._data{indi}); + df_is_char = df_is_char & ischar(df._data{indi}); + endfor + + resu = df_is_num | df_is_char; + +endfunction Property changes on: trunk/octave-forge/extra/dataframe/inst/@dataframe/ismatrix.m ___________________________________________________________________ Added: svn:keywords + Id Added: trunk/octave-forge/extra/dataframe/inst/@dataframe/isscalar.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/isscalar.m (rev 0) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/isscalar.m 2010-11-24 15:33:54 UTC (rev 7943) @@ -0,0 +1,31 @@ +function resu = isscalar(df) + %# function resu = isscalar(df) + %# returns true if the dataframe can be converted to a vector + + %% 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 = ismatrix(df) & (length(find(df._cnt > 1)) < 1); + +endfunction Property changes on: trunk/octave-forge/extra/dataframe/inst/@dataframe/isscalar.m ___________________________________________________________________ Added: svn:keywords + Id Added: trunk/octave-forge/extra/dataframe/inst/@dataframe/isvector.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/isvector.m (rev 0) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/isvector.m 2010-11-24 15:33:54 UTC (rev 7943) @@ -0,0 +1,31 @@ +function resu = isvector(df) + %# function resu = isvector(df) + %# returns true if the dataframe can be converted to a vector + + %% 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 = ismatrix(df) & (length(find(df._cnt > 1)) <= 1); + +endfunction Property changes on: trunk/octave-forge/extra/dataframe/inst/@dataframe/isvector.m ___________________________________________________________________ Added: svn:keywords + Id Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/numel.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/numel.m 2010-11-23 17:35:27 UTC (rev 7942) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/numel.m 2010-11-24 15:33:54 UTC (rev 7943) @@ -27,22 +27,16 @@ %# $Id$ %# - if isempty(varargin), - n = builtin('numel', df); - else - n = builtin('numel', df, varargin); - endif - return; +%# if 1 == nargout, +%# n = feval(@numel, df, varargin{:}); +%# else + if 1 == nargin, + n = prod(df._cnt([1 end])); + else + error(print_usage()); + endif +%# endif - %# dead code -- MatLab usage of numel is inconsistant between arrays - %# and objects. Compare numel(randn(3)) and numel(some_class) - - if 1 == nargin, - n = prod(df._cnt([1 end])); - else - error(print_usage()); - endif - endfunction function usage = print_usage() Added: trunk/octave-forge/extra/dataframe/inst/@dataframe/power.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/power.m (rev 0) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/power.m 2010-11-24 15:33:54 UTC (rev 7943) @@ -0,0 +1,29 @@ +function resu = power(df, varargin) + + %% 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 = df_mapper(@power, df, varargin{:}); + +endfunction Property changes on: trunk/octave-forge/extra/dataframe/inst/@dataframe/power.m ___________________________________________________________________ Added: svn:keywords + Id Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_basecomp.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_basecomp.m 2010-11-23 17:35:27 UTC (rev 7942) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_basecomp.m 2010-11-24 15:33:54 UTC (rev 7943) @@ -1,8 +1,9 @@ function [A, B] = df_basecomp(A, B); %# function [A, B] = df_basecomp(A, B) - %# Basic size verifcation for binary operations on dataframe. Returns - %# a scalar, a matrix, or a dataframe. Cell arrays are converted to df. + %# Basic size and metadata compatibility verifications for + %# two-arguments operations on dataframe. Returns a scalar, a matrix, + %# or a dataframe. Cell arrays are converted to df. %% Copyright (C) 2009-2010 Pascal Dupuis <Pas...@uc...> %% @@ -28,35 +29,39 @@ %# $Id$ %# - if isscalar(A) || isscalar(B) - return - endif - - if iscell(A), - A = dataframe(A); - elseif iscell(B), - B = dataframe(B); - endif - - if any(size(A) - size(B)), - error("Non compatible sizes"); - endif - if !isa(A, 'dataframe') || !isa(B, 'dataframe'), - return; %# don't go further with names/indexes comparisons - endif - - if any(A._ridx-B._ridx), - error("Non compatible indexes"); - endif - if !isempty(A._name{1}) && !isempty(B._name{1}) - if !any(strcmp(cellstr(A._name{1}), cellstr(B._name{1}))), - error("Incompatible row names"); + if !(isscalar(A) || isscalar(B)) + if (iscell(A)), + A = dataframe(A); + elseif (iscell(B)), + B = dataframe(B); endif - endif - if !isempty(A._name{2}) && !isempty(B._name{2}) - if !any(strcmp(cellstr(A._name{2}), cellstr(B._name{2}))), - error("Incompatible column names"); + + if (any(size(A) - size(B))), + disp([size(A) size(B)]) + error("Non compatible sizes"); endif + + if (isa(A, 'dataframe') && isa(B, 'dataframe')), + + %# compare indexes if both exist + if (!isempty(A._ridx) && !isempty(B._ridx)) + if (any(A._ridx-B._ridx)), + error("Non compatible indexes"); + endif + endif + + if (!isempty(A._name{1}) && !isempty(B._name{1})) + if (!any(strcmp(cellstr(A._name{1}), cellstr(B._name{1})))), + error("Incompatible row names"); + endif + endif + + if !isempty(A._name{2}) && !isempty(B._name{2}) + if !any(strcmp(cellstr(A._name{2}), cellstr(B._name{2}))), + error("Incompatible column names"); + endif + endif + endif endif endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m 2010-11-23 17:35:27 UTC (rev 7942) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m 2010-11-24 15:33:54 UTC (rev 7943) @@ -28,7 +28,13 @@ %# $Id$ %# - [A, B] = df_basecomp(A, B); + try + [A, B] = df_basecomp(A, B); + catch + A + B + keyboard + end_try_catch if isa(B, 'dataframe') if !isa(A, 'dataframe'), Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_mapper2.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_mapper2.m 2010-11-23 17:35:27 UTC (rev 7942) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_mapper2.m 2010-11-24 15:33:54 UTC (rev 7943) @@ -40,7 +40,7 @@ switch(dim) case {1}, %# remove row metadata - resu._ridx = 1; resu._name{1, 1} = []; resu._over{1, 1} = []; + resu._ridx = []; resu._name{1, 1} = []; resu._over{1, 1} = []; for indi = resu._cnt(2):-1:1, resu._data{indi} = feval(func, resu._data{indi}, vout{:}); endfor Added: trunk/octave-forge/extra/dataframe/inst/@dataframe/repmat.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/repmat.m (rev 0) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/repmat.m 2010-11-24 15:33:54 UTC (rev 7943) @@ -0,0 +1,61 @@ +function resu = repmat(df, varargin) + + %% 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 = df; idx = horzcat(varargin{:}); + %# for the second dim, use either 1 either the 3rd one + dummy = idx; + if (length(dummy) > 2), + dummy(2) = []; + else + dummy(2) = 1; + endif + %# operate on first and third dim first + if (idx(1) > 1 || length(idx) > 2) + resu = df_mapper(@repmat, df, dummy); + if (!isempty(df._name{1})), + resu._name{1} = feval(@repmat, df._name{1}, [idx(1) 1]); + resu._over{1} = feval(@repmat, df._over{1}, [idx(1) 1]); + endif + resu._cnt(1) = resu._cnt(1) * idx(1); + endif + + %# operate on ridx + resu._ridx = feval(@repmat, resu._ridx, dummy); + + %# operate on second dim + if (length(idx) > 1 && idx(2) > 1), + resu._data = feval(@repmat, resu._data, [1 idx(2)]); + resu._name{2} = feval(@repmat, df._name{2}, [idx(2) 1]); + resu._over{2} = feval(@repmat, df._over{2}, [1 idx(2)]); + resu._type = feval(@repmat, df._type, [1 idx(2)]); + resu._cnt(2) = resu._cnt(2) * idx(2); + endif + + if (any([length(resu._cnt) length(idx)] > 2)), + resu._cnt(3) = sum(cellfun('size', resu._data, 2)); + endif + +endfunction Property changes on: trunk/octave-forge/extra/dataframe/inst/@dataframe/repmat.m ___________________________________________________________________ Added: svn:keywords + Id Added: trunk/octave-forge/extra/dataframe/inst/@dataframe/reshape.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/reshape.m (rev 0) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/reshape.m 2010-11-24 15:33:54 UTC (rev 7943) @@ -0,0 +1,30 @@ +function resu = reshape(df, varargin) + %# function resu = reshape(df, varargin) + + %% 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$ + %# + + error('Function not yet implemented on dataframe'); + +endfunction Property changes on: trunk/octave-forge/extra/dataframe/inst/@dataframe/reshape.m ___________________________________________________________________ Added: svn:keywords + Id Added: trunk/octave-forge/extra/dataframe/inst/@dataframe/rows.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/rows.m (rev 0) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/rows.m 2010-11-24 15:33:54 UTC (rev 7943) @@ -0,0 +1,31 @@ +function resu = rows(df) + %# function resu = rows(df) + %# returns the number of rows of a dataframe + + %% 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 = df._cnt(1); + +endfunction Property changes on: trunk/octave-forge/extra/dataframe/inst/@dataframe/rows.m ___________________________________________________________________ Added: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |