/usr/include/octave-4.0.0/octave/ops.h is in liboctave-dev 4.0.0-3ubuntu9.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | /*
Copyright (C) 1996-2015 John W. Eaton
Copyright (C) 2009 VZLU Prague, a.s.
This file is part of Octave.
Octave is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.
Octave is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with Octave; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
#if !defined (octave_ops_h)
#define octave_ops_h 1
#include "Array-util.h"
// Concatenation macros that enforce argument prescan
#define CONCAT2X(x,y) x ## y
#define CONCAT2(x,y) CONCAT2X(x,y)
#define CONCAT3X(x,y,z) x ## y ## z
#define CONCAT3(x,y,z) CONCAT3X(x,y,z)
extern void install_ops (void);
#define INSTALL_UNOP(op, t, f) \
octave_value_typeinfo::register_unary_op \
(octave_value::op, t::static_type_id (), CONCAT2(oct_unop_, f));
#define INSTALL_NCUNOP(op, t, f) \
octave_value_typeinfo::register_non_const_unary_op \
(octave_value::op, t::static_type_id (), CONCAT2(oct_unop_, f));
#define INSTALL_BINOP(op, t1, t2, f) \
octave_value_typeinfo::register_binary_op \
(octave_value::op, t1::static_type_id (), t2::static_type_id (), \
CONCAT2(oct_binop_, f));
#define INSTALL_CATOP(t1, t2, f) \
octave_value_typeinfo::register_cat_op \
(t1::static_type_id (), t2::static_type_id (), CONCAT2(oct_catop_, f));
#define INSTALL_ASSIGNOP(op, t1, t2, f) \
octave_value_typeinfo::register_assign_op \
(octave_value::op, t1::static_type_id (), t2::static_type_id (), \
CONCAT2(oct_assignop_, f));
#define INSTALL_ASSIGNANYOP(op, t1, f) \
octave_value_typeinfo::register_assignany_op \
(octave_value::op, t1::static_type_id (), CONCAT2(oct_assignop_, f));
#define INSTALL_ASSIGNCONV(t1, t2, tr) \
octave_value_typeinfo::register_pref_assign_conv \
(t1::static_type_id (), t2::static_type_id (), tr::static_type_id ());
#define INSTALL_CONVOP(t1, t2, f) \
octave_value_typeinfo::register_type_conv_op \
(t1::static_type_id (), t2::static_type_id (), CONCAT2(oct_conv_, f));
#define INSTALL_WIDENOP(t1, t2, f) \
octave_value_typeinfo::register_widening_op \
(t1::static_type_id (), t2::static_type_id (), CONCAT2(oct_conv_, f));
#define CAST_UNOP_ARG(t) \
t v = dynamic_cast<t> (a)
#define CAST_BINOP_ARGS(t1, t2) \
t1 v1 = dynamic_cast<t1> (a1); \
t2 v2 = dynamic_cast<t2> (a2)
#define CAST_CONV_ARG(t) \
t v = dynamic_cast<t> (a)
#define ASSIGNOPDECL(name) \
static octave_value \
CONCAT2(oct_assignop_, name) (octave_base_value& a1, \
const octave_value_list& idx, \
const octave_base_value& a2)
#define NULLASSIGNOPDECL(name) \
static octave_value \
CONCAT2(oct_assignop_, name) (octave_base_value& a, \
const octave_value_list& idx, \
const octave_base_value&)
#define ASSIGNANYOPDECL(name) \
static octave_value \
CONCAT2(oct_assignop_, name) (octave_base_value& a1, \
const octave_value_list& idx, \
const octave_value& a2)
#define DEFASSIGNOP(name, t1, t2) \
ASSIGNOPDECL (name)
#define DEFASSIGNOP_FN(name, t1, t2, f) \
ASSIGNOPDECL (name) \
{ \
CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
\
v1.f (idx, v2.CONCAT2(t1, _value) ()); \
return octave_value (); \
}
#define DEFNULLASSIGNOP_FN(name, t, f) \
NULLASSIGNOPDECL (name) \
{ \
CAST_UNOP_ARG (CONCAT2(octave_, t)&); \
\
v.f (idx); \
return octave_value (); \
}
#define DEFNDASSIGNOP_FN(name, t1, t2, e, f) \
ASSIGNOPDECL (name) \
{ \
CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
\
v1.f (idx, v2.CONCAT2(e, _value) ()); \
return octave_value (); \
}
// FIXME: the following currently don't handle index.
#define DEFNDASSIGNOP_OP(name, t1, t2, f, op) \
ASSIGNOPDECL (name) \
{ \
CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
\
assert (idx.empty ()); \
v1.matrix_ref () op v2.CONCAT2(f, _value) (); \
\
return octave_value (); \
}
#define DEFNDASSIGNOP_FNOP(name, t1, t2, f, fnop) \
ASSIGNOPDECL (name) \
{ \
CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
\
assert (idx.empty ()); \
fnop (v1.matrix_ref (), v2.CONCAT2(f, _value) ()); \
\
return octave_value (); \
}
#define DEFASSIGNANYOP_FN(name, t1, f) \
ASSIGNANYOPDECL (name) \
{ \
CONCAT2(octave_, t1)& v1 = dynamic_cast<CONCAT2(octave_, t1)&> (a1); \
\
v1.f (idx, a2); \
return octave_value (); \
}
#define CONVDECL(name) \
static octave_base_value * \
CONCAT2(oct_conv_, name) (const octave_base_value& a)
#define CONVDECLX(name) \
static octave_base_value * \
CONCAT2(oct_conv_, name) (const octave_base_value&)
#define DEFCONV(name, a_dummy, b_dummy) \
CONVDECL (name)
#define DEFCONVFNX(name, tfrom, ovtto, tto, e) \
CONVDECL (name) \
{ \
CAST_CONV_ARG (const CONCAT2(octave_, tfrom)&); \
\
return new CONCAT2(octave_, ovtto) (CONCAT2(tto, NDArray) (v.CONCAT2(e, array_value) ())); \
}
#define DEFCONVFNX2(name, tfrom, ovtto, e) \
CONVDECL (name) \
{ \
CAST_CONV_ARG (const CONCAT2(octave_, tfrom)&); \
\
return new CONCAT2(octave_, ovtto) (v.CONCAT2(e, array_value) ()); \
}
#define DEFDBLCONVFN(name, ovtfrom, e) \
CONVDECL (name) \
{ \
CAST_CONV_ARG (const CONCAT2(octave_, ovtfrom)&); \
\
return new octave_matrix (NDArray (v.CONCAT2(e, _value) ())); \
}
#define DEFFLTCONVFN(name, ovtfrom, e) \
CONVDECL (name) \
{ \
CAST_CONV_ARG (const CONCAT2(octave_, ovtfrom)&); \
\
return new octave_float_matrix (FloatNDArray (v.CONCAT2(e, _value) ())); \
}
#define DEFSTRINTCONVFN(name, tto) \
DEFCONVFNX(name, char_matrix_str, CONCAT2(tto, _matrix), tto, char_)
#define DEFSTRDBLCONVFN(name, tfrom) \
DEFCONVFNX(name, tfrom, matrix, , char_)
#define DEFSTRFLTCONVFN(name, tfrom) \
DEFCONVFNX(name, tfrom, float_matrix, Float, char_)
#define DEFCONVFN(name, tfrom, tto) \
DEFCONVFNX2 (name, tfrom, CONCAT2(tto, _matrix), CONCAT2(tto, _))
#define DEFCONVFN2(name, tfrom, sm, tto) \
DEFCONVFNX2 (name, CONCAT3(tfrom, _, sm), CONCAT2(tto, _matrix), CONCAT2(tto, _))
#define UNOPDECL(name, a) \
static octave_value \
CONCAT2(oct_unop_, name) (const octave_base_value& a)
#define DEFUNOPX(name, t) \
UNOPDECL (name, , )
#define DEFUNOP(name, t) \
UNOPDECL (name, a)
#define DEFUNOP_OP(name, t, op) \
UNOPDECL (name, a) \
{ \
CAST_UNOP_ARG (const CONCAT2(octave_, t)&); \
return octave_value (op v.CONCAT2(t, _value) ()); \
}
#define DEFNDUNOP_OP(name, t, e, op) \
UNOPDECL (name, a) \
{ \
CAST_UNOP_ARG (const CONCAT2(octave_, t)&); \
return octave_value (op v.CONCAT2(e, _value) ()); \
}
// FIXME: in some cases, the constructor isn't necessary.
#define DEFUNOP_FN(name, t, f) \
UNOPDECL (name, a) \
{ \
CAST_UNOP_ARG (const CONCAT2(octave_, t)&); \
return octave_value (f (v.CONCAT2(t, _value) ())); \
}
#define DEFNDUNOP_FN(name, t, e, f) \
UNOPDECL (name, a) \
{ \
CAST_UNOP_ARG (const CONCAT2(octave_, t)&); \
return octave_value (f (v.CONCAT2(e, _value) ())); \
}
#define DEFNCUNOP_METHOD(name, t, method) \
static void \
CONCAT2(oct_unop_, name) (octave_base_value& a) \
{ \
CAST_UNOP_ARG (CONCAT2(octave_, t)&); \
v.method (); \
}
#define BINOPDECL(name, a1, a2) \
static octave_value \
CONCAT2(oct_binop_, name) (const octave_base_value& a1, const octave_base_value& a2)
#define DEFBINOPX(name, t1, t2) \
BINOPDECL (name, , )
#define DEFBINOP(name, t1, t2) \
BINOPDECL (name, a1, a2)
#define DEFBINOP_OP(name, t1, t2, op) \
BINOPDECL (name, a1, a2) \
{ \
CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
return octave_value \
(v1.CONCAT2(t1, _value) () op v2.CONCAT2(t2, _value) ()); \
}
#define DEFCMPLXCMPOP_OP(name, t1, t2, op) \
BINOPDECL (name, a1, a2) \
{ \
CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
gripe_warn_complex_cmp (); \
return octave_value \
(v1.CONCAT2(t1, _value) () op v2.CONCAT2(t2, _value) ()); \
}
#define DEFSCALARBOOLOP_OP(name, t1, t2, op) \
BINOPDECL (name, a1, a2) \
{ \
CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
if (xisnan (v1.CONCAT2(t1, _value) ()) || xisnan (v2.CONCAT2(t2, _value) ())) \
{ \
gripe_nan_to_logical_conversion (); \
return octave_value (); \
} \
else \
return octave_value \
(v1.CONCAT2(t1, _value) () op v2.CONCAT2(t2, _value) ()); \
}
#define DEFNDBINOP_OP(name, t1, t2, e1, e2, op) \
BINOPDECL (name, a1, a2) \
{ \
CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
return octave_value \
(v1.CONCAT2(e1, _value) () op v2.CONCAT2(e2, _value) ()); \
}
// FIXME: in some cases, the constructor isn't necessary.
#define DEFBINOP_FN(name, t1, t2, f) \
BINOPDECL (name, a1, a2) \
{ \
CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
return octave_value (f (v1.CONCAT2(t1, _value) (), v2.CONCAT2(t2, _value) ())); \
}
#define DEFNDBINOP_FN(name, t1, t2, e1, e2, f) \
BINOPDECL (name, a1, a2) \
{ \
CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
return octave_value (f (v1.CONCAT2(e1, _value) (), v2.CONCAT2(e2, _value) ())); \
}
#define DEFNDCMPLXCMPOP_FN(name, t1, t2, e1, e2, f) \
BINOPDECL (name, a1, a2) \
{ \
CAST_BINOP_ARGS (const CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
return octave_value (f (v1.CONCAT2(e1, _value) (), v2.CONCAT2(e2, _value) ())); \
}
#define CATOPDECL(name, a1, a2) \
static octave_value \
CONCAT2(oct_catop_, name) (octave_base_value& a1, const octave_base_value& a2, \
const Array<octave_idx_type>& ra_idx)
#define DEFCATOPX(name, t1, t2) \
CATOPDECL (name, , )
#define DEFCATOP(name, t1, t2) \
CATOPDECL (name, a1, a2)
// FIXME: in some cases, the constructor isn't necessary.
#define DEFCATOP_FN(name, t1, t2, f) \
CATOPDECL (name, a1, a2) \
{ \
CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
return octave_value (v1.CONCAT2(t1, _value) () . f (v2.CONCAT2(t2, _value) (), ra_idx)); \
}
#define DEFNDCATOP_FN(name, t1, t2, e1, e2, f) \
CATOPDECL (name, a1, a2) \
{ \
CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
return octave_value (v1.CONCAT2(e1, _value) () . f (v2.CONCAT2(e2, _value) (), ra_idx)); \
}
#define DEFNDCHARCATOP_FN(name, t1, t2, f) \
CATOPDECL (name, a1, a2) \
{ \
CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
\
return octave_value (v1.char_array_value () . f (v2.char_array_value (), ra_idx), \
((a1.is_sq_string () || a2.is_sq_string ()) \
? '\'' : '"')); \
}
// For compatibility, the second arg is always converted to the type
// of the first. Hmm.
#define DEFNDCATOP_FN2(name, t1, t2, tc1, tc2, e1, e2, f) \
CATOPDECL (name, a1, a2) \
{ \
CAST_BINOP_ARGS (CONCAT2(octave_, t1)&, const CONCAT2(octave_, t2)&); \
return octave_value (tc1 (v1.CONCAT2(e1, _value) ()) . f (tc2 (v2.CONCAT2(e2, _value) ()), ra_idx)); \
}
#define CATOP_NONCONFORMANT(msg) \
gripe_nonconformant (msg, \
a1.rows (), a1.columns (), \
a2.rows (), a2.columns ()); \
return octave_value ()
#endif
|