From: <cde...@us...> - 2010-11-24 21:57:22
|
Revision: 7947 http://octave.svn.sourceforge.net/octave/?rev=7947&view=rev Author: cdemills Date: 2010-11-24 21:57:16 +0000 (Wed, 24 Nov 2010) Log Message: ----------- Made df_func return a dataframe, extract as much metadata as it can from its inputs Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/eq.m trunk/octave-forge/extra/dataframe/inst/@dataframe/plus.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_mapper.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/eq.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/eq.m 2010-11-24 21:28:59 UTC (rev 7946) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/eq.m 2010-11-24 21:57:16 UTC (rev 7947) @@ -27,6 +27,6 @@ %# $Id$ %# - resu = cell2mat(df_func(@eq, A, B)); + resu = df_func(@eq, A, B); endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/plus.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/plus.m 2010-11-24 21:28:59 UTC (rev 7946) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/plus.m 2010-11-24 21:57:16 UTC (rev 7947) @@ -27,34 +27,6 @@ %# $Id$ %# - [A, B] = df_basecomp(A, B); - - if isa(B, 'dataframe') - if !isa(A, 'dataframe'), - resu = B; - if isscalar(A) - resu._data = cellfun(@(x) A+x, B._data, "UniformOutput", false); - elseif ismatrix(A), - resu._data = cellfun(@(x, y) x+y, num2cell(A, 1), B._data,\ - "UniformOutput", false); - else - error("Operator + not implemented"); - endif - else - resu = A; - resu._data = cellfun(@(x, y) x+y, A._data, B._data,\ - "UniformOutput", false); - endif - else - resu = A; - if isscalar(B), - resu._data = cellfun(@(x) x+B, A._data, "UniformOutput", false); - elseif ismatrix(B), - resu._data = cellfun(@(x, y) x+y, A._data, num2cell(B, 1),\ - "UniformOutput", false); - else - error("Operator + not implemented"); - endif - endif + resu = df_func(@plus, A, B); 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-24 21:28:59 UTC (rev 7946) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m 2010-11-24 21:57:16 UTC (rev 7947) @@ -1,8 +1,9 @@ -function resu = df_func(func, A, B); +function resu = df_func(func, A, B, varargin); %# function resu = df_func(func, A, B) %# Implements an iterator to apply some func when at least one - %# argument is a dataframe. The output is NOT a dataframe. + %# argument is a dataframe. The output is a dataframe with the same + %# metadata, types may be altered, like f.i. double=>logical. %% Copyright (C) 2009-2010 Pascal Dupuis <Pas...@uc...> %% @@ -28,37 +29,44 @@ %# $Id$ %# - try - [A, B] = df_basecomp(A, B); - catch - A - B - keyboard - end_try_catch - + [A, B] = df_basecomp(A, B); + if isa(B, 'dataframe') + resu = df_allmeta(B); if !isa(A, 'dataframe'), if isscalar(A) - resu = cellfun(@(x) feval(func, A, x), B._data, "UniformOutput", false); + resu._data = cellfun(@(x) feval(func, A, x, varargin{:}), B._data, \ + "UniformOutput", false); elseif ismatrix(A), - resu = cellfun(@(x, y) feval(func, x, y), num2cell(A, 1), B._data, \ - "UniformOutput", false); + resu._data = cellfun(@(x, y) feval(func, x, y, varargin{:}), \ + num2cell(A, 1), B._data, "UniformOutput", false); else - error("Function %s not implemented", func2str(func)); + error("Function %s not implemented for %s by %s", \ + func2str(func), class(A), class(B)); endif else - resu = cellfun(@(x, y) feval(func, x, y), A._data, B._data, \ - "UniformOutput", false); - endif + resu._data = cellfun(@(x, y) feval(func, x, y, varargin{:}), A._data, \ + B._data, "UniformOutput", false); + endif else + resu = df_allmeta(A); if isscalar(B), - resu = cellfun(@(x) feval(func, x, B), A._data, "UniformOutput", false); + resu._data = cellfun(@(x) feval(func, x, B, varargin{:}), A._data, \ + "UniformOutput", false); elseif ismatrix(B), - resu = cellfun(@(x, y) feval(func, x, y), A._data, num2cell(B, 1), \ - "UniformOutput", false); + resu._data = cellfun(@(x, y) feval(func, x, y, varargin{:}), A._data, \ + num2cell(B, 1), "UniformOutput", false); else - error("Operator < not implemented"); + error("Function %s not implemented for %s by %s", \ + func2str(func), class(A), class(B)); endif endif - + + resu._type = cellfun(@(x) class(x(1)), resu._data, "UniformOutput", false); + %# sanity check + dummy = sum(cellfun('size', resu._data, 2)); + if dummy != resu._cnt(2), + resu._cnt(3) = dummy; + endif + endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_mapper.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_mapper.m 2010-11-24 21:28:59 UTC (rev 7946) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_mapper.m 2010-11-24 21:57:16 UTC (rev 7947) @@ -27,10 +27,9 @@ %# resu = df_allmeta(df); - for indi = df._cnt(2):-1:1, - resu._data{indi} = feval(func, df._data{indi}, varargin{:}); - endfor - + resu._data = cellfun(@(x) feval(func, x, varargin{:}), df._data, "UniformOutput", false); + resu._type = cellfun(@(x) class(x(1)), resu._data, "UniformOutput", false); + %# sanity check dummy = sum(cellfun('size', resu._data, 2)); if dummy != resu._cnt(2), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |