Mercurial > hg > octave-nkf
annotate libinterp/corefcn/bsxfun.cc @ 20830:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | f90c8372b7ba |
children |
rev | line source |
---|---|
6869 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18111
diff
changeset
|
3 Copyright (C) 2007-2015 David Bateman |
9783
119d97db51f0
avoid repeated table init in bsxfun
Jaroslav Hajek <highegg@gmail.com>
parents:
9743
diff
changeset
|
4 Copyright (C) 2009 VZLU Prague |
6869 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
6869 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
6869 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include <string> | |
29 #include <vector> | |
30 #include <list> | |
31 | |
32 #include "lo-mappers.h" | |
33 | |
34 #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
|
35 #include "defun.h" |
6869 | 36 #include "parse.h" |
37 #include "variables.h" | |
38 #include "ov-colon.h" | |
39 #include "unwind-prot.h" | |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
40 #include "ov-fcn-handle.h" |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
41 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
42 // Optimized bsxfun operations |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
43 enum bsxfun_builtin_op |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
44 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
45 bsxfun_builtin_plus = 0, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
46 bsxfun_builtin_minus, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
47 bsxfun_builtin_times, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
48 bsxfun_builtin_divide, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
49 bsxfun_builtin_max, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
50 bsxfun_builtin_min, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
51 bsxfun_builtin_eq, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
52 bsxfun_builtin_ne, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
53 bsxfun_builtin_lt, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
54 bsxfun_builtin_le, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
55 bsxfun_builtin_gt, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
56 bsxfun_builtin_ge, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
57 bsxfun_builtin_and, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
58 bsxfun_builtin_or, |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
59 bsxfun_builtin_power, |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
60 bsxfun_builtin_unknown, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
61 bsxfun_num_builtin_ops = bsxfun_builtin_unknown |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
62 }; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
63 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
64 const char *bsxfun_builtin_names[] = |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
65 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
66 "plus", |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
67 "minus", |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
68 "times", |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
69 "rdivide", |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
70 "max", |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
71 "min", |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
72 "eq", |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
73 "ne", |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
74 "lt", |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
75 "le", |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
76 "gt", |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
77 "ge", |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
78 "and", |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
79 "or", |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
80 "power" |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
81 }; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
82 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
83 static bsxfun_builtin_op |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
84 bsxfun_builtin_lookup (const std::string& name) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
85 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
86 for (int i = 0; i < bsxfun_num_builtin_ops; i++) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
87 if (name == bsxfun_builtin_names[i]) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
88 return static_cast<bsxfun_builtin_op> (i); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
89 return bsxfun_builtin_unknown; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
90 } |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
91 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
92 typedef octave_value (*bsxfun_handler) (const octave_value&, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
93 const octave_value&); |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
94 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
95 // Static table of handlers. |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
96 bsxfun_handler bsxfun_handler_table[bsxfun_num_builtin_ops][btyp_num_types]; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
97 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
98 template <class NDA, NDA (bsxfun_op) (const NDA&, const NDA&)> |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
99 static octave_value |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
100 bsxfun_forward_op (const octave_value& x, const octave_value& y) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
101 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
102 NDA xa = octave_value_extract<NDA> (x); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
103 NDA ya = octave_value_extract<NDA> (y); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
104 return octave_value (bsxfun_op (xa, ya)); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
105 } |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
106 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
107 template <class NDA, boolNDArray (bsxfun_rel) (const NDA&, const NDA&)> |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
108 static octave_value |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
109 bsxfun_forward_rel (const octave_value& x, const octave_value& y) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
110 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
111 NDA xa = octave_value_extract<NDA> (x); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
112 NDA ya = octave_value_extract<NDA> (y); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
113 return octave_value (bsxfun_rel (xa, ya)); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
114 } |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
115 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
116 // pow() needs a special handler for reals |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
117 // because of the potentially complex result. |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
118 template <class NDA, class CNDA> |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
119 static octave_value |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
120 do_bsxfun_real_pow (const octave_value& x, const octave_value& y) |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
121 { |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
122 NDA xa = octave_value_extract<NDA> (x); |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
123 NDA ya = octave_value_extract<NDA> (y); |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
124 if (! ya.all_integers () && xa.any_element_is_negative ()) |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
125 return octave_value (bsxfun_pow (CNDA (xa), ya)); |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
126 else |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
127 return octave_value (bsxfun_pow (xa, ya)); |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
128 } |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
129 |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
130 static void maybe_fill_table (void) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
131 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
132 static bool filled = false; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
133 if (filled) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
134 return; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
135 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
136 #define REGISTER_OP_HANDLER(OP, BTYP, NDA, FUNOP) \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
137 bsxfun_handler_table[OP][BTYP] = bsxfun_forward_op<NDA, FUNOP> |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
138 #define REGISTER_REL_HANDLER(REL, BTYP, NDA, FUNREL) \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
139 bsxfun_handler_table[REL][BTYP] = bsxfun_forward_rel<NDA, FUNREL> |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
140 #define REGISTER_STD_HANDLERS(BTYP, NDA) \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
141 REGISTER_OP_HANDLER (bsxfun_builtin_plus, BTYP, NDA, bsxfun_add); \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
142 REGISTER_OP_HANDLER (bsxfun_builtin_minus, BTYP, NDA, bsxfun_sub); \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
143 REGISTER_OP_HANDLER (bsxfun_builtin_times, BTYP, NDA, bsxfun_mul); \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
144 REGISTER_OP_HANDLER (bsxfun_builtin_divide, BTYP, NDA, bsxfun_div); \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
145 REGISTER_OP_HANDLER (bsxfun_builtin_max, BTYP, NDA, bsxfun_max); \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
146 REGISTER_OP_HANDLER (bsxfun_builtin_min, BTYP, NDA, bsxfun_min); \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
147 REGISTER_REL_HANDLER (bsxfun_builtin_eq, BTYP, NDA, bsxfun_eq); \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
148 REGISTER_REL_HANDLER (bsxfun_builtin_ne, BTYP, NDA, bsxfun_ne); \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
149 REGISTER_REL_HANDLER (bsxfun_builtin_lt, BTYP, NDA, bsxfun_lt); \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
150 REGISTER_REL_HANDLER (bsxfun_builtin_le, BTYP, NDA, bsxfun_le); \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
151 REGISTER_REL_HANDLER (bsxfun_builtin_gt, BTYP, NDA, bsxfun_gt); \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
152 REGISTER_REL_HANDLER (bsxfun_builtin_ge, BTYP, NDA, bsxfun_ge) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
153 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
154 REGISTER_STD_HANDLERS (btyp_double, NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
155 REGISTER_STD_HANDLERS (btyp_float, FloatNDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
156 REGISTER_STD_HANDLERS (btyp_complex, ComplexNDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
157 REGISTER_STD_HANDLERS (btyp_float_complex, FloatComplexNDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
158 REGISTER_STD_HANDLERS (btyp_int8, int8NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
159 REGISTER_STD_HANDLERS (btyp_int16, int16NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
160 REGISTER_STD_HANDLERS (btyp_int32, int32NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
161 REGISTER_STD_HANDLERS (btyp_int64, int64NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
162 REGISTER_STD_HANDLERS (btyp_uint8, uint8NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
163 REGISTER_STD_HANDLERS (btyp_uint16, uint16NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
164 REGISTER_STD_HANDLERS (btyp_uint32, uint32NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
165 REGISTER_STD_HANDLERS (btyp_uint64, uint64NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
166 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
167 // For bools, we register and/or. |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
168 REGISTER_OP_HANDLER (bsxfun_builtin_and, btyp_bool, boolNDArray, bsxfun_and); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
169 REGISTER_OP_HANDLER (bsxfun_builtin_or, btyp_bool, boolNDArray, bsxfun_or); |
9783
119d97db51f0
avoid repeated table init in bsxfun
Jaroslav Hajek <highegg@gmail.com>
parents:
9743
diff
changeset
|
170 |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
171 // Register power handlers. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
172 bsxfun_handler_table[bsxfun_builtin_power][btyp_double] = |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
173 do_bsxfun_real_pow<NDArray, ComplexNDArray>; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
174 bsxfun_handler_table[bsxfun_builtin_power][btyp_float] = |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
175 do_bsxfun_real_pow<FloatNDArray, FloatComplexNDArray>; |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
176 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
177 REGISTER_OP_HANDLER (bsxfun_builtin_power, btyp_complex, ComplexNDArray, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
178 bsxfun_pow); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
179 REGISTER_OP_HANDLER (bsxfun_builtin_power, btyp_float_complex, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
180 FloatComplexNDArray, bsxfun_pow); |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
181 |
10107
fd262afea1d1
optimize bsxfun for chars
Jaroslav Hajek <highegg@gmail.com>
parents:
9827
diff
changeset
|
182 // For chars, we want just relational handlers. |
fd262afea1d1
optimize bsxfun for chars
Jaroslav Hajek <highegg@gmail.com>
parents:
9827
diff
changeset
|
183 REGISTER_REL_HANDLER (bsxfun_builtin_eq, btyp_char, charNDArray, bsxfun_eq); |
fd262afea1d1
optimize bsxfun for chars
Jaroslav Hajek <highegg@gmail.com>
parents:
9827
diff
changeset
|
184 REGISTER_REL_HANDLER (bsxfun_builtin_ne, btyp_char, charNDArray, bsxfun_ne); |
fd262afea1d1
optimize bsxfun for chars
Jaroslav Hajek <highegg@gmail.com>
parents:
9827
diff
changeset
|
185 REGISTER_REL_HANDLER (bsxfun_builtin_lt, btyp_char, charNDArray, bsxfun_lt); |
fd262afea1d1
optimize bsxfun for chars
Jaroslav Hajek <highegg@gmail.com>
parents:
9827
diff
changeset
|
186 REGISTER_REL_HANDLER (bsxfun_builtin_le, btyp_char, charNDArray, bsxfun_le); |
fd262afea1d1
optimize bsxfun for chars
Jaroslav Hajek <highegg@gmail.com>
parents:
9827
diff
changeset
|
187 REGISTER_REL_HANDLER (bsxfun_builtin_gt, btyp_char, charNDArray, bsxfun_gt); |
fd262afea1d1
optimize bsxfun for chars
Jaroslav Hajek <highegg@gmail.com>
parents:
9827
diff
changeset
|
188 REGISTER_REL_HANDLER (bsxfun_builtin_ge, btyp_char, charNDArray, bsxfun_ge); |
fd262afea1d1
optimize bsxfun for chars
Jaroslav Hajek <highegg@gmail.com>
parents:
9827
diff
changeset
|
189 |
9783
119d97db51f0
avoid repeated table init in bsxfun
Jaroslav Hajek <highegg@gmail.com>
parents:
9743
diff
changeset
|
190 filled = true; |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
191 } |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
192 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
193 static octave_value |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
194 maybe_optimized_builtin (const std::string& name, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
195 const octave_value& a, const octave_value& b) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
196 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
197 octave_value retval; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
198 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
199 maybe_fill_table (); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
200 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
201 bsxfun_builtin_op op = bsxfun_builtin_lookup (name); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
202 if (op != bsxfun_builtin_unknown) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
203 { |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
204 builtin_type_t btyp_a = a.builtin_type (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
205 builtin_type_t btyp_b = b.builtin_type (); |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
206 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
207 // Simplify single/double combinations. |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
208 if (btyp_a == btyp_float && btyp_b == btyp_double) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
209 btyp_b = btyp_float; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
210 else if (btyp_a == btyp_double && btyp_b == btyp_float) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
211 btyp_a = btyp_float; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
212 else if (btyp_a == btyp_float_complex && btyp_b == btyp_complex) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
213 btyp_b = btyp_float_complex; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
214 else if (btyp_a == btyp_complex && btyp_b == btyp_float_complex) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
215 btyp_a = btyp_float_complex; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
216 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
217 if (btyp_a == btyp_b && btyp_a != btyp_unknown) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
218 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
219 bsxfun_handler handler = bsxfun_handler_table[op][btyp_a]; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
220 if (handler) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
221 retval = handler (a, b); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
222 } |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
223 } |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
224 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
225 return retval; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
226 } |
6869 | 227 |
228 static bool | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
229 maybe_update_column (octave_value& Ac, const octave_value& A, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
230 const dim_vector& dva, const dim_vector& dvc, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
231 octave_idx_type i, octave_value_list &idx) |
6869 | 232 { |
233 octave_idx_type nd = dva.length (); | |
234 | |
235 if (i == 0) | |
236 { | |
237 idx(0) = octave_value (':'); | |
238 for (octave_idx_type j = 1; j < nd; j++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
239 { |
20428
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
20382
diff
changeset
|
240 if (dva(j) == 1) |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
241 idx(j) = octave_value (1); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
242 else |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
243 idx(j) = octave_value ((i % dvc(j)) + 1); |
6869 | 244 |
20440
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
245 i /= dvc(j); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
246 } |
6869 | 247 |
248 Ac = A; | |
249 Ac = Ac.single_subsref ("(", idx); | |
250 return true; | |
251 } | |
252 else | |
253 { | |
254 bool is_changed = false; | |
255 octave_idx_type k = i; | |
256 octave_idx_type k1 = i - 1; | |
257 for (octave_idx_type j = 1; j < nd; j++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
258 { |
20428
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
20382
diff
changeset
|
259 if (dva(j) != 1 && k % dvc(j) != k1 % dvc(j)) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
260 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
261 idx (j) = octave_value ((k % dvc(j)) + 1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
262 is_changed = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
263 } |
6869 | 264 |
20440
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
265 k /= dvc(j); |
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
266 k1 /= dvc(j); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
267 } |
6869 | 268 |
269 if (is_changed) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
270 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
271 Ac = A; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
272 Ac = Ac.single_subsref ("(", idx); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
273 return true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
274 } |
6869 | 275 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
276 return false; |
6869 | 277 } |
278 } | |
279 | |
6959 | 280 #if 0 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
281 // FIXME: this function is not used; is it OK to delete it? |
6869 | 282 static void |
283 update_index (octave_value_list& idx, const dim_vector& dv, octave_idx_type i) | |
284 { | |
285 octave_idx_type nd = dv.length (); | |
286 | |
287 if (i == 0) | |
288 { | |
289 for (octave_idx_type j = nd - 1; j > 0; j--) | |
19944
3fa35defe495
Adjust spacing of static_cast<> calls to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
290 idx(j) = octave_value (1.0); |
6869 | 291 idx(0) = octave_value (':'); |
292 } | |
293 else | |
294 { | |
295 for (octave_idx_type j = 1; j < nd; j++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
296 { |
20428
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
20382
diff
changeset
|
297 idx (j) = octave_value (i % dv(j) + 1); |
20440
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
298 i /= dv(j); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
299 } |
6869 | 300 } |
301 } | |
6959 | 302 #endif |
6869 | 303 |
304 static void | |
305 update_index (Array<int>& idx, const dim_vector& dv, octave_idx_type i) | |
306 { | |
307 octave_idx_type nd = dv.length (); | |
308 | |
309 idx(0) = 0; | |
310 for (octave_idx_type j = 1; j < nd; j++) | |
311 { | |
20428
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
20382
diff
changeset
|
312 idx(j) = i % dv(j); |
20440
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
20428
diff
changeset
|
313 i /= dv(j); |
6869 | 314 } |
315 } | |
316 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
317 DEFUN (bsxfun, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
318 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
319 @deftypefn {Built-in Function} {} bsxfun (@var{f}, @var{A}, @var{B})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
320 The binary singleton expansion function performs broadcasting,\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
321 that is, it applies a binary function @var{f} element-by-element to two\n\ |
12972
e4f82a337d66
bsxfun.cc: Expand cryptic bsxfun acronym in docstring and explain it a bit more
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12639
diff
changeset
|
322 array arguments @var{A} and @var{B}, and expands as necessary\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
323 singleton dimensions in either input argument.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
324 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
325 @var{f} is a function handle, inline function, or string containing the name\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
326 of the function to evaluate. The function @var{f} must be capable of\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
327 accepting two column-vector arguments of equal length, or one column vector\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20307
diff
changeset
|
328 argument and a scalar.\n\ |
6869 | 329 \n\ |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13013
diff
changeset
|
330 The dimensions of @var{A} and @var{B} must be equal or singleton. The\n\ |
12972
e4f82a337d66
bsxfun.cc: Expand cryptic bsxfun acronym in docstring and explain it a bit more
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12639
diff
changeset
|
331 singleton dimensions of the arrays will be expanded to the same\n\ |
e4f82a337d66
bsxfun.cc: Expand cryptic bsxfun acronym in docstring and explain it a bit more
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12639
diff
changeset
|
332 dimensionality as the other array.\n\ |
6869 | 333 @seealso{arrayfun, cellfun}\n\ |
334 @end deftypefn") | |
335 { | |
336 int nargin = args.length (); | |
337 octave_value_list retval; | |
338 | |
339 if (nargin != 3) | |
340 print_usage (); | |
341 else | |
342 { | |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
343 octave_value func = args(0); |
6869 | 344 |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
345 if (func.is_string ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
346 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
347 std::string name = func.string_value (); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
348 func = symbol_table::find_function (name); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
349 if (func.is_undefined ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
350 error ("bsxfun: invalid function name: %s", name.c_str ()); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
351 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
352 else if (! (args(0).is_function_handle () |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
353 || args(0).is_inline_function ())) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
354 error ("bsxfun: F must be a string or function handle"); |
6869 | 355 |
18111
b560bac0fca2
maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents:
18099
diff
changeset
|
356 const octave_value A = args(1); |
b560bac0fca2
maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents:
18099
diff
changeset
|
357 const octave_value B = args(2); |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
358 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
359 if (func.is_builtin_function () |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
360 || (func.is_function_handle () |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
361 && ! A.is_object () && ! B.is_object ())) |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
362 { |
20307
1f9ed81bd173
maint: Fix spelling and grammar mistakes in docs and comments (bug #44878)
Rafael Laboissiere <rafael@laboissiere.net>
parents:
20071
diff
changeset
|
363 // This may break if the default behavior is overridden. But if you |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
364 // override arithmetic operators for builtin classes, you should |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
365 // expect mayhem anyway (constant folding etc). Querying |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
366 // is_overloaded() may not be exactly what we need here. |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
367 octave_function *fcn_val = func.function_value (); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
368 if (fcn_val) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
369 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
370 octave_value tmp = maybe_optimized_builtin (fcn_val->name (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
371 A, B); |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
372 if (tmp.is_defined ()) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
373 retval(0) = tmp; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
374 } |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
375 } |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
376 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
377 if (retval.empty ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
378 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
379 dim_vector dva = A.dims (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
380 octave_idx_type nda = dva.length (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
381 dim_vector dvb = B.dims (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
382 octave_idx_type ndb = dvb.length (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
383 octave_idx_type nd = nda; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
384 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
385 if (nda > ndb) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
386 dvb.resize (nda, 1); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
387 else if (nda < ndb) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
388 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
389 dva.resize (ndb, 1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
390 nd = ndb; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
391 } |
6869 | 392 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
393 for (octave_idx_type i = 0; i < nd; i++) |
20428
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
20382
diff
changeset
|
394 if (dva(i) != dvb(i) && dva(i) != 1 && dvb(i) != 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
395 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
396 error ("bsxfun: dimensions of A and B must match"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
397 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
398 } |
6869 | 399 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
400 // Find the size of the output |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
401 dim_vector dvc; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
402 dvc.resize (nd); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
403 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
404 for (octave_idx_type i = 0; i < nd; i++) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
405 dvc(i) = (dva(i) < 1 ? dva(i) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
406 : (dvb(i) < 1 ? dvb(i) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
407 : (dva(i) > dvb(i) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
408 ? dva(i) : dvb(i)))); |
6869 | 409 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
410 if (dva == dvb || dva.numel () == 1 || dvb.numel () == 1) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
411 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
412 octave_value_list inputs; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
413 inputs (0) = A; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
414 inputs (1) = B; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
415 retval = func.do_multi_index_op (1, inputs); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
416 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
417 else if (dvc.numel () < 1) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
418 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
419 octave_value_list inputs; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
420 inputs (0) = A.resize (dvc); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
421 inputs (1) = B.resize (dvc); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
422 retval = func.do_multi_index_op (1, inputs); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
423 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
424 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
425 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
426 octave_idx_type ncount = 1; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
427 for (octave_idx_type i = 1; i < nd; i++) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
428 ncount *= dvc(i); |
6869 | 429 |
430 #define BSXDEF(T) \ | |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
431 T result_ ## T; \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
432 bool have_ ## T = false; |
6869 | 433 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
434 BSXDEF(NDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
435 BSXDEF(ComplexNDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
436 BSXDEF(FloatNDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
437 BSXDEF(FloatComplexNDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
438 BSXDEF(boolNDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
439 BSXDEF(int8NDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
440 BSXDEF(int16NDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
441 BSXDEF(int32NDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
442 BSXDEF(int64NDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
443 BSXDEF(uint8NDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
444 BSXDEF(uint16NDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
445 BSXDEF(uint32NDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
446 BSXDEF(uint64NDArray); |
6869 | 447 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
448 octave_value Ac ; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
449 octave_value_list idxA; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
450 octave_value Bc; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
451 octave_value_list idxB; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
452 octave_value C; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
453 octave_value_list inputs; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
454 Array<int> ra_idx (dim_vector (dvc.length (), 1), 0); |
6869 | 455 |
456 | |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
457 for (octave_idx_type i = 0; i < ncount; i++) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
458 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
459 if (maybe_update_column (Ac, A, dva, dvc, i, idxA)) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
460 inputs (0) = Ac; |
6869 | 461 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
462 if (maybe_update_column (Bc, B, dvb, dvc, i, idxB)) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
463 inputs (1) = Bc; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
464 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
465 octave_value_list tmp = func.do_multi_index_op (1, |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
466 inputs); |
6869 | 467 |
468 #define BSXINIT(T, CLS, EXTRACTOR) \ | |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
469 (result_type == CLS) \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
470 { \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
471 have_ ## T = true; \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
472 result_ ## T = tmp (0). EXTRACTOR ## _array_value (); \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
473 result_ ## T .resize (dvc); \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
474 } |
6869 | 475 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
476 if (i == 0) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
477 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
478 if (! tmp(0).is_sparse_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
479 { |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
480 std::string result_type = tmp(0).class_name (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
481 if (result_type == "double") |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
482 { |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
483 if (tmp(0).is_real_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
484 { |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
485 have_NDArray = true; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
486 result_NDArray = tmp(0).array_value (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
487 result_NDArray.resize (dvc); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
488 } |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
489 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
490 { |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
491 have_ComplexNDArray = true; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
492 result_ComplexNDArray = |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
493 tmp(0).complex_array_value (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
494 result_ComplexNDArray.resize (dvc); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
495 } |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
496 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
497 else if (result_type == "single") |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
498 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
499 if (tmp(0).is_real_type ()) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
500 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
501 have_FloatNDArray = true; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
502 result_FloatNDArray |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
503 = tmp(0).float_array_value (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
504 result_FloatNDArray.resize (dvc); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
505 } |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
506 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
507 { |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
508 have_ComplexNDArray = true; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
509 result_ComplexNDArray = |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
510 tmp(0).complex_array_value (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
511 result_ComplexNDArray.resize (dvc); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
512 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
513 } |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
514 else if BSXINIT(boolNDArray, "logical", bool) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
515 else if BSXINIT(int8NDArray, "int8", int8) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
516 else if BSXINIT(int16NDArray, "int16", int16) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
517 else if BSXINIT(int32NDArray, "int32", int32) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
518 else if BSXINIT(int64NDArray, "int64", int64) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
519 else if BSXINIT(uint8NDArray, "uint8", uint8) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
520 else if BSXINIT(uint16NDArray, "uint16", uint16) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
521 else if BSXINIT(uint32NDArray, "uint32", uint32) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
522 else if BSXINIT(uint64NDArray, "uint64", uint64) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
523 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
524 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
525 C = tmp (0); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
526 C = C.resize (dvc); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
527 } |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
528 } |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
529 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
530 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
531 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
532 update_index (ra_idx, dvc, i); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
533 |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
534 if (have_FloatNDArray |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
535 || have_FloatComplexNDArray) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
536 { |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
537 if (! tmp(0).is_float_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
538 { |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
539 if (have_FloatNDArray) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
540 { |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
541 have_FloatNDArray = false; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
542 C = result_FloatNDArray; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
543 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
544 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
545 { |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
546 have_FloatComplexNDArray = false; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
547 C = result_FloatComplexNDArray; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
548 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
549 C = do_cat_op (C, tmp(0), ra_idx); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
550 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
551 else if (tmp(0).is_double_type ()) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
552 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
553 if (tmp(0).is_complex_type () |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
554 && have_FloatNDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
555 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
556 result_ComplexNDArray = |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
557 ComplexNDArray (result_FloatNDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
558 result_ComplexNDArray.insert |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
559 (tmp(0).complex_array_value (), ra_idx); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
560 have_FloatComplexNDArray = false; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
561 have_ComplexNDArray = true; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
562 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
563 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
564 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
565 result_NDArray = |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
566 NDArray (result_FloatNDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
567 result_NDArray.insert |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
568 (tmp(0).array_value (), ra_idx); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
569 have_FloatNDArray = false; |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
570 have_NDArray = true; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
571 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
572 } |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
573 else if (tmp(0).is_real_type ()) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
574 result_FloatNDArray.insert |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
575 (tmp(0).float_array_value (), ra_idx); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
576 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
577 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
578 result_FloatComplexNDArray = |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
579 FloatComplexNDArray (result_FloatNDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
580 result_FloatComplexNDArray.insert |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
581 (tmp(0).float_complex_array_value (), |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
582 ra_idx); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
583 have_FloatNDArray = false; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
584 have_FloatComplexNDArray = true; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
585 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
586 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
587 else if (have_NDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
588 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
589 if (! tmp(0).is_float_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
590 { |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
591 have_NDArray = false; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
592 C = result_NDArray; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
593 C = do_cat_op (C, tmp(0), ra_idx); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
594 } |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
595 else if (tmp(0).is_real_type ()) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
596 result_NDArray.insert (tmp(0).array_value (), |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
597 ra_idx); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
598 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
599 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
600 result_ComplexNDArray = |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
601 ComplexNDArray (result_NDArray); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
602 result_ComplexNDArray.insert |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
603 (tmp(0).complex_array_value (), ra_idx); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
604 have_NDArray = false; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
605 have_ComplexNDArray = true; |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
606 } |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
607 } |
6869 | 608 |
609 #define BSXLOOP(T, CLS, EXTRACTOR) \ | |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
610 (have_ ## T) \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
611 { \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
612 if (tmp (0).class_name () != CLS) \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
613 { \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
614 have_ ## T = false; \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
615 C = result_ ## T; \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
616 C = do_cat_op (C, tmp (0), ra_idx); \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
617 } \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
618 else \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
619 result_ ## T .insert (tmp(0). EXTRACTOR ## _array_value (), ra_idx); \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
620 } |
6869 | 621 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
622 else if BSXLOOP(ComplexNDArray, "double", complex) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
623 else if BSXLOOP(boolNDArray, "logical", bool) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
624 else if BSXLOOP(int8NDArray, "int8", int8) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
625 else if BSXLOOP(int16NDArray, "int16", int16) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
626 else if BSXLOOP(int32NDArray, "int32", int32) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
627 else if BSXLOOP(int64NDArray, "int64", int64) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
628 else if BSXLOOP(uint8NDArray, "uint8", uint8) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
629 else if BSXLOOP(uint16NDArray, "uint16", uint16) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
630 else if BSXLOOP(uint32NDArray, "uint32", uint32) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
631 else if BSXLOOP(uint64NDArray, "uint64", uint64) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
632 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
633 C = do_cat_op (C, tmp(0), ra_idx); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
634 } |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
635 } |
6869 | 636 |
637 #define BSXEND(T) \ | |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
638 (have_ ## T) \ |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
639 retval(0) = result_ ## T; |
6869 | 640 |
20762
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
641 if BSXEND(NDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
642 else if BSXEND(ComplexNDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
643 else if BSXEND(FloatNDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
644 else if BSXEND(FloatComplexNDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
645 else if BSXEND(boolNDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
646 else if BSXEND(int8NDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
647 else if BSXEND(int16NDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
648 else if BSXEND(int32NDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
649 else if BSXEND(int64NDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
650 else if BSXEND(uint8NDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
651 else if BSXEND(uint16NDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
652 else if BSXEND(uint32NDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
653 else if BSXEND(uint64NDArray) |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
654 else |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20440
diff
changeset
|
655 retval(0) = C; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
656 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
657 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
658 } |
6869 | 659 |
660 return retval; | |
661 } | |
662 | |
663 /* | |
664 | |
665 %!shared a, b, c, f | |
666 %! a = randn (4, 4); | |
667 %! b = mean (a, 1); | |
668 %! c = mean (a, 2); | |
669 %! f = @minus; | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
670 %!error (bsxfun (f)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
671 %!error (bsxfun (f, a)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
672 %!error (bsxfun (a, b)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
673 %!error (bsxfun (a, b, c)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
674 %!error (bsxfun (f, a, b, c)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
675 %!error (bsxfun (f, ones (4, 0), ones (4, 4))) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
676 %!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
677 %!assert (bsxfun (f, ones (1, 4), ones (4, 1)), zeros (4, 4)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
678 %!assert (bsxfun (f, a, b), a - repmat (b, 4, 1)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
679 %!assert (bsxfun (f, a, c), a - repmat (c, 1, 4)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
680 %!assert (bsxfun ("minus", ones (1, 4), ones (4, 1)), zeros (4, 4)) |
6869 | 681 |
682 %!shared a, b, c, f | |
683 %! a = randn (4, 4); | |
684 %! a(1) *= 1i; | |
685 %! b = mean (a, 1); | |
686 %! c = mean (a, 2); | |
687 %! f = @minus; | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
688 %!error (bsxfun (f)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
689 %!error (bsxfun (f, a)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
690 %!error (bsxfun (a, b)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
691 %!error (bsxfun (a, b, c)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
692 %!error (bsxfun (f, a, b, c)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
693 %!error (bsxfun (f, ones (4, 0), ones (4, 4))) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
694 %!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
695 %!assert (bsxfun (f, ones (1, 4), ones (4, 1)), zeros (4, 4)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
696 %!assert (bsxfun (f, a, b), a - repmat (b, 4, 1)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
697 %!assert (bsxfun (f, a, c), a - repmat (c, 1, 4)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
698 %!assert (bsxfun ("minus", ones (1, 4), ones (4, 1)), zeros (4, 4)) |
6869 | 699 |
700 %!shared a, b, c, f | |
701 %! a = randn (4, 4); | |
702 %! a(end) *= 1i; | |
703 %! b = mean (a, 1); | |
704 %! c = mean (a, 2); | |
705 %! f = @minus; | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
706 %!error (bsxfun (f)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
707 %!error (bsxfun (f, a)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
708 %!error (bsxfun (a, b)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
709 %!error (bsxfun (a, b, c)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
710 %!error (bsxfun (f, a, b, c)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
711 %!error (bsxfun (f, ones (4, 0), ones (4, 4))) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
712 %!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
713 %!assert (bsxfun (f, ones (1, 4), ones (4, 1)), zeros (4, 4)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
714 %!assert (bsxfun (f, a, b), a - repmat (b, 4, 1)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
715 %!assert (bsxfun (f, a, c), a - repmat (c, 1, 4)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
716 %!assert (bsxfun ("minus", ones (1, 4), ones (4, 1)), zeros (4, 4)) |
6869 | 717 |
718 %!shared a, b, c, f | |
719 %! a = randn (4, 4); | |
720 %! b = a (1, :); | |
721 %! c = a (:, 1); | |
722 %! f = @(x, y) x == y; | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
723 %!error (bsxfun (f)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
724 %!error (bsxfun (f, a)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
725 %!error (bsxfun (a, b)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
726 %!error (bsxfun (a, b, c)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
727 %!error (bsxfun (f, a, b, c)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
728 %!error (bsxfun (f, ones (4, 0), ones (4, 4))) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
729 %!assert (bsxfun (f, ones (4, 0), ones (4, 1)), zeros (4, 0, "logical")) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
730 %!assert (bsxfun (f, ones (1, 4), ones (4, 1)), ones (4, 4, "logical")) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
731 %!assert (bsxfun (f, a, b), a == repmat (b, 4, 1)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
732 %!assert (bsxfun (f, a, c), a == repmat (c, 1, 4)) |
6869 | 733 |
734 %!shared a, b, c, d, f | |
735 %! a = randn (4, 4, 4); | |
736 %! b = mean (a, 1); | |
737 %! c = mean (a, 2); | |
738 %! d = mean (a, 3); | |
739 %! f = @minus; | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
740 %!error (bsxfun (f, ones ([4, 0, 4]), ones ([4, 4, 4]))) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
741 %!assert (bsxfun (f, ones ([4, 0, 4]), ones ([4, 1, 4])), zeros ([4, 0, 4])) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
742 %!assert (bsxfun (f, ones ([4, 4, 0]), ones ([4, 1, 1])), zeros ([4, 4, 0])) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
743 %!assert (bsxfun (f, ones ([1, 4, 4]), ones ([4, 1, 4])), zeros ([4, 4, 4])) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
744 %!assert (bsxfun (f, ones ([4, 4, 1]), ones ([4, 1, 4])), zeros ([4, 4, 4])) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
745 %!assert (bsxfun (f, ones ([4, 1, 4]), ones ([1, 4, 4])), zeros ([4, 4, 4])) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
746 %!assert (bsxfun (f, ones ([4, 1, 4]), ones ([1, 4, 1])), zeros ([4, 4, 4])) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
747 %!assert (bsxfun (f, a, b), a - repmat (b, [4, 1, 1])) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
748 %!assert (bsxfun (f, a, c), a - repmat (c, [1, 4, 1])) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
749 %!assert (bsxfun (f, a, d), a - repmat (d, [1, 1, 4])) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
750 %!assert (bsxfun ("minus", ones ([4, 0, 4]), ones ([4, 1, 4])), zeros ([4, 0, 4])) |
6869 | 751 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
752 %% The test below is a very hard case to treat |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
753 %!assert (bsxfun (f, ones ([4, 1, 4, 1]), ones ([1, 4, 1, 4])), zeros ([4, 4, 4, 4])); |
6869 | 754 |
10141 | 755 %!shared a, b, aa, bb |
756 %! a = randn (3, 1, 3); | |
757 %! aa = a(:, ones (1, 3), :, ones (1, 3)); | |
758 %! b = randn (1, 3, 3, 3); | |
759 %! bb = b(ones (1, 3), :, :, :); | |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
760 %!assert (bsxfun (@plus, a, b), aa + bb) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
761 %!assert (bsxfun (@minus, a, b), aa - bb) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
762 %!assert (bsxfun (@times, a, b), aa .* bb) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
763 %!assert (bsxfun (@rdivide, a, b), aa ./ bb) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
764 %!assert (bsxfun (@ldivide, a, b), aa .\ bb) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
765 %!assert (bsxfun (@power, a, b), aa .^ bb) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
766 %!assert (bsxfun (@power, abs (a), b), abs (aa) .^ bb) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
767 %!assert (bsxfun (@eq, round (a), round (b)), round (aa) == round (bb)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
768 %!assert (bsxfun (@ne, round (a), round (b)), round (aa) != round (bb)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
769 %!assert (bsxfun (@lt, a, b), aa < bb) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
770 %!assert (bsxfun (@le, a, b), aa <= bb) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
771 %!assert (bsxfun (@gt, a, b), aa > bb) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
772 %!assert (bsxfun (@ge, a, b), aa >= bb) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
773 %!assert (bsxfun (@min, a, b), min (aa, bb)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
774 %!assert (bsxfun (@max, a, b), max (aa, bb)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
775 %!assert (bsxfun (@and, a > 0, b > 0), (aa > 0) & (bb > 0)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
776 %!assert (bsxfun (@or, a > 0, b > 0), (aa > 0) | (bb > 0)) |
13013
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
777 |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
778 %% Test automatic bsxfun |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
779 % |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
780 %!test |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
781 %! funs = {@plus, @minus, @times, @rdivide, @ldivide, @power, @max, @min, ... |
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
782 %! @rem, @mod, @atan2, @hypot, @eq, @ne, @lt, @le, @gt, @ge, ... |
13013
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
783 %! @and, @or, @xor }; |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
784 %! |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
785 %! float_types = {@single, @double}; |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
786 %! int_types = {@int8, @int16, @int32, @int64, ... |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
787 %! @uint8, @uint16, @uint32, @uint64}; |
13013
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
788 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
789 %! x = rand (3) * 10-5; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
790 %! y = rand (3,1) * 10-5; |
13013
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
791 %! |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
792 %! for i=1:length (funs) |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
793 %! for j = 1:length (float_types) |
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
794 %! for k = 1:length (int_types) |
13013
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
795 %! |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
796 %! fun = funs{i}; |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
797 %! f_type = float_types{j}; |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
798 %! i_type = int_types{k}; |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
799 %! |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
800 %! assert (bsxfun (fun, f_type (x), i_type (y)), ... |
13013
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
801 %! fun (f_type(x), i_type (y))); |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
802 %! assert (bsxfun (fun, f_type (y), i_type (x)), ... |
13013
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
803 %! fun (f_type(y), i_type (x))); |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
804 %! |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
805 %! assert (bsxfun (fun, i_type (x), i_type (y)), ... |
13013
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
806 %! fun (i_type (x), i_type (y))); |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
807 %! assert (bsxfun (fun, i_type (y), i_type (x)), ... |
13013
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
808 %! fun (i_type (y), i_type (x))); |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
809 %! |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
810 %! assert (bsxfun (fun, f_type (x), f_type (y)), ... |
13013
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
811 %! fun (f_type (x), f_type (y))); |
17245
7babcdb9bc13
Use ... instead of \ for line continuation marker.
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
812 %! assert (bsxfun (fun, f_type(y), f_type(x)), ... |
13013
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
813 %! fun (f_type (y), f_type (x))); |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
814 %! endfor |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
815 %! endfor |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
816 %! endfor |
5307bf69cd88
Add tests for automatic bsxfun
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12972
diff
changeset
|
817 %! |
6869 | 818 */ |