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