From: <cde...@us...> - 2010-11-26 11:05:42
|
Revision: 7953 http://octave.svn.sourceforge.net/octave/?rev=7953&view=rev Author: cdemills Date: 2010-11-26 11:05:35 +0000 (Fri, 26 Nov 2010) Log Message: ----------- Back to unified df_func; implented 'inv'; by default, df.array let downclassing occur Modified Paths: -------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/and.m trunk/octave-forge/extra/dataframe/inst/@dataframe/ge.m trunk/octave-forge/extra/dataframe/inst/@dataframe/gt.m trunk/octave-forge/extra/dataframe/inst/@dataframe/ldivide.m trunk/octave-forge/extra/dataframe/inst/@dataframe/le.m trunk/octave-forge/extra/dataframe/inst/@dataframe/lt.m trunk/octave-forge/extra/dataframe/inst/@dataframe/minus.m trunk/octave-forge/extra/dataframe/inst/@dataframe/mldivide.m trunk/octave-forge/extra/dataframe/inst/@dataframe/mrdivide.m trunk/octave-forge/extra/dataframe/inst/@dataframe/mtimes.m trunk/octave-forge/extra/dataframe/inst/@dataframe/ne.m trunk/octave-forge/extra/dataframe/inst/@dataframe/or.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m trunk/octave-forge/extra/dataframe/inst/@dataframe/rdivide.m trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m trunk/octave-forge/extra/dataframe/inst/@dataframe/times.m trunk/octave-forge/extra/dataframe/inst/@dataframe/xor.m Added Paths: ----------- trunk/octave-forge/extra/dataframe/inst/@dataframe/inv.m Removed Paths: ------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_ccfunc.m trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_rcfunc.m Property Changed: ---------------- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/and.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/and.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/and.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -27,6 +27,6 @@ %# $Id$ %# - resu = df_ccfunc(@and, A, B); + resu = df_func(@and, A, B); endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/ge.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/ge.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/ge.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -27,6 +27,6 @@ %# $Id$ %# - resu = df_ccfunc(@ge, A, B); + resu = df_func(@ge, A, B); endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/gt.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/gt.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/gt.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -27,6 +27,6 @@ %# $Id$ %# - resu = df_ccfunc(@gt, A, B); + resu = df_func(@gt, A, B); endfunction Added: trunk/octave-forge/extra/dataframe/inst/@dataframe/inv.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/inv.m (rev 0) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/inv.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -0,0 +1,52 @@ +function [resu, rcond] = inv(df); + + %# function [x, rcond] = inv(df) + %# Overloaded function computing the inverse of a dataframe. To + %# succeed, the dataframe must be convertible to an square array. Row + %# and column meta-information are exchanged. + + %% 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 (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{:})); + + 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)); + endif + for indi = resu._cnt(1):-1:1, + resu._data{indi} = dummy(:, indi); + endfor + resu._type(:) = class(dummy); + +endfunction Property changes on: trunk/octave-forge/extra/dataframe/inst/@dataframe/inv.m ___________________________________________________________________ Added: svn:keywords + Id Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/ldivide.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/ldivide.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/ldivide.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -28,7 +28,7 @@ %# try - resu = df_ccfunc(@ldivide, A, B); + resu = df_func(@ldivide, A, B); catch disp(lasterr()); error("Operator .\\ problem for %s vs. %s", class(A), class(B)); Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/le.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/le.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/le.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -27,6 +27,6 @@ %# $Id$ %# - resu = df_ccfunc(@le, A, B); + resu = df_func(@le, A, B); endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/lt.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/lt.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/lt.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -27,6 +27,6 @@ %# $Id$ %# - resu = df_ccfunc(@lt, A, B); + resu = df_func(@lt, A, B); endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/minus.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/minus.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/minus.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -28,7 +28,7 @@ %# try - resu = df_ccfunc(@minus, A, B); + resu = df_func(@minus, A, B); catch disp(lasterr()); error("Operator - problem for %s vs. %s", class(A), class(B)); Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/mldivide.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/mldivide.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/mldivide.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -28,7 +28,7 @@ %# try - resu = df_rcfunc(@mldivide, A, B); + resu = df_func(@mldivide, A, B); catch disp(lasterr()); error("Operator \\ problem for %s vs. %s", class(A), class(B)); Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/mrdivide.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/mrdivide.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/mrdivide.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -28,7 +28,7 @@ %# try - resu = df_rcfunc(@mrdivide, A, B); + resu = df_func(@mrdivide, A, B); catch disp(lasterr()); error("Operator / problem for %s vs. %s", class(A), class(B)); Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/mtimes.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/mtimes.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/mtimes.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -28,7 +28,7 @@ %# try - resu = df_rcfunc(@mtimes, A, B, true); + resu = df_func(@mtimes, A, B, false, [true false]); catch disp(lasterr()); error("Operator * problem for %s vs. %s", class(A), class(B)); Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/ne.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/ne.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/ne.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -27,6 +27,6 @@ %# $Id$ %# - resu = df_ccfunc(@ne, A, B); + resu = df_func(@ne, A, B); endfunction Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/or.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/or.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/or.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -27,6 +27,6 @@ %# $Id$ %# - resu = df_ccfunc(@or, A, B); + resu = df_func(@or, A, B); endfunction Deleted: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_ccfunc.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_ccfunc.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_ccfunc.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -1,89 +0,0 @@ -function resu = df_ccfunc(func, A, B, whole); - - %# function resu = df_ccfunc(func, A, B, whole) - %# Implements an column vs column iterator to apply some func when at - %# least one argument is a dataframe. The output is a dataframe with - %# the same metadata, types may be altered, like f.i. double=>logical. - %# 'whole' indicate if the LHS as to be taken in block, default = false. - - %% 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_func.m 7947 2010-11-24 21:57:16Z cdemills $ - %# - - [A, B, resu] = df_basecomp(A, B); - if nargin < 4, whole = false; endif - - if (isa(B, 'dataframe')) - if (!isa(A, 'dataframe')), - if (isscalar(A) || (ismatrix(A) && whole)), - for indi = resu._cnt(2):-1:1, - switch resu._type{indi} - case "char" - resu._data{indi} = feval(func, A, char(B._data{indi})); - otherwise - resu._data{indi} = feval(func, A, B._data{indi}); - endswitch - endfor - elseif (ismatrix(A)), - for indi = resu._cnt(2):-1:1, - switch resu._type{indi} - case "char" - resu._data{indi} = feval(func, A(:, indi), char(B._data{indi})); - otherwise - resu._data{indi} = feval(func, A(:, indi), B._data{indi}); - endswitch - endfor - else - error("Function %s not implemented for %s by %s", \ - func2str(func), class(A), class(B)); - endif - else - resu._data = cellfun(@(x, y) feval(func, x, y, varargin{:}), A._data, \ - B._data, "UniformOutput", false); - endif - else - if (isscalar(B) || ismatrix(B)), - for indi = resu._cnt(2):-1:1, - switch resu._type{indi} - case "char" - resu._data{indi} = feval(func, char(A._data{indi}), \ - B, varargin{:}); - otherwise - resu._data{indi} = feval(func, A._data{indi}, \ - B, varargin{:}); - endswitch - endfor - else - error("Function %s not implemented for %s by %s", \ - func2str(func), class(A), class(B)); - endif - endif - - resu._type = cellfun(@class, 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_func.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -29,7 +29,7 @@ %% Suite 330, Boston, MA 02111-1307, USA. %# - %# $Id: df_rcfunc.m 7950 2010-11-25 18:07:59Z cdemills $ + %# $Id$ %# [A, B, resu] = df_basecomp(A, B); Property changes on: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_func.m ___________________________________________________________________ Added: svn:keywords + Id Deleted: trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_rcfunc.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_rcfunc.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/private/df_rcfunc.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -1,82 +0,0 @@ -function resu = df_rcfunc(func, A, B, whole); - - %# function resu = df_rcfunc(func, A, B, whole) - %# Implements an row vs column iterator to apply some func when at - %# least one argument is a dataframe. The output is a dataframe with - %# the same metadata, types may be altered, like f.i. double=>logical. - %# 'whole' indicate if the LHS as to be taken in block, default = false. - - %% 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$ - %# - - [A, B, resu] = df_basecomp(A, B); - if nargin < 4, whole = false; endif - - if (isa(B, 'dataframe')) - if (!isa(A, 'dataframe')), - if (isscalar(A) || (ismatrix(A) && whole)), - for indi = resu._cnt(2):-1:1, - switch resu._type{indi} - case "char" - resu._data{indi} = feval(func, A, char(B._data{indi})); - otherwise - resu._data{indi} = feval(func, A, B._data{indi}); - endswitch - endfor - elseif (ismatrix(A)), - for indi = resu._cnt(2):-1:1, - switch resu._type{indi} - case "char" - resu._data{indi} = feval(func, A(indi, :), char(B._data{indi})); - otherwise - resu._data{indi} = feval(func, A(indi, :), B._data{indi}); - endswitch - endfor - else - error("Function %s not implemented for %s by %s", \ - func2str(func), class(A), class(B)); - endif - else - error('To be implemented'); - resu._data = cellfun(@(x, y) feval(func, x, y, varargin{:}), A._data, \ - B._data, "UniformOutput", false); - endif - else - if (isscalar(B) || ismatrix(B)), - resu._data = cellfun(@(x) feval(func, x, B, varargin{:}), A._data, \ - "UniformOutput", false); - else - error("Function %s not implemented for %s by %s", \ - func2str(func), class(A), class(B)); - endif - endif - - resu._type = cellfun(@class, 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/rdivide.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/rdivide.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/rdivide.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -28,7 +28,7 @@ %# try - resu = df_ccfunc(@rdivide, A, B); + resu = df_func(@rdivide, A, B); catch disp(lasterr()); error("Operator ./ problem for %s vs. %s", class(A), class(B)); Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/subsref.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -262,12 +262,16 @@ output_type = asked_output_type; else %# can the data be merged ? - output_type = df._type{indc(1)}; + output_type = df._data{indc(1)}(1); dummy = isnumeric(df._data{indc(1)}); for indi = 2:ncol, dummy = dummy & isnumeric(df._data{indc(indi)}); if ~strcmp(output_type, df._type{indc(indi)}), - if dummy, continue; endif + if dummy, + %# let downclassing occur + output_type = horzcat(output_type, df._data{indc(indi)}(1)); + continue; + endif %# unmixable args -- falls back to type of parent container error("Selected columns %s not compatible with cat() -- use 'cell' as output format", mat2str(indc)); %# dead code -- suppress previous line for switching automagically the output format to df @@ -275,6 +279,8 @@ break; endif endfor + asked_output_format = class(output_type); + output_type = "array"; endif endif @@ -312,7 +318,7 @@ endif endif endif - + if (strcmp(output_type, class(df))), %# disp('line 295 ') %# export the result as a dataframe Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/times.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/times.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/times.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -28,7 +28,7 @@ %# try - resu = df_ccfunc(@times, A, B); + resu = df_func(@times, A, B); catch disp(lasterr()); error("Operator .* problem for %s vs. %s", class(A), class(B)); Modified: trunk/octave-forge/extra/dataframe/inst/@dataframe/xor.m =================================================================== --- trunk/octave-forge/extra/dataframe/inst/@dataframe/xor.m 2010-11-26 09:31:51 UTC (rev 7952) +++ trunk/octave-forge/extra/dataframe/inst/@dataframe/xor.m 2010-11-26 11:05:35 UTC (rev 7953) @@ -27,6 +27,6 @@ %# $Id$ %# - resu = df_ccfunc(@xor, A, B); + resu = df_func(@xor, A, B); endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |