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. |