Mercurial > octave-nkf
annotate src/DLD-FUNCTIONS/bsxfun.cc @ 11586:12df7854fa7c
strip trailing whitespace from source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:24:59 -0500 |
parents | 57632dea2446 |
children | 4d777e05d47c |
rev | line source |
---|---|
6869 | 1 /* |
2 | |
11523 | 3 Copyright (C) 2007-2011 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" | |
35 #include "defun-dld.h" | |
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 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
92 typedef octave_value (*bsxfun_handler) (const octave_value&, const octave_value&); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
93 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
94 // Static table of handlers. |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
95 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
|
96 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
97 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
|
98 static octave_value |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
99 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
|
100 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
101 NDA xa = octave_value_extract<NDA> (x); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
102 NDA ya = octave_value_extract<NDA> (y); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
103 return octave_value (bsxfun_op (xa, ya)); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
104 } |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
105 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
106 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
|
107 static octave_value |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
108 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
|
109 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
110 NDA xa = octave_value_extract<NDA> (x); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
111 NDA ya = octave_value_extract<NDA> (y); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
112 return octave_value (bsxfun_rel (xa, ya)); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
113 } |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
114 |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
115 // Pow needs a special handler for reals because of the potentially complex result. |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
116 template <class NDA, class CNDA> |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
117 static octave_value |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
118 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
|
119 { |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
120 NDA xa = octave_value_extract<NDA> (x); |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
121 NDA ya = octave_value_extract<NDA> (y); |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
122 if (! ya.all_integers () && xa.any_element_is_negative ()) |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
123 return octave_value (bsxfun_pow (CNDA (xa), ya)); |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
124 else |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
125 return octave_value (bsxfun_pow (xa, ya)); |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
126 } |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
127 |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
128 static void maybe_fill_table (void) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
129 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
130 static bool filled = false; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
131 if (filled) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
132 return; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
133 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
134 #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
|
135 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
|
136 #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
|
137 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
|
138 #define REGISTER_STD_HANDLERS(BTYP, NDA) \ |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
152 REGISTER_STD_HANDLERS (btyp_double, NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
153 REGISTER_STD_HANDLERS (btyp_float, FloatNDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
154 REGISTER_STD_HANDLERS (btyp_complex, ComplexNDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
155 REGISTER_STD_HANDLERS (btyp_float_complex, FloatComplexNDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
156 REGISTER_STD_HANDLERS (btyp_int8, int8NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
157 REGISTER_STD_HANDLERS (btyp_int16, int16NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
158 REGISTER_STD_HANDLERS (btyp_int32, int32NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
159 REGISTER_STD_HANDLERS (btyp_int64, int64NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
160 REGISTER_STD_HANDLERS (btyp_uint8, uint8NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
161 REGISTER_STD_HANDLERS (btyp_uint16, uint16NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
162 REGISTER_STD_HANDLERS (btyp_uint32, uint32NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
163 REGISTER_STD_HANDLERS (btyp_uint64, uint64NDArray); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
164 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
165 // For bools, we register and/or. |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
166 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
|
167 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
|
168 |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
169 // Register power handlers. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
170 bsxfun_handler_table[bsxfun_builtin_power][btyp_double] = |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
171 do_bsxfun_real_pow<NDArray, ComplexNDArray>; |
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_float] = |
9827
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
173 do_bsxfun_real_pow<FloatNDArray, FloatComplexNDArray>; |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
174 |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
175 REGISTER_OP_HANDLER (bsxfun_builtin_power, btyp_complex, ComplexNDArray, bsxfun_pow); |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
176 REGISTER_OP_HANDLER (bsxfun_builtin_power, btyp_float_complex, FloatComplexNDArray, bsxfun_pow); |
c15a5ed0da58
optimize bsxfun (@power, ...)
Jaroslav Hajek <highegg@gmail.com>
parents:
9783
diff
changeset
|
177 |
10107
fd262afea1d1
optimize bsxfun for chars
Jaroslav Hajek <highegg@gmail.com>
parents:
9827
diff
changeset
|
178 // For chars, we want just relational handlers. |
fd262afea1d1
optimize bsxfun for chars
Jaroslav Hajek <highegg@gmail.com>
parents:
9827
diff
changeset
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 |
9783
119d97db51f0
avoid repeated table init in bsxfun
Jaroslav Hajek <highegg@gmail.com>
parents:
9743
diff
changeset
|
186 filled = true; |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
187 } |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
188 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
189 static octave_value |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
190 maybe_optimized_builtin (const std::string& name, |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
191 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
|
192 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
193 octave_value retval; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
194 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
195 maybe_fill_table (); |
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 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
|
198 if (op != bsxfun_builtin_unknown) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
199 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
200 builtin_type_t btyp_a = a.builtin_type (), btyp_b = b.builtin_type (); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
201 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
202 // Simplify single/double combinations. |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
203 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
|
204 btyp_b = btyp_float; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
205 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
|
206 btyp_a = btyp_float; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
207 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
|
208 btyp_b = btyp_float_complex; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
209 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
|
210 btyp_a = btyp_float_complex; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
211 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
212 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
|
213 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
214 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
|
215 if (handler) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
216 retval = handler (a, b); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
217 } |
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 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
220 return retval; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
221 } |
6869 | 222 |
223 static bool | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
224 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
|
225 const dim_vector& dva, const dim_vector& dvc, |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
226 octave_idx_type i, octave_value_list &idx) |
6869 | 227 { |
228 octave_idx_type nd = dva.length (); | |
229 | |
230 if (i == 0) | |
231 { | |
232 idx(0) = octave_value (':'); | |
233 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
|
234 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
235 if (dva (j) == 1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
236 idx (j) = octave_value (1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
237 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
238 idx (j) = octave_value ((i % dvc(j)) + 1); |
6869 | 239 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
240 i = i / dvc (j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
241 } |
6869 | 242 |
243 Ac = A; | |
244 Ac = Ac.single_subsref ("(", idx); | |
245 return true; | |
246 } | |
247 else | |
248 { | |
249 bool is_changed = false; | |
250 octave_idx_type k = i; | |
251 octave_idx_type k1 = i - 1; | |
252 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
|
253 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
254 if (dva(j) != 1 && k % dvc (j) != k1 % dvc (j)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
255 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
256 idx (j) = octave_value ((k % dvc(j)) + 1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
257 is_changed = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
258 } |
6869 | 259 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
260 k = k / dvc (j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
261 k1 = k1 / dvc (j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
262 } |
6869 | 263 |
264 if (is_changed) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
265 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
266 Ac = A; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
267 Ac = Ac.single_subsref ("(", idx); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
268 return true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
269 } |
6869 | 270 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
271 return false; |
6869 | 272 } |
273 } | |
274 | |
6959 | 275 #if 0 |
276 // FIXME -- this function is not used; is it OK to delete it? | |
6869 | 277 static void |
278 update_index (octave_value_list& idx, const dim_vector& dv, octave_idx_type i) | |
279 { | |
280 octave_idx_type nd = dv.length (); | |
281 | |
282 if (i == 0) | |
283 { | |
284 for (octave_idx_type j = nd - 1; j > 0; j--) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
285 idx(j) = octave_value (static_cast<double>(1)); |
6869 | 286 idx(0) = octave_value (':'); |
287 } | |
288 else | |
289 { | |
290 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
|
291 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
292 idx (j) = octave_value (i % dv (j) + 1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
293 i = i / dv (j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
294 } |
6869 | 295 } |
296 } | |
6959 | 297 #endif |
6869 | 298 |
299 static void | |
300 update_index (Array<int>& idx, const dim_vector& dv, octave_idx_type i) | |
301 { | |
302 octave_idx_type nd = dv.length (); | |
303 | |
304 idx(0) = 0; | |
305 for (octave_idx_type j = 1; j < nd; j++) | |
306 { | |
307 idx (j) = i % dv (j); | |
308 i = i / dv (j); | |
309 } | |
310 } | |
311 | |
6959 | 312 DEFUN_DLD (bsxfun, args, , |
8715 | 313 "-*- texinfo -*-\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
314 @deftypefn {Loadable Function} {} bsxfun (@var{f}, @var{A}, @var{B})\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
315 Apply a binary function @var{f} element-by-element to two matrix arguments\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
316 @var{A} and @var{B}. The function @var{f} must be capable of accepting\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
317 two column-vector arguments of equal length, or one column vector\n\ |
6869 | 318 argument and a scalar.\n\ |
319 \n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
320 The dimensions of @var{A} and @var{B} must be equal or singleton. The\n\ |
7001 | 321 singleton dimensions of the matrices will be expanded to the same\n\ |
6881 | 322 dimensionality as the other matrix.\n\ |
6869 | 323 @seealso{arrayfun, cellfun}\n\ |
324 @end deftypefn") | |
325 { | |
326 int nargin = args.length (); | |
327 octave_value_list retval; | |
328 | |
329 if (nargin != 3) | |
330 print_usage (); | |
331 else | |
332 { | |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
333 octave_value func = args(0); |
6869 | 334 |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
335 if (func.is_string ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
336 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
337 std::string name = func.string_value (); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
338 func = symbol_table::find_function (name); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
339 if (func.is_undefined ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
340 error ("bsxfun: invalid function name: %s", name.c_str ()); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
341 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9041
diff
changeset
|
342 else if (! (args(0).is_function_handle () || args(0).is_inline_function ())) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
343 error ("bsxfun: F must be a string or function handle"); |
6869 | 344 |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
345 const octave_value A = args (1); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
346 const octave_value B = args (2); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
347 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
348 if (func.is_builtin_function () |
10294
816b91eebe79
remove redundant test in bsxfun
Jaroslav Hajek <highegg@gmail.com>
parents:
10154
diff
changeset
|
349 || (func.is_function_handle () && ! A.is_object () && ! B.is_object ())) |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
350 { |
10294
816b91eebe79
remove redundant test in bsxfun
Jaroslav Hajek <highegg@gmail.com>
parents:
10154
diff
changeset
|
351 // This may break if the default behavior is overriden. But if you override |
816b91eebe79
remove redundant test in bsxfun
Jaroslav Hajek <highegg@gmail.com>
parents:
10154
diff
changeset
|
352 // arithmetic operators for builtin classes, you should expect mayhem |
816b91eebe79
remove redundant test in bsxfun
Jaroslav Hajek <highegg@gmail.com>
parents:
10154
diff
changeset
|
353 // anyway (constant folding etc). Querying is_overloaded may not be |
816b91eebe79
remove redundant test in bsxfun
Jaroslav Hajek <highegg@gmail.com>
parents:
10154
diff
changeset
|
354 // exactly what we need here. |
9743
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
355 octave_function *fcn_val = func.function_value (); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
356 if (fcn_val) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
357 { |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
358 octave_value tmp = maybe_optimized_builtin (fcn_val->name (), A, B); |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
359 if (tmp.is_defined ()) |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
360 retval(0) = tmp; |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
361 } |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
362 } |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
363 |
26abff55f6fe
optimize bsxfun for common built-in operations
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
364 if (! error_state && retval.empty ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
365 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
366 dim_vector dva = A.dims (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
367 octave_idx_type nda = dva.length (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
368 dim_vector dvb = B.dims (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
369 octave_idx_type ndb = dvb.length (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
370 octave_idx_type nd = nda; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
371 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
372 if (nda > ndb) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
373 dvb.resize (nda, 1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
374 else if (nda < ndb) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
375 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
376 dva.resize (ndb, 1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
377 nd = ndb; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
378 } |
6869 | 379 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
380 for (octave_idx_type i = 0; i < nd; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
381 if (dva (i) != dvb (i) && dva (i) != 1 && dvb (i) != 1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
382 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
383 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
|
384 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
385 } |
6869 | 386 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
387 if (!error_state) |
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 // Find the size of the output |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
390 dim_vector dvc; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
391 dvc.resize (nd); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
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++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
394 dvc (i) = (dva (i) < 1 ? dva (i) : (dvb (i) < 1 ? dvb (i) : |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
395 (dva (i) > dvb (i) ? dva (i) : dvb (i)))); |
6869 | 396 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
397 if (dva == dvb || dva.numel () == 1 || dvb.numel () == 1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
398 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
399 octave_value_list inputs; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
400 inputs (0) = A; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
401 inputs (1) = B; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
402 retval = func.do_multi_index_op (1, inputs); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
403 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
404 else if (dvc.numel () < 1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
405 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
406 octave_value_list inputs; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
407 inputs (0) = A.resize (dvc); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
408 inputs (1) = B.resize (dvc); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
409 retval = func.do_multi_index_op (1, inputs); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
410 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
411 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
412 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
413 octave_idx_type ncount = 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
414 for (octave_idx_type i = 1; i < nd; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
415 ncount *= dvc (i); |
6869 | 416 |
417 #define BSXDEF(T) \ | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
418 T result_ ## T; \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
419 bool have_ ## T = false; |
6869 | 420 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
421 BSXDEF(NDArray); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
422 BSXDEF(ComplexNDArray); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
423 BSXDEF(FloatNDArray); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
424 BSXDEF(FloatComplexNDArray); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
425 BSXDEF(boolNDArray); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
426 BSXDEF(int8NDArray); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
427 BSXDEF(int16NDArray); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
428 BSXDEF(int32NDArray); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
429 BSXDEF(int64NDArray); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
430 BSXDEF(uint8NDArray); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
431 BSXDEF(uint16NDArray); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
432 BSXDEF(uint32NDArray); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
433 BSXDEF(uint64NDArray); |
6869 | 434 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
435 octave_value Ac ; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
436 octave_value_list idxA; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
437 octave_value Bc; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
438 octave_value_list idxB; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
439 octave_value C; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
440 octave_value_list inputs; |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
441 Array<int> ra_idx (dim_vector (dvc.length(), 1), 0); |
6869 | 442 |
443 | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
444 for (octave_idx_type i = 0; i < ncount; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
445 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
446 if (maybe_update_column (Ac, A, dva, dvc, i, idxA)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
447 inputs (0) = Ac; |
6869 | 448 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
449 if (maybe_update_column (Bc, B, dvb, dvc, i, idxB)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
450 inputs (1) = Bc; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
451 |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
452 octave_value_list tmp = func.do_multi_index_op (1, inputs); |
6869 | 453 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
454 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
455 break; |
6869 | 456 |
457 #define BSXINIT(T, CLS, EXTRACTOR) \ | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
458 (result_type == CLS) \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
459 { \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
460 have_ ## T = true; \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
461 result_ ## T = \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
462 tmp (0). EXTRACTOR ## _array_value (); \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
463 result_ ## T .resize (dvc); \ |
6869 | 464 } |
465 | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
466 if (i == 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
467 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
468 if (! tmp(0).is_sparse_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
469 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
470 std::string result_type = tmp(0).class_name (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
471 if (result_type == "double") |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
472 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
473 if (tmp(0).is_real_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
474 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
475 have_NDArray = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
476 result_NDArray = tmp(0).array_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
477 result_NDArray.resize (dvc); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
478 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
479 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
480 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
481 have_ComplexNDArray = true; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
482 result_ComplexNDArray = |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
483 tmp(0).complex_array_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
484 result_ComplexNDArray.resize (dvc); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
485 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
486 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
487 else if (result_type == "single") |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
488 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
489 if (tmp(0).is_real_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
490 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
491 have_FloatNDArray = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
492 result_FloatNDArray = tmp(0).float_array_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
493 result_FloatNDArray.resize (dvc); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
494 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
495 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
496 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
497 have_ComplexNDArray = true; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
498 result_ComplexNDArray = |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
499 tmp(0).complex_array_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
500 result_ComplexNDArray.resize (dvc); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
501 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
502 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
503 else if BSXINIT(boolNDArray, "logical", bool) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
504 else if BSXINIT(int8NDArray, "int8", int8) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
505 else if BSXINIT(int16NDArray, "int16", int16) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
506 else if BSXINIT(int32NDArray, "int32", int32) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
507 else if BSXINIT(int64NDArray, "int64", int64) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
508 else if BSXINIT(uint8NDArray, "uint8", uint8) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
509 else if BSXINIT(uint16NDArray, "uint16", uint16) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
510 else if BSXINIT(uint32NDArray, "uint32", uint32) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
511 else if BSXINIT(uint64NDArray, "uint64", uint64) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
512 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
513 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
514 C = tmp (0); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
515 C = C.resize (dvc); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
516 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
517 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
518 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
519 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
520 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
521 update_index (ra_idx, dvc, i); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
522 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
523 if (have_FloatNDArray || |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
524 have_FloatComplexNDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
525 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
526 if (! tmp(0).is_float_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
527 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
528 if (have_FloatNDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
529 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
530 have_FloatNDArray = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
531 C = result_FloatNDArray; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
532 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
533 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
534 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
535 have_FloatComplexNDArray = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
536 C = result_FloatComplexNDArray; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
537 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
538 C = do_cat_op (C, tmp(0), ra_idx); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
539 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
540 else if (tmp(0).is_double_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
541 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
542 if (tmp(0).is_complex_type () && |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
543 have_FloatNDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
544 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
545 result_ComplexNDArray = |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
546 ComplexNDArray (result_FloatNDArray); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
547 result_ComplexNDArray.insert |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
548 (tmp(0).complex_array_value(), ra_idx); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
549 have_FloatComplexNDArray = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
550 have_ComplexNDArray = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
551 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
552 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
553 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
554 result_NDArray = |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
555 NDArray (result_FloatNDArray); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
556 result_NDArray.insert |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
557 (tmp(0).array_value(), ra_idx); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
558 have_FloatNDArray = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
559 have_NDArray = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
560 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
561 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
562 else if (tmp(0).is_real_type ()) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
563 result_FloatNDArray.insert |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
564 (tmp(0).float_array_value(), ra_idx); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
565 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
566 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
567 result_FloatComplexNDArray = |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
568 FloatComplexNDArray (result_FloatNDArray); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
569 result_FloatComplexNDArray.insert |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
570 (tmp(0).float_complex_array_value(), ra_idx); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
571 have_FloatNDArray = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
572 have_FloatComplexNDArray = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
573 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
574 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
575 else if (have_NDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
576 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
577 if (! tmp(0).is_float_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
578 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
579 have_NDArray = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
580 C = result_NDArray; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
581 C = do_cat_op (C, tmp(0), ra_idx); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
582 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
583 else if (tmp(0).is_real_type ()) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
584 result_NDArray.insert (tmp(0).array_value(), |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
585 ra_idx); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
586 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
587 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
588 result_ComplexNDArray = |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
589 ComplexNDArray (result_NDArray); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
590 result_ComplexNDArray.insert |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
591 (tmp(0).complex_array_value(), ra_idx); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
592 have_NDArray = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
593 have_ComplexNDArray = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
594 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
595 } |
6869 | 596 |
597 #define BSXLOOP(T, CLS, EXTRACTOR) \ | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
598 (have_ ## T) \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
599 { \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
600 if (tmp (0).class_name () != CLS) \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
601 { \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
602 have_ ## T = false; \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
603 C = result_ ## T; \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
604 C = do_cat_op (C, tmp (0), ra_idx); \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
605 } \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
606 else \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
607 result_ ## T .insert \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
608 (tmp(0). EXTRACTOR ## _array_value (), \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
609 ra_idx); \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
610 } |
6869 | 611 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
612 else if BSXLOOP(ComplexNDArray, "double", complex) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
613 else if BSXLOOP(boolNDArray, "logical", bool) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
614 else if BSXLOOP(int8NDArray, "int8", int8) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
615 else if BSXLOOP(int16NDArray, "int16", int16) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
616 else if BSXLOOP(int32NDArray, "int32", int32) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
617 else if BSXLOOP(int64NDArray, "int64", int64) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
618 else if BSXLOOP(uint8NDArray, "uint8", uint8) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
619 else if BSXLOOP(uint16NDArray, "uint16", uint16) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
620 else if BSXLOOP(uint32NDArray, "uint32", uint32) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
621 else if BSXLOOP(uint64NDArray, "uint64", uint64) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
622 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
623 C = do_cat_op (C, tmp(0), ra_idx); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
624 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
625 } |
6869 | 626 |
627 #define BSXEND(T) \ | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
628 (have_ ## T) \ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
629 retval (0) = result_ ## T; |
6869 | 630 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
631 if BSXEND(NDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
632 else if BSXEND(ComplexNDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
633 else if BSXEND(FloatNDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
634 else if BSXEND(FloatComplexNDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
635 else if BSXEND(boolNDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
636 else if BSXEND(int8NDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
637 else if BSXEND(int16NDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
638 else if BSXEND(int32NDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
639 else if BSXEND(int64NDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
640 else if BSXEND(uint8NDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
641 else if BSXEND(uint16NDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
642 else if BSXEND(uint32NDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
643 else if BSXEND(uint64NDArray) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
644 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
645 retval(0) = C; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
646 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
647 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10141
diff
changeset
|
648 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
649 } |
6869 | 650 |
651 return retval; | |
652 } | |
653 | |
654 /* | |
655 | |
656 %!shared a, b, c, f | |
657 %! a = randn (4, 4); | |
658 %! b = mean (a, 1); | |
659 %! c = mean (a, 2); | |
660 %! f = @minus; | |
661 %!error(bsxfun (f)); | |
662 %!error(bsxfun (f, a)); | |
663 %!error(bsxfun (a, b)); | |
664 %!error(bsxfun (a, b, c)); | |
665 %!error(bsxfun (f, a, b, c)); | |
666 %!error(bsxfun (f, ones(4, 0), ones(4, 4))) | |
667 %!assert(bsxfun (f, ones(4, 0), ones(4, 1)), zeros(4, 0)); | |
668 %!assert(bsxfun (f, ones(1, 4), ones(4, 1)), zeros(4, 4)); | |
669 %!assert(bsxfun (f, a, b), a - repmat(b, 4, 1)); | |
670 %!assert(bsxfun (f, a, c), a - repmat(c, 1, 4)); | |
671 %!assert(bsxfun ("minus", ones(1, 4), ones(4, 1)), zeros(4, 4)); | |
672 | |
673 %!shared a, b, c, f | |
674 %! a = randn (4, 4); | |
675 %! a(1) *= 1i; | |
676 %! b = mean (a, 1); | |
677 %! c = mean (a, 2); | |
678 %! f = @minus; | |
679 %!error(bsxfun (f)); | |
680 %!error(bsxfun (f, a)); | |
681 %!error(bsxfun (a, b)); | |
682 %!error(bsxfun (a, b, c)); | |
683 %!error(bsxfun (f, a, b, c)); | |
684 %!error(bsxfun (f, ones(4, 0), ones(4, 4))) | |
685 %!assert(bsxfun (f, ones(4, 0), ones(4, 1)), zeros(4, 0)); | |
686 %!assert(bsxfun (f, ones(1, 4), ones(4, 1)), zeros(4, 4)); | |
687 %!assert(bsxfun (f, a, b), a - repmat(b, 4, 1)); | |
688 %!assert(bsxfun (f, a, c), a - repmat(c, 1, 4)); | |
689 %!assert(bsxfun ("minus", ones(1, 4), ones(4, 1)), zeros(4, 4)); | |
690 | |
691 %!shared a, b, c, f | |
692 %! a = randn (4, 4); | |
693 %! a(end) *= 1i; | |
694 %! b = mean (a, 1); | |
695 %! c = mean (a, 2); | |
696 %! f = @minus; | |
697 %!error(bsxfun (f)); | |
698 %!error(bsxfun (f, a)); | |
699 %!error(bsxfun (a, b)); | |
700 %!error(bsxfun (a, b, c)); | |
701 %!error(bsxfun (f, a, b, c)); | |
702 %!error(bsxfun (f, ones(4, 0), ones(4, 4))) | |
703 %!assert(bsxfun (f, ones(4, 0), ones(4, 1)), zeros(4, 0)); | |
704 %!assert(bsxfun (f, ones(1, 4), ones(4, 1)), zeros(4, 4)); | |
705 %!assert(bsxfun (f, a, b), a - repmat(b, 4, 1)); | |
706 %!assert(bsxfun (f, a, c), a - repmat(c, 1, 4)); | |
707 %!assert(bsxfun ("minus", ones(1, 4), ones(4, 1)), zeros(4, 4)); | |
708 | |
709 %!shared a, b, c, f | |
710 %! a = randn (4, 4); | |
711 %! b = a (1, :); | |
712 %! c = a (:, 1); | |
713 %! f = @(x, y) x == y; | |
714 %!error(bsxfun (f)); | |
715 %!error(bsxfun (f, a)); | |
716 %!error(bsxfun (a, b)); | |
717 %!error(bsxfun (a, b, c)); | |
718 %!error(bsxfun (f, a, b, c)); | |
719 %!error(bsxfun (f, ones(4, 0), ones(4, 4))) | |
720 %!assert(bsxfun (f, ones(4, 0), ones(4, 1)), zeros(4, 0, "logical")); | |
721 %!assert(bsxfun (f, ones(1, 4), ones(4, 1)), ones(4, 4, "logical")); | |
722 %!assert(bsxfun (f, a, b), a == repmat(b, 4, 1)); | |
723 %!assert(bsxfun (f, a, c), a == repmat(c, 1, 4)); | |
724 | |
725 %!shared a, b, c, d, f | |
726 %! a = randn (4, 4, 4); | |
727 %! b = mean (a, 1); | |
728 %! c = mean (a, 2); | |
729 %! d = mean (a, 3); | |
730 %! f = @minus; | |
731 %!error(bsxfun (f, ones([4, 0, 4]), ones([4, 4, 4]))); | |
732 %!assert(bsxfun (f, ones([4, 0, 4]), ones([4, 1, 4])), zeros([4, 0, 4])); | |
733 %!assert(bsxfun (f, ones([4, 4, 0]), ones([4, 1, 1])), zeros([4, 4, 0])); | |
734 %!assert(bsxfun (f, ones([1, 4, 4]), ones([4, 1, 4])), zeros([4, 4, 4])); | |
735 %!assert(bsxfun (f, ones([4, 4, 1]), ones([4, 1, 4])), zeros([4, 4, 4])); | |
736 %!assert(bsxfun (f, ones([4, 1, 4]), ones([1, 4, 4])), zeros([4, 4, 4])); | |
737 %!assert(bsxfun (f, ones([4, 1, 4]), ones([1, 4, 1])), zeros([4, 4, 4])); | |
738 %!assert(bsxfun (f, a, b), a - repmat(b, [4, 1, 1])); | |
739 %!assert(bsxfun (f, a, c), a - repmat(c, [1, 4, 1])); | |
740 %!assert(bsxfun (f, a, d), a - repmat(d, [1, 1, 4])); | |
741 %!assert(bsxfun ("minus", ones([4, 0, 4]), ones([4, 1, 4])), zeros([4, 0, 4])); | |
742 | |
743 %% The below is a very hard case to treat | |
744 %!assert(bsxfun (f, ones([4, 1, 4, 1]), ones([1, 4, 1, 4])), zeros([4, 4, 4, 4])); | |
745 | |
10141 | 746 %!shared a, b, aa, bb |
747 %! a = randn (3, 1, 3); | |
748 %! aa = a(:, ones (1, 3), :, ones (1, 3)); | |
749 %! b = randn (1, 3, 3, 3); | |
750 %! bb = b(ones (1, 3), :, :, :); | |
751 %!assert (bsxfun (@plus, a, b), aa + bb); | |
752 %!assert (bsxfun (@minus, a, b), aa - bb); | |
753 %!assert (bsxfun (@times, a, b), aa .* bb); | |
754 %!assert (bsxfun (@rdivide, a, b), aa ./ bb); | |
755 %!assert (bsxfun (@ldivide, a, b), aa .\ bb); | |
756 %!assert (bsxfun (@power, a, b), aa .^ bb); | |
757 %!assert (bsxfun (@power, abs (a), b), abs (aa) .^ bb); | |
758 %!assert (bsxfun (@eq, round (a), round (b)), round (aa) == round (bb)); | |
759 %!assert (bsxfun (@ne, round (a), round (b)), round (aa) != round (bb)); | |
760 %!assert (bsxfun (@lt, a, b), aa < bb); | |
761 %!assert (bsxfun (@le, a, b), aa <= bb); | |
762 %!assert (bsxfun (@gt, a, b), aa > bb); | |
763 %!assert (bsxfun (@ge, a, b), aa >= bb); | |
764 %!assert (bsxfun (@min, a, b), min (aa, bb)); | |
765 %!assert (bsxfun (@max, a, b), max (aa, bb)); | |
766 %!assert (bsxfun (@and, a > 0, b > 0), (aa > 0) & (bb > 0)); | |
767 %!assert (bsxfun (@or, a > 0, b > 0), (aa > 0) | (bb > 0)); | |
6869 | 768 */ |