Mercurial > octave
annotate libinterp/corefcn/cellfun.cc @ 30723:08b08b7f05b2
Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Define 4 new inline functions in error.h (panic_if, panic_unless, error_if,
error_unless) that call either assert() or Octave's own error() function.
Replace calls to assert() in code that maintains state and for which no
recovery on detection of a problem is possible with calls to panic_XXX.
Replace calls to assert() in interpreter code which could simply return to the
Octave prompt when a problem is detected with calls to error_XXX.
* error.h (panic_if, panic_unless): New functions which eventually call
can call assert(). panic_if (COND) calls assert if COND is true.
panic_unless (COND) calls assert if COND is false.
* error.h (error_if, error_unless): New functions which eventually call
can call Octave's error() function. error_if (COND) calls assert if COND is
true. error_unless (COND) calls assert if COND is false.
* cellfun.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, dot.cc, error.cc,
graphics.cc, kron.cc, mex.cc, oct-map.cc, oct-stream.cc, pr-output.cc,
schur.cc, stack-frame.cc, typecast.cc, variables.cc, ov-base.cc, ov-class.cc,
ov-fcn-handle.cc, ov-struct.cc, ov-usr-fcn.cc, ov.h, ovl.cc, ops.h,
profiler.cc, pt-classdef.cc, pt-eval.cc, pt-idx.cc, pt-pr-code.cc,
pt-tm-const.cc, token.cc: Replace direct calls to C library assert() with
Octave specialty functions.
author | Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org> |
---|---|
date | Mon, 07 Feb 2022 21:47:53 -0800 |
parents | 83f9f8bda883 |
children | 32d2b6604a9f |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30390
diff
changeset
|
3 // Copyright (C) 2005-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
5205 | 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 |
35 #include "lo-mappers.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8373
diff
changeset
|
36 #include "oct-locbuf.h" |
22280
26109cce022e
New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents:
22197
diff
changeset
|
37 #include "oct-string.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" |
26864
041caa61ed34
use get_function_handle instead of extract_function
John W. Eaton <jwe@octave.org>
parents:
26847
diff
changeset
|
42 #include "interpreter-private.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
43 #include "interpreter.h" |
5205 | 44 #include "parse.h" |
45 #include "variables.h" | |
5988 | 46 #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
|
47 #include "errwarn.h" |
9728
70925b11ba46
again allow the obsolete syntax for cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
9684
diff
changeset
|
48 #include "utils.h" |
5205 | 49 |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
50 #include "ov-bool.h" |
13329
80f7564a3849
handle class objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13234
diff
changeset
|
51 #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
|
52 #include "ov-colon.h" |
10044
2d7a8c227713
rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
10043
diff
changeset
|
53 #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
|
54 #include "ov-float.h" |
10044
2d7a8c227713
rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
10043
diff
changeset
|
55 #include "ov-flt-complex.h" |
2d7a8c227713
rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
10043
diff
changeset
|
56 #include "ov-int16.h" |
2d7a8c227713
rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
10043
diff
changeset
|
57 #include "ov-int32.h" |
2d7a8c227713
rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
10043
diff
changeset
|
58 #include "ov-int64.h" |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
59 #include "ov-int8.h" |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
60 #include "ov-scalar.h" |
10044
2d7a8c227713
rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
10043
diff
changeset
|
61 #include "ov-uint16.h" |
2d7a8c227713
rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
10043
diff
changeset
|
62 #include "ov-uint32.h" |
2d7a8c227713
rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
10043
diff
changeset
|
63 #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
|
64 #include "ov-uint8.h" |
10044
2d7a8c227713
rewrite uniformoutput optimization in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
10043
diff
changeset
|
65 |
12952
5a5cb2a4b71d
cellfun: Fix a regression for function handles to overloaded functions
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12949
diff
changeset
|
66 #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
|
67 |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
68 OCTAVE_NAMESPACE_BEGIN |
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
69 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
70 static octave_value_list |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
71 get_output_list (error_system& es, |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
26964
diff
changeset
|
72 octave_idx_type count, octave_idx_type nargout, |
10181
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
73 const octave_value_list& inputlist, |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
74 octave_value& func, |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
75 octave_value& error_handler) |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
76 { |
16000
3f93cd251bdb
fix ErrorHandler in cellfun (bug #38256)
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
77 octave_value_list tmp; |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20443
diff
changeset
|
78 |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20443
diff
changeset
|
79 bool execution_error = false; |
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20443
diff
changeset
|
80 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
81 try |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
82 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
83 tmp = feval (func, inputlist, nargout); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
84 } |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
85 catch (const execution_exception& ee) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
86 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
87 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
|
88 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
89 interpreter& interp |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
90 = __get_interpreter__ ("get_output_list"); |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
91 |
29028
9a84aa8c4552
save last error info when cellfun error handler is defined (bug #58411)
John W. Eaton <jwe@octave.org>
parents:
28819
diff
changeset
|
92 es.save_exception (ee); |
27474
3fec8e9fa2aa
make recover_from_exception a member function
John W. Eaton <jwe@octave.org>
parents:
27471
diff
changeset
|
93 interp.recover_from_exception (); |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
94 |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
95 execution_error = true; |
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
96 } |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20443
diff
changeset
|
97 else |
29028
9a84aa8c4552
save last error info when cellfun error handler is defined (bug #58411)
John W. Eaton <jwe@octave.org>
parents:
28819
diff
changeset
|
98 throw; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
99 } |
10181
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
100 |
20535
b70cc4bd8109
begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents:
20443
diff
changeset
|
101 if (execution_error) |
10181
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
102 { |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
103 if (error_handler.is_defined ()) |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
104 { |
11046
14993c9e857e
amd.cc, cellfun.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10964
diff
changeset
|
105 octave_scalar_map msg; |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
26964
diff
changeset
|
106 msg.assign ("identifier", es.last_error_id ()); |
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
26964
diff
changeset
|
107 msg.assign ("message", es.last_error_message ()); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
108 msg.assign ("index", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
109 static_cast<double> (count |
25688
b2917b7858ba
maint: Use Octave convention for spacing of C++ cast statements.
Rik <rik@octave.org>
parents:
25646
diff
changeset
|
110 + static_cast<octave_idx_type> (1))); |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
111 |
10181
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
112 octave_value_list errlist = inputlist; |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
113 errlist.prepend (msg); |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
114 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
115 tmp = feval (error_handler, errlist, nargout); |
10181
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 else |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
118 tmp.clear (); |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
119 } |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
120 |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
121 return tmp; |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
122 } |
a668fbd32e34
improve cellfun & avoid undefined values from builtins
Jaroslav Hajek <highegg@gmail.com>
parents:
10155
diff
changeset
|
123 |
17892
5401637c3fa7
Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17787
diff
changeset
|
124 // 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
|
125 // 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
|
126 // 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
|
127 template <typename BNDA, typename NDA> |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
128 static octave_value_list |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
129 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
|
130 { |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
131 octave_value_list retval; |
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 std::string name = args(0).string_value (); |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
134 |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
135 const Cell f_args = args(1).cell_value (); |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
136 |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
137 octave_idx_type k = f_args.numel (); |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
138 |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
139 if (name == "isempty") |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
140 { |
17892
5401637c3fa7
Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17787
diff
changeset
|
141 BNDA result (f_args.dims ()); |
13231
20ed9548070f
maint: style fixes for cellfun
John W. Eaton <jwe@octave.org>
parents:
13230
diff
changeset
|
142 for (octave_idx_type count = 0; count < k; count++) |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
143 result(count) = f_args.elem (count).isempty (); |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
144 retval(0) = result; |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
145 } |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
146 else if (name == "islogical") |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
147 { |
17892
5401637c3fa7
Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17787
diff
changeset
|
148 BNDA result (f_args.dims ()); |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
149 for (octave_idx_type count= 0; count < k; count++) |
23579
c20a0fa91c0c
maint: Deprecate is_bool_type and replace with islogical.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
150 result(count) = f_args.elem (count).islogical (); |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
151 retval(0) = result; |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
152 } |
17002
dd783018709b
Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents:
16047
diff
changeset
|
153 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
|
154 { |
17892
5401637c3fa7
Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17787
diff
changeset
|
155 BNDA result (f_args.dims ()); |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
156 for (octave_idx_type count= 0; count < k; count++) |
23586
f6c5db0a02e7
maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents:
23584
diff
changeset
|
157 result(count) = f_args.elem (count).isnumeric (); |
17002
dd783018709b
Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents:
16047
diff
changeset
|
158 retval(0) = result; |
dd783018709b
Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents:
16047
diff
changeset
|
159 } |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
160 else if (name == "isreal") |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
161 { |
17892
5401637c3fa7
Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17787
diff
changeset
|
162 BNDA result (f_args.dims ()); |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
163 for (octave_idx_type count= 0; count < k; count++) |
23582
0cc2011d800e
maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents:
23581
diff
changeset
|
164 result(count) = f_args.elem (count).isreal (); |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
165 retval(0) = result; |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
166 } |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
167 else if (name == "length") |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
168 { |
17892
5401637c3fa7
Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17787
diff
changeset
|
169 NDA result (f_args.dims ()); |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
170 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
|
171 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
|
172 retval(0) = result; |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
173 } |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
174 else if (name == "ndims") |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
175 { |
17892
5401637c3fa7
Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17787
diff
changeset
|
176 NDA result (f_args.dims ()); |
13231
20ed9548070f
maint: style fixes for cellfun
John W. Eaton <jwe@octave.org>
parents:
13230
diff
changeset
|
177 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
|
178 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
|
179 retval(0) = result; |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
180 } |
17004
19b7c7412a63
cell2mat.m: Re-vamp input validation for 30% speedup
Rik <rik@octave.org>
parents:
17002
diff
changeset
|
181 else if (name == "numel" || name == "prodofsize") |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
182 { |
17892
5401637c3fa7
Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17787
diff
changeset
|
183 NDA result (f_args.dims ()); |
13231
20ed9548070f
maint: style fixes for cellfun
John W. Eaton <jwe@octave.org>
parents:
13230
diff
changeset
|
184 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
|
185 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
|
186 retval(0) = result; |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
187 } |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
188 else if (name == "size") |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
189 { |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
190 if (nargin != 3) |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
191 error (R"(cellfun: not enough arguments for "size")"); |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
192 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
193 int d = args(2).nint_value () - 1; |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
194 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
195 if (d < 0) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
196 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
|
197 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
198 NDA result (f_args.dims ()); |
20560
56fee8f84fe7
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
199 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
200 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
|
201 { |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
202 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
|
203 if (d < dv.ndims ()) |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
204 result(count) = static_cast<double> (dv(d)); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
205 else |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
206 result(count) = 1.0; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
207 } |
20560
56fee8f84fe7
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
208 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
209 retval(0) = result; |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
210 } |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
211 else if (name == "isclass") |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
212 { |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
213 if (nargin != 3) |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23693
diff
changeset
|
214 error (R"(cellfun: not enough arguments for "isclass")"); |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
215 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
216 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
|
217 BNDA result (f_args.dims ()); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
218 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
|
219 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
|
220 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
221 retval(0) = result; |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
222 } |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
223 |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
224 return retval; |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
225 } |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
226 |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
227 static void |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
228 get_mapper_fun_options (symbol_table& symtab, |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
229 const octave_value_list& args, |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
230 int& nargin, bool& uniform_output, |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
231 octave_value& error_handler) |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
232 { |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
233 while (nargin > 3 && args(nargin-2).is_string ()) |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
234 { |
22280
26109cce022e
New string utility functions to replace caseless_str for liboctave (bug #48726)
Carnë Draug <carandraug@octave.org>
parents:
22197
diff
changeset
|
235 std::string arg = args(nargin-2).string_value (); |
14076
9aff66860e03
accept abbreviated cellfun option names
John W. Eaton <jwe@octave.org>
parents:
13960
diff
changeset
|
236 |
29654
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
237 std::size_t compare_len |
d13d090cb03a
use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
238 = std::max (arg.length (), static_cast<std::size_t> (2)); |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
239 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
240 if (string::strncmpi (arg, "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
|
241 uniform_output = args(nargin-1).bool_value (); |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
242 else if (string::strncmpi (arg, "errorhandler", compare_len)) |
13229
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 if (args(nargin-1).is_function_handle () |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
245 || args(nargin-1).is_inline_function ()) |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
246 { |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
247 error_handler = args(nargin-1); |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
248 } |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
249 else if (args(nargin-1).is_string ()) |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
250 { |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
251 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
|
252 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
253 error_handler = symtab.find_function (err_name); |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
254 |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
255 if (error_handler.is_undefined ()) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
256 error ("cellfun: invalid function NAME: %s", |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
257 err_name.c_str ()); |
13229
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 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
260 error ("cellfun: invalid value for 'ErrorHandler' function"); |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
261 } |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
262 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
263 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
|
264 |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
265 nargin -= 2; |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
266 } |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
267 |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
268 nargin -= 1; |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
269 } |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
270 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
271 DEFMETHOD (cellfun, interp, args, nargout, |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
272 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
273 @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
|
274 @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
|
275 @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
|
276 @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
|
277 @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
|
278 @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
|
279 @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
|
280 @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
|
281 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
282 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
|
283 @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
|
284 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
285 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
|
286 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
|
287 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
288 @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
|
289 @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
|
290 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
|
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 islogical |
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 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
|
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 isnumeric |
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 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
|
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 isreal |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
299 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
|
300 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
301 @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
|
302 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
|
303 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
304 @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
|
305 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
|
306 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
307 @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
|
308 @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
|
309 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
|
310 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
|
311 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
312 @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
|
313 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
|
314 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
315 @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
|
316 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
|
317 @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
|
318 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
319 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
325 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
326 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
327 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
|
328 @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
|
329 @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
|
330 @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
|
331 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
332 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
|
333 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
|
334 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
|
335 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
336 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
337 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
338 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
|
339 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
|
340 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
|
341 endfunction |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
342 [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
|
343 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
344 aa = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
345 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
|
346 bb = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
347 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
|
348 @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
|
349 @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
|
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 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
|
352 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
|
353 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
|
354 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
355 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
|
356 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
|
357 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
|
358 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
|
359 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
360 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
361 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
362 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
|
363 "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
|
364 @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
|
365 @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
|
366 @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
|
367 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
368 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
|
369 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
|
370 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
|
371 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
372 @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 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
|
374 @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
|
375 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
376 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
377 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
|
378 @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
|
379 @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
|
380 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
|
381 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
|
382 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
383 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
384 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
385 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
|
386 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
|
387 @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
|
388 @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
|
389 @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
|
390 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
391 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
|
392 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
|
393 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
|
394 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
|
395 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
|
396 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
|
397 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
398 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
399 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
400 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
|
401 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
|
402 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
|
403 @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
|
404 @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
|
405 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
406 @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
|
407 @end deftypefn */) |
5205 | 408 { |
409 int nargin = args.length (); | |
410 | |
411 if (nargin < 2) | |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
412 print_usage (); |
5205 | 413 |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
414 if (! args(1).iscell ()) |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
415 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
|
416 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
417 octave_value_list retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
418 int nargout1 = (nargout < 1 ? 1 : nargout); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
419 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
420 octave_value func = args(0); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
421 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
422 symbol_table& symtab = interp.get_symbol_table (); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
423 |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
424 if (func.is_string ()) |
5205 | 425 { |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
426 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
|
427 |
20560
56fee8f84fe7
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
428 if (! retval.empty ()) |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
429 return retval; |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
430 |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
431 // 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
|
432 |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
433 std::string name = args(0).string_value (); |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
434 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
435 if (! valid_identifier (name)) |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
436 func = get_function_handle (interp, args(0), "x"); |
5205 | 437 else |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
438 { |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
439 func = symtab.find_function (name); |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
440 |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
441 if (func.is_undefined ()) |
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
442 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
|
443 } |
5205 | 444 } |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
445 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
446 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
|
447 && ! func.is_function ()) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
448 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
|
449 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
450 bool uniform_output = true; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
451 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
|
452 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
453 get_mapper_fun_options (symtab, args, nargin, uniform_output, error_handler); |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
454 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
455 // 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
|
456 // 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
|
457 // 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
|
458 { |
28427
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27957
diff
changeset
|
459 if (func.is_function_handle () || func.is_inline_function ()) |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
460 { |
28819
bd71a227c562
* cellfun.cc: Update comments about overloaded function handles.
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
461 // FIXME: instead of checking for overloaded functions as we did |
bd71a227c562
* cellfun.cc: Update comments about overloaded function handles.
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
462 // previously but is no longer possible, we could check whether |
bd71a227c562
* cellfun.cc: Update comments about overloaded function handles.
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
463 // the types of all the cell array elements are the same, then |
bd71a227c562
* cellfun.cc: Update comments about overloaded function handles.
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
464 // lookup the function for that type just once. |
17892
5401637c3fa7
Make cellfun obey "UniformOutput" for optimised internal functions (bug #40467)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17787
diff
changeset
|
465 |
28819
bd71a227c562
* cellfun.cc: Update comments about overloaded function handles.
John W. Eaton <jwe@octave.org>
parents:
28427
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 (); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
470 octave_value f = symtab.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) |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
482 retval = try_cellfun_internal_ops<boolNDArray, NDArray> (tmp_args, nargin); |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
483 else |
27277
db687716fed6
style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents:
27160
diff
changeset
|
484 retval = 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
|
485 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
486 if (! retval.empty ()) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
487 return retval; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
488 } |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
489 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
490 // 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
|
491 // 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
|
492 func = f; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
493 } |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
494 } |
9465
40de4692c860
auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
9459
diff
changeset
|
495 |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
496 nevermind: |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
497 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
498 // Extract cell arguments. |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
499 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
500 octave_value_list inputlist (nargin, octave_value ()); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
501 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
502 OCTAVE_LOCAL_BUFFER (Cell, inputs, nargin); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
503 OCTAVE_LOCAL_BUFFER (bool, mask, nargin); |
9465
40de4692c860
auto-expanding scalar cells in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
9459
diff
changeset
|
504 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
505 // This is to prevent copy-on-write. |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
506 const Cell *cinputs = inputs; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
507 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
508 octave_idx_type k = 1; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
509 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
510 dim_vector fdims (1, 1); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
511 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
512 // 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
|
513 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
514 for (int j = 0; j < nargin; j++) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
515 { |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
516 if (! args(j+1).iscell ()) |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
517 error ("cellfun: arguments must be cells"); |
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 inputs[j] = args(j+1).cell_value (); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
520 mask[j] = inputs[j].numel () != 1; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
521 if (! mask[j]) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
522 inputlist(j) = cinputs[j](0); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
523 } |
5988 | 524 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
525 for (int j = 0; j < nargin; j++) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
526 { |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
527 if (mask[j]) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
528 { |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
529 fdims = inputs[j].dims (); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
530 k = inputs[j].numel (); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
531 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
|
532 { |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
533 if (mask[i] && inputs[i].dims () != fdims) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
534 error ("cellfun: dimensions mismatch"); |
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 break; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
537 } |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
538 } |
10670
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
539 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
540 error_system& es = interp.get_error_system (); |
5988 | 541 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
542 // Apply functions. |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
543 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
544 if (uniform_output) |
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 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
|
547 idx_list.front ().resize (1); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
548 std::string idx_type = "("; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
549 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
550 OCTAVE_LOCAL_BUFFER (octave_value, retv, nargout1); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
551 |
29045
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
552 int expected_nargout; |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
553 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
|
554 { |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
555 for (int j = 0; j < nargin; j++) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
556 { |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
557 if (mask[j]) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
558 inputlist.xelem (j) = cinputs[j](count); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
559 } |
5988 | 560 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
561 const octave_value_list tmp |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
26964
diff
changeset
|
562 = get_output_list (es, count, nargout, inputlist, func, |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
563 error_handler); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
564 |
29045
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
565 int tmp_numel = tmp.length (); |
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
566 if (count == 0) |
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
567 expected_nargout = tmp_numel; |
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
568 else if (tmp_numel != expected_nargout) |
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
569 error ("cellfun: function returned unexpected number of values"); |
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
570 |
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
571 if (nargout > 0 && tmp_numel < nargout) |
20980
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 |
22777
4a31bd79d7e8
maint: Correct spacing around if and opening parentheses of condition.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
574 if (nargout > 0 |
29045
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
575 || (nargout == 0 && tmp_numel > 0 && tmp(0).is_defined ())) |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
576 { |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
577 int num_to_copy = tmp.length (); |
5988 | 578 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
579 if (num_to_copy > nargout1) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
580 num_to_copy = nargout1; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
581 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
582 if (count == 0) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
583 { |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
584 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
|
585 { |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
586 if (tmp(j).is_defined ()) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
587 { |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
588 octave_value val = tmp(j); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
589 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
590 if (val.numel () != 1) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
591 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
|
592 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
593 retv[j] = val.resize (fdims); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
594 } |
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 else |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
598 { |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
599 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
|
600 { |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
601 if (tmp(j).is_defined ()) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
602 { |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
603 octave_value val = tmp(j); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
604 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
605 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
|
606 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
607 if (val.numel () != 1) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
608 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
|
609 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
610 idx_list.front ()(0) = count + 1.0; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
611 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
|
612 idx_type, idx_list, val); |
10670
654fbde5dceb
make cellfun's fast scalar collection mechanism public
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
613 } |
8994 | 614 } |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
615 } |
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 } |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
618 } |
8994 | 619 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
620 retval.resize (nargout1); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
621 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
622 for (int j = 0; j < nargout1; j++) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
623 { |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
624 if (nargout > 0 && retv[j].is_undefined ()) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
625 retval(j) = NDArray (fdims); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
626 else |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
627 retval(j) = retv[j]; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
628 } |
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 else |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
631 { |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
632 OCTAVE_LOCAL_BUFFER (Cell, results, nargout1); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
633 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
634 for (int j = 0; j < nargout1; j++) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
635 results[j].resize (fdims, Matrix ()); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
636 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
637 bool have_some_output = false; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
638 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
639 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
|
640 { |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
641 for (int j = 0; j < nargin; j++) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
642 { |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
643 if (mask[j]) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
644 inputlist.xelem (j) = cinputs[j](count); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
645 } |
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 const octave_value_list tmp |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
26964
diff
changeset
|
648 = get_output_list (es, count, nargout, inputlist, func, |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
649 error_handler); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
650 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
651 if (nargout > 0 && tmp.length () < nargout) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
652 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
|
653 |
22777
4a31bd79d7e8
maint: Correct spacing around if and opening parentheses of condition.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
654 if (nargout > 0 |
4a31bd79d7e8
maint: Correct spacing around if and opening parentheses of condition.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
655 || (nargout == 0 |
4a31bd79d7e8
maint: Correct spacing around if and opening parentheses of condition.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
656 && tmp.length () > 0 && tmp(0).is_defined ())) |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
657 { |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
658 int num_to_copy = tmp.length (); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
659 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
660 if (num_to_copy > nargout1) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
661 num_to_copy = nargout1; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
662 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
663 if (num_to_copy > 0) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
664 have_some_output = true; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
665 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
666 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
|
667 results[j](count) = tmp(j); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
668 } |
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 if (have_some_output || fdims.any_zero ()) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
672 { |
9988
76cf4aec34e9
allow functions returning no value in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
9740
diff
changeset
|
673 retval.resize (nargout1); |
13229
983720941822
maint: improve readability of cellfun
John W. Eaton <jwe@octave.org>
parents:
12952
diff
changeset
|
674 |
9988
76cf4aec34e9
allow functions returning no value in cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
9740
diff
changeset
|
675 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
|
676 retval(j) = results[j]; |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
677 } |
5205 | 678 } |
679 | |
680 return retval; | |
681 } | |
682 | |
5988 | 683 /* |
684 | |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14076
diff
changeset
|
685 %!function r = __f11 (x) |
13230
c73cc5b67feb
fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents:
13229
diff
changeset
|
686 %! r = x; |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14076
diff
changeset
|
687 %!endfunction |
13230
c73cc5b67feb
fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents:
13229
diff
changeset
|
688 |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14076
diff
changeset
|
689 %!function __f01 (x) |
25762
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
690 %! ## Empty function |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14076
diff
changeset
|
691 %!endfunction |
13230
c73cc5b67feb
fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents:
13229
diff
changeset
|
692 |
29045
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
693 %!function varargout = __f02 (out) |
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
694 %! if (out) |
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
695 %! varargout{1} = out; |
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
696 %! endif |
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
697 %!endfunction |
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
698 |
13230
c73cc5b67feb
fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents:
13229
diff
changeset
|
699 %!test |
25762
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
700 %! __cellfun_test_num_outputs__ = -1; |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
701 %! |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
702 %! function r = __subf11 (x) |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
703 %! __cellfun_test_num_outputs__ = nargout; |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
704 %! r = x; |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
705 %! endfunction |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
706 %! |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
707 %! cellfun ("__subf11", {1}); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
708 %! assert (__cellfun_test_num_outputs__, 0); |
25762
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
709 %! |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
710 %! __cellfun_test_num_outputs__ = -1; |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
711 %! x = cellfun ("__subf11", {1}); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
712 %! 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
|
713 |
c73cc5b67feb
fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents:
13229
diff
changeset
|
714 %!test |
25762
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
715 %! __cellfun_test_num_outputs__ = -1; |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
716 %! function __subf01 (x) |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
717 %! __cellfun_test_num_outputs__ = nargout; |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
718 %! endfunction |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
719 %! cellfun ("__subf01", {1}); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
720 %! 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
|
721 |
21581
6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents:
21580
diff
changeset
|
722 %!error x = cellfun (@__f01, {1, 2}) |
29045
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
723 %!error x = cellfun (@__f01, {1, 2}) |
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
724 |
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
725 %!error x = cellfun (@__f02, {0, 2}, "uniformoutput", false) |
4ec8a36990e8
cellfun and uniformoutput: don't fail if function returns nothing (bug #58411)
Rik <rik@octave.org>
parents:
29028
diff
changeset
|
726 %!error x = cellfun (@__f02, {0, 2}, "uniformoutput", true) |
13230
c73cc5b67feb
fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents:
13229
diff
changeset
|
727 |
c73cc5b67feb
fix nargout handling for functions called by cellfun
John W. Eaton <jwe@octave.org>
parents:
13229
diff
changeset
|
728 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
729 %! 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
|
730 %! 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
|
731 |
11457 | 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,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
|
734 %! 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
|
735 %! assert (b, zeros (2, 0)); |
11457 | 736 |
737 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
738 %! [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
|
739 %! 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
|
740 %! assert (b, cell (2, 0)); |
11457 | 741 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
742 ## 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
|
743 %!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
|
744 %! z = S; |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14076
diff
changeset
|
745 %!endfunction |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
746 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
747 ## First input argument can be a string, an inline function, |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
748 ## a function_handle or an anonymous function |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
749 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
750 %! 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
|
751 %! assert (A, [true, false, true, false]); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
752 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
753 %! 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
|
754 %! assert (A, [true, false, true, false]); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
755 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
756 %! 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
|
757 %! assert (A, [true, false, true, false]); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
758 %!test |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
759 %! 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
|
760 %! assert (A, [true, false, true, false]); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
761 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
762 ## First input argument can be the special string "isreal", |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
763 ## "isempty", "islogical", "isnumeric", "length", "ndims" or "prodofsize" |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
764 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
765 %! 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
|
766 %! 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
|
767 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
768 %! 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
|
769 %! 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
|
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 ("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
|
772 %! 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
|
773 %!test |
17002
dd783018709b
Add special case function "isnumeric" to cellfun.cc (bug #39387).
Olaf Till <i7tiol@t-online.de>
parents:
16047
diff
changeset
|
774 %! 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
|
775 %! 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
|
776 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
777 %! 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
|
778 %! 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
|
779 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
780 %! 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
|
781 %! assert (A, [2; 4]); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
782 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
783 %! A = 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
|
784 %! assert (A, [4, 24]); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
785 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
786 ## Number of input and output arguments may not be limited to one |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
787 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
788 %! 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
|
789 %! assert (A, [6, 7, 8]); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
790 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
791 %! 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
|
792 %! "UniformOutput", false); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
793 %! assert (A, {6, 7, 8}); |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
794 %!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
|
795 %! 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
|
796 %! assert (A, [true, false]); |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
797 %!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
|
798 %! y = true; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
799 %! 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
|
800 %! assert (A, [true, false]); |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
26963
diff
changeset
|
801 %!test # Three output 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
|
802 %! [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
|
803 %! 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
|
804 %! 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
|
805 %! assert (isequal (C, {10, 11; [], 12})); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
806 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
807 ## Input arguments can be of type cell array of logical |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
808 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
809 %! 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
|
810 %! assert (A, [false, true]); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
811 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
812 %! 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
|
813 %! "UniformOutput", true); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
814 %! assert (A, [false; true]); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
815 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
816 %! A = cellfun (@(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
|
817 %! assert (A, {false, true; false, true}); |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
26963
diff
changeset
|
818 %!test # Three output arguments of same type |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
819 %! [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
|
820 %! "UniformOutput", false); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
821 %! 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
|
822 %! 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
|
823 %! assert (isequal (C, {true, []; [], true})); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
824 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
825 %! 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
|
826 %! "ErrorHandler", @__cellfunerror); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
827 %! 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
|
828 %! 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
|
829 %! 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
|
830 %! 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
|
831 %! assert (A.index, 1); |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
832 %!test # Overwriting setting of "UniformOutput" true |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
833 %! 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
|
834 %! "UniformOutput", true, "ErrorHandler", @__cellfunerror); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
835 %! 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
|
836 %! 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
|
837 %! 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
|
838 %! 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
|
839 %! assert (A.index, 1); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
840 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
841 ## Input arguments can be of type cell array of numeric |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
842 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
843 %! 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
|
844 %! assert (A, [false, true]); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
845 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
846 %! 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
|
847 %! "UniformOutput", true); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
848 %! assert (A, [false, true; false, false]); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
849 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
850 %! 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
|
851 %! 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
|
852 %! assert (isequal (A{2}, [4, 5, 6])); |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
26963
diff
changeset
|
853 %!test # Three output 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
|
854 %! [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
|
855 %! 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
|
856 %! 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
|
857 %! assert (isequal (C, {10, 11; [], 12})); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
858 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
859 %! 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
|
860 %! "ErrorHandler", @__cellfunerror); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
861 %! B = isfield (A(1), "message") && isfield (A(1), "index"); |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
862 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
863 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
864 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
865 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
866 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
867 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
868 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
869 %! [false, false]); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
870 %! assert ([A(1).index, A(2).index], [1, 2]); |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
871 %!test # Overwriting setting of "UniformOutput" true |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
872 %! 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
|
873 %! "UniformOutput", true, "ErrorHandler", @__cellfunerror); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
874 %! B = isfield (A(1), "message") && isfield (A(1), "index"); |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
875 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
876 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
877 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
878 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
879 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
880 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
881 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
882 %! [false, false]); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
883 %! 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
|
884 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
885 ## Input arguments can be of type cell arrays of character or strings |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
886 %!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
|
887 %! 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
|
888 %!test |
14501
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>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
|
890 %! assert (A, [false; true]); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
891 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
892 %! 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
|
893 %! assert (A, {"abc", "def"}); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
894 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
895 %! 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
|
896 %! "ErrorHandler", @__cellfunerror); |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
897 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
898 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
899 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
900 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
901 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
902 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
903 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
904 %! [false, false]); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
905 %! assert ([A(1).index, A(2).index], [1, 2]); |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
906 %!test # Overwriting setting of "UniformOutput" true |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
907 %! 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
|
908 %! "UniformOutput", true, "ErrorHandler", @__cellfunerror); |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
909 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
910 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
911 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
912 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
913 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
914 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
915 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
916 %! [false, false]); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
917 %! 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
|
918 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
919 ## Structures cannot be handled by cellfun |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
920 %!error |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
921 %! 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
|
922 %! 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
|
923 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
924 ## Input arguments can be of type cell array of cell arrays |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
925 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
926 %! A = cellfun (@(x,y) x{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
|
927 %! assert (A, [1, 0], 1e-16); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
928 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
929 %! 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
|
930 %! "UniformOutput", true); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
931 %! assert (A, [1; 0], 1e-16); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
932 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
933 %! 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
|
934 %! "UniformOutput", false); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
935 %! assert (A, {true, false}); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
936 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
937 %! 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
|
938 %! "ErrorHandler", @__cellfunerror); |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
939 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
940 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
941 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
942 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
943 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
944 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
945 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
946 %! [false, false]); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
947 %! assert ([A(1).index, A(2).index], [1, 2]); |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
948 %!test # Overwriting setting of "UniformOutput" true |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
949 %! 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
|
950 %! "UniformOutput", true, "ErrorHandler", @__cellfunerror); |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
951 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
952 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
953 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
954 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
955 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
956 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
957 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
958 %! [false, false]); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
959 %! 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
|
960 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
961 ## Input arguments can be of type cell array of structure arrays |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
962 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
963 %! 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
|
964 %! 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
|
965 %! assert (A, true); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
966 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
967 %! 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
|
968 %! 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
|
969 %! "UniformOutput", true); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
970 %! assert (A, true); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
971 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
972 %! 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
|
973 %! 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
|
974 %! "UniformOutput", false); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
975 %! assert (A, {true}); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
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 = 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
|
978 %! 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
|
979 %! "ErrorHandler", @__cellfunerror); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
980 %! 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
|
981 %! 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
|
982 %! 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
|
983 %! 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
|
984 %! assert (A.index, 1); |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
985 %!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
|
986 %! 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
|
987 %! 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
|
988 %! "UniformOutput", true, "ErrorHandler", @__cellfunerror); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
989 %! 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
|
990 %! 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
|
991 %! 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
|
992 %! 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
|
993 %! assert (A.index, 1); |
8373
63fe023d7898
Added more tests for cellfun.
Thomas Treichl <Thomas.Treichl@gmx.net>
parents:
8347
diff
changeset
|
994 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
995 ## 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
|
996 %!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
|
997 %!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
|
998 %!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
|
999 %!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
|
1000 %!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
|
1001 %!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
|
1002 %!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
|
1003 %!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
|
1004 %!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
|
1005 %!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
|
1006 %!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
|
1007 %!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
|
1008 %!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
|
1009 %!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
|
1010 %!assert (cellfun (@atan2, {1,1}, {1,2}), [atan2(1,1), atan2(1,2)]) |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1011 %!assert (cellfun (@atan2, {1,1}, {1,2},"UniformOutput", false), |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1012 %! {atan2(1,1), atan2(1,2)}) |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1013 %!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
|
1014 %!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
|
1015 %!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
|
1016 %!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
|
1017 %!assert (cellfun (@(x) x(2),{[1],[1,2]},"ErrorHandler",@(x,y) NaN), [NaN,2]) |
5988 | 1018 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1019 %! [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
|
1020 %! 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
|
1021 %! assert (b, {"c", "g"}); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1022 %! assert (c, {".d", ".h"}); |
5988 | 1023 |
23573
1b4f4ec53b4a
use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents:
23572
diff
changeset
|
1024 %!assert <*40467> (cellfun (@isreal, {1 inf nan []}), [true, true, true, true]) |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1025 %!assert <*40467> (cellfun (@isreal, {1 inf nan []}, "UniformOutput", false), |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1026 %! {true, true, true, true}) |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1027 %!assert <*40467> (cellfun (@iscomplex, {1 inf nan []}), |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1028 %! [false, false, false, false]) |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1029 %!assert <*40467> (cellfun (@iscomplex, {1 inf nan []}, "UniformOutput", false), |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1030 %! {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
|
1031 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1032 %!error cellfun (1) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1033 %!error cellfun ("isclass", 1) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1034 %!error cellfun ("size", 1) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1035 %!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
|
1036 %!error cellfun (@sin, {[]}, "UniformOuput") |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1037 %!error cellfun (@sin, {[]}, "ErrorHandler") |
29028
9a84aa8c4552
save last error info when cellfun error handler is defined (bug #58411)
John W. Eaton <jwe@octave.org>
parents:
28819
diff
changeset
|
1038 |
9a84aa8c4552
save last error info when cellfun error handler is defined (bug #58411)
John W. Eaton <jwe@octave.org>
parents:
28819
diff
changeset
|
1039 %!function retval = __errfcn (S, varargin) |
9a84aa8c4552
save last error info when cellfun error handler is defined (bug #58411)
John W. Eaton <jwe@octave.org>
parents:
28819
diff
changeset
|
1040 %! global __errmsg; |
9a84aa8c4552
save last error info when cellfun error handler is defined (bug #58411)
John W. Eaton <jwe@octave.org>
parents:
28819
diff
changeset
|
1041 %! __errmsg = S.message; |
9a84aa8c4552
save last error info when cellfun error handler is defined (bug #58411)
John W. Eaton <jwe@octave.org>
parents:
28819
diff
changeset
|
1042 %! retval = NaN; |
9a84aa8c4552
save last error info when cellfun error handler is defined (bug #58411)
John W. Eaton <jwe@octave.org>
parents:
28819
diff
changeset
|
1043 %!endfunction |
30322 | 1044 %!test <*58411> |
29028
9a84aa8c4552
save last error info when cellfun error handler is defined (bug #58411)
John W. Eaton <jwe@octave.org>
parents:
28819
diff
changeset
|
1045 %! global __errmsg; |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1046 %! assert (cellfun (@factorial, {1, 2, -3}, "ErrorHandler", @__errfcn), |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1047 %! [1, 2, NaN]); |
29028
9a84aa8c4552
save last error info when cellfun error handler is defined (bug #58411)
John W. Eaton <jwe@octave.org>
parents:
28819
diff
changeset
|
1048 %! assert (! isempty (__errmsg)); |
9a84aa8c4552
save last error info when cellfun error handler is defined (bug #58411)
John W. Eaton <jwe@octave.org>
parents:
28819
diff
changeset
|
1049 %! clear -global __errmsg; |
5988 | 1050 */ |
1051 | |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1052 // 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
|
1053 // 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
|
1054 // handle the nargout = 0 case. |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1055 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
1056 DEFMETHOD (arrayfun, interp, args, nargout, |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
1057 doc: /* -*- texinfo -*- |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1058 @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
|
1059 @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
|
1060 @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
|
1061 @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
|
1062 @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
|
1063 @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
|
1064 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1065 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
|
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 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
|
1068 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
|
1069 directly. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1070 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1071 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
|
1072 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
|
1073 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
|
1074 array, a structure array, or a cell array. By a call of the function |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22280
diff
changeset
|
1075 @code{arrayfun} all elements of @var{A} are passed on to the named |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1076 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
|
1077 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1078 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
|
1079 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
|
1080 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
|
1081 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
|
1082 example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1083 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1084 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1085 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1086 arrayfun (@@atan2, [1, 0], [0, 1]) |
22699
2100cd2e1be0
doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
1087 @result{} [ 1.57080 0.00000 ] |
21966
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 group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1089 @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
|
1090 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1091 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
|
1092 @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
|
1093 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
|
1094 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
|
1095 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
|
1096 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
|
1097 |
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 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1100 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
|
1101 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1102 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1103 [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
|
1104 [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
|
1105 [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
|
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 @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
|
1108 @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
|
1109 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1110 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
|
1111 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
|
1112 example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1113 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1114 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1115 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1116 [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
|
1117 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1118 A = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1119 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1120 [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
|
1121 [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
|
1122 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1123 B = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1124 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1125 [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
|
1126 [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
|
1127 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1128 C = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1129 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1130 [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
|
1131 [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
|
1132 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1133 @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
|
1134 @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
|
1135 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1136 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
|
1137 @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
|
1138 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
|
1139 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
|
1140 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
|
1141 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1142 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1143 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
|
1144 @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
|
1145 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1146 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1147 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
|
1148 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
|
1149 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
|
1150 @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
|
1151 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
|
1152 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
|
1153 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
|
1154 example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1155 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1156 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1157 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1158 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
|
1159 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
|
1160 "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
|
1161 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1162 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1163 [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
|
1164 @} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1165 @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
|
1166 @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
|
1167 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1168 @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
|
1169 @end deftypefn */) |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1170 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1171 int nargin = args.length (); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1172 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1173 if (nargin < 2) |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1174 print_usage (); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1175 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1176 octave_value_list retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1177 int nargout1 = (nargout < 1 ? 1 : nargout); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1178 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
|
1179 octave_value func = args(0); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1180 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1181 symbol_table& symtab = interp.get_symbol_table (); |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
1182 |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1183 if (func.is_string ()) |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1184 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1185 // 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
|
1186 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
|
1187 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1188 if (! valid_identifier (name)) |
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1189 func = get_function_handle (interp, args(0), "x"); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1190 else |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1191 { |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
1192 func = symtab.find_function (name); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1193 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1194 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
|
1195 error_with_id ("Octave:invalid-input-arg", |
16010
c5d548e4101f
* cellfun.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
16004
diff
changeset
|
1196 "arrayfun: invalid function NAME: %s", |
c5d548e4101f
* cellfun.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
16004
diff
changeset
|
1197 name.c_str ()); |
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 symbol_table_lookup = true; |
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 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1202 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1203 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
|
1204 || func.is_function ()) |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1205 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1206 // 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
|
1207 // 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
|
1208 // 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
|
1209 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18112
diff
changeset
|
1210 if (! symbol_table_lookup) |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1211 { |
28427
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27957
diff
changeset
|
1212 if (func.is_function_handle () || func.class_name () == "inline") |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1213 { |
28819
bd71a227c562
* cellfun.cc: Update comments about overloaded function handles.
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
1214 // FIXME: instead of checking for overloaded functions as |
bd71a227c562
* cellfun.cc: Update comments about overloaded function handles.
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
1215 // we did previously but is no longer possible, we could |
bd71a227c562
* cellfun.cc: Update comments about overloaded function handles.
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
1216 // check whether the types of all the cell array elements |
bd71a227c562
* cellfun.cc: Update comments about overloaded function handles.
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
1217 // are the same, then lookup the function for that type |
bd71a227c562
* cellfun.cc: Update comments about overloaded function handles.
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
1218 // just once. |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1219 |
28819
bd71a227c562
* cellfun.cc: Update comments about overloaded function handles.
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
1220 goto nevermind; |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1221 } |
26847
8bd9fd99c12a
lazily evaluate fcn handles; fix overload resolution (bug #29447, bug #31821, bug #48802)
John W. Eaton <jwe@octave.org>
parents:
26577
diff
changeset
|
1222 |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1223 octave_value f |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
1224 = symtab.find_function (func.function_value () -> name ()); |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1225 |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1226 if (f.is_defined ()) |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1227 func = f; |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1228 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1229 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1230 nevermind: |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1231 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1232 bool uniform_output = true; |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1233 octave_value error_handler; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1234 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
1235 get_mapper_fun_options (symtab, args, nargin, uniform_output, |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23592
diff
changeset
|
1236 error_handler); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1237 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1238 octave_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
|
1239 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1240 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
|
1241 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
|
1242 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1243 octave_idx_type k = 1; |
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 dim_vector fdims (1, 1); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1246 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1247 // 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
|
1248 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1249 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
|
1250 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1251 inputs[j] = args(j+1); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1252 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
|
1253 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1254 if (! mask[j]) |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1255 inputlist(j) = inputs[j]; |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1256 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1257 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1258 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
|
1259 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1260 if (mask[j]) |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1261 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1262 fdims = inputs[j].dims (); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1263 k = inputs[j].numel (); |
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 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
|
1266 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1267 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
|
1268 error_with_id ("Octave:invalid-input-arg", |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1269 "arrayfun: dimensions mismatch"); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1270 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1271 break; |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1272 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1273 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1274 |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
1275 error_system& es = interp.get_error_system (); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1276 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1277 // Apply functions. |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1278 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1279 if (uniform_output) |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1280 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1281 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
|
1282 idx_list.front ().resize (1); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1283 std::string idx_type = "("; |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1284 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1285 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
|
1286 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1287 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
|
1288 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1289 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
|
1290 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1291 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
|
1292 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1293 if (mask[j]) |
28631
70cdf8de553d
move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
1294 inputlist.xelem (j) = inputs[j].index_op (idx_list); |
13234
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 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1297 const octave_value_list tmp |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
26964
diff
changeset
|
1298 = get_output_list (es, count, nargout, inputlist, func, |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1299 error_handler); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1300 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1301 if (nargout > 0 && tmp.length () < nargout) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1302 error_with_id ("Octave:invalid-fun-call", |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1303 "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
|
1304 |
22777
4a31bd79d7e8
maint: Correct spacing around if and opening parentheses of condition.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1305 if (nargout > 0 |
4a31bd79d7e8
maint: Correct spacing around if and opening parentheses of condition.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1306 || (nargout == 0 |
4a31bd79d7e8
maint: Correct spacing around if and opening parentheses of condition.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1307 && tmp.length () > 0 && tmp(0).is_defined ())) |
13234
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 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
|
1310 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1311 if (num_to_copy > nargout1) |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1312 num_to_copy = nargout1; |
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 (count == 0) |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1315 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1316 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
|
1317 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1318 if (tmp(j).is_defined ()) |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1319 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1320 octave_value val = tmp(j); |
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 if (val.numel () == 1) |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1323 retv[j] = val.resize (fdims); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1324 else |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1325 error_with_id ("Octave:invalid-fun-call", |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1326 "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
|
1327 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1328 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1329 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1330 else |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1331 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1332 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
|
1333 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1334 if (tmp(j).is_defined ()) |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1335 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1336 octave_value val = tmp(j); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1337 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1338 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
|
1339 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1340 if (val.numel () == 1) |
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 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
|
1343 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
|
1344 idx_type, idx_list, val); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1345 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1346 else |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1347 error_with_id ("Octave:invalid-fun-call", |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1348 "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
|
1349 } |
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 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1352 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1353 } |
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 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1356 retval.resize (nargout1); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1357 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1358 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
|
1359 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1360 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
|
1361 retval(j) = NDArray (fdims); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1362 else |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1363 retval(j) = retv[j]; |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1364 } |
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 else |
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 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
|
1369 idx_list.front ().resize (1); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1370 std::string idx_type = "("; |
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 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
|
1373 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1374 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
|
1375 results[j].resize (fdims, Matrix ()); |
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 bool have_some_output = false; |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1378 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1379 for (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
|
1380 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1381 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
|
1382 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1383 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
|
1384 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1385 if (mask[j]) |
28631
70cdf8de553d
move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
1386 inputlist.xelem (j) = inputs[j].index_op (idx_list); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1387 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1388 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1389 const octave_value_list tmp |
27160
6b0c61a5a0f0
move global error configuration and status variables inside a class
John W. Eaton <jwe@octave.org>
parents:
26964
diff
changeset
|
1390 = get_output_list (es, count, nargout, inputlist, func, |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1391 error_handler); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1392 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1393 if (nargout > 0 && tmp.length () < nargout) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1394 error_with_id ("Octave:invalid-fun-call", |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1395 "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
|
1396 |
22777
4a31bd79d7e8
maint: Correct spacing around if and opening parentheses of condition.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1397 if (nargout > 0 |
4a31bd79d7e8
maint: Correct spacing around if and opening parentheses of condition.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1398 || (nargout == 0 |
4a31bd79d7e8
maint: Correct spacing around if and opening parentheses of condition.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
1399 && tmp.length () > 0 && tmp(0).is_defined ())) |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1400 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1401 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
|
1402 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1403 if (num_to_copy > nargout1) |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1404 num_to_copy = nargout1; |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1405 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1406 if (num_to_copy > 0) |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1407 have_some_output = true; |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1408 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1409 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
|
1410 results[j](count) = tmp(j); |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1411 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1412 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1413 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1414 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
|
1415 { |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1416 retval.resize (nargout1); |
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 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
|
1419 retval(j) = results[j]; |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1420 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1421 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1422 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1423 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1424 error_with_id ("Octave:invalid-fun-call", |
16010
c5d548e4101f
* cellfun.cc: Style fixes.
John W. Eaton <jwe@octave.org>
parents:
16004
diff
changeset
|
1425 "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
|
1426 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1427 return retval; |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1428 } |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1429 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1430 /* |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14076
diff
changeset
|
1431 %!function r = __f11 (x) |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1432 %! r = x; |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14076
diff
changeset
|
1433 %!endfunction |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1434 |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14076
diff
changeset
|
1435 %!function __f01 (x) |
25762
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1436 %! ## Empty function |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14076
diff
changeset
|
1437 %!endfunction |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1438 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1439 %!test |
25762
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1440 %! __arrayfun_test_num_outputs__ = -1; |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1441 %! |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1442 %! function r = __subf11 (x) |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1443 %! __arrayfun_test_num_outputs__ = nargout; |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1444 %! r = x; |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1445 %! endfunction |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1446 %! |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1447 %! arrayfun ("__subf11", {1}); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1448 %! assert (__arrayfun_test_num_outputs__, 0); |
25762
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1449 %! |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1450 %! __arrayfun_test_num_outputs__ = -1; |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1451 %! x = arrayfun ("__subf11", {1}); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1452 %! 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
|
1453 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1454 %!test |
25762
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1455 %! __arrayfun_test_num_outputs__ = -1; |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1456 %! |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1457 %! function __subf01 (x) |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1458 %! __arrayfun_test_num_outputs__ = nargout; |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1459 %! endfunction |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1460 %! |
97ea2329d5d8
Use nested functions to prevent leaking globals in BIST tests.
Rik <rik@octave.org>
parents:
25688
diff
changeset
|
1461 %! arrayfun ("__subf01", {1}); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1462 %! 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
|
1463 |
21581
6fab85c1538f
maint: Follow Octave conventions for use of semicolon in BIST tests.
Rik <rik@octave.org>
parents:
21580
diff
changeset
|
1464 %!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
|
1465 |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1466 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1467 %! 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
|
1468 %! 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
|
1469 %! 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
|
1470 %! 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
|
1471 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1472 %!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
|
1473 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1474 ## 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
|
1475 %!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
|
1476 %! z = S; |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14076
diff
changeset
|
1477 %!endfunction |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1478 ## First input argument can be a string, an inline function, a |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1479 ## function_handle or an anonymous function |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1480 %!test |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
1481 %! 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
|
1482 %!error |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
21562
diff
changeset
|
1483 %! 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
|
1484 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1485 %! 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
|
1486 %! assert (A, [false, true]); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1487 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1488 %! 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
|
1489 %! assert (A, [false, true]); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1490 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1491 %! 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
|
1492 %! assert (A, [false, true]); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1493 %!test |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1494 %! 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
|
1495 %! assert (A, [false, true]); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1496 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1497 ## Number of input and output arguments may be greater than one |
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1498 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1499 %! 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
|
1500 %! assert (A, true); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1501 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1502 %! 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
|
1503 %! assert (A, [6, 7, 8], 1e-16); |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1504 %!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
|
1505 %! 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
|
1506 %! assert (A, true); |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1507 %!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
|
1508 %! y = true; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1509 %! 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
|
1510 %! assert (A, true); |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
26963
diff
changeset
|
1511 %!test # Three output 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
|
1512 %! [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
|
1513 %! 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
|
1514 %! 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
|
1515 %! 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
|
1516 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1517 ## Input arguments can be of type logical |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1518 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1519 %! 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
|
1520 %! assert (A, [false, true]); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1521 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1522 %! 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
|
1523 %! assert (A, [false; true]); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1524 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1525 %! 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
|
1526 %! assert (A, {false, true, false, true}); |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
26963
diff
changeset
|
1527 %!test # Three output 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
|
1528 %! [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
|
1529 %! 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
|
1530 %! 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
|
1531 %! 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
|
1532 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
1533 %! 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
|
1534 %! "ErrorHandler", @__arrayfunerror); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1535 %! 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
|
1536 %! 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
|
1537 %! 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
|
1538 %! 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
|
1539 %! assert (A.index, 1); |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1540 %!test # Overwriting setting of "UniformOutput" true |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
1541 %! 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
|
1542 %! "ErrorHandler", @__arrayfunerror); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1543 %! 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
|
1544 %! 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
|
1545 %! 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
|
1546 %! 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
|
1547 %! assert (A.index, 1); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1548 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1549 ## Input arguments can be of type numeric |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1550 %!test |
14501
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>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
|
1552 %! assert (A, [false, 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 = 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
|
1555 %! 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
|
1556 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1557 %! A = arrayfun (@(x,y) 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
|
1558 %! 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
|
1559 %! assert (isequal (A{2}, [4, 5, 6])); |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
26963
diff
changeset
|
1560 %!test # Three output 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
|
1561 %! [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
|
1562 %! 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
|
1563 %! 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
|
1564 %! 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
|
1565 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
1566 %! 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
|
1567 %! "ErrorHandler", @__arrayfunerror); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1568 %! B = isfield (A(1), "message") && isfield (A(1), "index"); |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1569 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1570 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1571 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1572 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1573 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1574 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1575 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1576 %! [false, false]); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1577 %! assert ([A(1).index, A(2).index], [1, 2]); |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1578 %!test # Overwriting setting of "UniformOutput" true |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
1579 %! 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
|
1580 %! "UniformOutput", true, "ErrorHandler", @__arrayfunerror); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1581 %! B = isfield (A(1), "message") && isfield (A(1), "index"); |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1582 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1583 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1584 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1585 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1586 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1587 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1588 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1589 %! [false, false]); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1590 %! 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
|
1591 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1592 ## Input arguments can be of type character or strings |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1593 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1594 %! 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
|
1595 %! 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
|
1596 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1597 %! 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
|
1598 %! assert (A, [false; true]); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1599 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1600 %! 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
|
1601 %! assert (A, {"abc", "def"}); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1602 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
1603 %! 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
|
1604 %! "ErrorHandler", @__arrayfunerror); |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1605 %! B = isfield (A(1), "identifier") && isfield (A(1), "message") ... |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1606 %! && isfield (A(1), "index"); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1607 %! assert (B, true); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1608 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1609 ## Input arguments can be of type structure |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1610 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1611 %! 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
|
1612 %! 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
|
1613 %! assert (A, true); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1614 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1615 %! 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
|
1616 %! 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
|
1617 %! assert (A, true); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1618 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1619 %! 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
|
1620 %! 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
|
1621 %! 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
|
1622 %!test |
28915
c40a367a84c0
maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents:
28820
diff
changeset
|
1623 %! A = arrayfun (@(x) mat2str (x), "a", "ErrorHandler", @__arrayfunerror); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1624 %! 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
|
1625 %! 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
|
1626 %! 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
|
1627 %! 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
|
1628 %! assert (A.index, 1); |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1629 %!test # Overwriting setting of "UniformOutput" true |
28915
c40a367a84c0
maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents:
28820
diff
changeset
|
1630 %! 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
|
1631 %! "ErrorHandler", @__arrayfunerror); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1632 %! 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
|
1633 %! 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
|
1634 %! 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
|
1635 %! 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
|
1636 %! assert (A.index, 1); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1637 |
22737
7abc25e6206a
maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
22716
diff
changeset
|
1638 ## Input arguments can be of type cell array |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1639 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1640 %! 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
|
1641 %! assert (A, [true, false]); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1642 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1643 %! 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
|
1644 %! assert (A, [true; false]); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1645 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1646 %! 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
|
1647 %! assert (A, {true, false}); |
13234
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1648 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1649 %! A = arrayfun (@(x,y) num2str(x,y), {1.1, 4.2}, {3.1, 2}, "ErrorHandler", @__arrayfunerror); |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1650 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1651 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1652 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1653 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1654 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1655 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1656 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1657 %! [false, false]); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1658 %! 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
|
1659 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
17199
diff
changeset
|
1660 %! 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
|
1661 %! "UniformOutput", true, "ErrorHandler", @__arrayfunerror); |
30346
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1662 %! assert ([(isfield (A(1), "identifier")), (isfield (A(2), "identifier"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1663 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1664 %! assert ([(isfield (A(1), "message")), (isfield (A(2), "message"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1665 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1666 %! assert ([(isfield (A(1), "index")), (isfield (A(2), "index"))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1667 %! [true, true]); |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1668 %! assert ([(isempty (A(1).message)), (isempty (A(2).message))], |
91c6288781ba
maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1669 %! [false, false]); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1670 %! 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
|
1671 */ |
e066d173aae6
improve compatibility of arrayfun for nargout = 0 case
John W. Eaton <jwe@octave.org>
parents:
13231
diff
changeset
|
1672 |
9678
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1673 static void |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1674 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
|
1675 const Array<int>& dimv, |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1676 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
|
1677 Array<int>& perm) |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1678 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
1679 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
|
1680 int maxd = dv.ndims (); |
9678
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1681 celldv = dv; |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1682 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
|
1683 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
|
1684 if (maxd > dv.ndims ()) |
9678
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1685 celldv.resize (maxd, 1); |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1686 arraydv = celldv; |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1687 |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1688 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
|
1689 |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10291
diff
changeset
|
1690 perm.clear (maxd, 1); |
9678
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1691 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
|
1692 { |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1693 int k = dimv(i) - 1; |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1694 if (k < 0) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
1695 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
|
1696 |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
1697 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
|
1698 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
|
1699 |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1700 sing[k] = true; |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1701 perm(i) = k; |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1702 } |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1703 |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1704 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
|
1705 if (! sing[k]) |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1706 perm(i++) = k; |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1707 |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1708 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
|
1709 if (sing[i]) |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1710 celldv(i) = 1; |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1711 else |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1712 arraydv(i) = 1; |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1713 } |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1714 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
1715 template <typename NDA> |
10756
d808eb829d48
optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1716 static inline typename NDA::element_type |
d808eb829d48
optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1717 do_num2cell_elem (const NDA& array, octave_idx_type i) |
d808eb829d48
optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1718 { return array(i); } |
d808eb829d48
optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1719 |
d808eb829d48
optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1720 static inline Cell |
d808eb829d48
optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1721 do_num2cell_elem (const Cell& array, octave_idx_type i) |
d808eb829d48
optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1722 { return Cell (array(i)); } |
d808eb829d48
optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1723 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
1724 template <typename NDA> |
9678
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1725 static Cell |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1726 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
|
1727 { |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
1728 if (dimv.isempty ()) |
9678
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1729 { |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1730 Cell retval (array.dims ()); |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1731 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
|
1732 for (octave_idx_type i = 0; i < nel; i++) |
10756
d808eb829d48
optimize num2cell on structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1733 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
|
1734 |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1735 return retval; |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1736 } |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1737 else |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1738 { |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1739 dim_vector celldv, arraydv; |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1740 Array<int> perm; |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1741 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
|
1742 |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1743 NDA parray = array.permute (perm); |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1744 |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17893
diff
changeset
|
1745 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
|
1746 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
|
1747 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
|
1748 |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1749 Cell retval (celldv); |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1750 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
|
1751 { |
9731 | 1752 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
|
1753 } |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1754 |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1755 return retval; |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1756 } |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1757 } |
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1758 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1759 // 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
|
1760 // 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
|
1761 // internal dims method. |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1762 |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1763 static dim_vector |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1764 get_object_dims (octave_value& obj) |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1765 { |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1766 dim_vector retval; |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1767 |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1768 Matrix m = obj.size (); |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1769 |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1770 int n = m.numel (); |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1771 |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1772 retval.resize (n); |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1773 |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1774 for (int i = 0; i < n; i++) |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1775 retval(i) = m(i); |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1776 |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1777 return retval; |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1778 } |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1779 |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1780 static Cell |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1781 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
|
1782 { |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1783 Cell retval; |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1784 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1785 // 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
|
1786 // method is not const. |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1787 octave_value array = obj; |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1788 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23576
diff
changeset
|
1789 if (! dimv.isempty ()) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
1790 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
|
1791 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
1792 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
|
1793 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
1794 retval.resize (dv); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
1795 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
1796 octave_value_list idx (1); |
13695
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1797 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
1798 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
|
1799 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
1800 octave_quit (); |
13695
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1801 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
1802 idx(0) = double (i+1); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
1803 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
1804 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
|
1805 } |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1806 |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1807 return retval; |
348857854c52
correctly handle multidimensional objects in num2cell
John W. Eaton <jwe@octave.org>
parents:
13329
diff
changeset
|
1808 } |
9678
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1809 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
1810 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
|
1811 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
|
1812 @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
|
1813 @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
|
1814 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
|
1815 |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1816 When no @var{dim} is specified, each element of @var{A} becomes a 1x1 element |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1817 in the output @var{C}. |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1818 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1819 If @var{dim} is defined then individual elements of @var{C} contain all of the |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1820 elements from @var{A} along the specified dimension. @var{dim} may also be a |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1821 vector of dimensions with the same rule applied. |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1822 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1823 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
|
1824 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1825 @example |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1826 x = [1,2;3,4] |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1827 @result{} |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1828 1 2 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1829 3 4 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1830 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1831 ## each element of A becomes a 1x1 element of C |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1832 num2cell (x) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1833 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1834 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1835 [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
|
1836 [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
|
1837 [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
|
1838 [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
|
1839 @} |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1840 ## all rows (dim 1) of A appear in each element of C |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1841 num2cell (x, 1) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1842 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1843 @{ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1844 [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
|
1845 1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1846 3 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1847 [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
|
1848 2 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1849 4 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1850 @} |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1851 ## all columns (dim 2) of A appear in each element of C |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1852 num2cell (x, 2) |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1853 @result{} |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1854 @{ |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1855 [1,1] = |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1856 1 2 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1857 [2,1] = |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1858 3 4 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1859 @} |
26577
ae1542fb58ba
documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
1860 ## all rows and cols appear in each element of C |
ae1542fb58ba
documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
1861 ## (hence, only 1 output) |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1862 num2cell (x, [1, 2]) |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1863 @result{} |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1864 @{ |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1865 [1,1] = |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1866 1 2 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1867 3 4 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
1868 @} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1869 @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
|
1870 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
1871 @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
|
1872 @end deftypefn */) |
5451 | 1873 { |
20897
9aad16a799c9
maint: Replace argc variable name with nargin in C++ code.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
1874 int nargin = args.length (); |
5451 | 1875 |
1876 if (nargin < 1 || nargin > 2) | |
5823 | 1877 print_usage (); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1878 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1879 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
1880 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1881 octave_value array = args(0); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1882 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1883 Array<int> dimv; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1884 if (nargin > 1) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1885 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
|
1886 |
23579
c20a0fa91c0c
maint: Deprecate is_bool_type and replace with islogical.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
1887 if (array.islogical ()) |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1888 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
|
1889 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
|
1890 retval = do_num2cell (array.char_array_value (), dimv); |
23586
f6c5db0a02e7
maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents:
23584
diff
changeset
|
1891 else if (array.isnumeric ()) |
5451 | 1892 { |
23580
2230f9e10fb3
maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents:
23579
diff
changeset
|
1893 if (array.isinteger ()) |
9678
c929f09457b7
rewrite num2cell for speed-up + a few associated fixes
Jaroslav Hajek <highegg@gmail.com>
parents:
9622
diff
changeset
|
1894 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1895 if (array.is_int8_type ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1896 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
|
1897 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
|
1898 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
|
1899 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
|
1900 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
|
1901 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
|
1902 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
|
1903 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
|
1904 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
|
1905 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
|
1906 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
|
1907 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
|
1908 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
|
1909 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
|
1910 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
|
1911 } |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23580
diff
changeset
|
1912 else if (array.iscomplex ()) |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1913 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1914 if (array.is_single_type ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1915 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
|
1916 else |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1917 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
|
1918 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1919 else |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1920 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1921 if (array.is_single_type ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1922 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
|
1923 else |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1924 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
|
1925 } |
5451 | 1926 } |
23587
0c468af9dc00
maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents:
23586
diff
changeset
|
1927 else if (array.isobject ()) |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1928 retval = do_object2cell (array, dimv); |
23584
7ed6b258db91
maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents:
23583
diff
changeset
|
1929 else if (array.isstruct ()) |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1930 retval = do_num2cell (array.map_value (), dimv); |
23576
00e518162fda
maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents:
23573
diff
changeset
|
1931 else if (array.iscell ()) |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1932 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
|
1933 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20980
diff
changeset
|
1934 err_wrong_type_arg ("num2cell", array); |
5451 | 1935 |
1936 return retval; | |
1937 } | |
1938 | |
5988 | 1939 /* |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
1940 %!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
|
1941 %!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
|
1942 %!assert (num2cell ([1,2;3,4], 2), {[1,2];[3,4]}) |
5988 | 1943 */ |
1944 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1945 static bool |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1946 mat2cell_mismatch (const dim_vector& dv, |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1947 const Array<octave_idx_type> *d, int nd) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1948 { |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1949 for (int i = 0; i < nd; i++) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1950 { |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1951 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
|
1952 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
|
1953 s += d[i](j); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1954 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
1955 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
|
1956 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1957 if (s != r) |
26164
7f6a50f73625
Silence compiler warnings about format identifier for octave_idx_type (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25762
diff
changeset
|
1958 error ("mat2cell: mismatch on dimension %d (%" OCTAVE_IDX_TYPE_FORMAT |
7f6a50f73625
Silence compiler warnings about format identifier for octave_idx_type (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25762
diff
changeset
|
1959 " != %" OCTAVE_IDX_TYPE_FORMAT ")", i+1, r, s); |
10786
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 return false; |
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 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
1965 template <typename container> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
1966 static void |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1967 prepare_idx (container *idx, int idim, int nd, |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
1968 const Array<octave_idx_type> *d) |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1969 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
1970 octave_idx_type nidx = (idim < nd ? d[idim].numel () : 1); |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1971 if (nidx == 1) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1972 idx[0] = idx_vector::colon; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1973 else |
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_idx_type l = 0; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1976 for (octave_idx_type i = 0; i < nidx; i++) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1977 { |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1978 octave_idx_type u = l + d[idim](i); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1979 idx[i] = idx_vector (l, u); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1980 l = u; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1981 } |
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 } |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1984 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1985 // 2D specialization, works for Array, Sparse and octave_map. |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1986 // Uses 1D or 2D indexing. |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1987 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
1988 template <typename Array2D> |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1989 static Cell |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1990 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
|
1991 { |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27474
diff
changeset
|
1992 Cell retval; |
30723
08b08b7f05b2
Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents:
30565
diff
changeset
|
1993 error_unless (nd == 1 || nd == 2); |
08b08b7f05b2
Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents:
30565
diff
changeset
|
1994 error_unless (a.ndims () == 2); |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1995 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1996 if (mat2cell_mismatch (a.dims (), d, nd)) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1997 return retval; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
1998 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
1999 octave_idx_type nridx = d[0].numel (); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
2000 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
|
2001 retval.clear (nridx, ncidx); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2002 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2003 int ivec = -1; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2004 if (a.rows () > 1 && a.cols () == 1 && ncidx == 1) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2005 ivec = 0; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2006 else if (a.rows () == 1 && nridx == 1 && nd == 2) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2007 ivec = 1; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2008 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2009 if (ivec >= 0) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2010 { |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21743
diff
changeset
|
2011 // 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
|
2012 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
|
2013 octave_idx_type nidx = (ivec == 0 ? nridx : ncidx); |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2014 for (octave_idx_type i = 0; i < nidx; i++) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2015 { |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2016 octave_idx_type u = l + d[ivec](i); |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27474
diff
changeset
|
2017 retval.xelem (i) = a.index (idx_vector (l, u)); |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2018 l = u; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2019 } |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2020 } |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2021 else |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2022 { |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21743
diff
changeset
|
2023 // General 2D case. Use 2D indexing. |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2024 OCTAVE_LOCAL_BUFFER (idx_vector, ridx, nridx); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2025 prepare_idx (ridx, 0, nd, d); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2026 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2027 OCTAVE_LOCAL_BUFFER (idx_vector, cidx, ncidx); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2028 prepare_idx (cidx, 1, nd, d); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2029 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2030 for (octave_idx_type j = 0; j < ncidx; j++) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2031 for (octave_idx_type i = 0; i < nridx; i++) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2032 { |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2033 octave_quit (); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2034 |
30390
a61e1a0f6024
maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
30323
diff
changeset
|
2035 retval.xelem (i, j) = a.index (ridx[i], cidx[j]); |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2036 } |
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 return retval; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2040 } |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2041 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21743
diff
changeset
|
2042 // Nd case. Works for Arrays and octave_map. |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2043 // Uses Nd indexing. |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2044 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
2045 template <typename ArrayND> |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2046 Cell |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2047 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
|
2048 { |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27474
diff
changeset
|
2049 Cell retval; |
30723
08b08b7f05b2
Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents:
30565
diff
changeset
|
2050 error_unless (nd >= 1); |
10786
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 if (mat2cell_mismatch (a.dims (), d, nd)) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2053 return retval; |
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 dim_vector rdv = dim_vector::alloc (nd); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2056 OCTAVE_LOCAL_BUFFER (octave_idx_type, nidx, nd); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2057 octave_idx_type idxtot = 0; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2058 for (int i = 0; i < nd; i++) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2059 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
2060 rdv(i) = nidx[i] = d[i].numel (); |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2061 idxtot += nidx[i]; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2062 } |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2063 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2064 retval.clear (rdv); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2065 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2066 OCTAVE_LOCAL_BUFFER (idx_vector, xidx, idxtot); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2067 OCTAVE_LOCAL_BUFFER (idx_vector *, idx, nd); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2068 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2069 idxtot = 0; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2070 for (int i = 0; i < nd; i++) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2071 { |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2072 idx[i] = xidx + idxtot; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2073 prepare_idx (idx[i], i, nd, d); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2074 idxtot += nidx[i]; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2075 } |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2076 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2077 OCTAVE_LOCAL_BUFFER_INIT (octave_idx_type, ridx, nd, 0); |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27474
diff
changeset
|
2078 Array<idx_vector> ra_idx |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
2079 (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
|
2080 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2081 for (octave_idx_type j = 0; j < retval.numel (); j++) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2082 { |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2083 octave_quit (); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2084 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2085 for (int i = 0; i < nd; i++) |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27474
diff
changeset
|
2086 ra_idx.xelem (i) = idx[i][ridx[i]]; |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2087 |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27474
diff
changeset
|
2088 retval.xelem (j) = a.index (ra_idx); |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2089 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2090 rdv.increment_index (ridx); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2091 } |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2092 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2093 return retval; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2094 } |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2095 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2096 // Dispatcher. |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21127
diff
changeset
|
2097 template <typename ArrayND> |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2098 Cell |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2099 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
|
2100 { |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2101 if (a.ndims () == 2 && nd <= 2) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2102 return do_mat2cell_2d (a, d, nd); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2103 else |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2104 return do_mat2cell_nd (a, d, nd); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2105 } |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2106 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21743
diff
changeset
|
2107 // 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
|
2108 // Uses Nd indexing. |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2109 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2110 Cell |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2111 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
|
2112 { |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27474
diff
changeset
|
2113 Cell retval; |
30723
08b08b7f05b2
Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents:
30565
diff
changeset
|
2114 error_unless (nd >= 1); |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2115 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2116 if (mat2cell_mismatch (a.dims (), d, nd)) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2117 return retval; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2118 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2119 dim_vector rdv = dim_vector::alloc (nd); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2120 OCTAVE_LOCAL_BUFFER (octave_idx_type, nidx, nd); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2121 octave_idx_type idxtot = 0; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2122 for (int i = 0; i < nd; i++) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2123 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
2124 rdv(i) = nidx[i] = d[i].numel (); |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2125 idxtot += nidx[i]; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2126 } |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2127 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2128 retval.clear (rdv); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2129 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2130 OCTAVE_LOCAL_BUFFER (octave_value, xidx, idxtot); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2131 OCTAVE_LOCAL_BUFFER (octave_value *, idx, nd); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2132 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2133 idxtot = 0; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2134 for (int i = 0; i < nd; i++) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2135 { |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2136 idx[i] = xidx + idxtot; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2137 prepare_idx (idx[i], i, nd, d); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2138 idxtot += nidx[i]; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2139 } |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2140 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2141 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
|
2142 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
|
2143 octave_value::magic_colon_t); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2144 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2145 for (octave_idx_type j = 0; j < retval.numel (); j++) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2146 { |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2147 octave_quit (); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2148 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2149 for (int i = 0; i < nd; i++) |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2150 ra_idx(i) = idx[i][ridx[i]]; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2151 |
28631
70cdf8de553d
move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
2152 retval.xelem (j) = a.index_op (ra_idx); |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2153 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2154 rdv.increment_index (ridx); |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2155 } |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2156 |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2157 return retval; |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2158 } |
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2159 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
2160 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
|
2161 doc: /* -*- texinfo -*- |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2162 @deftypefn {} {@var{C} =} mat2cell (@var{A}, @var{dim1}, @var{dim2}, @dots{}, @var{dimi}, @dots{}, @var{dimn}) |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2163 @deftypefnx {} {@var{C} =} mat2cell (@var{A}, @var{rowdim}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2164 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
|
2165 |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2166 Each dimension argument (@var{dim1}, @var{dim2}, etc.@:) is a vector of |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2167 integers which specifies how to divide that dimension's elements amongst the |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2168 new elements in the output @var{C}. The number of elements in the @var{i}-th |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2169 dimension is @code{size (@var{A}, @var{i})}. Because all elements in @var{A} |
26963
589b00536a39
doc: Small fixes to mat2cell and polyeig docstrings (bug #55985).
Rik <rik@octave.org>
parents:
26577
diff
changeset
|
2170 must be partitioned, there is a requirement that @code{sum (@var{dimi}) == size |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2171 (@var{A}, i)}. The size of the output cell @var{C} is numel (@var{dim1}) x |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2172 numel (@var{dim2}) x @dots{} x numel (@var{dimn}). |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2173 |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2174 Given a single dimensional argument, @var{rowdim}, the output is divided into |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2175 rows as specified. All other dimensions are not divided and thus all |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2176 columns (dim 2), pages (dim 3), etc.@: appear in each output element. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2177 |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2178 Examples |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2179 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2180 @example |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2181 x = reshape (1:12, [3, 4])' |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2182 @result{} |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2183 1 2 3 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2184 4 5 6 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2185 7 8 9 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2186 10 11 12 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2187 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2188 @group |
26577
ae1542fb58ba
documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
2189 ## The 4 rows (dim1) are divided in to two cell elements |
ae1542fb58ba
documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
2190 ## with 2 rows each. |
ae1542fb58ba
documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
2191 ## The 3 cols (dim2) are divided in to three cell elements |
ae1542fb58ba
documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
2192 ## with 1 col each. |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2193 mat2cell (x, [2,2], [1,1,1]) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2194 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2195 @{ |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2196 [1,1] = |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2197 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2198 1 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2199 4 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2200 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2201 [2,1] = |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2202 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2203 7 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2204 10 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2205 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2206 [1,2] = |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2207 |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2208 2 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2209 5 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2210 |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2211 [2,2] = |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2212 8 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2213 11 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2214 |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2215 [1,3] = |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2216 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2217 3 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2218 6 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2219 |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2220 [2,3] = |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2221 9 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2222 12 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2223 @} |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2224 @end group |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2225 |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2226 @group |
26577
ae1542fb58ba
documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
2227 ## The 4 rows (dim1) are divided in to two cell elements |
ae1542fb58ba
documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
2228 ## with a 3/1 split. |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2229 ## All columns appear in each output element. |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2230 mat2cell (x, [3,1]) |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2231 @result{} |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2232 @{ |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2233 [1,1] = |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2234 |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2235 1 2 3 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2236 4 5 6 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2237 7 8 9 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2238 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2239 [2,1] = |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2240 |
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2241 10 11 12 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2242 @} |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2243 @end group |
21966
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 example |
26165
b326eeae92d0
doc: Rewrite docstrings for mat2cell and num2cell (bug #53335).
Rik <rik@octave.org>
parents:
25103
diff
changeset
|
2245 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2246 @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
|
2247 @end deftypefn */) |
5784 | 2248 { |
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
|
2249 int nargin = args.length (); |
5784 | 2250 |
2251 if (nargin < 2) | |
7038 | 2252 print_usage (); |
5784 | 2253 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
2254 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20897
diff
changeset
|
2255 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2256 // Prepare indices. |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2257 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
|
2258 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2259 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
|
2260 d[i-1] = args(i).octave_idx_type_vector_value (true); |
5784 | 2261 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2262 octave_value a = args(0); |
23583
b7747a2c88b2
maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
2263 bool sparse = a.issparse (); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2264 if (sparse && nargin > 3) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2265 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
|
2266 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2267 switch (a.builtin_type ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2268 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2269 case btyp_double: |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2270 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2271 if (sparse) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2272 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
|
2273 else |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2274 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
|
2275 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2276 break; |
5784 | 2277 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2278 case btyp_complex: |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2279 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2280 if (sparse) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2281 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
|
2282 nargin-1); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2283 else |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2284 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
|
2285 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2286 break; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2287 |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
2288 #define BTYP_BRANCH(X, Y) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
2289 case btyp_ ## X: \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
2290 retval = do_mat2cell (a.Y ## _value (), d, nargin - 1); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22094
diff
changeset
|
2291 break |
5784 | 2292 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2293 BTYP_BRANCH (float, float_array); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2294 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
|
2295 BTYP_BRANCH (bool, bool_array); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2296 BTYP_BRANCH (char, char_array); |
5784 | 2297 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2298 BTYP_BRANCH (int8, int8_array); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2299 BTYP_BRANCH (int16, int16_array); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2300 BTYP_BRANCH (int32, int32_array); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2301 BTYP_BRANCH (int64, int64_array); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2302 BTYP_BRANCH (uint8, uint8_array); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2303 BTYP_BRANCH (uint16, uint16_array); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2304 BTYP_BRANCH (uint32, uint32_array); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2305 BTYP_BRANCH (uint64, uint64_array); |
5784 | 2306 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2307 BTYP_BRANCH (cell, cell); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2308 BTYP_BRANCH (struct, map); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2309 |
10786
146a97c3bc97
some optimizations for mat2cell
Jaroslav Hajek <highegg@gmail.com>
parents:
10756
diff
changeset
|
2310 #undef BTYP_BRANCH |
5784 | 2311 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2312 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
|
2313 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
|
2314 break; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2315 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2316 default: |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2317 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
|
2318 break; |
5784 | 2319 } |
2320 | |
2321 return retval; | |
2322 } | |
2323 | |
2324 /* | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
2325 %!test |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
2326 %! 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
|
2327 %! 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
|
2328 %! assert (c, {[1,6,11;2,7,12;3,8,13],[16;17;18];[4,9,14;5,10,15],[19;20]}); |
5784 | 2329 |
2330 %!test | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
2331 %! x = "abcdefghij"; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
2332 %! 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
|
2333 %! empty1by0str = resize ("", 1, 0); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14366
diff
changeset
|
2334 %! assert (c, {empty1by0str,"abcd","ef",empty1by0str,"ghij",empty1by0str}); |
5784 | 2335 */ |
8985
193804a4f82f
add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2336 |
9740
78ac37d73557
fix cellslices to handle empty ranges with non-positive bounds
Jaroslav Hajek <highegg@gmail.com>
parents:
9731
diff
changeset
|
2337 // 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
|
2338 template <typename NDA> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2339 static Cell |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2340 do_cellslices_nda (const NDA& array, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
2341 const Array<octave_idx_type>& lb, |
10125 | 2342 const Array<octave_idx_type>& ub, |
2343 int dim = -1) | |
8985
193804a4f82f
add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2344 { |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
2345 octave_idx_type n = lb.numel (); |
8985
193804a4f82f
add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2346 Cell retval (1, n); |
23592
80e3bfb7bd5a
maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents:
23587
diff
changeset
|
2347 if (array.isvector () && (dim == -1 |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
2348 || (dim == 0 && array.columns () == 1) |
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
2349 || (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
|
2350 { |
20560
56fee8f84fe7
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
2351 for (octave_idx_type i = 0; i < n; i++) |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27474
diff
changeset
|
2352 retval.xelem (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
|
2353 } |
8b263623d0f3
have cellslices index the last dim of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9042
diff
changeset
|
2354 else |
8b263623d0f3
have cellslices index the last dim of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9042
diff
changeset
|
2355 { |
10125 | 2356 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
|
2357 int ndims = dv.ndims (); |
10125 | 2358 if (dim < 0) |
2359 dim = dv.first_non_singleton (); | |
2360 ndims = std::max (ndims, dim + 1); | |
2361 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
2362 Array<idx_vector> idx (dim_vector (ndims, 1), idx_vector::colon); |
10125 | 2363 |
20560
56fee8f84fe7
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
2364 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
|
2365 { |
10125 | 2366 idx(dim) = idx_vector (lb(i) - 1, ub(i)); |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27474
diff
changeset
|
2367 retval.xelem (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
|
2368 } |
8b263623d0f3
have cellslices index the last dim of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9042
diff
changeset
|
2369 } |
8b263623d0f3
have cellslices index the last dim of n-d arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
9042
diff
changeset
|
2370 |
8985
193804a4f82f
add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2371 return retval; |
193804a4f82f
add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2372 } |
193804a4f82f
add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2373 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
2374 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
|
2375 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
|
2376 @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
|
2377 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
|
2378 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
|
2379 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
|
2380 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2381 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
|
2382 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2383 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2384 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2385 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
|
2386 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
|
2387 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
|
2388 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
|
2389 endfor |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2390 @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
|
2391 @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
|
2392 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2393 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
|
2394 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
|
2395 @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
|
2396 @end deftypefn */) |
8985
193804a4f82f
add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2397 { |
193804a4f82f
add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2398 int nargin = args.length (); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2399 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2400 if (nargin < 3 || nargin > 4) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2401 print_usage (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2402 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2403 octave_value x = args(0); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2404 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
|
2405 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
|
2406 int dim = -1; |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2407 if (nargin == 4) |
8985
193804a4f82f
add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2408 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2409 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
|
2410 if (dim < 0) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2411 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
|
2412 } |
10125 | 2413 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2414 if (lb.numel () != ub.numel ()) |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2415 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
|
2416 |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2417 Cell retcell; |
23583
b7747a2c88b2
maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
2418 if (! x.issparse () && x.is_matrix_type ()) |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2419 { |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2420 // specialize for some dense arrays. |
23579
c20a0fa91c0c
maint: Deprecate is_bool_type and replace with islogical.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
2421 if (x.islogical ()) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2422 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
|
2423 lb, ub, dim); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2424 else if (x.is_char_matrix ()) |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2425 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
|
2426 lb, ub, dim); |
23580
2230f9e10fb3
maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents:
23579
diff
changeset
|
2427 else if (x.isinteger ()) |
8985
193804a4f82f
add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2428 { |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2429 if (x.is_int8_type ()) |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2430 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
|
2431 lb, ub, dim); |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2432 else if (x.is_int16_type ()) |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2433 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
|
2434 lb, ub, dim); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2435 else if (x.is_int32_type ()) |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2436 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
|
2437 lb, ub, dim); |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2438 else if (x.is_int64_type ()) |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2439 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
|
2440 lb, ub, dim); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2441 else if (x.is_uint8_type ()) |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2442 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
|
2443 lb, ub, dim); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2444 else if (x.is_uint16_type ()) |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2445 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
|
2446 lb, ub, dim); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2447 else if (x.is_uint32_type ()) |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2448 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
|
2449 lb, ub, dim); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2450 else if (x.is_uint64_type ()) |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2451 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
|
2452 lb, ub, dim); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2453 } |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23580
diff
changeset
|
2454 else if (x.iscomplex ()) |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2455 { |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2456 if (x.is_single_type ()) |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2457 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
|
2458 lb, ub, dim); |
20560
56fee8f84fe7
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20535
diff
changeset
|
2459 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2460 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
|
2461 lb, ub, dim); |
8985
193804a4f82f
add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2462 } |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2463 else |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2464 { |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2465 if (x.is_single_type ()) |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2466 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
|
2467 lb, ub, dim); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2468 else |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2469 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
|
2470 lb, ub, dim); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2471 } |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2472 } |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2473 else |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2474 { |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2475 // generic code. |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2476 octave_idx_type n = lb.numel (); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2477 retcell = Cell (1, n); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2478 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
|
2479 int ndims = dv.ndims (); |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2480 if (dim < 0) |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2481 dim = dv.first_non_singleton (); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2482 ndims = std::max (ndims, dim + 1); |
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2483 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
|
2484 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
|
2485 { |
29961
7d6709900da7
eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents:
29958
diff
changeset
|
2486 idx(dim) = range<double> (lb(i), ub(i)); |
28631
70cdf8de553d
move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
2487 retcell.xelem (i) = x.index_op (idx); |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20804
diff
changeset
|
2488 } |
8985
193804a4f82f
add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2489 } |
193804a4f82f
add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2490 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
2491 return ovl (retcell); |
8985
193804a4f82f
add cellslices function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2492 } |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10075
diff
changeset
|
2493 |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10075
diff
changeset
|
2494 /* |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10075
diff
changeset
|
2495 %!test |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
10075
diff
changeset
|
2496 %! m = [1, 2, 3, 4; 5, 6, 7, 8; 9, 10, 11, 12]; |
10125 | 2497 %! 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
|
2498 %! 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
|
2499 */ |
10963
0d7624852beb
implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
2500 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
2501 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
|
2502 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
|
2503 @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
|
2504 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
|
2505 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2506 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
|
2507 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2508 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2509 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2510 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
|
2511 for i = 1:numel (X) |
22716
c2f0e687471e
doc: Improve docstring for cellindexmat().
Rik <rik@octave.org>
parents:
22699
diff
changeset
|
2512 Y@{i@} = X@{i@}(varargin@{1@}, varargin@{2@}, @dots{}, varargin@{N@}); |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2513 endfor |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2514 @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
|
2515 @end example |
22716
c2f0e687471e
doc: Improve docstring for cellindexmat().
Rik <rik@octave.org>
parents:
22699
diff
changeset
|
2516 |
c2f0e687471e
doc: Improve docstring for cellindexmat().
Rik <rik@octave.org>
parents:
22699
diff
changeset
|
2517 The indexing arguments may be scalar (@code{2}), arrays (@code{[1, 3]}), |
c2f0e687471e
doc: Improve docstring for cellindexmat().
Rik <rik@octave.org>
parents:
22699
diff
changeset
|
2518 ranges (@code{1:3}), or the colon operator (@qcode{":"}). However, the |
c2f0e687471e
doc: Improve docstring for cellindexmat().
Rik <rik@octave.org>
parents:
22699
diff
changeset
|
2519 indexing keyword @code{end} is not available. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
2520 @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
|
2521 @end deftypefn */) |
10963
0d7624852beb
implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
2522 { |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2523 if (args.length () == 0) |
10963
0d7624852beb
implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
2524 print_usage (); |
0d7624852beb
implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
2525 |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2526 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
|
2527 |
27666
3e8faed1b7d8
Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents:
27474
diff
changeset
|
2528 Cell y (x.dims ()); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2529 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
|
2530 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
|
2531 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2532 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
|
2533 { |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2534 octave_quit (); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2535 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2536 octave_value tmp = x(i); |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2537 |
28631
70cdf8de553d
move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents:
28427
diff
changeset
|
2538 y.xelem (i) = tmp.index_op (idx); |
20804
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2539 } |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2540 |
a6eaedd8bd75
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
2541 return octave_value (y); |
10963
0d7624852beb
implement cellindexmat function
Jaroslav Hajek <highegg@gmail.com>
parents:
10846
diff
changeset
|
2542 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
2543 |
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29655
diff
changeset
|
2544 OCTAVE_NAMESPACE_END |