/usr/share/octave/packages/dataframe-1.0.1/@dataframe/private/df_mapper2.m is in octave-dataframe 1.0.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | function resu = df_mapper2(func, df, varargin)
%# resu = df_mapper2(func, df)
%# small interface to iterate some vector func over the elements of a
%# dataframe. This one is specifically adapted to all functions where
%# the first argument, if numeric, is 'dim'.
%% Copyright (C) 2009-2012 Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
%%
%% 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, 51 Franklin Street -
%% Fifth Floor, Boston, MA 02110-1301, USA.
%#
%# $Id$
%#
dim = 1; resu = []; vout = varargin;
%# take care of constructs as min(x, [], dim)
if (~isempty(varargin))
indk = 1; while (indk <= length (varargin))
if (isnumeric (varargin{indk}))
if (isempty (varargin{indk}))
indk = indk + 1; continue;
endif
dim = varargin{indk};
%# the "third" dim is the second on stored data
if (3 == dim) vout(indk) = 2; endif
endif
break;
endwhile
endif
switch (dim)
case {1}
resu = df_colmeta (df);
for indi = (1:df._cnt(2))
resu._data{indi} = feval (func, df._data{indi}(:, df._rep{indi}), ...
vout{:});
resu._rep{indi} = 1:size (resu._data{indi}, 2);
endfor
resu._cnt(1) = max (cellfun ('size', resu._data, 1));
if (resu._cnt(1) == df._cnt(1))
%# the func was not contracting
resu._ridx = df._ridx;
resu._name{1} = resu._name{1}; resu._over{1} = resu._over{1};
endif
case {2}
error ('Operation not implemented');
case {3}
resu = df_allmeta(df);
for indi = (1:df._cnt(2))
resu._data{indi} = feval (func, df._data{indi}(:, df._rep{indi}), ...
vout{:});
resu._rep{indi} = 1:size (resu._data{indi}, 2);
endfor
otherwise
error ("Invalid dimension %d", dim);
endswitch
resu = df_thirddim (resu);
endfunction
|