annotate libinterp/corefcn/cellfun.cc @ 20207:4f45eaf83908 stable

doc: Update more docstrings to have one sentence summary as first line. Reviewed libinterp/corefcn directory. * libinterp/corefcn/__ilu__.cc, libinterp/corefcn/balance.cc, libinterp/corefcn/besselj.cc, libinterp/corefcn/betainc.cc, libinterp/corefcn/bitfcns.cc, libinterp/corefcn/bsxfun.cc, libinterp/corefcn/cellfun.cc, libinterp/corefcn/colloc.cc, libinterp/corefcn/conv2.cc, libinterp/corefcn/data.cc, libinterp/corefcn/debug.cc, libinterp/corefcn/defaults.cc, libinterp/corefcn/det.cc, libinterp/corefcn/dirfns.cc, libinterp/corefcn/dlmread.cc, libinterp/corefcn/dot.cc, libinterp/corefcn/eig.cc, libinterp/corefcn/error.cc, libinterp/corefcn/fft2.cc, libinterp/corefcn/fftn.cc, libinterp/corefcn/file-io.cc, libinterp/corefcn/filter.cc, libinterp/corefcn/find.cc, libinterp/corefcn/gammainc.cc, libinterp/corefcn/gcd.cc, libinterp/corefcn/getgrent.cc, libinterp/corefcn/getpwent.cc, libinterp/corefcn/getrusage.cc, libinterp/corefcn/graphics.cc, libinterp/corefcn/help.cc, libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc, libinterp/corefcn/inv.cc, libinterp/corefcn/kron.cc, libinterp/corefcn/load-path.cc, libinterp/corefcn/load-save.cc, libinterp/corefcn/lookup.cc, libinterp/corefcn/ls-oct-ascii.cc, libinterp/corefcn/lsode.cc, libinterp/corefcn/lu.cc, libinterp/corefcn/luinc.cc, libinterp/corefcn/mappers.cc, libinterp/corefcn/matrix_type.cc, libinterp/corefcn/max.cc, libinterp/corefcn/md5sum.cc, libinterp/corefcn/mgorth.cc, libinterp/corefcn/nproc.cc, libinterp/corefcn/oct-hist.cc, libinterp/corefcn/ordschur.cc, libinterp/corefcn/pager.cc, libinterp/corefcn/pinv.cc, libinterp/corefcn/pr-output.cc, libinterp/corefcn/pt-jit.cc, libinterp/corefcn/quad.cc, libinterp/corefcn/quadcc.cc, libinterp/corefcn/qz.cc, libinterp/corefcn/rand.cc, libinterp/corefcn/rcond.cc, libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc, libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sparse.cc, libinterp/corefcn/spparms.cc, libinterp/corefcn/str2double.cc, libinterp/corefcn/strfind.cc, libinterp/corefcn/strfns.cc, libinterp/corefcn/sub2ind.cc, libinterp/corefcn/svd.cc, libinterp/corefcn/symtab.cc, libinterp/corefcn/syscalls.cc, libinterp/corefcn/sysdep.cc, libinterp/corefcn/time.cc, libinterp/corefcn/toplev.cc, libinterp/corefcn/tril.cc, libinterp/corefcn/tsearch.cc, libinterp/corefcn/typecast.cc, libinterp/corefcn/urlwrite.cc, libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc, scripts/polynomial/spline.m: Update more docstrings to have one sentence summary as first line.
author Rik <rik@octave.org>
date Sat, 09 May 2015 17:19:30 -0700
parents 19755f4fc851
children a9574e3c6e9e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
1 /*
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
2
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18896
diff changeset
3 Copyright (C) 2005-2015 Mohamed Kamoun
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18896
diff changeset
4 Copyright (C) 2006-2015 Bill Denney
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
5 Copyright (C) 2009 Jaroslav Hajek
10521
4d1fc073fbb7 add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents: 10428
diff changeset
6 Copyright (C) 2010 VZLU Prague
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
7
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
8 This file is part of Octave.
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
9
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
10 Octave is free software; you can redistribute it and/or modify it
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
11 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
12 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
13 option) any later version.
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
14
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
15 Octave is distributed in the hope that it will be useful, but WITHOUT
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
18 for more details.
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
19
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
21 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
22 <http://www.gnu.org/licenses/>.
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
23
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
24 */
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
25
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
26 #ifdef HAVE_CONFIG_H
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
27 #include <config.h>
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
28 #endif
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
29
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
30 #include <string>
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
31 #include <vector>
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
32 #include <list>
8994
a8d30dc1beec cellfun optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8985
diff changeset
33 #include <memory>
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
34
14076
9aff66860e03 accept abbreviated cellfun option names
John W. Eaton <jwe@octave.org>
parents: 13960
diff changeset
35 #include "caseless-str.h"
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
36 #include "lo-mappers.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8373
diff changeset
37 #include "oct-locbuf.h"
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
38
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
39 #include "Cell.h"
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
40 #include "oct-map.h"
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
41 #include "defun.h"
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
42 #include "parse.h"
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
43 #include "variables.h"
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
44 #include "ov-colon.h"
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
45 #include "unwind-prot.h"
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
46 #include "gripes.h"
9728
70925b11ba46 again allow the obsolete syntax for cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9684
diff changeset
47 #include "utils.h"
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
48
13329
80f7564a3849 handle class objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13234
diff changeset
49 #include "ov-class.h"
10044
2d7a8c227713 rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 10043
diff changeset
50 #include "ov-scalar.h"
2d7a8c227713 rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 10043
diff changeset
51 #include "ov-float.h"
2d7a8c227713 rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 10043
diff changeset
52 #include "ov-complex.h"
2d7a8c227713 rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 10043
diff changeset
53 #include "ov-flt-complex.h"
2d7a8c227713 rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 10043
diff changeset
54 #include "ov-bool.h"
2d7a8c227713 rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 10043
diff changeset
55 #include "ov-int8.h"
2d7a8c227713 rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 10043
diff changeset
56 #include "ov-int16.h"
2d7a8c227713 rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 10043
diff changeset
57 #include "ov-int32.h"
2d7a8c227713 rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 10043
diff changeset
58 #include "ov-int64.h"
2d7a8c227713 rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 10043
diff changeset
59 #include "ov-uint8.h"
2d7a8c227713 rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 10043
diff changeset
60 #include "ov-uint16.h"
2d7a8c227713 rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 10043
diff changeset
61 #include "ov-uint32.h"
2d7a8c227713 rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 10043
diff changeset
62 #include "ov-uint64.h"
2d7a8c227713 rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 10043
diff changeset
63
12952
5a5cb2a4b71d cellfun: Fix a regression for function handles to overloaded functions
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12949
diff changeset
64 #include "ov-fcn-handle.h"
5a5cb2a4b71d cellfun: Fix a regression for function handles to overloaded functions
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12949
diff changeset
65
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
66 static octave_value_list
10181
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
67 get_output_list (octave_idx_type count, octave_idx_type nargout,
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
68 const octave_value_list& inputlist,
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
69 octave_value& func,
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
70 octave_value& error_handler)
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
71 {
16000
3f93cd251bdb fix ErrorHandler in cellfun (bug #38256)
Stefan Mahr <dac922@gmx.de>
parents: 15195
diff changeset
72 octave_value_list tmp;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
73 try
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
74 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
75 tmp = func.do_multi_index_op (nargout, inputlist);
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
76 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
77 catch (octave_execution_exception)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
78 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
79 if (error_handler.is_defined ())
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
80 error_state = 1;
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
81 }
10181
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
82
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
83 if (error_state)
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
84 {
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
85 if (error_handler.is_defined ())
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
86 {
11046
14993c9e857e amd.cc, cellfun.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents: 10964
diff changeset
87 octave_scalar_map msg;
10181
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
88 msg.assign ("identifier", last_error_id ());
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
89 msg.assign ("message", last_error_message ());
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
90 msg.assign ("index",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
91 static_cast<double> (count
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
92 + static_cast<octave_idx_type>(1)));
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
93
10181
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
94 octave_value_list errlist = inputlist;
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
95 errlist.prepend (msg);
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
96
10181
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
97 buffer_error_messages--;
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
98
10181
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
99 error_state = 0;
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
100
10181
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
101 tmp = error_handler.do_multi_index_op (nargout, errlist);
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
102
10181
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
103 buffer_error_messages++;
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
104
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
105 if (error_state)
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
106 tmp.clear ();
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
107 }
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
108 else
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
109 tmp.clear ();
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
110 }
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
111
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
112 return tmp;
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
113 }
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
114
17892
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
115 // Templated function because the user can be stubborn enough to request
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
116 // a cell array as an output even in these cases where the output fits
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
117 // in an ordinary array
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
118 template<typename BNDA, typename NDA>
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
119 static octave_value_list
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
120 try_cellfun_internal_ops (const octave_value_list& args, int nargin)
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
121 {
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
122 octave_value_list retval;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
123
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
124 std::string name = args(0).string_value ();
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
125
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
126 const Cell f_args = args(1).cell_value ();
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
127
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
128 octave_idx_type k = f_args.numel ();
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
129
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
130 if (name == "isempty")
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
131 {
17892
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
132 BNDA result (f_args.dims ());
13231
20ed9548070f maint: style fixes for cellfun
John W. Eaton <jwe@octave.org>
parents: 13230
diff changeset
133 for (octave_idx_type count = 0; count < k; count++)
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
134 result(count) = f_args.elem (count).is_empty ();
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
135 retval(0) = result;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
136 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
137 else if (name == "islogical")
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
138 {
17892
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
139 BNDA result (f_args.dims ());
13231
20ed9548070f maint: style fixes for cellfun
John W. Eaton <jwe@octave.org>
parents: 13230
diff changeset
140 for (octave_idx_type count= 0; count < k; count++)
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
141 result(count) = f_args.elem (count).is_bool_type ();
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
142 retval(0) = result;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
143 }
17002
dd783018709b Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents: 16047
diff changeset
144 else if (name == "isnumeric")
dd783018709b Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents: 16047
diff changeset
145 {
17892
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
146 BNDA result (f_args.dims ());
17002
dd783018709b Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents: 16047
diff changeset
147 for (octave_idx_type count= 0; count < k; count++)
dd783018709b Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents: 16047
diff changeset
148 result(count) = f_args.elem (count).is_numeric_type ();
dd783018709b Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents: 16047
diff changeset
149 retval(0) = result;
dd783018709b Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents: 16047
diff changeset
150 }
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
151 else if (name == "isreal")
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
152 {
17892
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
153 BNDA result (f_args.dims ());
13231
20ed9548070f maint: style fixes for cellfun
John W. Eaton <jwe@octave.org>
parents: 13230
diff changeset
154 for (octave_idx_type count= 0; count < k; count++)
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
155 result(count) = f_args.elem (count).is_real_type ();
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
156 retval(0) = result;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
157 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
158 else if (name == "length")
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
159 {
17892
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
160 NDA result (f_args.dims ());
13231
20ed9548070f maint: style fixes for cellfun
John W. Eaton <jwe@octave.org>
parents: 13230
diff changeset
161 for (octave_idx_type count= 0; count < k; count++)
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
162 result(count) = static_cast<double> (f_args.elem (count).length ());
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
163 retval(0) = result;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
164 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
165 else if (name == "ndims")
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
166 {
17892
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
167 NDA result (f_args.dims ());
13231
20ed9548070f maint: style fixes for cellfun
John W. Eaton <jwe@octave.org>
parents: 13230
diff changeset
168 for (octave_idx_type count = 0; count < k; count++)
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
169 result(count) = static_cast<double> (f_args.elem (count).ndims ());
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
170 retval(0) = result;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
171 }
17004
19b7c7412a63 cell2mat.m: Re-vamp input validation for 30% speedup
Rik <rik@octave.org>
parents: 17002
diff changeset
172 else if (name == "numel" || name == "prodofsize")
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
173 {
17892
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
174 NDA result (f_args.dims ());
13231
20ed9548070f maint: style fixes for cellfun
John W. Eaton <jwe@octave.org>
parents: 13230
diff changeset
175 for (octave_idx_type count = 0; count < k; count++)
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
176 result(count) = static_cast<double> (f_args.elem (count).numel ());
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
177 retval(0) = result;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
178 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
179 else if (name == "size")
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
180 {
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
181 if (nargin == 3)
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
182 {
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
183 int d = args(2).nint_value () - 1;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
184
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
185 if (d < 0)
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
186 error ("cellfun: K must be a positive integer");
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
187
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
188 if (! error_state)
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
189 {
17892
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
190 NDA result (f_args.dims ());
13231
20ed9548070f maint: style fixes for cellfun
John W. Eaton <jwe@octave.org>
parents: 13230
diff changeset
191 for (octave_idx_type count = 0; count < k; count++)
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
192 {
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
193 dim_vector dv = f_args.elem (count).dims ();
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
194 if (d < dv.length ())
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
195 result(count) = static_cast<double> (dv(d));
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
196 else
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
197 result(count) = 1.0;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
198 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
199 retval(0) = result;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
200 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
201 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
202 else
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
203 error ("cellfun: not enough arguments for \"size\"");
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
204 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
205 else if (name == "isclass")
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
206 {
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
207 if (nargin == 3)
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
208 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
209 std::string class_name = args(2).string_value ();
17892
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
210 BNDA result (f_args.dims ());
13231
20ed9548070f maint: style fixes for cellfun
John W. Eaton <jwe@octave.org>
parents: 13230
diff changeset
211 for (octave_idx_type count = 0; count < k; count++)
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
212 result(count) = (f_args.elem (count).class_name () == class_name);
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
213
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
214 retval(0) = result;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
215 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
216 else
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
217 error ("cellfun: not enough arguments for \"isclass\"");
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
218 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
219
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
220 return retval;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
221 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
222
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
223 static void
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
224 get_mapper_fun_options (const octave_value_list& args, int& nargin,
14076
9aff66860e03 accept abbreviated cellfun option names
John W. Eaton <jwe@octave.org>
parents: 13960
diff changeset
225 bool& uniform_output, octave_value& error_handler)
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
226 {
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
227 while (nargin > 3 && args(nargin-2).is_string ())
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
228 {
14076
9aff66860e03 accept abbreviated cellfun option names
John W. Eaton <jwe@octave.org>
parents: 13960
diff changeset
229 caseless_str arg = args(nargin-2).string_value ();
9aff66860e03 accept abbreviated cellfun option names
John W. Eaton <jwe@octave.org>
parents: 13960
diff changeset
230
9aff66860e03 accept abbreviated cellfun option names
John W. Eaton <jwe@octave.org>
parents: 13960
diff changeset
231 size_t compare_len = std::max (arg.length (), static_cast<size_t> (2));
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
232
14076
9aff66860e03 accept abbreviated cellfun option names
John W. Eaton <jwe@octave.org>
parents: 13960
diff changeset
233 if (arg.compare ("uniformoutput", compare_len))
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
234 uniform_output = args(nargin-1).bool_value ();
14076
9aff66860e03 accept abbreviated cellfun option names
John W. Eaton <jwe@octave.org>
parents: 13960
diff changeset
235 else if (arg.compare ("errorhandler", compare_len))
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
236 {
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
237 if (args(nargin-1).is_function_handle ()
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
238 || args(nargin-1).is_inline_function ())
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
239 {
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
240 error_handler = args(nargin-1);
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
241 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
242 else if (args(nargin-1).is_string ())
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
243 {
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
244 std::string err_name = args(nargin-1).string_value ();
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
245
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
246 error_handler = symbol_table::find_function (err_name);
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
247
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
248 if (error_handler.is_undefined ())
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
249 {
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
250 error ("cellfun: invalid function NAME: %s",
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
251 err_name.c_str ());
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
252 break;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
253 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
254 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
255 else
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
256 {
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
257 error ("cellfun: invalid value for 'ErrorHandler' function");
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
258 break;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
259 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
260 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
261 else
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
262 {
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
263 error ("cellfun: unrecognized parameter %s",
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
264 arg.c_str ());
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
265 break;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
266 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
267
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
268 nargin -= 2;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
269 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
270
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
271 nargin -= 1;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
272 }
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
273
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
274 DEFUN (cellfun, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
275 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
276 @deftypefn {Built-in Function} {} cellfun (@var{name}, @var{C})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
277 @deftypefnx {Built-in Function} {} cellfun (\"size\", @var{C}, @var{k})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
278 @deftypefnx {Built-in Function} {} cellfun (\"isclass\", @var{C}, @var{class})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
279 @deftypefnx {Built-in Function} {} cellfun (@var{func}, @var{C})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
280 @deftypefnx {Built-in Function} {} cellfun (@var{func}, @var{C}, @var{D})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
281 @deftypefnx {Built-in Function} {[@var{a}, @dots{}] =} cellfun (@dots{})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
282 @deftypefnx {Built-in Function} {} cellfun (@dots{}, \"ErrorHandler\", @var{errfunc})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
283 @deftypefnx {Built-in Function} {} cellfun (@dots{}, \"UniformOutput\", @var{val})\n\
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
284 \n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
285 Evaluate the function named @var{name} on the elements of the cell array\n\
20207
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
286 @var{C}.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
287 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
288 Elements in @var{C} are passed on to the named function individually. The\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
289 function @var{name} can be one of the functions\n\
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
290 \n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
291 @table @code\n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
292 @item isempty\n\
5543
4d52e637a72a [project @ 2005-11-21 16:13:47 by jwe]
jwe
parents: 5451
diff changeset
293 Return 1 for empty elements.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
294 \n\
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
295 @item islogical\n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
296 Return 1 for logical elements.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
297 \n\
17002
dd783018709b Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents: 16047
diff changeset
298 @item isnumeric\n\
dd783018709b Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents: 16047
diff changeset
299 Return 1 for numeric elements.\n\
dd783018709b Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents: 16047
diff changeset
300 \n\
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
301 @item isreal\n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
302 Return 1 for real elements.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
303 \n\
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
304 @item length\n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
305 Return a vector of the lengths of cell elements.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
306 \n\
5543
4d52e637a72a [project @ 2005-11-21 16:13:47 by jwe]
jwe
parents: 5451
diff changeset
307 @item ndims\n\
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
308 Return the number of dimensions of each element.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
309 \n\
17170
d6499c14021c doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 17004
diff changeset
310 @item numel\n\
12932
f951ffdd0133 doc: Document numel option to cellfun. Use fewer function handles in examples.
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
311 @itemx prodofsize\n\
f951ffdd0133 doc: Document numel option to cellfun. Use fewer function handles in examples.
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
312 Return the number of elements contained within each cell element. The\n\
f951ffdd0133 doc: Document numel option to cellfun. Use fewer function handles in examples.
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
313 number is the product of the dimensions of the object at each cell element.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
314 \n\
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
315 @item size\n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
316 Return the size along the @var{k}-th dimension.\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
317 \n\
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
318 @item isclass\n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
319 Return 1 for elements of @var{class}.\n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
320 @end table\n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
321 \n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
322 Additionally, @code{cellfun} accepts an arbitrary function @var{func}\n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
323 in the form of an inline function, function handle, or the name of a\n\
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18712
diff changeset
324 function (in a character string). The function can take one or more\n\
20207
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
325 arguments, with the inputs arguments given by @var{C}, @var{D}, etc.\n\
18851
9ac2357f19bc doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents: 18712
diff changeset
326 Equally the function can return one or more output arguments. For example:\n\
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
327 \n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
328 @example\n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
329 @group\n\
12932
f951ffdd0133 doc: Document numel option to cellfun. Use fewer function handles in examples.
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
330 cellfun (\"atan2\", @{1, 0@}, @{0, 1@})\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
331 @result{} [ 1.57080 0.00000 ]\n\
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
332 @end group\n\
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
333 @end example\n\
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
334 \n\
10122
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
335 The number of output arguments of @code{cellfun} matches the number of output\n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
336 arguments of the function. The outputs of the function will be collected\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
337 into the output arguments of @code{cellfun} like this:\n\
10122
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
338 \n\
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
339 @example\n\
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
340 @group\n\
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
341 function [a, b] = twoouts (x)\n\
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
342 a = x;\n\
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
343 b = x*x;\n\
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
344 endfunction\n\
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
345 [aa, bb] = cellfun (@@twoouts, @{1, 2, 3@})\n\
10122
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
346 @result{}\n\
12642
f96b9b9f141b doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 12483
diff changeset
347 aa =\n\
10122
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
348 1 2 3\n\
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
349 bb =\n\
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
350 1 4 9\n\
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
351 @end group\n\
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
352 @end example\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
353 \n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
354 Note that per default the output argument(s) are arrays of the same size as\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
355 the input arguments. Input arguments that are singleton (1x1) cells will be\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
356 automatically expanded to the size of the other arguments.\n\
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
357 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
358 If the parameter @qcode{\"UniformOutput\"} is set to true (the default),\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
359 then the function must return scalars which will be concatenated into the\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
360 return array(s). If @qcode{\"UniformOutput\"} is false, the outputs are\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
361 concatenated into a cell array (or cell arrays). For example:\n\
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
362 \n\
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
363 @example\n\
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
364 @group\n\
12932
f951ffdd0133 doc: Document numel option to cellfun. Use fewer function handles in examples.
Rik <octave@nomad.inbox5.com>
parents: 12642
diff changeset
365 cellfun (\"tolower\", @{\"Foo\", \"Bar\", \"FooBar\"@},\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
366 \"UniformOutput\", false)\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
367 @result{} @{\"foo\", \"bar\", \"foobar\"@}\n\
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
368 @end group\n\
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
369 @end example\n\
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
370 \n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
371 Given the parameter @qcode{\"ErrorHandler\"}, then @var{errfunc} defines a\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
372 function to call in case @var{func} generates an error. The form of the\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
373 function is\n\
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
374 \n\
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
375 @example\n\
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
376 function [@dots{}] = errfunc (@var{s}, @dots{})\n\
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
377 @end example\n\
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
378 \n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
379 @noindent\n\
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
380 where there is an additional input argument to @var{errfunc} relative to\n\
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
381 @var{func}, given by @var{s}. This is a structure with the elements\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
382 @qcode{\"identifier\"}, @qcode{\"message\"} and @qcode{\"index\"}, giving\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
383 respectively the error identifier, the error message, and the index into the\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
384 input arguments of the element that caused the error. For example:\n\
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
385 \n\
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
386 @example\n\
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
387 @group\n\
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
388 function y = foo (s, x), y = NaN; endfunction\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
389 cellfun (\"factorial\", @{-1,2@}, \"ErrorHandler\", @@foo)\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
390 @result{} [NaN 2]\n\
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
391 @end group\n\
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
392 @end example\n\
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
393 \n\
14119
94e2a76f1e5a doc: Final grammarcheck and spellcheck before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 14116
diff changeset
394 Use @code{cellfun} intelligently. The @code{cellfun} function is a\n\
94e2a76f1e5a doc: Final grammarcheck and spellcheck before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 14116
diff changeset
395 useful tool for avoiding loops. It is often used with anonymous\n\
14116
951eacaf9381 Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14093
diff changeset
396 function handles; however, calling an anonymous function involves an\n\
951eacaf9381 Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14093
diff changeset
397 overhead quite comparable to the overhead of an m-file function.\n\
951eacaf9381 Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14093
diff changeset
398 Passing a handle to a built-in function is faster, because the\n\
14119
94e2a76f1e5a doc: Final grammarcheck and spellcheck before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 14116
diff changeset
399 interpreter is not involved in the internal loop. For example:\n\
14116
951eacaf9381 Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14093
diff changeset
400 \n\
951eacaf9381 Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14093
diff changeset
401 @example\n\
951eacaf9381 Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14093
diff changeset
402 @group\n\
951eacaf9381 Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14093
diff changeset
403 a = @{@dots{}@}\n\
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
404 v = cellfun (@@(x) det (x), a); # compute determinants\n\
14116
951eacaf9381 Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14093
diff changeset
405 v = cellfun (@@det, a); # faster\n\
951eacaf9381 Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14093
diff changeset
406 @end group\n\
951eacaf9381 Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14093
diff changeset
407 @end example\n\
951eacaf9381 Initial documentation for broadcasting and general vectorization guidelines
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14093
diff changeset
408 \n\
10687
a8ce6bdecce5 Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents: 10670
diff changeset
409 @seealso{arrayfun, structfun, spfun}\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5544
diff changeset
410 @end deftypefn")
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
411 {
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
412 octave_value_list retval;
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
413 int nargin = args.length ();
9988
76cf4aec34e9 allow functions returning no value in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9740
diff changeset
414 int nargout1 = (nargout < 1 ? 1 : nargout);
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
415
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
416 if (nargin < 2)
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
417 {
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
418 error ("cellfun: function requires at least 2 arguments");
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5784
diff changeset
419 print_usage ();
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
420 return retval;
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
421 }
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
422
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
423 octave_value func = args(0);
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
424
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
425 if (! args(1).is_cell ())
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
426 {
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
427 error ("cellfun: C must be a cell array");
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
428
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
429 return retval;
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
430 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
431
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
432 if (func.is_string ())
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
433 {
17892
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
434 retval = try_cellfun_internal_ops<boolNDArray,NDArray>(args, nargin);
9465
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
435
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
436 if (error_state || ! retval.empty ())
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
437 return retval;
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
438
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
439 // See if we can convert the string into a function.
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
440
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
441 std::string name = args(0).string_value ();
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
442
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
443 if (! valid_identifier (name))
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
444 {
18896
6825522c25e4 maint: Use names beginning and ending with "__" for internal only functions.
Rik <rik@octave.org>
parents: 18851
diff changeset
445 std::string fcn_name = unique_symbol_name ("__cellfun_fcn__");
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
446 std::string fname = "function y = " + fcn_name + "(x) y = ";
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
447
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
448 octave_function *ptr_func
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
449 = extract_function (args(0), "cellfun", fcn_name,
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
450 fname, "; endfunction");
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
451
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
452 if (ptr_func && ! error_state)
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
453 func = octave_value (ptr_func, true);
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
454 }
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
455 else
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
456 {
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
457 func = symbol_table::find_function (name);
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
458
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
459 if (func.is_undefined ())
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
460 error ("cellfun: invalid function NAME: %s", name.c_str ());
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
461 }
12949
d1db86336a49 cellfun.cc (cellfun): Small optimisation for function handles to built-ins
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12948
diff changeset
462
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
463 if (error_state || ! retval.empty ())
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
464 return retval;
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
465 }
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
466
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
467 if (func.is_function_handle () || func.is_inline_function ()
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
468 || func.is_function ())
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
469 {
13960
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
470
17892
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
471 bool uniform_output = true;
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
472 octave_value error_handler;
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
473
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
474 get_mapper_fun_options (args, nargin, uniform_output, error_handler);
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
475
12949
d1db86336a49 cellfun.cc (cellfun): Small optimisation for function handles to built-ins
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12948
diff changeset
476 // The following is an optimisation because the symbol table can
d1db86336a49 cellfun.cc (cellfun): Small optimisation for function handles to built-ins
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12948
diff changeset
477 // give a more specific function class, so this can result in
d1db86336a49 cellfun.cc (cellfun): Small optimisation for function handles to built-ins
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12948
diff changeset
478 // fewer polymorphic function calls as the function gets called
d1db86336a49 cellfun.cc (cellfun): Small optimisation for function handles to built-ins
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12948
diff changeset
479 // for each value of the array.
13960
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
480 {
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
481 if (func.is_function_handle ())
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
482 {
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
483 octave_fcn_handle* f = func.fcn_handle_value ();
12952
5a5cb2a4b71d cellfun: Fix a regression for function handles to overloaded functions
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents: 12949
diff changeset
484
13960
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
485 // Overloaded function handles need to check the type of the
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
486 // arguments for each element of the array, so they cannot
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
487 // be optimised this way.
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
488 if (f -> is_overloaded ())
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
489 goto nevermind;
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
490 }
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
491
13960
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
492 std::string name = func.function_value () -> name ();
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
493 octave_value f = symbol_table::find_function (name);
13959
cf8cd43cdeb3 cellfun: further optimisations for the string vs function handle cases
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13928
diff changeset
494
13960
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
495 if (f.is_defined ())
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
496 {
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
497 //Except for these two which are special cases...
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
498 if (name != "size" && name != "class")
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
499 {
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
500 //Try first the optimised code path for built-in functions
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
501 octave_value_list tmp_args = args;
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
502 tmp_args(0) = name;
17892
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
503
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
504 if (uniform_output)
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
505 retval =
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
506 try_cellfun_internal_ops<boolNDArray, NDArray> (tmp_args,
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
507 nargin);
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
508 else
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
509 retval =
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
510 try_cellfun_internal_ops<Cell, Cell> (tmp_args, nargin);
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
511
13960
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
512 if (error_state || ! retval.empty ())
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
513 return retval;
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
514 }
13959
cf8cd43cdeb3 cellfun: further optimisations for the string vs function handle cases
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13928
diff changeset
515
13960
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
516 //Okay, we tried, doesn't work, let's do the best we can
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
517 //instead and avoid polymorphic calls for each element of
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
518 //the array.
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
519 func = f;
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
520 }
ef96344a6e58 cellfun: get rid of unnecessary symbol_table_lookup flag
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13959
diff changeset
521 }
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
522 nevermind:
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
523
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
524 if (error_state)
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
525 return octave_value_list ();
9465
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
526
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
527 // Extract cell arguments.
9465
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
528
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
529 octave_value_list inputlist (nargin, octave_value ());
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
530
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
531 OCTAVE_LOCAL_BUFFER (Cell, inputs, nargin);
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
532 OCTAVE_LOCAL_BUFFER (bool, mask, nargin);
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
533
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
534 // This is to prevent copy-on-write.
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
535 const Cell *cinputs = inputs;
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
536
9684
c5ff5f858cfd omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 9683
diff changeset
537 octave_idx_type k = 1;
9465
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
538
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
539 dim_vector fdims (1, 1);
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
540
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
541 // Collect arguments. Pre-fill scalar elements of inputlist
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
542 // array.
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
543
9465
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
544 for (int j = 0; j < nargin; j++)
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
545 {
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
546 if (! args(j+1).is_cell ())
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
547 {
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
548 error ("cellfun: arguments must be cells");
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10044
diff changeset
549 return octave_value_list ();
9465
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
550 }
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
551
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
552 inputs[j] = args(j+1).cell_value ();
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
553 mask[j] = inputs[j].numel () != 1;
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
554 if (! mask[j])
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
555 inputlist(j) = cinputs[j](0);
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
556 }
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
557
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
558 for (int j = 0; j < nargin; j++)
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
559 {
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
560 if (mask[j])
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
561 {
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
562 fdims = inputs[j].dims ();
9683
5b3b9dcfd59c fix crash in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9678
diff changeset
563 k = inputs[j].numel ();
9465
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
564 for (int i = j+1; i < nargin; i++)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
565 {
9465
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
566 if (mask[i] && inputs[i].dims () != fdims)
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
567 {
11590
4ced6b90fffb style fixes for warning and error messages in source files
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
568 error ("cellfun: dimensions mismatch");
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 10044
diff changeset
569 return octave_value_list ();
9465
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
570 }
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
571 }
9683
5b3b9dcfd59c fix crash in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9678
diff changeset
572 break;
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
573 }
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
574 }
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
575
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
576 unwind_protect frame;
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
577 frame.protect_var (buffer_error_messages);
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
578
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
579 if (error_handler.is_defined ())
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
580 buffer_error_messages++;
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
581
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
582 // Apply functions.
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
583
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
584 if (uniform_output)
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
585 {
10670
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
586 std::list<octave_value_list> idx_list (1);
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
587 idx_list.front ().resize (1);
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
588 std::string idx_type = "(";
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
589
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
590 OCTAVE_LOCAL_BUFFER (octave_value, retv, nargout1);
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
591
13231
20ed9548070f maint: style fixes for cellfun
John W. Eaton <jwe@octave.org>
parents: 13230
diff changeset
592 for (octave_idx_type count = 0; count < k; count++)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
593 {
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
594 for (int j = 0; j < nargin; j++)
9465
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
595 {
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
596 if (mask[j])
10181
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
597 inputlist.xelem (j) = cinputs[j](count);
9465
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
598 }
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
599
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
600 const octave_value_list tmp
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
601 = get_output_list (count, nargout, inputlist, func,
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
602 error_handler);
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
603
9459
cb0b21f34abc avoid double error messages in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9450
diff changeset
604 if (error_state)
10181
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
605 return retval;
9459
cb0b21f34abc avoid double error messages in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9450
diff changeset
606
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
607 if (nargout > 0 && tmp.length () < nargout)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
608 {
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
609 error ("cellfun: function returned fewer than nargout values");
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
610 return retval;
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
611 }
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
612
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
613 if (nargout > 0
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
614 || (nargout == 0
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
615 && tmp.length () > 0 && tmp(0).is_defined ()))
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
616 {
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
617 int num_to_copy = tmp.length ();
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
618
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
619 if (num_to_copy > nargout1)
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
620 num_to_copy = nargout1;
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
621
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
622 if (count == 0)
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
623 {
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
624 for (int j = 0; j < num_to_copy; j++)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
625 {
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
626 if (tmp(j).is_defined ())
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
627 {
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
628 octave_value val = tmp(j);
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
629
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
630 if (val.numel () == 1)
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
631 retv[j] = val.resize (fdims);
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
632 else
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
633 {
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
634 error ("cellfun: all values must be scalars when UniformOutput = true");
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
635 break;
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
636 }
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
637 }
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
638 }
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
639 }
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
640 else
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
641 {
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
642 for (int j = 0; j < num_to_copy; j++)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
643 {
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
644 if (tmp(j).is_defined ())
10670
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
645 {
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
646 octave_value val = tmp(j);
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
647
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
648 if (! retv[j].fast_elem_insert (count, val))
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
649 {
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
650 if (val.numel () == 1)
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
651 {
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
652 idx_list.front ()(0) = count + 1.0;
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
653 retv[j].assign (octave_value::op_asn_eq,
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
654 idx_type, idx_list, val);
10670
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
655
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
656 if (error_state)
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
657 break;
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
658 }
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
659 else
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
660 {
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
661 error ("cellfun: all values must be scalars when UniformOutput = true");
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
662 break;
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
663 }
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
664 }
10670
654fbde5dceb make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents: 10521
diff changeset
665 }
8994
a8d30dc1beec cellfun optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8985
diff changeset
666 }
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
667 }
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
668 }
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
669
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
670 if (error_state)
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
671 break;
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
672 }
8994
a8d30dc1beec cellfun optimizations
Jaroslav Hajek <highegg@gmail.com>
parents: 8985
diff changeset
673
9988
76cf4aec34e9 allow functions returning no value in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9740
diff changeset
674 retval.resize (nargout1);
13229
983720941822 maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents: 12952
diff changeset
675
9988
76cf4aec34e9 allow functions returning no value in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9740
diff changeset
676 for (int j = 0; j < nargout1; j++)
11457
33f6384d2b78 cellfun compatibility fix
John W. Eaton <jwe@octave.org>
parents: 11046
diff changeset
677 {
33f6384d2b78 cellfun compatibility fix
John W. Eaton <jwe@octave.org>
parents: 11046
diff changeset
678 if (nargout > 0 && retv[j].is_undefined ())
33f6384d2b78 cellfun compatibility fix
John W. Eaton <jwe@octave.org>
parents: 11046
diff changeset
679 retval(j) = NDArray (fdims);
33f6384d2b78 cellfun compatibility fix
John W. Eaton <jwe@octave.org>
parents: 11046
diff changeset
680 else
33f6384d2b78 cellfun compatibility fix
John W. Eaton <jwe@octave.org>
parents: 11046
diff changeset
681 retval(j) = retv[j];
33f6384d2b78 cellfun compatibility fix
John W. Eaton <jwe@octave.org>
parents: 11046
diff changeset
682 }
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
683 }
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
684 else
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
685 {
9988
76cf4aec34e9 allow functions returning no value in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9740
diff changeset
686 OCTAVE_LOCAL_BUFFER (Cell, results, nargout1);
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
687
9988
76cf4aec34e9 allow functions returning no value in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9740
diff changeset
688 for (int j = 0; j < nargout1; j++)
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
689 results[j].resize (fdims, Matrix ());
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
690
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
691 bool have_some_output = false;
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
692
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
693 for (octave_idx_type count = 0; count < k; count++)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
694 {
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
695 for (int j = 0; j < nargin; j++)
9465
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
696 {
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
697 if (mask[j])
10181
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
698 inputlist.xelem (j) = cinputs[j](count);
9465
40de4692c860 auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9459
diff changeset
699 }
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
700
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
701 const octave_value_list tmp
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
702 = get_output_list (count, nargout, inputlist, func,
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
703 error_handler);
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
704
9459
cb0b21f34abc avoid double error messages in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9450
diff changeset
705 if (error_state)
10181
a668fbd32e34 improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents: 10155
diff changeset
706 return retval;
9459
cb0b21f34abc avoid double error messages in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9450
diff changeset
707
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
708 if (nargout > 0 && tmp.length () < nargout)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
709 {
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
710 error ("cellfun: function returned fewer than nargout values");
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
711 return retval;
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
712 }
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
713
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
714 if (nargout > 0
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
715 || (nargout == 0
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
716 && tmp.length () > 0 && tmp(0).is_defined ()))
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
717 {
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
718 int num_to_copy = tmp.length ();
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
719
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
720 if (num_to_copy > nargout1)
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
721 num_to_copy = nargout1;
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
722
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
723 if (num_to_copy > 0)
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
724 have_some_output = true;
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
725
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
726 for (int j = 0; j < num_to_copy; j++)
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
727 results[j](count) = tmp(j);
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
728 }
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
729 }
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
730
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
731 if (have_some_output || fdims.any_zero ())
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
732 {
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
733 retval.resize (nargout1);
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
734
9988
76cf4aec34e9 allow functions returning no value in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents: 9740
diff changeset
735 for (int j = 0; j < nargout1; j++)
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
736 retval(j) = results[j];
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
737 }
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
738 }
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
739 }
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
740 else
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
741 error ("cellfun: argument NAME must be a string or function handle");
5205
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
742
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
743 return retval;
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
744 }
59592dcbb5d8 [project @ 2005-03-15 16:04:56 by jwe]
jwe
parents:
diff changeset
745
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
746 /*
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
747
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
748 %!function r = __f11 (x)
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
749 %! global __cellfun_test_num_outputs__;
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
750 %! __cellfun_test_num_outputs__ = nargout;
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
751 %! r = x;
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
752 %!endfunction
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
753
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
754 %!function __f01 (x)
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
755 %! global __cellfun_test_num_outputs__;
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
756 %! __cellfun_test_num_outputs__ = nargout;
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
757 %!endfunction
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
758
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
759 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
760 %! global __cellfun_test_num_outputs__;
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
761 %! cellfun (@__f11, {1});
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
762 %! assert (__cellfun_test_num_outputs__, 0);
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
763 %! x = cellfun (@__f11, {1});
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
764 %! assert (__cellfun_test_num_outputs__, 1);
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
765
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
766 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
767 %! global __cellfun_test_num_outputs__;
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
768 %! cellfun (@__f01, {1});
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
769 %! assert (__cellfun_test_num_outputs__, 0);
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
770
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
771 %!error x = cellfun (@__f01, {1, 2});
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
772
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
773 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
774 %! assert (cellfun (@__f11, {1, 2}), [1, 2]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
775 %! assert (cellfun (@__f11, {1, 2}, 'uniformoutput', false), {1, 2});
13230
c73cc5b67feb fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents: 13229
diff changeset
776
11457
33f6384d2b78 cellfun compatibility fix
John W. Eaton <jwe@octave.org>
parents: 11046
diff changeset
777 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
778 %! [a,b] = cellfun (@(x) x, cell (2, 0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
779 %! assert (a, zeros (2, 0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
780 %! assert (b, zeros (2, 0));
11457
33f6384d2b78 cellfun compatibility fix
John W. Eaton <jwe@octave.org>
parents: 11046
diff changeset
781
33f6384d2b78 cellfun compatibility fix
John W. Eaton <jwe@octave.org>
parents: 11046
diff changeset
782 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
783 %! [a,b] = cellfun (@(x) x, cell (2, 0), "uniformoutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
784 %! assert (a, cell (2, 0));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
785 %! assert (b, cell (2, 0));
11457
33f6384d2b78 cellfun compatibility fix
John W. Eaton <jwe@octave.org>
parents: 11046
diff changeset
786
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
787 %% Test function to check the "Errorhandler" option
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
788 %!function z = __cellfunerror (S, varargin)
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
789 %! z = S;
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
790 %!endfunction
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
791
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
792 %% First input argument can be a string, an inline function,
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
793 %% a function_handle or an anonymous function
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
794 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
795 %! A = cellfun ("islogical", {true, 0.1, false, i*2});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
796 %! assert (A, [true, false, true, false]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
797 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
798 %! A = cellfun (inline ("islogical (x)", "x"), {true, 0.1, false, i*2});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
799 %! assert (A, [true, false, true, false]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
800 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
801 %! A = cellfun (@islogical, {true, 0.1, false, i*2});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
802 %! assert (A, [true, false, true, false]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
803 %!test
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
804 %! A = cellfun (@(x) islogical (x), {true, 0.1, false, i*2});
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
805 %! assert (A, [true, false, true, false]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
806
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
807 %% First input argument can be the special string "isreal",
17002
dd783018709b Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents: 16047
diff changeset
808 %% "isempty", "islogical", "isnumeric", "length", "ndims" or "prodofsize"
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
809 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
810 %! A = cellfun ("isreal", {true, 0.1, {}, i*2, [], "abc"});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
811 %! assert (A, [true, true, false, false, true, true]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
812 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
813 %! A = cellfun ("isempty", {true, 0.1, false, i*2, [], "abc"});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
814 %! assert (A, [false, false, false, false, true, false]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
815 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
816 %! A = cellfun ("islogical", {true, 0.1, false, i*2, [], "abc"});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
817 %! assert (A, [true, false, true, false, false, false]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
818 %!test
17002
dd783018709b Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents: 16047
diff changeset
819 %! A = cellfun ("isnumeric", {true, 0.1, false, i*2, [], "abc"});
dd783018709b Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents: 16047
diff changeset
820 %! assert (A, [false, true, false, true, true, false]);
dd783018709b Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents: 16047
diff changeset
821 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
822 %! A = cellfun ("length", {true, 0.1, false, i*2, [], "abc"});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
823 %! assert (A, [1, 1, 1, 1, 0, 3]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
824 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
825 %! A = cellfun ("ndims", {[1, 2; 3, 4]; (cell (1,2,3,4))});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
826 %! assert (A, [2; 4]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
827 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
828 %! A = cellfun ("prodofsize", {[1, 2; 3, 4], (cell (1,2,3,4))});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
829 %! assert (A, [4, 24]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
830
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
831 %% Number of input and output arguments may not be limited to one
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
832 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
833 %! A = cellfun (@(x,y,z) x + y + z, {1, 1, 1}, {2, 2, 2}, {3, 4, 5});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
834 %! assert (A, [6, 7, 8]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
835 %!test
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
836 %! A = cellfun (@(x,y,z) x + y + z, {1, 1, 1}, {2, 2, 2}, {3, 4, 5}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
837 %! "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
838 %! assert (A, {6, 7, 8});
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
839 %!test %% Two input arguments of different types
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
840 %! A = cellfun (@(x,y) islogical (x) && ischar (y), {false, true}, {"a", 3});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
841 %! assert (A, [true, false]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
842 %!test %% Pass another variable to the anonymous function
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
843 %! y = true;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
844 %! A = cellfun (@(x) islogical (x) && y, {false, 0.3});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
845 %! assert (A, [true, false]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
846 %!test %% Three ouptut arguments of different type
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
847 %! [A, B, C] = cellfun (@find, {10, 11; 0, 12}, "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
848 %! assert (isequal (A, {true, true; [], true}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
849 %! assert (isequal (B, {true, true; [], true}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
850 %! assert (isequal (C, {10, 11; [], 12}));
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
851
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
852 %% Input arguments can be of type cell array of logical
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
853 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
854 %! A = cellfun (@(x,y) x == y, {false, true}, {true, true});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
855 %! assert (A, [false, true]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
856 %!test
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
857 %! A = cellfun (@(x,y) x == y, {false; true}, {true; true}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
858 %! "UniformOutput", true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
859 %! assert (A, [false; true]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
860 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
861 %! A = cellfun (@(x) x, {false, true; false, true}, "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
862 %! assert (A, {false, true; false, true});
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
863 %!test %% Three ouptut arguments of same type
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
864 %! [A, B, C] = cellfun (@find, {true, false; false, true}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
865 %! "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
866 %! assert (isequal (A, {true, []; [], true}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
867 %! assert (isequal (B, {true, []; [], true}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
868 %! assert (isequal (C, {true, []; [], true}));
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
869 %!test
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
870 %! A = cellfun (@(x,y) cell2str (x,y), {true}, {true}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
871 %! "ErrorHandler", @__cellfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
872 %! assert (isfield (A, "identifier"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
873 %! assert (isfield (A, "message"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
874 %! assert (isfield (A, "index"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
875 %! assert (isempty (A.message), false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
876 %! assert (A.index, 1);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
877 %!test %% Overwriting setting of "UniformOutput" true
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
878 %! A = cellfun (@(x,y) cell2str (x,y), {true}, {true}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
879 %! "UniformOutput", true, "ErrorHandler", @__cellfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
880 %! assert (isfield (A, "identifier"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
881 %! assert (isfield (A, "message"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
882 %! assert (isfield (A, "index"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
883 %! assert (isempty (A.message), false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
884 %! assert (A.index, 1);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
885
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
886 %% Input arguments can be of type cell array of numeric
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
887 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
888 %! A = cellfun (@(x,y) x>y, {1.1, 4.2}, {3.1, 2+3*i});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
889 %! assert (A, [false, true]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
890 %!test
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
891 %! A = cellfun (@(x,y) x>y, {1.1, 4.2; 2, 4}, {3.1, 2; 2, 4+2*i}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
892 %! "UniformOutput", true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
893 %! assert (A, [false, true; false, false]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
894 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
895 %! A = cellfun (@(x,y) x:y, {1.1, 4}, {3.1, 6}, "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
896 %! assert (isequal (A{1}, [1.1, 2.1, 3.1]));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
897 %! assert (isequal (A{2}, [4, 5, 6]));
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
898 %!test %% Three ouptut arguments of different type
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
899 %! [A, B, C] = cellfun (@find, {10, 11; 0, 12}, "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
900 %! assert (isequal (A, {true, true; [], true}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
901 %! assert (isequal (B, {true, true; [], true}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
902 %! assert (isequal (C, {10, 11; [], 12}));
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
903 %!test
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
904 %! A = cellfun (@(x,y) cell2str (x,y), {1.1, 4}, {3.1, 6}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
905 %! "ErrorHandler", @__cellfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
906 %! B = isfield (A(1), "message") && isfield (A(1), "index");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
907 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
908 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
909 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
910 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
911 %! assert ([A(1).index, A(2).index], [1, 2]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
912 %!test %% Overwriting setting of "UniformOutput" true
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
913 %! A = cellfun (@(x,y) cell2str (x,y), {1.1, 4}, {3.1, 6}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
914 %! "UniformOutput", true, "ErrorHandler", @__cellfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
915 %! B = isfield (A(1), "message") && isfield (A(1), "index");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
916 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
917 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
918 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
919 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
920 %! assert ([A(1).index, A(2).index], [1, 2]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
921
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
922 %% Input arguments can be of type cell arrays of character or strings
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
923 %!error %% "UniformOutput" false should be used
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
924 %! A = cellfun (@(x,y) x>y, {"ad", "c", "ghi"}, {"cc", "d", "fgh"});
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
925 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
926 %! A = cellfun (@(x,y) x>y, {"a"; "f"}, {"c"; "d"}, "UniformOutput", true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
927 %! assert (A, [false; true]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
928 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
929 %! A = cellfun (@(x,y) x:y, {"a", "d"}, {"c", "f"}, "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
930 %! assert (A, {"abc", "def"});
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
931 %!test
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
932 %! A = cellfun (@(x,y) cell2str (x,y), {"a", "d"}, {"c", "f"}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
933 %! "ErrorHandler", @__cellfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
934 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
935 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
936 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
937 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
938 %! assert ([A(1).index, A(2).index], [1, 2]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
939 %!test %% Overwriting setting of "UniformOutput" true
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
940 %! A = cellfun (@(x,y) cell2str (x,y), {"a", "d"}, {"c", "f"}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
941 %! "UniformOutput", true, "ErrorHandler", @__cellfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
942 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
943 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
944 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
945 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
946 %! assert ([A(1).index, A(2).index], [1, 2]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
947
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
948 %% Structures cannot be handled by cellfun
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
949 %!error
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
950 %! vst1.a = 1.1; vst1.b = 4.2; vst2.a = 3.1; vst2.b = 2;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
951 %! A = cellfun (@(x,y) (x.a < y.a) && (x.b > y.b), vst1, vst2);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
952
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
953 %% Input arguments can be of type cell array of cell arrays
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
954 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
955 %! A = cellfun (@(x,y) x{1} < y{1}, {{1.1}, {4.2}}, {{3.1}, {2}});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
956 %! assert (A, [1, 0], 1e-16);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
957 %!test
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
958 %! A = cellfun (@(x,y) x{1} < y{1}, {{1.1}; {4.2}}, {{3.1}; {2}}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
959 %! "UniformOutput", true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
960 %! assert (A, [1; 0], 1e-16);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
961 %!test
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
962 %! A = cellfun (@(x,y) x{1} < y{1}, {{1.1}, {4.2}}, {{3.1}, {2}}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
963 %! "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
964 %! assert (A, {true, false});
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
965 %!test
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
966 %! A = cellfun (@(x,y) mat2str (x,y), {{1.1}, {4.2}}, {{3.1}, {2}}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
967 %! "ErrorHandler", @__cellfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
968 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
969 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
970 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
971 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
972 %! assert ([A(1).index, A(2).index], [1, 2]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
973 %!test %% Overwriting setting of "UniformOutput" true
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
974 %! A = cellfun (@(x,y) mat2str (x,y), {{1.1}, {4.2}}, {{3.1}, {2}}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
975 %! "UniformOutput", true, "ErrorHandler", @__cellfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
976 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
977 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
978 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
979 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
980 %! assert ([A(1).index, A(2).index], [1, 2]);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
981
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
982 %% Input arguments can be of type cell array of structure arrays
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
983 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
984 %! a = struct ("a", 1, "b", 2); b = struct ("a", 1, "b", 3);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
985 %! A = cellfun (@(x,y) (x.a == y.a) && (x.b < y.b), {a}, {b});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
986 %! assert (A, true);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
987 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
988 %! a = struct ("a", 1, "b", 2); b = struct ("a", 1, "b", 3);
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
989 %! A = cellfun (@(x,y) (x.a == y.a) && (x.b < y.b) , {a}, {b}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
990 %! "UniformOutput", true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
991 %! assert (A, true);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
992 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
993 %! a = struct ("a", 1, "b", 2); b = struct ("a", 1, "b", 3);
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
994 %! A = cellfun (@(x,y) (x.a == y.a) && (x.b < y.b) , {a}, {b}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
995 %! "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
996 %! assert (A, {true});
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
997 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
998 %! a = struct ("a", 1, "b", 2); b = struct ("a", 1, "b", 3);
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
999 %! A = cellfun (@(x,y) cell2str (x.a, y.a), {a}, {b}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1000 %! "ErrorHandler", @__cellfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1001 %! assert (isfield (A, "identifier"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1002 %! assert (isfield (A, "message"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1003 %! assert (isfield (A, "index"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1004 %! assert (isempty (A.message), false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1005 %! assert (A.index, 1);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
1006 %!test %% Overwriting setting of "UniformOutput" true
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1007 %! a = struct ("a", 1, "b", 2); b = struct ("a", 1, "b", 3);
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
1008 %! A = cellfun (@(x,y) cell2str (x.a, y.a), {a}, {b}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1009 %! "UniformOutput", true, "ErrorHandler", @__cellfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1010 %! assert (isfield (A, "identifier"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1011 %! assert (isfield (A, "message"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1012 %! assert (isfield (A, "index"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1013 %! assert (isempty (A.message), false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1014 %! assert (A.index, 1);
8373
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
1015
63fe023d7898 Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents: 8347
diff changeset
1016 %% A lot of other tests
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1017 %!assert (cellfun (@sin, {0,1}), sin ([0,1]))
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1018 %!assert (cellfun (inline ("sin (x)"), {0,1}), sin ([0,1]))
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1019 %!assert (cellfun ("sin", {0,1}), sin ([0,1]))
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1020 %!assert (cellfun ("isempty", {1,[]}), [false,true])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1021 %!assert (cellfun ("islogical", {false,pi}), [true,false])
17002
dd783018709b Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents: 16047
diff changeset
1022 %!assert (cellfun ("isnumeric", {false,pi,struct()}), [false,true,false])
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1023 %!assert (cellfun ("isreal", {1i,1}), [false,true])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1024 %!assert (cellfun ("length", {zeros(2,2),1}), [2,1])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1025 %!assert (cellfun ("prodofsize", {zeros(2,2),1}), [4,1])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1026 %!assert (cellfun ("ndims", {zeros([2,2,2]),1}), [3,2])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1027 %!assert (cellfun ("isclass", {zeros([2,2,2]),"test"}, "double"), [true,false])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1028 %!assert (cellfun ("size", {zeros([1,2,3]),1}, 1), [1,1])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1029 %!assert (cellfun ("size", {zeros([1,2,3]),1}, 2), [2,1])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1030 %!assert (cellfun ("size", {zeros([1,2,3]),1}, 3), [3,1])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1031 %!assert (cellfun (@atan2, {1,1}, {1,2}), [atan2(1,1), atan2(1,2)])
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1032 %!assert (cellfun (@atan2, {1,1}, {1,2},"UniformOutput", false), {atan2(1,1), atan2(1,2)})
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1033 %!assert (cellfun (@sin, {1,2;3,4}), sin ([1,2;3,4]))
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1034 %!assert (cellfun (@atan2, {1,1;1,1}, {1,2;1,2}), atan2 ([1,1;1,1],[1,2;1,2]))
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1035 %!error cellfun (@factorial, {-1,3})
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1036 %!assert (cellfun (@factorial,{-1,3},"ErrorHandler",@(x,y) NaN), [NaN,6])
16000
3f93cd251bdb fix ErrorHandler in cellfun (bug #38256)
Stefan Mahr <dac922@gmx.de>
parents: 15195
diff changeset
1037 %!assert (cellfun (@(x) x(2),{[1],[1,2]},"ErrorHandler",@(x,y) NaN), [NaN,2])
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
1038 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1039 %! [a,b,c] = cellfun (@fileparts, {fullfile("a","b","c.d"), fullfile("e","f","g.h")}, "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1040 %! assert (a, {fullfile("a","b"), fullfile("e","f")});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1041 %! assert (b, {"c", "g"});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1042 %! assert (c, {".d", ".h"});
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
1043
17892
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
1044 ## Tests for bug #40467
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
1045 %!assert (cellfun (@isreal, {1 inf nan []}), [true, true, true, true]);
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
1046 %!assert (cellfun (@isreal, {1 inf nan []}, "UniformOutput", false), {true, true, true, true});
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
1047 %!assert (cellfun (@iscomplex, {1 inf nan []}), [false, false, false, false]);
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
1048 %!assert (cellfun (@iscomplex, {1 inf nan []}, "UniformOutput", false), {false, false, false, false});
5401637c3fa7 Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 17787
diff changeset
1049
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1050 %!error cellfun (1)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1051 %!error cellfun ("isclass", 1)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1052 %!error cellfun ("size", 1)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1053 %!error cellfun (@sin, {[]}, "BadParam", false)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1054 %!error cellfun (@sin, {[]}, "UniformOuput")
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1055 %!error cellfun (@sin, {[]}, "ErrorHandler")
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
1056 */
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
1057
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1058 // Arrayfun was originally a .m file written by Bill Denney and Jaroslav
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1059 // Hajek. It was converted to C++ by jwe so that it could properly
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1060 // handle the nargout = 0 case.
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1061
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
1062 DEFUN (arrayfun, args, nargout,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1063 "-*- texinfo -*-\n\
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1064 @deftypefn {Function File} {} arrayfun (@var{func}, @var{A})\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1065 @deftypefnx {Function File} {@var{x} =} arrayfun (@var{func}, @var{A})\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1066 @deftypefnx {Function File} {@var{x} =} arrayfun (@var{func}, @var{A}, @var{b}, @dots{})\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1067 @deftypefnx {Function File} {[@var{x}, @var{y}, @dots{}] =} arrayfun (@var{func}, @var{A}, @dots{})\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1068 @deftypefnx {Function File} {} arrayfun (@dots{}, \"UniformOutput\", @var{val})\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1069 @deftypefnx {Function File} {} arrayfun (@dots{}, \"ErrorHandler\", @var{errfunc})\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1070 \n\
20207
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
1071 Execute a function on each element of an array.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
1072 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
1073 This is useful for functions that do not accept array arguments. If the\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
1074 function does accept array arguments it is better to call the function\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
1075 directly.\n\
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1076 \n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1077 The first input argument @var{func} can be a string, a function\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1078 handle, an inline function, or an anonymous function. The input\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1079 argument @var{A} can be a logic array, a numeric array, a string\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1080 array, a structure array, or a cell array. By a call of the function\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1081 @command{arrayfun} all elements of @var{A} are passed on to the named\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1082 function @var{func} individually.\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1083 \n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1084 The named function can also take more than two input arguments, with\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1085 the input arguments given as third input argument @var{b}, fourth\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1086 input argument @var{c}, @dots{} If given more than one array input\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1087 argument then all input arguments must have the same sizes, for\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1088 example:\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1089 \n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1090 @example\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1091 @group\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1092 arrayfun (@@atan2, [1, 0], [0, 1])\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1093 @result{} [ 1.5708 0.0000 ]\n\
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1094 @end group\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1095 @end example\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1096 \n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1097 If the parameter @var{val} after a further string input argument\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
1098 @qcode{\"UniformOutput\"} is set @code{true} (the default), then the named\n\
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1099 function @var{func} must return a single element which then will be\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1100 concatenated into the return value and is of type matrix. Otherwise,\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1101 if that parameter is set to @code{false}, then the outputs are\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1102 concatenated in a cell array. For example:\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1103 \n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1104 @example\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1105 @group\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1106 arrayfun (@@(x,y) x:y, \"abc\", \"def\", \"UniformOutput\", false)\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1107 @result{}\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1108 @{\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1109 [1,1] = abcd\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1110 [1,2] = bcde\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1111 [1,3] = cdef\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1112 @}\n\
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1113 @end group\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1114 @end example\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1115 \n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1116 If more than one output arguments are given then the named function\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1117 must return the number of return values that also are expected, for\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1118 example:\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1119 \n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1120 @example\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1121 @group\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1122 [A, B, C] = arrayfun (@@find, [10; 0], \"UniformOutput\", false)\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1123 @result{}\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1124 A =\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1125 @{\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1126 [1,1] = 1\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1127 [2,1] = [](0x0)\n\
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1128 @}\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1129 B =\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1130 @{\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1131 [1,1] = 1\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1132 [2,1] = [](0x0)\n\
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1133 @}\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1134 C =\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1135 @{\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1136 [1,1] = 10\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1137 [2,1] = [](0x0)\n\
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1138 @}\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1139 @end group\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1140 @end example\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1141 \n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1142 If the parameter @var{errfunc} after a further string input argument\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
1143 @qcode{\"ErrorHandler\"} is another string, a function handle, an inline\n\
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1144 function, or an anonymous function, then @var{errfunc} defines a\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1145 function to call in the case that @var{func} generates an error.\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1146 The definition of the function must be of the form\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1147 \n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1148 @example\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1149 function [@dots{}] = errfunc (@var{s}, @dots{})\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1150 @end example\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1151 \n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1152 @noindent\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1153 where there is an additional input argument to @var{errfunc}\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1154 relative to @var{func}, given by @var{s}. This is a structure with\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
1155 the elements @qcode{\"identifier\"}, @qcode{\"message\"}, and\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
1156 @qcode{\"index\"} giving, respectively, the error identifier, the error\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
1157 message, and the index of the array elements that caused the error. The\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
1158 size of the output argument of @var{errfunc} must have the same size as the\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 17245
diff changeset
1159 output argument of @var{func}, otherwise a real error is thrown. For\n\
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1160 example:\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1161 \n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1162 @example\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1163 @group\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1164 function y = ferr (s, x), y = \"MyString\"; endfunction\n\
14093
050bc580cb60 doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 14085
diff changeset
1165 arrayfun (@@str2num, [1234],\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1166 \"UniformOutput\", false, \"ErrorHandler\", @@ferr)\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1167 @result{}\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1168 @{\n\
14093
050bc580cb60 doc: Various docstring improvements before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 14085
diff changeset
1169 [1,1] = MyString\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1170 @}\n\
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1171 @end group\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1172 @end example\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1173 \n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1174 @seealso{spfun, cellfun, structfun}\n\
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1175 @end deftypefn")
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1176 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1177 octave_value_list retval;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1178 int nargin = args.length ();
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1179 int nargout1 = (nargout < 1 ? 1 : nargout);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1180
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1181 if (nargin < 2)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1182 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1183 error_with_id ("Octave:invalid-fun-call",
16010
c5d548e4101f * cellfun.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 16004
diff changeset
1184 "arrayfun: function requires at least 2 arguments");
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1185 print_usage ();
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1186 return retval;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1187 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1188
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1189 octave_value func = args(0);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1190 bool symbol_table_lookup = false;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1191
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1192 if (func.is_string ())
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1193 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1194 // See if we can convert the string into a function.
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1195
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1196 std::string name = args(0).string_value ();
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1197
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1198 if (! valid_identifier (name))
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1199 {
18896
6825522c25e4 maint: Use names beginning and ending with "__" for internal only functions.
Rik <rik@octave.org>
parents: 18851
diff changeset
1200 std::string fcn_name = unique_symbol_name ("__arrayfun_fcn__");
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1201 std::string fname = "function y = " + fcn_name + "(x) y = ";
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1202
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1203 octave_function *ptr_func
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1204 = extract_function (args(0), "arrayfun", fcn_name,
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1205 fname, "; endfunction");
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1206
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1207 if (ptr_func && ! error_state)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1208 func = octave_value (ptr_func, true);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1209 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1210 else
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1211 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1212 func = symbol_table::find_function (name);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1213
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1214 if (func.is_undefined ())
16003
3b3321f9db9f arrayfun: adding IDs to error messages in accordance with error_ids.
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 15195
diff changeset
1215 error_with_id ("Octave:invalid-input-arg",
16010
c5d548e4101f * cellfun.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 16004
diff changeset
1216 "arrayfun: invalid function NAME: %s",
c5d548e4101f * cellfun.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 16004
diff changeset
1217 name.c_str ());
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1218
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1219 symbol_table_lookup = true;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1220 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1221
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1222 if (error_state)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1223 return retval;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1224 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1225
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1226 if (func.is_function_handle () || func.is_inline_function ()
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1227 || func.is_function ())
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1228 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1229 // The following is an optimisation because the symbol table can
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1230 // give a more specific function class, so this can result in
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1231 // fewer polymorphic function calls as the function gets called
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1232 // for each value of the array.
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1233
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18111
diff changeset
1234 if (! symbol_table_lookup)
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1235 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1236 if (func.is_function_handle ())
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1237 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1238 octave_fcn_handle* f = func.fcn_handle_value ();
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1239
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1240 // Overloaded function handles need to check the type of
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1241 // the arguments for each element of the array, so they
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1242 // cannot be optimised this way.
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1243
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1244 if (f -> is_overloaded ())
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1245 goto nevermind;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1246 }
19895
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1247 octave_value f
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1248 = symbol_table::find_function (func.function_value () -> name ());
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
1249
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1250 if (f.is_defined ())
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1251 func = f;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1252 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1253
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1254 nevermind:
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1255
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1256 bool uniform_output = true;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1257 octave_value error_handler;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1258
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1259 get_mapper_fun_options (args, nargin, uniform_output, error_handler);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1260
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1261 if (error_state)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1262 return octave_value_list ();
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1263
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1264 octave_value_list inputlist (nargin, octave_value ());
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1265
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1266 OCTAVE_LOCAL_BUFFER (octave_value, inputs, nargin);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1267 OCTAVE_LOCAL_BUFFER (bool, mask, nargin);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1268
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1269 octave_idx_type k = 1;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1270
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1271 dim_vector fdims (1, 1);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1272
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1273 // Collect arguments. Pre-fill scalar elements of inputlist
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1274 // array.
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1275
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1276 for (int j = 0; j < nargin; j++)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1277 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1278 inputs[j] = args(j+1);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1279 mask[j] = inputs[j].numel () != 1;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1280
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1281 if (! mask[j])
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1282 inputlist(j) = inputs[j];
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1283 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1284
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1285 for (int j = 0; j < nargin; j++)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1286 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1287 if (mask[j])
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1288 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1289 fdims = inputs[j].dims ();
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1290 k = inputs[j].numel ();
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1291
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1292 for (int i = j+1; i < nargin; i++)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1293 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1294 if (mask[i] && inputs[i].dims () != fdims)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1295 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1296 error_with_id ("Octave:invalid-input-arg",
16010
c5d548e4101f * cellfun.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 16004
diff changeset
1297 "arrayfun: dimensions mismatch");
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1298 return retval;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1299 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1300 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1301 break;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1302 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1303 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1304
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1305
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1306 unwind_protect frame;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1307 frame.protect_var (buffer_error_messages);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1308
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1309 if (error_handler.is_defined ())
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1310 buffer_error_messages++;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1311
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1312 // Apply functions.
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1313
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1314 if (uniform_output)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1315 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1316 std::list<octave_value_list> idx_list (1);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1317 idx_list.front ().resize (1);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1318 std::string idx_type = "(";
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1319
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1320 OCTAVE_LOCAL_BUFFER (octave_value, retv, nargout1);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1321
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1322 for (octave_idx_type count = 0; count < k; count++)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1323 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1324 idx_list.front ()(0) = count + 1.0;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1325
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1326 for (int j = 0; j < nargin; j++)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1327 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1328 if (mask[j])
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1329 inputlist.xelem (j) = inputs[j].do_index_op (idx_list);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1330
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1331 if (error_state)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1332 return retval;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1333 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1334
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1335 const octave_value_list tmp
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1336 = get_output_list (count, nargout, inputlist, func,
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1337 error_handler);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1338
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1339 if (error_state)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1340 return retval;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1341
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1342 if (nargout > 0 && tmp.length () < nargout)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1343 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1344 error_with_id ("Octave:invalid-fun-call",
16010
c5d548e4101f * cellfun.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 16004
diff changeset
1345 "arrayfun: function returned fewer than nargout values");
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1346 return retval;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1347 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1348
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1349 if (nargout > 0
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1350 || (nargout == 0
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1351 && tmp.length () > 0 && tmp(0).is_defined ()))
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1352 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1353 int num_to_copy = tmp.length ();
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1354
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1355 if (num_to_copy > nargout1)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1356 num_to_copy = nargout1;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1357
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1358 if (count == 0)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1359 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1360 for (int j = 0; j < num_to_copy; j++)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1361 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1362 if (tmp(j).is_defined ())
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1363 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1364 octave_value val = tmp(j);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1365
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1366 if (val.numel () == 1)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1367 retv[j] = val.resize (fdims);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1368 else
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1369 {
16003
3b3321f9db9f arrayfun: adding IDs to error messages in accordance with error_ids.
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 15195
diff changeset
1370 error_with_id ("Octave:invalid-fun-call",
16010
c5d548e4101f * cellfun.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 16004
diff changeset
1371 "arrayfun: all values must be scalars when UniformOutput = true");
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1372 break;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1373 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1374 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1375 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1376 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1377 else
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1378 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1379 for (int j = 0; j < num_to_copy; j++)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1380 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1381 if (tmp(j).is_defined ())
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1382 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1383 octave_value val = tmp(j);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1384
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1385 if (! retv[j].fast_elem_insert (count, val))
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1386 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1387 if (val.numel () == 1)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1388 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1389 idx_list.front ()(0) = count + 1.0;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1390 retv[j].assign (octave_value::op_asn_eq,
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1391 idx_type, idx_list, val);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1392
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1393 if (error_state)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1394 break;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1395 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1396 else
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1397 {
16003
3b3321f9db9f arrayfun: adding IDs to error messages in accordance with error_ids.
Juan Pablo Carbajal <ajuanpi+dev@gmail.com>
parents: 15195
diff changeset
1398 error_with_id ("Octave:invalid-fun-call",
16010
c5d548e4101f * cellfun.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 16004
diff changeset
1399 "arrayfun: all values must be scalars when UniformOutput = true");
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1400 break;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1401 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1402 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1403 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1404 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1405 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1406 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1407
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1408 if (error_state)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1409 break;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1410 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1411
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1412 retval.resize (nargout1);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1413
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1414 for (int j = 0; j < nargout1; j++)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1415 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1416 if (nargout > 0 && retv[j].is_undefined ())
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1417 retval(j) = NDArray (fdims);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1418 else
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1419 retval(j) = retv[j];
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1420 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1421 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1422 else
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1423 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1424 std::list<octave_value_list> idx_list (1);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1425 idx_list.front ().resize (1);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1426 std::string idx_type = "(";
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1427
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1428 OCTAVE_LOCAL_BUFFER (Cell, results, nargout1);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1429
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1430 for (int j = 0; j < nargout1; j++)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1431 results[j].resize (fdims, Matrix ());
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1432
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1433 bool have_some_output = false;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1434
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1435 for (octave_idx_type count = 0; count < k; count++)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1436 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1437 idx_list.front ()(0) = count + 1.0;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1438
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1439 for (int j = 0; j < nargin; j++)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1440 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1441 if (mask[j])
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1442 inputlist.xelem (j) = inputs[j].do_index_op (idx_list);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1443
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1444 if (error_state)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1445 return retval;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1446 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1447
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1448 const octave_value_list tmp
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1449 = get_output_list (count, nargout, inputlist, func,
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1450 error_handler);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1451
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1452 if (error_state)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1453 return retval;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1454
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1455 if (nargout > 0 && tmp.length () < nargout)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1456 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1457 error_with_id ("Octave:invalid-fun-call",
16010
c5d548e4101f * cellfun.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 16004
diff changeset
1458 "arrayfun: function returned fewer than nargout values");
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1459 return retval;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1460 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1461
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1462 if (nargout > 0
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1463 || (nargout == 0
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1464 && tmp.length () > 0 && tmp(0).is_defined ()))
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1465 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1466 int num_to_copy = tmp.length ();
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1467
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1468 if (num_to_copy > nargout1)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1469 num_to_copy = nargout1;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1470
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1471 if (num_to_copy > 0)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1472 have_some_output = true;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1473
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1474 for (int j = 0; j < num_to_copy; j++)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1475 results[j](count) = tmp(j);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1476 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1477 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1478
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1479 if (have_some_output || fdims.any_zero ())
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1480 {
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1481 retval.resize (nargout1);
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1482
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1483 for (int j = 0; j < nargout1; j++)
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1484 retval(j) = results[j];
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1485 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1486 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1487 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1488 else
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1489 error_with_id ("Octave:invalid-fun-call",
16010
c5d548e4101f * cellfun.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents: 16004
diff changeset
1490 "arrayfun: argument NAME must be a string or function handle");
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1491
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1492 return retval;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1493 }
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1494
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1495 /*
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
1496 %!function r = __f11 (x)
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1497 %! global __arrayfun_test_num_outputs__;
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1498 %! __arrayfun_test_num_outputs__ = nargout;
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1499 %! r = x;
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
1500 %!endfunction
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1501
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
1502 %!function __f01 (x)
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1503 %! global __arrayfun_test_num_outputs__;
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1504 %! __arrayfun_test_num_outputs__ = nargout;
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
1505 %!endfunction
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1506
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1507 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1508 %! global __arrayfun_test_num_outputs__;
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
1509 %! arrayfun (@__f11, {1});
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1510 %! assert (__arrayfun_test_num_outputs__, 0);
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
1511 %! x = arrayfun (@__f11, {1});
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1512 %! assert (__arrayfun_test_num_outputs__, 1);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1513
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1514 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1515 %! global __arrayfun_test_num_outputs__;
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
1516 %! arrayfun (@__f01, {1});
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1517 %! assert (__arrayfun_test_num_outputs__, 0);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1518
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
1519 %!error x = arrayfun (@__f01, [1, 2]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1520
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1521 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1522 %! assert (arrayfun (@__f11, [1, 2]), [1, 2]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1523 %! assert (arrayfun (@__f11, [1, 2], "uniformoutput", false), {1, 2});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1524 %! assert (arrayfun (@__f11, {1, 2}), {1, 2});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1525 %! assert (arrayfun (@__f11, {1, 2}, "uniformoutput", false), {{1}, {2}});
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1526
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1527 %!assert (arrayfun (@ones, 1, [2,3], "uniformoutput", false), {[1,1], [1,1,1]})
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1528
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1529 %% Test function to check the "Errorhandler" option
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1530 %!function z = __arrayfunerror (S, varargin)
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1531 %! z = S;
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14076
diff changeset
1532 %!endfunction
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1533 %% First input argument can be a string, an inline function, a
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1534 %% function_handle or an anonymous function
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1535 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1536 %! arrayfun (@isequal, [false, true], [true, true]); %% No output argument
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1537 %!error
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1538 %! arrayfun (@isequal); %% One or less input arguments
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1539 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1540 %! A = arrayfun ("isequal", [false, true], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1541 %! assert (A, [false, true]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1542 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1543 %! A = arrayfun (inline ("(x == y)", "x", "y"), [false, true], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1544 %! assert (A, [false, true]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1545 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1546 %! A = arrayfun (@isequal, [false, true], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1547 %! assert (A, [false, true]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1548 %!test
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
1549 %! A = arrayfun (@(x,y) isequal (x,y), [false, true], [true, true]);
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1550 %! assert (A, [false, true]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1551
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1552 %% Number of input and output arguments may be greater than one
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1553 %#!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1554 %! A = arrayfun (@(x) islogical (x), false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1555 %! assert (A, true);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1556 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1557 %! A = arrayfun (@(x,y,z) x + y + z, [1, 1, 1], [2, 2, 2], [3, 4, 5]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1558 %! assert (A, [6, 7, 8], 1e-16);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1559 %!test %% Two input arguments of different types
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1560 %! A = arrayfun (@(x,y) islogical (x) && ischar (y), false, "a");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1561 %! assert (A, true);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1562 %!test %% Pass another variable to the anonymous function
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1563 %! y = true;
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1564 %! A = arrayfun (@(x) islogical (x && y), false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1565 %! assert (A, true);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1566 %!test %% Three ouptut arguments of different type
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1567 %! [A, B, C] = arrayfun (@find, [10, 11; 0, 12], "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1568 %! assert (isequal (A, {true, true; [], true}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1569 %! assert (isequal (B, {true, true; [], true}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1570 %! assert (isequal (C, {10, 11; [], 12}));
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1571
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1572 %% Input arguments can be of type logical
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1573 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1574 %! A = arrayfun (@(x,y) x == y, [false, true], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1575 %! assert (A, [false, true]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1576 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1577 %! A = arrayfun (@(x,y) x == y, [false; true], [true; true], "UniformOutput", true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1578 %! assert (A, [false; true]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1579 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1580 %! A = arrayfun (@(x) x, [false, true, false, true], "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1581 %! assert (A, {false, true, false, true});
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1582 %!test %% Three ouptut arguments of same type
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1583 %! [A, B, C] = arrayfun (@find, [true, false; false, true], "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1584 %! assert (isequal (A, {true, []; [], true}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1585 %! assert (isequal (B, {true, []; [], true}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1586 %! assert (isequal (C, {true, []; [], true}));
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1587 %!test
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
1588 %! A = arrayfun (@(x,y) array2str (x,y), true, true, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1589 %! "ErrorHandler", @__arrayfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1590 %! assert (isfield (A, "identifier"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1591 %! assert (isfield (A, "message"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1592 %! assert (isfield (A, "index"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1593 %! assert (isempty (A.message), false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1594 %! assert (A.index, 1);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1595 %!test %% Overwriting setting of "UniformOutput" true
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
1596 %! A = arrayfun (@(x,y) array2str (x,y), true, true, "UniformOutput", true, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1597 %! "ErrorHandler", @__arrayfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1598 %! assert (isfield (A, "identifier"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1599 %! assert (isfield (A, "message"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1600 %! assert (isfield (A, "index"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1601 %! assert (isempty (A.message), false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1602 %! assert (A.index, 1);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1603
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1604 %% Input arguments can be of type numeric
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1605 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1606 %! A = arrayfun (@(x,y) x>y, [1.1, 4.2], [3.1, 2+3*i]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1607 %! assert (A, [false, true]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1608 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1609 %! A = arrayfun (@(x,y) x>y, [1.1, 4.2; 2, 4], [3.1, 2; 2, 4+2*i], "UniformOutput", true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1610 %! assert (A, [false, true; false, false]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1611 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1612 %! A = arrayfun (@(x,y) x:y, [1.1, 4], [3.1, 6], "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1613 %! assert (isequal (A{1}, [1.1, 2.1, 3.1]));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1614 %! assert (isequal (A{2}, [4, 5, 6]));
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1615 %!test %% Three ouptut arguments of different type
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1616 %! [A, B, C] = arrayfun (@find, [10, 11; 0, 12], "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1617 %! assert (isequal (A, {true, true; [], true}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1618 %! assert (isequal (B, {true, true; [], true}));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1619 %! assert (isequal (C, {10, 11; [], 12}));
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1620 %!test
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
1621 %! A = arrayfun (@(x,y) array2str (x,y), {1.1, 4}, {3.1, 6}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1622 %! "ErrorHandler", @__arrayfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1623 %! B = isfield (A(1), "message") && isfield (A(1), "index");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1624 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1625 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1626 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1627 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1628 %! assert ([A(1).index, A(2).index], [1, 2]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1629 %!test %% Overwriting setting of "UniformOutput" true
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
1630 %! A = arrayfun (@(x,y) array2str (x,y), {1.1, 4}, {3.1, 6}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1631 %! "UniformOutput", true, "ErrorHandler", @__arrayfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1632 %! B = isfield (A(1), "message") && isfield (A(1), "index");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1633 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1634 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1635 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1636 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1637 %! assert ([A(1).index, A(2).index], [1, 2]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1638
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1639 %% Input arguments can be of type character or strings
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1640 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1641 %! A = arrayfun (@(x,y) x>y, ["ad", "c", "ghi"], ["cc", "d", "fgh"]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1642 %! assert (A, [false, true, false, true, true, true]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1643 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1644 %! A = arrayfun (@(x,y) x>y, ["a"; "f"], ["c"; "d"], "UniformOutput", true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1645 %! assert (A, [false; true]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1646 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1647 %! A = arrayfun (@(x,y) x:y, ["a", "d"], ["c", "f"], "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1648 %! assert (A, {"abc", "def"});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1649 %!test
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
1650 %! A = arrayfun (@(x,y) cell2str (x,y), ["a", "d"], ["c", "f"], ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1651 %! "ErrorHandler", @__arrayfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1652 %! B = isfield (A(1), "identifier") && isfield (A(1), "message") && isfield (A(1), "index");
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1653 %! assert (B, true);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1654
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1655 %% Input arguments can be of type structure
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1656 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1657 %! a = struct ("a", 1.1, "b", 4.2); b = struct ("a", 3.1, "b", 2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1658 %! A = arrayfun (@(x,y) (x.a < y.a) && (x.b > y.b), a, b);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1659 %! assert (A, true);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1660 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1661 %! a = struct ("a", 1.1, "b", 4.2); b = struct ("a", 3.1, "b", 2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1662 %! A = arrayfun (@(x,y) (x.a < y.a) && (x.b > y.b), a, b, "UniformOutput", true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1663 %! assert (A, true);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1664 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1665 %! a = struct ("a", 1.1, "b", 4.2); b = struct ("a", 3.1, "b", 2);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1666 %! A = arrayfun (@(x,y) x.a:y.a, a, b, "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1667 %! assert (isequal (A, {[1.1, 2.1, 3.1]}));
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1668 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1669 %! A = arrayfun (@(x) mat2str(x), "a", "ErrorHandler", @__arrayfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1670 %! assert (isfield (A, "identifier"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1671 %! assert (isfield (A, "message"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1672 %! assert (isfield (A, "index"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1673 %! assert (isempty (A.message), false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1674 %! assert (A.index, 1);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1675 %!test %% Overwriting setting of "UniformOutput" true
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
1676 %! A = arrayfun (@(x) mat2str(x), "a", "UniformOutput", true, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1677 %! "ErrorHandler", @__arrayfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1678 %! assert (isfield (A, "identifier"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1679 %! assert (isfield (A, "message"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1680 %! assert (isfield (A, "index"), true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1681 %! assert (isempty (A.message), false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1682 %! assert (A.index, 1);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1683
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1684 %% Input arguments can be of type cell array
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1685 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1686 %! A = arrayfun (@(x,y) x{1} < y{1}, {1.1, 4.2}, {3.1, 2});
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1687 %! assert (A, [true, false]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1688 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1689 %! A = arrayfun (@(x,y) x{1} < y{1}, {1.1; 4.2}, {3.1; 2}, "UniformOutput", true);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1690 %! assert (A, [true; false]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1691 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1692 %! A = arrayfun (@(x,y) x{1} < y{1}, {1.1, 4.2}, {3.1, 2}, "UniformOutput", false);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1693 %! assert (A, {true, false});
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1694 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1695 %! A = arrayfun (@(x,y) num2str(x,y), {1.1, 4.2}, {3.1, 2}, "ErrorHandler", @__arrayfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1696 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1697 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1698 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1699 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1700 %! assert ([A(1).index, A(2).index], [1, 2]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1701 %!test
17245
7babcdb9bc13 Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents: 17199
diff changeset
1702 %! A = arrayfun (@(x,y) num2str (x,y), {1.1, 4.2}, {3.1, 2}, ...
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1703 %! "UniformOutput", true, "ErrorHandler", @__arrayfunerror);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1704 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1705 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1706 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], [true, true]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1707 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], [false, false]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1708 %! assert ([A(1).index, A(2).index], [1, 2]);
13234
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1709 */
e066d173aae6 improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents: 13231
diff changeset
1710
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1711 static void
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1712 do_num2cell_helper (const dim_vector& dv,
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1713 const Array<int>& dimv,
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1714 dim_vector& celldv, dim_vector& arraydv,
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1715 Array<int>& perm)
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1716 {
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1717 int dvl = dimv.length ();
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1718 int maxd = dv.length ();
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1719 celldv = dv;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1720 for (int i = 0; i < dvl; i++)
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1721 maxd = std::max (maxd, dimv(i));
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1722 if (maxd > dv.length ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1723 celldv.resize (maxd, 1);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1724 arraydv = celldv;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1725
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1726 OCTAVE_LOCAL_BUFFER_INIT (bool, sing, maxd, false);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1727
10350
12884915a8e4 merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents: 10291
diff changeset
1728 perm.clear (maxd, 1);
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1729 for (int i = 0; i < dvl; i++)
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1730 {
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1731 int k = dimv(i) - 1;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1732 if (k < 0)
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1733 {
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1734 error ("num2cell: dimension indices must be positive");
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1735 return;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1736 }
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1737 else if (i > 0 && k < dimv(i-1) - 1)
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1738 {
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1739 error ("num2cell: dimension indices must be strictly increasing");
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1740 return;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1741 }
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1742
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1743 sing[k] = true;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1744 perm(i) = k;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1745 }
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1746
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1747 for (int k = 0, i = dvl; k < maxd; k++)
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1748 if (! sing[k])
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1749 perm(i++) = k;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1750
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1751 for (int i = 0; i < maxd; i++)
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1752 if (sing[i])
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1753 celldv(i) = 1;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1754 else
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1755 arraydv(i) = 1;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1756 }
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1757
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1758 template<class NDA>
10756
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1759 static inline typename NDA::element_type
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1760 do_num2cell_elem (const NDA& array, octave_idx_type i)
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1761 { return array(i); }
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1762
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1763 static inline Cell
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1764 do_num2cell_elem (const Cell& array, octave_idx_type i)
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1765 { return Cell (array(i)); }
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1766
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1767
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1768 template<class NDA>
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1769 static Cell
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1770 do_num2cell (const NDA& array, const Array<int>& dimv)
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1771 {
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1772 if (dimv.is_empty ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1773 {
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1774 Cell retval (array.dims ());
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1775 octave_idx_type nel = array.numel ();
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1776 for (octave_idx_type i = 0; i < nel; i++)
10756
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1777 retval.xelem (i) = do_num2cell_elem (array, i);
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1778
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1779 return retval;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1780 }
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1781 else
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1782 {
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1783 dim_vector celldv, arraydv;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1784 Array<int> perm;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1785 do_num2cell_helper (array.dims (), dimv, celldv, arraydv, perm);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1786 if (error_state)
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1787 return Cell ();
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1788
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1789 NDA parray = array.permute (perm);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1790
18099
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17893
diff changeset
1791 octave_idx_type nela = arraydv.numel ();
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17893
diff changeset
1792 octave_idx_type nelc = celldv.numel ();
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1793 parray = parray.reshape (dim_vector (nela, nelc));
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1794
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1795 Cell retval (celldv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1796 for (octave_idx_type i = 0; i < nelc; i++)
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1797 {
9731
7b9cbaad68d6 extend Array<T>
Jaroslav Hajek <highegg@gmail.com>
parents: 9728
diff changeset
1798 retval.xelem (i) = NDA (parray.column (i).reshape (arraydv));
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1799 }
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1800
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1801 return retval;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1802 }
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1803 }
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1804
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1805 // FIXME: this is a mess, but if a size method for the object exists,
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1806 // we have to call it to get the size of the object instead of using the
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1807 // internal dims method.
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1808
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1809 static dim_vector
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1810 get_object_dims (octave_value& obj)
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1811 {
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1812 dim_vector retval;
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1813
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1814 Matrix m = obj.size ();
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1815
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1816 int n = m.numel ();
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1817
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1818 retval.resize (n);
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1819
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1820 for (int i = 0; i < n; i++)
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1821 retval(i) = m(i);
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1822
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1823 return retval;
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1824 }
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1825
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1826 static Cell
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1827 do_object2cell (const octave_value& obj, const Array<int>& dimv)
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1828 {
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1829 Cell retval;
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1830
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1831 // FIXME: this copy is only needed because the octave_value::size
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1832 // method is not const.
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1833 octave_value array = obj;
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1834
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1835 if (dimv.is_empty ())
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1836 {
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1837 dim_vector dv = get_object_dims (array);
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1838
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1839 if (! error_state)
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1840 {
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1841 retval.resize (dv);
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1842
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1843 octave_value_list idx (1);
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1844
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1845 for (octave_idx_type i = 0; i < dv.numel (); i++)
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1846 {
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1847 octave_quit ();
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1848
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1849 idx(0) = double (i+1);
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1850
14854
5ae9f0f77635 maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
1851 retval.xelem (i) = array.single_subsref ("(", idx);
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1852
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1853 if (error_state)
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1854 break;
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1855 }
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1856 }
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1857 }
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1858 else
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1859 {
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1860 error ("num2cell (A, dim) not implemented for class objects");
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1861 }
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1862
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1863 return retval;
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1864 }
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1865
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
1866 DEFUN (num2cell, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1867 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
1868 @deftypefn {Built-in Function} {@var{C} =} num2cell (@var{A})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
1869 @deftypefnx {Built-in Function} {@var{C} =} num2cell (@var{A}, @var{dim})\n\
20207
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
1870 Convert the numeric matrix @var{A} to a cell array.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
1871 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
1872 If @var{dim} is defined, the value @var{C} is of dimension 1 in this\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
1873 dimension and the elements of @var{A} are placed into @var{C} in slices.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
1874 For example:\n\
10122
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
1875 \n\
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
1876 @example\n\
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
1877 @group\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1878 num2cell ([1,2;3,4])\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1879 @result{}\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1880 @{\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1881 [1,1] = 1\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1882 [2,1] = 3\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1883 [1,2] = 2\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1884 [2,2] = 4\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1885 @}\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1886 num2cell ([1,2;3,4],1)\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1887 @result{}\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1888 @{\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1889 [1,1] =\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1890 1\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1891 3\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1892 [1,2] =\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1893 2\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1894 4\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
1895 @}\n\
10122
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
1896 @end group\n\
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
1897 @end example\n\
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
1898 \n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5544
diff changeset
1899 @seealso{mat2cell}\n\
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
1900 @end deftypefn")
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
1901 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
1902 int nargin = args.length ();
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
1903 octave_value retval;
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
1904
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
1905 if (nargin < 1 || nargin > 2)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5784
diff changeset
1906 print_usage ();
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
1907 else
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
1908 {
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1909 octave_value array = args(0);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1910 Array<int> dimv;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1911 if (nargin > 1)
18111
b560bac0fca2 maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents: 18099
diff changeset
1912 dimv = args(1).int_vector_value (true);
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
1913
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1914 if (error_state)
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1915 ;
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1916 else if (array.is_bool_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1917 retval = do_num2cell (array.bool_array_value (), dimv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1918 else if (array.is_char_matrix ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1919 retval = do_num2cell (array.char_array_value (), dimv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1920 else if (array.is_numeric_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1921 {
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1922 if (array.is_integer_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1923 {
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1924 if (array.is_int8_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1925 retval = do_num2cell (array.int8_array_value (), dimv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1926 else if (array.is_int16_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1927 retval = do_num2cell (array.int16_array_value (), dimv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1928 else if (array.is_int32_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1929 retval = do_num2cell (array.int32_array_value (), dimv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1930 else if (array.is_int64_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1931 retval = do_num2cell (array.int64_array_value (), dimv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1932 else if (array.is_uint8_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1933 retval = do_num2cell (array.uint8_array_value (), dimv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1934 else if (array.is_uint16_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1935 retval = do_num2cell (array.uint16_array_value (), dimv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1936 else if (array.is_uint32_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1937 retval = do_num2cell (array.uint32_array_value (), dimv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1938 else if (array.is_uint64_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1939 retval = do_num2cell (array.uint64_array_value (), dimv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1940 }
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1941 else if (array.is_complex_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1942 {
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1943 if (array.is_single_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1944 retval = do_num2cell (array.float_complex_array_value (), dimv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1945 else
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1946 retval = do_num2cell (array.complex_array_value (), dimv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1947 }
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1948 else
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1949 {
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1950 if (array.is_single_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1951 retval = do_num2cell (array.float_array_value (), dimv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1952 else
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1953 retval = do_num2cell (array.array_value (), dimv);
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1954 }
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1955 }
13695
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1956 else if (array.is_object ())
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1957 retval = do_object2cell (array, dimv);
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1958 else if (array.is_map ())
348857854c52 correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13329
diff changeset
1959 retval = do_num2cell (array.map_value (), dimv);
10756
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1960 else if (array.is_cell ())
d808eb829d48 optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1961 retval = do_num2cell (array.cell_value (), dimv);
13329
80f7564a3849 handle class objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13234
diff changeset
1962 else if (array.is_object ())
80f7564a3849 handle class objects in num2cell
John W. Eaton <jwe@octave.org>
parents: 13234
diff changeset
1963 retval = do_num2cell (array.cell_value (), dimv);
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1964 else
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
1965 gripe_wrong_type_arg ("num2cell", array);
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
1966 }
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
1967
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
1968 return retval;
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
1969 }
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5307
diff changeset
1970
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
1971 /*
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1972 %!assert (num2cell ([1,2;3,4]), {1,2;3,4})
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1973 %!assert (num2cell ([1,2;3,4], 1), {[1;3],[2;4]})
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
1974 %!assert (num2cell ([1,2;3,4], 2), {[1,2];[3,4]})
5988
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
1975 */
d9ce802628e6 [project @ 2006-09-12 21:31:41 by dbateman]
dbateman
parents: 5829
diff changeset
1976
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
1977 static bool
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1978 mat2cell_mismatch (const dim_vector& dv,
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1979 const Array<octave_idx_type> *d, int nd)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1980 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1981 for (int i = 0; i < nd; i++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1982 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1983 octave_idx_type s = 0;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1984 for (octave_idx_type j = 0; j < d[i].length (); j++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1985 s += d[i](j);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1986
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1987 octave_idx_type r = i < dv.length () ? dv(i) : 1;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1988
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1989 if (s != r)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1990 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1991 error ("mat2cell: mismatch on %d-th dimension (%d != %d)",
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1992 i+1, r, s);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1993 return true;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1994 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1995 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1996
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1997 return false;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1998 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
1999
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2000 template<class container>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
2001 static void
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2002 prepare_idx (container *idx, int idim, int nd,
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2003 const Array<octave_idx_type>* d)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2004 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2005 octave_idx_type nidx = idim < nd ? d[idim].numel () : 1;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2006 if (nidx == 1)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2007 idx[0] = idx_vector::colon;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2008 else
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2009 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2010 octave_idx_type l = 0;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2011 for (octave_idx_type i = 0; i < nidx; i++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2012 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2013 octave_idx_type u = l + d[idim](i);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2014 idx[i] = idx_vector (l, u);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2015 l = u;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2016 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2017 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2018 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2019
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2020 // 2D specialization, works for Array, Sparse and octave_map.
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2021 // Uses 1D or 2D indexing.
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2022
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2023 template <class Array2D>
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2024 static Cell
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2025 do_mat2cell_2d (const Array2D& a, const Array<octave_idx_type> *d, int nd)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2026 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2027 NoAlias<Cell> retval;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2028 assert (nd == 1 || nd == 2);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2029 assert (a.ndims () == 2);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2030
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2031 if (mat2cell_mismatch (a.dims (), d, nd))
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2032 return retval;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2033
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2034 octave_idx_type nridx = d[0].length ();
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2035 octave_idx_type ncidx = nd == 1 ? 1 : d[1].length ();
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2036 retval.clear (nridx, ncidx);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2037
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2038 int ivec = -1;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2039 if (a.rows () > 1 && a.cols () == 1 && ncidx == 1)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2040 ivec = 0;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2041 else if (a.rows () == 1 && nridx == 1 && nd == 2)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2042 ivec = 1;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2043
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2044 if (ivec >= 0)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2045 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2046 // Vector split. Use 1D indexing.
18099
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17893
diff changeset
2047 octave_idx_type l = 0;
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17893
diff changeset
2048 octave_idx_type nidx = (ivec == 0 ? nridx : ncidx);
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2049 for (octave_idx_type i = 0; i < nidx; i++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2050 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2051 octave_idx_type u = l + d[ivec](i);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2052 retval(i) = a.index (idx_vector (l, u));
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2053 l = u;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2054 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2055 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2056 else
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2057 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2058 // General 2D case. Use 2D indexing.
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2059 OCTAVE_LOCAL_BUFFER (idx_vector, ridx, nridx);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2060 prepare_idx (ridx, 0, nd, d);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2061
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2062 OCTAVE_LOCAL_BUFFER (idx_vector, cidx, ncidx);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2063 prepare_idx (cidx, 1, nd, d);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2064
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2065 for (octave_idx_type j = 0; j < ncidx; j++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2066 for (octave_idx_type i = 0; i < nridx; i++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2067 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2068 octave_quit ();
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2069
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2070 retval(i,j) = a.index (ridx[i], cidx[j]);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2071 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2072 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2073
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2074 return retval;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2075 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2076
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2077 // Nd case. Works for Arrays and octave_map.
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2078 // Uses Nd indexing.
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2079
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2080 template <class ArrayND>
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2081 Cell
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2082 do_mat2cell_nd (const ArrayND& a, const Array<octave_idx_type> *d, int nd)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2083 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2084 NoAlias<Cell> retval;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2085 assert (nd >= 1);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2086
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2087 if (mat2cell_mismatch (a.dims (), d, nd))
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2088 return retval;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2089
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2090 dim_vector rdv = dim_vector::alloc (nd);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2091 OCTAVE_LOCAL_BUFFER (octave_idx_type, nidx, nd);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2092 octave_idx_type idxtot = 0;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2093 for (int i = 0; i < nd; i++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2094 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2095 rdv(i) = nidx[i] = d[i].length ();
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2096 idxtot += nidx[i];
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2097 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2098
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2099 retval.clear (rdv);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2100
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2101 OCTAVE_LOCAL_BUFFER (idx_vector, xidx, idxtot);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2102 OCTAVE_LOCAL_BUFFER (idx_vector *, idx, nd);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2103
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2104 idxtot = 0;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2105 for (int i = 0; i < nd; i++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2106 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2107 idx[i] = xidx + idxtot;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2108 prepare_idx (idx[i], i, nd, d);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2109 idxtot += nidx[i];
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2110 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2111
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2112 OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, ridx, nd, 0);
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
2113 NoAlias< Array<idx_vector> > ra_idx
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
2114 (dim_vector (1, std::max (nd, a.ndims ())), idx_vector::colon);
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2115
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2116 for (octave_idx_type j = 0; j < retval.numel (); j++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2117 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2118 octave_quit ();
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2119
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2120 for (int i = 0; i < nd; i++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2121 ra_idx(i) = idx[i][ridx[i]];
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2122
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2123 retval(j) = a.index (ra_idx);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2124
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2125 rdv.increment_index (ridx);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2126 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2127
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2128 return retval;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2129 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2130
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2131 // Dispatcher.
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2132 template <class ArrayND>
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2133 Cell
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2134 do_mat2cell (const ArrayND& a, const Array<octave_idx_type> *d, int nd)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2135 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2136 if (a.ndims () == 2 && nd <= 2)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2137 return do_mat2cell_2d (a, d, nd);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2138 else
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2139 return do_mat2cell_nd (a, d, nd);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2140 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2141
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2142 // General case. Works for any class supporting do_index_op.
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2143 // Uses Nd indexing.
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2144
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2145 Cell
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2146 do_mat2cell (octave_value& a, const Array<octave_idx_type> *d, int nd)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2147 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2148 NoAlias<Cell> retval;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2149 assert (nd >= 1);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2150
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2151 if (mat2cell_mismatch (a.dims (), d, nd))
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2152 return retval;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2153
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2154 dim_vector rdv = dim_vector::alloc (nd);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2155 OCTAVE_LOCAL_BUFFER (octave_idx_type, nidx, nd);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2156 octave_idx_type idxtot = 0;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2157 for (int i = 0; i < nd; i++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2158 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2159 rdv(i) = nidx[i] = d[i].length ();
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2160 idxtot += nidx[i];
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2161 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2162
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2163 retval.clear (rdv);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2164
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2165 OCTAVE_LOCAL_BUFFER (octave_value, xidx, idxtot);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2166 OCTAVE_LOCAL_BUFFER (octave_value *, idx, nd);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2167
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2168 idxtot = 0;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2169 for (int i = 0; i < nd; i++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2170 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2171 idx[i] = xidx + idxtot;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2172 prepare_idx (idx[i], i, nd, d);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2173 idxtot += nidx[i];
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2174 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2175
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2176 OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, ridx, nd, 0);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
2177 octave_value_list ra_idx (std::max (nd, a.ndims ()),
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2178 octave_value::magic_colon_t);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2179
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2180 for (octave_idx_type j = 0; j < retval.numel (); j++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2181 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2182 octave_quit ();
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2183
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2184 for (int i = 0; i < nd; i++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2185 ra_idx(i) = idx[i][ridx[i]];
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2186
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2187 retval(j) = a.do_index_op (ra_idx);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2188
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2189 if (error_state)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2190 break;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2191
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2192 rdv.increment_index (ridx);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2193 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2194
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2195 return retval;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2196 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2197
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
2198 DEFUN (mat2cell, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2199 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
2200 @deftypefn {Built-in Function} {@var{C} =} mat2cell (@var{A}, @var{m}, @var{n})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
2201 @deftypefnx {Built-in Function} {@var{C} =} mat2cell (@var{A}, @var{d1}, @var{d2}, @dots{})\n\
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
2202 @deftypefnx {Built-in Function} {@var{C} =} mat2cell (@var{A}, @var{r})\n\
20207
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
2203 Convert the matrix @var{A} to a cell array.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
2204 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
2205 If @var{A} is 2-D, then it is required that\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
2206 @code{sum (@var{m}) == size (@var{A}, 1)} and\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
2207 @code{sum (@var{n}) == size (@var{A}, 2)}. Similarly, if @var{A} is\n\
20207
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
2208 multi-dimensional and the number of dimensional arguments is equal to the\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
2209 dimensions of @var{A}, then it is required that\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
2210 @code{sum (@var{di}) == size (@var{A}, i)}.\n\
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2211 \n\
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2212 Given a single dimensional argument @var{r}, the other dimensional\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
2213 arguments are assumed to equal @code{size (@var{A},@var{i})}.\n\
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2214 \n\
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2215 An example of the use of mat2cell is\n\
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2216 \n\
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2217 @example\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2218 mat2cell (reshape (1:16,4,4), [3,1], [3,1])\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2219 @result{}\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2220 @{\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2221 [1,1] =\n\
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2222 \n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2223 1 5 9\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2224 2 6 10\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2225 3 7 11\n\
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2226 \n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2227 [2,1] =\n\
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2228 \n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2229 4 8 12\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2230 \n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2231 [1,2] =\n\
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2232 \n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2233 13\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2234 14\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2235 15\n\
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2236 \n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2237 [2,2] = 16\n\
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2238 @}\n\
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2239 @end example\n\
5829
93785a1b0f97 [project @ 2006-05-23 18:34:10 by jwe]
jwe
parents: 5823
diff changeset
2240 @seealso{num2cell, cell2mat}\n\
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2241 @end deftypefn")
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2242 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
2243 int nargin = args.length ();
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2244 octave_value retval;
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2245
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2246 if (nargin < 2)
7038
4482ba9814b7 [project @ 2007-10-19 16:05:48 by jwe]
jwe
parents: 7017
diff changeset
2247 print_usage ();
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2248 else
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2249 {
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2250 // Prepare indices.
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2251 OCTAVE_LOCAL_BUFFER (Array<octave_idx_type>, d, nargin-1);
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2252
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2253 for (int i = 1; i < nargin; i++)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2254 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2255 d[i-1] = args(i).octave_idx_type_vector_value (true);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2256 if (error_state)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2257 return retval;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2258 }
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2259
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2260 octave_value a = args(0);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2261 bool sparse = a.is_sparse_type ();
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2262 if (sparse && nargin > 3)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2263 {
17199
9deb214ae9d5 Use 2-D, not 2D, in error messages.
Rik <rik@octave.org>
parents: 17170
diff changeset
2264 error ("mat2cell: sparse arguments only support 2-D indexing");
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2265 return retval;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2266 }
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2267
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2268 switch (a.builtin_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10125
diff changeset
2269 {
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2270 case btyp_double:
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2271 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2272 if (sparse)
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2273 retval = do_mat2cell_2d (a.sparse_matrix_value (), d, nargin-1);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2274 else
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2275 retval = do_mat2cell (a.array_value (), d, nargin - 1);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2276 break;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2277 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2278 case btyp_complex:
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2279 {
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2280 if (sparse)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2281 retval = do_mat2cell_2d (a.sparse_complex_matrix_value (), d,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2282 nargin-1);
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2283 else
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2284 retval = do_mat2cell (a.complex_array_value (), d, nargin - 1);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2285 break;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2286 }
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2287 #define BTYP_BRANCH(X,Y) \
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2288 case btyp_ ## X: \
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2289 retval = do_mat2cell (a.Y ## _value (), d, nargin - 1); \
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2290 break
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2291
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2292 BTYP_BRANCH (float, float_array);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2293 BTYP_BRANCH (float_complex, float_complex_array);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2294 BTYP_BRANCH (bool, bool_array);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2295 BTYP_BRANCH (char, char_array);
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2296
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2297 BTYP_BRANCH (int8, int8_array);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2298 BTYP_BRANCH (int16, int16_array);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2299 BTYP_BRANCH (int32, int32_array);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2300 BTYP_BRANCH (int64, int64_array);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2301 BTYP_BRANCH (uint8, uint8_array);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2302 BTYP_BRANCH (uint16, uint16_array);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2303 BTYP_BRANCH (uint32, uint32_array);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2304 BTYP_BRANCH (uint64, uint64_array);
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2305
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2306 BTYP_BRANCH (cell, cell);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2307 BTYP_BRANCH (struct, map);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2308 #undef BTYP_BRANCH
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2309
10786
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2310 case btyp_func_handle:
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2311 gripe_wrong_type_arg ("mat2cell", a);
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2312 break;
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2313 default:
146a97c3bc97 some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents: 10756
diff changeset
2314 retval = do_mat2cell (a, d, nargin-1);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 10125
diff changeset
2315 }
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2316 }
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2317
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2318 return retval;
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2319 }
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2320
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2321 /*
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
2322 %!test
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
2323 %! x = reshape (1:20, 5, 4);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
2324 %! c = mat2cell (x, [3,2], [3,1]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
2325 %! assert (c, {[1,6,11;2,7,12;3,8,13],[16;17;18];[4,9,14;5,10,15],[19;20]});
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2326
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2327 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
2328 %! x = "abcdefghij";
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
2329 %! c = mat2cell (x, 1, [0,4,2,0,4,0]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
2330 %! empty1by0str = resize ("", 1, 0);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14366
diff changeset
2331 %! assert (c, {empty1by0str,"abcd","ef",empty1by0str,"ghij",empty1by0str});
5784
70f7659d0fb9 [project @ 2006-05-03 05:55:56 by dbateman]
dbateman
parents: 5642
diff changeset
2332 */
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2333
9740
78ac37d73557 fix cellslices to handle empty ranges with non-positive bounds
Jaroslav Hajek <highegg@gmail.com>
parents: 9731
diff changeset
2334 // FIXME: it would be nice to allow ranges being handled without a conversion.
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2335 template <class NDA>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
2336 static Cell
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
2337 do_cellslices_nda (const NDA& array,
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
2338 const Array<octave_idx_type>& lb,
10125
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2339 const Array<octave_idx_type>& ub,
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2340 int dim = -1)
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2341 {
9740
78ac37d73557 fix cellslices to handle empty ranges with non-positive bounds
Jaroslav Hajek <highegg@gmail.com>
parents: 9731
diff changeset
2342 octave_idx_type n = lb.length ();
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2343 Cell retval (1, n);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
2344 if (array.is_vector () && (dim == -1
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
2345 || (dim == 0 && array.columns () == 1)
10125
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2346 || (dim == 1 && array.rows () == 1)))
9057
8b263623d0f3 have cellslices index the last dim of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9042
diff changeset
2347 {
8b263623d0f3 have cellslices index the last dim of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9042
diff changeset
2348 for (octave_idx_type i = 0; i < n && ! error_state; i++)
9740
78ac37d73557 fix cellslices to handle empty ranges with non-positive bounds
Jaroslav Hajek <highegg@gmail.com>
parents: 9731
diff changeset
2349 retval(i) = array.index (idx_vector (lb(i) - 1, ub(i)));
9057
8b263623d0f3 have cellslices index the last dim of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9042
diff changeset
2350 }
8b263623d0f3 have cellslices index the last dim of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9042
diff changeset
2351 else
8b263623d0f3 have cellslices index the last dim of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9042
diff changeset
2352 {
10125
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2353 const dim_vector dv = array.dims ();
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2354 int ndims = dv.length ();
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2355 if (dim < 0)
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2356 dim = dv.first_non_singleton ();
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2357 ndims = std::max (ndims, dim + 1);
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2358
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
2359 Array<idx_vector> idx (dim_vector (ndims, 1), idx_vector::colon);
10125
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2360
9057
8b263623d0f3 have cellslices index the last dim of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9042
diff changeset
2361 for (octave_idx_type i = 0; i < n && ! error_state; i++)
8b263623d0f3 have cellslices index the last dim of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9042
diff changeset
2362 {
10125
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2363 idx(dim) = idx_vector (lb(i) - 1, ub(i));
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2364 retval(i) = array.index (idx);
9057
8b263623d0f3 have cellslices index the last dim of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9042
diff changeset
2365 }
8b263623d0f3 have cellslices index the last dim of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9042
diff changeset
2366 }
8b263623d0f3 have cellslices index the last dim of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents: 9042
diff changeset
2367
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2368 return retval;
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2369 }
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2370
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
2371 DEFUN (cellslices, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2372 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
2373 @deftypefn {Built-in Function} {@var{sl} =} cellslices (@var{x}, @var{lb}, @var{ub}, @var{dim})\n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
2374 Given an array @var{x}, this function produces a cell array of slices from\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
2375 the array determined by the index vectors @var{lb}, @var{ub}, for lower and\n\
20207
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
2376 upper bounds, respectively.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
2377 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
2378 In other words, it is equivalent to the following code:\n\
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2379 \n\
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2380 @example\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9057
diff changeset
2381 @group\n\
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2382 n = length (lb);\n\
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2383 sl = cell (1, n);\n\
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2384 for i = 1:length (lb)\n\
10125
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2385 sl@{i@} = x(:,@dots{},lb(i):ub(i),@dots{},:);\n\
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2386 endfor\n\
9064
7c02ec148a3c Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents: 9057
diff changeset
2387 @end group\n\
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2388 @end example\n\
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2389 \n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
2390 The position of the index is determined by @var{dim}. If not specified,\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
2391 slicing is done along the first non-singleton dimension.\n\
13928
2892fd834446 doc: Update seealso references for cellslices and cellindexmat
Rik <octave@nomad.inbox5.com>
parents: 13695
diff changeset
2392 @seealso{cell2mat, cellindexmat, cellfun}\n\
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2393 @end deftypefn")
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2394 {
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2395 octave_value retval;
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2396 int nargin = args.length ();
10125
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2397 if (nargin == 3 || nargin == 4)
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2398 {
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2399 octave_value x = args(0);
9740
78ac37d73557 fix cellslices to handle empty ranges with non-positive bounds
Jaroslav Hajek <highegg@gmail.com>
parents: 9731
diff changeset
2400 Array<octave_idx_type> lb = args(1).octave_idx_type_vector_value ();
78ac37d73557 fix cellslices to handle empty ranges with non-positive bounds
Jaroslav Hajek <highegg@gmail.com>
parents: 9731
diff changeset
2401 Array<octave_idx_type> ub = args(2).octave_idx_type_vector_value ();
10125
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2402 int dim = -1;
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2403 if (nargin == 4)
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2404 {
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2405 dim = args(3).int_value () - 1;
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2406 if (dim < 0)
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
2407 error ("cellslices: DIM must be a valid dimension");
10125
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2408 }
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2409
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2410 if (! error_state)
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2411 {
9740
78ac37d73557 fix cellslices to handle empty ranges with non-positive bounds
Jaroslav Hajek <highegg@gmail.com>
parents: 9731
diff changeset
2412 if (lb.length () != ub.length ())
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
2413 error ("cellslices: the lengths of LB and UB must match");
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2414 else
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2415 {
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2416 Cell retcell;
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2417 if (! x.is_sparse_type () && x.is_matrix_type ())
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2418 {
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2419 // specialize for some dense arrays.
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2420 if (x.is_bool_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2421 retcell = do_cellslices_nda (x.bool_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2422 lb, ub, dim);
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2423 else if (x.is_char_matrix ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2424 retcell = do_cellslices_nda (x.char_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2425 lb, ub, dim);
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
2426 else if (x.is_integer_type ())
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
2427 {
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
2428 if (x.is_int8_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2429 retcell = do_cellslices_nda (x.int8_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2430 lb, ub, dim);
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
2431 else if (x.is_int16_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2432 retcell = do_cellslices_nda (x.int16_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2433 lb, ub, dim);
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
2434 else if (x.is_int32_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2435 retcell = do_cellslices_nda (x.int32_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2436 lb, ub, dim);
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
2437 else if (x.is_int64_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2438 retcell = do_cellslices_nda (x.int64_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2439 lb, ub, dim);
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
2440 else if (x.is_uint8_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2441 retcell = do_cellslices_nda (x.uint8_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2442 lb, ub, dim);
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
2443 else if (x.is_uint16_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2444 retcell = do_cellslices_nda (x.uint16_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2445 lb, ub, dim);
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
2446 else if (x.is_uint32_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2447 retcell = do_cellslices_nda (x.uint32_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2448 lb, ub, dim);
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
2449 else if (x.is_uint64_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2450 retcell = do_cellslices_nda (x.uint64_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2451 lb, ub, dim);
9678
c929f09457b7 rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents: 9622
diff changeset
2452 }
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2453 else if (x.is_complex_type ())
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2454 {
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2455 if (x.is_single_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2456 retcell = do_cellslices_nda (x.float_complex_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2457 lb, ub, dim);
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2458 else
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2459 retcell = do_cellslices_nda (x.complex_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2460 lb, ub, dim);
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2461 }
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2462 else
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2463 {
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2464 if (x.is_single_type ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2465 retcell = do_cellslices_nda (x.float_array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2466 lb, ub, dim);
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2467 else
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2468 retcell = do_cellslices_nda (x.array_value (),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2469 lb, ub, dim);
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2470 }
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2471 }
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2472 else
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2473 {
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2474 // generic code.
9740
78ac37d73557 fix cellslices to handle empty ranges with non-positive bounds
Jaroslav Hajek <highegg@gmail.com>
parents: 9731
diff changeset
2475 octave_idx_type n = lb.length ();
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2476 retcell = Cell (1, n);
10125
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2477 const dim_vector dv = x.dims ();
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2478 int ndims = dv.length ();
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2479 if (dim < 0)
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2480 dim = dv.first_non_singleton ();
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2481 ndims = std::max (ndims, dim + 1);
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2482 octave_value_list idx (ndims, octave_value::magic_colon_t);
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2483 for (octave_idx_type i = 0; i < n && ! error_state; i++)
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2484 {
10125
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2485 idx(dim) = Range (lb(i), ub(i));
8985
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2486 retcell(i) = x.do_index_op (idx);
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2487 }
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2488 }
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2489 if (! error_state)
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2490 retval = retcell;
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2491 }
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2492 }
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2493 }
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2494 else
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2495 print_usage ();
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2496
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2497 return retval;
193804a4f82f add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2498 }
10122
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
2499
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
2500 /*
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
2501 %!test
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
2502 %! m = [1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12];
10125
82ed1b4c3011 improve cellslices
Jaroslav Hajek <highegg@gmail.com>
parents: 10122
diff changeset
2503 %! c = cellslices (m, [1, 2], [2, 3], 2);
10122
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
2504 %! assert (c, {[1, 2; 5, 6; 9, 10], [2, 3; 6, 7; 10, 11]});
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10075
diff changeset
2505 */
10963
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2506
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
2507 DEFUN (cellindexmat, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2508 "-*- texinfo -*-\n\
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14854
diff changeset
2509 @deftypefn {Built-in Function} {@var{y} =} cellindexmat (@var{x}, @var{varargin})\n\
20207
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
2510 Perform indexing of matrices in a cell array.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19895
diff changeset
2511 \n\
10963
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2512 Given a cell array of matrices @var{x}, this function computes\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
2513 \n\
10963
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2514 @example\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
2515 @group\n\
14360
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2516 Y = cell (size (X));\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2517 for i = 1:numel (X)\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2518 Y@{i@} = X@{i@}(varargin@{:@});\n\
97883071e8e4 doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
2519 endfor\n\
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
2520 @end group\n\
10963
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2521 @end example\n\
13928
2892fd834446 doc: Update seealso references for cellslices and cellindexmat
Rik <octave@nomad.inbox5.com>
parents: 13695
diff changeset
2522 @seealso{cellslices, cellfun}\n\
10963
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2523 @end deftypefn")
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2524 {
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2525 octave_value retval;
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2526 if (args.length () >= 1)
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2527 {
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2528 if (args(0).is_cell ())
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2529 {
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2530 const Cell x = args(0).cell_value ();
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2531 NoAlias<Cell> y(x.dims ());
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2532 octave_idx_type nel = x.numel ();
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2533 octave_value_list idx = args.slice (1, args.length () - 1);
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2534
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2535 for (octave_idx_type i = 0; i < nel; i++)
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2536 {
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2537 octave_quit ();
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2538 octave_value tmp = x(i);
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2539 y(i) = tmp.do_index_op (idx);
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2540 if (error_state)
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2541 break;
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2542 }
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2543
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2544 retval = y;
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2545 }
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2546 else
11553
01f703952eff Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
2547 error ("cellindexmat: X must be a cell");
10963
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2548 }
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2549 else
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2550 print_usage ();
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2551
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2552 return retval;
0d7624852beb implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
2553 }