Mercurial > hg > octave-nkf
annotate src/ops.h @ 12583:bb29b58e650c release-3-4-x
abandon release-3-4-x branch in favor of workflow using stable and default branches and merging stable to default periodically
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 08 Apr 2011 09:06:04 -0400 |
parents | fd0a3ac60b0e |
children | 72c96de7a403 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 John W. Eaton |
9601
a9b37bae1802
add a couple of missing copyright statements
Jaroslav Hajek <highegg@gmail.com>
parents:
9588
diff
changeset
|
4 Copyright (C) 2009 VZLU Prague, a.s. |
2376 | 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. | |
2376 | 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/>. | |
2376 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_ops_h) | |
25 #define octave_ops_h 1 | |
26 | |
4669 | 27 #include "Array-util.h" |
28 | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
29 // Concatenation macros that enforce argument prescan |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
30 #define CONCAT2X(x,y) x ## y |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
31 #define CONCAT2(x,y) CONCAT2X(x,y) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
32 |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
33 #define CONCAT3X(x,y,z) x ## y ## z |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
34 #define CONCAT3(x,y,z) CONCAT3X(x,y,z) |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
35 |
2376 | 36 extern void install_ops (void); |
37 | |
3203 | 38 #define INSTALL_UNOP(op, t, f) \ |
39 octave_value_typeinfo::register_unary_op \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
40 (octave_value::op, t::static_type_id (), CONCAT2(oct_unop_, f)); |
3203 | 41 |
42 #define INSTALL_NCUNOP(op, t, f) \ | |
43 octave_value_typeinfo::register_non_const_unary_op \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
44 (octave_value::op, t::static_type_id (), CONCAT2(oct_unop_, f)); |
3203 | 45 |
2376 | 46 #define INSTALL_BINOP(op, t1, t2, f) \ |
47 octave_value_typeinfo::register_binary_op \ | |
3203 | 48 (octave_value::op, t1::static_type_id (), t2::static_type_id (), \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
49 CONCAT2(oct_binop_, f)); |
2376 | 50 |
4915 | 51 #define INSTALL_CATOP(t1, t2, f) \ |
52 octave_value_typeinfo::register_cat_op \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
53 (t1::static_type_id (), t2::static_type_id (), CONCAT2(oct_catop_, f)); |
4915 | 54 |
2879 | 55 #define INSTALL_ASSIGNOP(op, t1, t2, f) \ |
2376 | 56 octave_value_typeinfo::register_assign_op \ |
3203 | 57 (octave_value::op, t1::static_type_id (), t2::static_type_id (), \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
58 CONCAT2(oct_assignop_, f)); |
2376 | 59 |
3195 | 60 #define INSTALL_ASSIGNANYOP(op, t1, f) \ |
61 octave_value_typeinfo::register_assignany_op \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
62 (octave_value::op, t1::static_type_id (), CONCAT2(oct_assignop_, f)); |
3195 | 63 |
2376 | 64 #define INSTALL_ASSIGNCONV(t1, t2, tr) \ |
65 octave_value_typeinfo::register_pref_assign_conv \ | |
66 (t1::static_type_id (), t2::static_type_id (), tr::static_type_id ()); | |
67 | |
4901 | 68 #define INSTALL_CONVOP(t1, t2, f) \ |
69 octave_value_typeinfo::register_type_conv_op \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
70 (t1::static_type_id (), t2::static_type_id (), CONCAT2(oct_conv_, f)); |
4901 | 71 |
2376 | 72 #define INSTALL_WIDENOP(t1, t2, f) \ |
73 octave_value_typeinfo::register_widening_op \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
74 (t1::static_type_id (), t2::static_type_id (), CONCAT2(oct_conv_, f)); |
2376 | 75 |
3203 | 76 #define CAST_UNOP_ARG(t) \ |
5760 | 77 t v = dynamic_cast<t> (a) |
3203 | 78 |
2376 | 79 #define CAST_BINOP_ARGS(t1, t2) \ |
10313 | 80 t1 v1 = dynamic_cast<t1> (a1); \ |
5760 | 81 t2 v2 = dynamic_cast<t2> (a2) |
2376 | 82 |
83 #define CAST_CONV_ARG(t) \ | |
5760 | 84 t v = dynamic_cast<t> (a) |
2376 | 85 |
2914 | 86 #define ASSIGNOPDECL(name) \ |
87 static octave_value \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
88 CONCAT2(oct_assignop_, name) (octave_base_value& a1, \ |
10313 | 89 const octave_value_list& idx, \ |
90 const octave_base_value& a2) | |
5759 | 91 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7997
diff
changeset
|
92 #define NULLASSIGNOPDECL(name) \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7997
diff
changeset
|
93 static octave_value \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
94 CONCAT2(oct_assignop_, name) (octave_base_value& a, \ |
10313 | 95 const octave_value_list& idx, \ |
96 const octave_base_value&) | |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7997
diff
changeset
|
97 |
5759 | 98 #define ASSIGNANYOPDECL(name) \ |
99 static octave_value \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
100 CONCAT2(oct_assignop_, name) (octave_base_value& a1, \ |
10313 | 101 const octave_value_list& idx, \ |
102 const octave_value& a2) | |
2914 | 103 |
104 #define DEFASSIGNOP(name, t1, t2) \ | |
105 ASSIGNOPDECL (name) | |
106 | |
107 #define DEFASSIGNOP_FN(name, t1, t2, f) \ | |
108 ASSIGNOPDECL (name) \ | |
109 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
110 CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
2914 | 111 \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
112 v1.f (idx, v2.CONCAT2(t1, _value) ()); \ |
2914 | 113 return octave_value (); \ |
114 } | |
115 | |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7997
diff
changeset
|
116 #define DEFNULLASSIGNOP_FN(name, t, f) \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7997
diff
changeset
|
117 NULLASSIGNOPDECL (name) \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7997
diff
changeset
|
118 { \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
119 CAST_UNOP_ARG (CONCAT2(octave_, t)&); \ |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7997
diff
changeset
|
120 \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7997
diff
changeset
|
121 v.f (idx); \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7997
diff
changeset
|
122 return octave_value (); \ |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7997
diff
changeset
|
123 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7997
diff
changeset
|
124 |
4686 | 125 #define DEFNDASSIGNOP_FN(name, t1, t2, e, f) \ |
126 ASSIGNOPDECL (name) \ | |
127 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
128 CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
4686 | 129 \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
130 v1.f (idx, v2.CONCAT2(e, _value) ()); \ |
4686 | 131 return octave_value (); \ |
132 } | |
133 | |
9548
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
134 // FIXME: the following currently don't handle index. |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
135 #define DEFNDASSIGNOP_OP(name, t1, t2, f, op) \ |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
136 ASSIGNOPDECL (name) \ |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
137 { \ |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
138 CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
139 \ |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
140 assert (idx.empty ()); \ |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
141 v1.matrix_ref () op v2.CONCAT2(f, _value) (); \ |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
142 \ |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
143 return octave_value (); \ |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
144 } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
145 |
9548
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
146 #define DEFNDASSIGNOP_FNOP(name, t1, t2, f, fnop) \ |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
147 ASSIGNOPDECL (name) \ |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
148 { \ |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
149 CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
150 \ |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
151 assert (idx.empty ()); \ |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
152 fnop (v1.matrix_ref (), v2.CONCAT2(f, _value) ()); \ |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
153 \ |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
154 return octave_value (); \ |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
155 } |
e5f7aee2ab8c
optimize &=, |= operators
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
156 |
3195 | 157 #define DEFASSIGNANYOP_FN(name, t1, f) \ |
5759 | 158 ASSIGNANYOPDECL (name) \ |
3195 | 159 { \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
160 CONCAT2(octave_, t1)& v1 = dynamic_cast<CONCAT2(octave_, t1)&> (a1); \ |
3195 | 161 \ |
162 v1.f (idx, a2); \ | |
163 return octave_value (); \ | |
164 } | |
165 | |
2914 | 166 #define CONVDECL(name) \ |
5759 | 167 static octave_base_value * \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
168 CONCAT2(oct_conv_, name) (const octave_base_value& a) |
3203 | 169 |
170 #define CONVDECLX(name) \ | |
5759 | 171 static octave_base_value * \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
172 CONCAT2(oct_conv_, name) (const octave_base_value&) |
2914 | 173 |
4901 | 174 #define DEFCONV(name, a_dummy, b_dummy) \ |
2914 | 175 CONVDECL (name) |
176 | |
4901 | 177 #define DEFCONVFNX(name, tfrom, ovtto, tto, e) \ |
178 CONVDECL (name) \ | |
179 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
180 CAST_CONV_ARG (const CONCAT2(octave_, tfrom)&); \ |
4901 | 181 \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
182 return new CONCAT2(octave_, ovtto) (CONCAT2(tto, NDArray) (v.CONCAT2(e, array_value) ())); \ |
4901 | 183 } |
184 | |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
185 #define DEFCONVFNX2(name, tfrom, ovtto, e) \ |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
186 CONVDECL (name) \ |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
187 { \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
188 CAST_CONV_ARG (const CONCAT2(octave_, tfrom)&); \ |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
189 \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
190 return new CONCAT2(octave_, ovtto) (v.CONCAT2(e, array_value) ()); \ |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
191 } |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7922
diff
changeset
|
192 |
4901 | 193 #define DEFDBLCONVFN(name, ovtfrom, e) \ |
194 CONVDECL (name) \ | |
195 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
196 CAST_CONV_ARG (const CONCAT2(octave_, ovtfrom)&); \ |
4901 | 197 \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
198 return new octave_matrix (NDArray (v.CONCAT2(e, _value) ())); \ |
4901 | 199 } |
200 | |
8852 | 201 #define DEFFLTCONVFN(name, ovtfrom, e) \ |
202 CONVDECL (name) \ | |
203 { \ | |
204 CAST_CONV_ARG (const CONCAT2(octave_, ovtfrom)&); \ | |
205 \ | |
206 return new octave_float_matrix (FloatNDArray (v.CONCAT2(e, _value) ())); \ | |
207 } | |
208 | |
5032 | 209 #define DEFSTRINTCONVFN(name, tto) \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
210 DEFCONVFNX(name, char_matrix_str, CONCAT2(tto, _matrix), tto, char_) |
5032 | 211 |
5992 | 212 #define DEFSTRDBLCONVFN(name, tfrom) \ |
213 DEFCONVFNX(name, tfrom, matrix, , char_) | |
5032 | 214 |
8852 | 215 #define DEFSTRFLTCONVFN(name, tfrom) \ |
216 DEFCONVFNX(name, tfrom, float_matrix, Float, char_) | |
217 | |
4901 | 218 #define DEFCONVFN(name, tfrom, tto) \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
219 DEFCONVFNX2 (name, tfrom, CONCAT2(tto, _matrix), CONCAT2(tto, _)) |
4901 | 220 |
221 #define DEFCONVFN2(name, tfrom, sm, tto) \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
222 DEFCONVFNX2 (name, CONCAT3(tfrom, _, sm), CONCAT2(tto, _matrix), CONCAT2(tto, _)) |
4901 | 223 |
3203 | 224 #define UNOPDECL(name, a) \ |
225 static octave_value \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
226 CONCAT2(oct_unop_, name) (const octave_base_value& a) |
3203 | 227 |
228 #define DEFUNOPX(name, t) \ | |
229 UNOPDECL (name, , ) | |
230 | |
231 #define DEFUNOP(name, t) \ | |
232 UNOPDECL (name, a) | |
233 | |
234 #define DEFUNOP_OP(name, t, op) \ | |
235 UNOPDECL (name, a) \ | |
236 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
237 CAST_UNOP_ARG (const CONCAT2(octave_, t)&); \ |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
238 return octave_value (op v.CONCAT2(t, _value) ()); \ |
3203 | 239 } |
240 | |
4550 | 241 #define DEFNDUNOP_OP(name, t, e, op) \ |
4543 | 242 UNOPDECL (name, a) \ |
243 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
244 CAST_UNOP_ARG (const CONCAT2(octave_, t)&); \ |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
245 return octave_value (op v.CONCAT2(e, _value) ()); \ |
4543 | 246 } |
247 | |
5775 | 248 // FIXME -- in some cases, the constructor isn't necessary. |
3203 | 249 |
250 #define DEFUNOP_FN(name, t, f) \ | |
251 UNOPDECL (name, a) \ | |
252 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
253 CAST_UNOP_ARG (const CONCAT2(octave_, t)&); \ |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
254 return octave_value (f (v.CONCAT2(t, _value) ())); \ |
3203 | 255 } |
256 | |
4550 | 257 #define DEFNDUNOP_FN(name, t, e, f) \ |
4543 | 258 UNOPDECL (name, a) \ |
259 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
260 CAST_UNOP_ARG (const CONCAT2(octave_, t)&); \ |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
261 return octave_value (f (v.CONCAT2(e, _value) ())); \ |
4543 | 262 } |
263 | |
3203 | 264 #define DEFNCUNOP_METHOD(name, t, method) \ |
265 static void \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
266 CONCAT2(oct_unop_, name) (octave_base_value& a) \ |
3203 | 267 { \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
268 CAST_UNOP_ARG (CONCAT2(octave_, t)&); \ |
3203 | 269 v.method (); \ |
270 } | |
271 | |
2914 | 272 #define BINOPDECL(name, a1, a2) \ |
273 static octave_value \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
274 CONCAT2(oct_binop_, name) (const octave_base_value& a1, const octave_base_value& a2) |
2914 | 275 |
276 #define DEFBINOPX(name, t1, t2) \ | |
277 BINOPDECL (name, , ) | |
278 | |
279 #define DEFBINOP(name, t1, t2) \ | |
280 BINOPDECL (name, a1, a2) | |
281 | |
282 #define DEFBINOP_OP(name, t1, t2, op) \ | |
283 BINOPDECL (name, a1, a2) \ | |
284 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
285 CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
2914 | 286 return octave_value \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
287 (v1.CONCAT2(t1, _value) () op v2.CONCAT2(t2, _value) ()); \ |
2914 | 288 } |
289 | |
9588
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
290 #define DEFCMPLXCMPOP_OP(name, t1, t2, op) \ |
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
291 BINOPDECL (name, a1, a2) \ |
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
292 { \ |
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
293 CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
294 gripe_warn_complex_cmp (); \ |
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
295 return octave_value \ |
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
296 (v1.CONCAT2(t1, _value) () op v2.CONCAT2(t2, _value) ()); \ |
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
297 } |
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
298 |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
299 #define DEFSCALARBOOLOP_OP(name, t1, t2, op) \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
300 BINOPDECL (name, a1, a2) \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
301 { \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
302 CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
303 if (xisnan (v1.CONCAT2(t1, _value) ()) || xisnan (v2.CONCAT2(t2, _value) ())) \ |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
304 { \ |
11129
0de5cc44e690
use gripe functions for NaN to logical and NaN to character conversions more consistently
John W. Eaton <jwe@octave.org>
parents:
10313
diff
changeset
|
305 gripe_nan_to_logical_conversion (); \ |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
306 return octave_value (); \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
307 } \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
308 else \ |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
309 return octave_value \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
310 (v1.CONCAT2(t1, _value) () op v2.CONCAT2(t2, _value) ()); \ |
7922
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
311 } |
935be827eaf8
error for NaN values in & and | expressions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
312 |
4543 | 313 #define DEFNDBINOP_OP(name, t1, t2, e1, e2, op) \ |
314 BINOPDECL (name, a1, a2) \ | |
315 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
316 CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
4543 | 317 return octave_value \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
318 (v1.CONCAT2(e1, _value) () op v2.CONCAT2(e2, _value) ()); \ |
4543 | 319 } |
320 | |
5775 | 321 // FIXME -- in some cases, the constructor isn't necessary. |
2914 | 322 |
323 #define DEFBINOP_FN(name, t1, t2, f) \ | |
324 BINOPDECL (name, a1, a2) \ | |
325 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
326 CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
327 return octave_value (f (v1.CONCAT2(t1, _value) (), v2.CONCAT2(t2, _value) ())); \ |
2914 | 328 } |
329 | |
4543 | 330 #define DEFNDBINOP_FN(name, t1, t2, e1, e2, f) \ |
331 BINOPDECL (name, a1, a2) \ | |
332 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
333 CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
334 return octave_value (f (v1.CONCAT2(e1, _value) (), v2.CONCAT2(e2, _value) ())); \ |
4543 | 335 } |
336 | |
9588
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
337 #define DEFNDCMPLXCMPOP_FN(name, t1, t2, e1, e2, f) \ |
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
338 BINOPDECL (name, a1, a2) \ |
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
339 { \ |
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
340 CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
341 return octave_value (f (v1.CONCAT2(e1, _value) (), v2.CONCAT2(e2, _value) ())); \ |
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
342 } |
319e2ab9b8ae
warn about the complex comparison ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9587
diff
changeset
|
343 |
2914 | 344 #define BINOP_NONCONFORMANT(msg) \ |
345 gripe_nonconformant (msg, \ | |
10313 | 346 a1.rows (), a1.columns (), \ |
347 a2.rows (), a2.columns ()); \ | |
2914 | 348 return octave_value () |
349 | |
10313 | 350 #define CATOPDECL(name, a1, a2) \ |
4915 | 351 static octave_value \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
352 CONCAT2(oct_catop_, name) (octave_base_value& a1, const octave_base_value& a2, \ |
10313 | 353 const Array<octave_idx_type>& ra_idx) |
4915 | 354 |
10313 | 355 #define DEFCATOPX(name, t1, t2) \ |
4915 | 356 CATOPDECL (name, , ) |
357 | |
10313 | 358 #define DEFCATOP(name, t1, t2) \ |
4915 | 359 CATOPDECL (name, a1, a2) |
360 | |
5775 | 361 // FIXME -- in some cases, the constructor isn't necessary. |
4915 | 362 |
363 #define DEFCATOP_FN(name, t1, t2, f) \ | |
5075 | 364 CATOPDECL (name, a1, a2) \ |
4915 | 365 { \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
366 CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
367 return octave_value (v1.CONCAT2(t1, _value) () . f (v2.CONCAT2(t2, _value) (), ra_idx)); \ |
4915 | 368 } |
369 | |
5075 | 370 #define DEFNDCATOP_FN(name, t1, t2, e1, e2, f) \ |
371 CATOPDECL (name, a1, a2) \ | |
4915 | 372 { \ |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
373 CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
374 return octave_value (v1.CONCAT2(e1, _value) () . f (v2.CONCAT2(e2, _value) (), ra_idx)); \ |
5533 | 375 } |
376 | |
377 #define DEFNDCHARCATOP_FN(name, t1, t2, f) \ | |
378 CATOPDECL (name, a1, a2) \ | |
379 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
380 CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
5533 | 381 \ |
382 return octave_value (v1.char_array_value () . f (v2.char_array_value (), ra_idx), \ | |
10313 | 383 ((a1.is_sq_string () || a2.is_sq_string ()) \ |
384 ? '\'' : '"')); \ | |
4915 | 385 } |
386 | |
5075 | 387 // For compatibility, the second arg is always converted to the type |
388 // of the first. Hmm. | |
389 | |
390 #define DEFNDCATOP_FN2(name, t1, t2, tc1, tc2, e1, e2, f) \ | |
391 CATOPDECL (name, a1, a2) \ | |
392 { \ | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
393 CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \ |
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
394 return octave_value (tc1 (v1.CONCAT2(e1, _value) ()) . f (tc2 (v2.CONCAT2(e2, _value) ()), ra_idx)); \ |
5075 | 395 } |
396 | |
4915 | 397 #define CATOP_NONCONFORMANT(msg) \ |
398 gripe_nonconformant (msg, \ | |
10313 | 399 a1.rows (), a1.columns (), \ |
400 a2.rows (), a2.columns ()); \ | |
4915 | 401 return octave_value () |
402 | |
2376 | 403 #endif |