octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

cellfun/arrayfun


From: John W. Eaton
Subject: cellfun/arrayfun
Date: Tue, 20 Mar 2007 12:57:59 -0400

On 19-Mar-2007, David Bateman wrote:

| Here is a patch that adds Bill's arrayfun function (cf
| 
http://www.cae.wisc.edu/pipermail/octave-maintainers/2006-October/000805.html),
| and fixes a problem in cellfun where the shape of the output array was
| not respected, as I noticed morning...

OK, please check in these changes.

Thanks,

jwe

| Regards
| David
| 
| -- 
| David Bateman                                address@hidden
| Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
| Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
| 91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 
| 
| The information contained in this communication has been classified as: 
| 
| [x] General Business Information 
| [ ] Motorola Internal Use Only 
| [ ] Motorola Confidential Proprietary
| 
| *** ./scripts/general/arrayfun.m.orig55       2007-03-19 14:07:42.652034652 
+0100
| --- ./scripts/general/arrayfun.m      2007-03-19 10:48:19.025807150 +0100
| ***************
| *** 0 ****
| --- 1,64 ----
| + ## Copyright (C) 2006  Bill Denney  <address@hidden>
| + ##
| + ## This program 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 of the License, or
| + ## (at your option) any later version.
| + ##
| + ## This program 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 this program; if not, write to the Free Software
| + ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
| + 
| + ## -*- texinfo -*-
| + ## @deftypefn {Command} @var{a} = arrayfun(@var{name}, @var{c})
| + ## @deftypefnx {Command} @var{a} = arrayfun(@var{func}, @var{c})
| + ## @deftypefnx {Command} @var{a} = arrayfun(@var{func}, @var{c}, @var{d})
| + ## @deftypefnx {Command} @var{a} = arrayfun(@var{func}, @var{c}, 
@var{options})
| + ## @deftypefnx {Command} address@hidden, @var{b}, @dots{}] = 
arrayfun(@var{func}, @var{c}, @dots{})
| + ## Execute a function on each element of an array.
| + ##
| + ## See cellfun for complete usage instructions.
| + ## @seealso{cellfun}
| + ## @end deftypefn
| + 
| + function [varargout] = arrayfun(func, varargin)
| + 
| +   if (nargin < 2)
| +     print_usage();
| +   endif
| + 
| +   ## convert everything to cells and call cellfun (let cellfun error
| +   ## check the options in case more options come available)
| +   sizetomatch = size(varargin{1});
| +   m2cargs{1} = ones (size (varargin{1}, 1), 1);
| +   m2cargs{2} = ones (size (varargin{1}, 2), 1);
| +   cfarg{1} = mat2cell (varargin{1}, m2cargs{:});
| +   stillmatches = true;
| +   idx = 1;
| +   while stillmatches && (idx < length(varargin))
| +     idx++;
| +     thissize = size (varargin{idx});
| +     if (length (thissize) == length (sizetomatch)) && \
| +       all (thissize == sizetomatch)
| +       if ischar (varargin{idx}) && \
| +         (strcmpi (varargin{idx}, "UniformOutput") || \
| +          strcmpi (varargin{idx}, "ErrorHandler"))
| +     ## catch these strings just in case they happen to be the same
| +     ## size as the other input.
| +     stillmatches = false;
| +       else
| +     cfarg{idx} = mat2cell (varargin{idx}, m2cargs{:});
| +       endif
| +     else
| +       stillmatches = false;
| +     endif
| +   endwhile
| + 
| +   varargout = cell (max ([nargout, 1]), 1);
| +   [varargout{:}] = cellfun (func, cfarg{:}, 
varargin{idx+1:length(varargin)});
| + endfunction
| *** ./scripts/general/Makefile.in.orig55      2007-03-19 14:07:50.198655233 
+0100
| --- ./scripts/general/Makefile.in     2007-03-19 14:08:22.483032120 +0100
| ***************
| *** 20,27 ****
|   INSTALL_PROGRAM = @INSTALL_PROGRAM@
|   INSTALL_DATA = @INSTALL_DATA@
|   
| ! SOURCES = __isequal__.m bicubic.m bitcmp.m bitget.m bitset.m \
| !   blkdiag.m cart2pol.m cart2sph.m cell2mat.m circshift.m \
|     common_size.m cplxpair.m cumtrapz.m deal.m diff.m flipdim.m \
|     fliplr.m flipud.m gradient.m ind2sub.m int2str.m interp1.m \
|     interp2.m interpft.m is_duplicate_entry.m isa.m isdefinite.m \
| --- 20,27 ----
|   INSTALL_PROGRAM = @INSTALL_PROGRAM@
|   INSTALL_DATA = @INSTALL_DATA@
|   
| ! SOURCES = __isequal__.m arrayfun.m bicubic.m bitcmp.m bitget.m \
| !   bitset.m blkdiag.m cart2pol.m cart2sph.m cell2mat.m circshift.m \
|     common_size.m cplxpair.m cumtrapz.m deal.m diff.m flipdim.m \
|     fliplr.m flipud.m gradient.m ind2sub.m int2str.m interp1.m \
|     interp2.m interpft.m is_duplicate_entry.m isa.m isdefinite.m \
| *** ./src/DLD-FUNCTIONS/cellfun.cc.orig55     2006-09-14 04:10:46.000000000 
+0200
| --- ./src/DLD-FUNCTIONS/cellfun.cc    2007-03-19 13:49:40.937343268 +0100
| ***************
| *** 401,408 ****
|                         if (error_state)
|                           goto cellfun_err;
|   
| !                       val.resize(f_args.dims());
| !                       retval(j) = val;
|                       }
|                   }
|                 else
| --- 401,407 ----
|                         if (error_state)
|                           goto cellfun_err;
|   
| !                       retval(j) = val.resize(f_args.dims());
|                       }
|                   }
|                 else
| ***************
| *** 521,526 ****
| --- 520,527 ----
|   %!assert(cellfun('size',{zeros([1,2,3]),1},3),[3,1])
|   %!assert(cellfun(@atan2,{1,1},{1,2}),[atan2(1,1),atan2(1,2)])
|   
%!assert(cellfun(@atan2,{1,1},{1,2},'UniformOutput',false),{atan2(1,1),atan2(1,2)})
| + %!assert(cellfun(@sin,{1,2;3,4}),sin([1,2;3,4]))
| + %!assert(cellfun(@atan2,{1,1;1,1},{1,2;1,2}),atan2([1,1;1,1],[1,2;1,2]))
|   %!error(cellfun(@factorial,{-1,3}))
|   %!assert(cellfun(@factorial,{-1,3},'ErrorHandler',@(x,y) NaN),[NaN,6])
|   %!test
| 2007-03-19  David Bateman  <address@hidden>
| 
|       * general/arrayfun.m: New function (for Bill Denney)
|       * general/Makefile.in: Include it in SOURCES
| 
| 2007-03-19  David Bateman  <address@hidden>
| 
|       * DLD-FUNCTIONS/cellfun.cc (Fcellfun): Correct for shape of return
|       matrix for the case of UniformOutput being true.
| 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]