1 function resu = df_mapper2(func, df, varargin)
2 %# resu = df_mapper2(func, df)
3 %# small interface to iterate some vector func over the elements of a
4 %# dataframe. This one is specifically adapted to all functions where
5 %# the first argument, if numeric, is 'dim'.
7 %% Copyright (C) 2009-2012 Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
9 %% This file is part of Octave.
11 %% Octave is free software; you can redistribute it and/or
12 %% modify it under the terms of the GNU General Public
13 %% License as published by the Free Software Foundation;
14 %% either version 2, or (at your option) any later version.
16 %% Octave is distributed in the hope that it will be useful,
17 %% but WITHOUT ANY WARRANTY; without even the implied
18 %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 %% PURPOSE. See the GNU General Public License for more
22 %% You should have received a copy of the GNU General Public
23 %% License along with Octave; see the file COPYING. If not,
24 %% write to the Free Software Foundation, 51 Franklin Street -
25 %% Fifth Floor, Boston, MA 02110-1301, USA.
28 %# $Id: df_mapper2.m 9585 2012-02-05 15:32:46Z cdemills $
31 dim = 1; resu = []; vout = varargin;
33 %# take care of constructs as min(x, [], dim)
34 if (!isempty(varargin)),
35 indk = 1; while indk <= length(varargin),
36 if (isnumeric(varargin{indk})),
37 if (isempty(varargin{indk})),
38 indk = indk + 1; continue;
41 %# the "third" dim is the second on stored data
42 if 3 == dim, vout(indk) = 2; endif
50 resu = df_colmeta(df);
51 for indi = 1:df._cnt(2),
52 resu._data{indi} = feval(func, df._data{indi}(:, df._rep{indi}), \
54 resu._rep{indi} = 1:size(resu._data{indi}, 2);
56 resu._cnt(1) = max(cellfun('size', resu._data, 1));
57 if (resu._cnt(1) == df._cnt(1)),
58 %# the func was not contracting
59 resu._ridx = df._ridx;
60 resu._name{1} = resu._name{1}; resu._over{1} = resu._over{1};
63 error('Operation not implemented');
65 resu = df_allmeta(df);
66 for indi = 1:df._cnt(2),
67 resu._data{indi} = feval(func, df._data{indi}(:, df._rep{indi}), \
69 resu._rep{indi} = 1:size(resu._data{indi}, 2);
72 error("Invalid dimension %d", dim);
75 resu = df_thirddim(resu);