26 #if defined (HAVE_CONFIG_H)
86 bsxfun_builtin_lookup (
const std::string& name)
101 template <
typename NDA, NDA (bsxfun_op) (const NDA&, const NDA&)>
105 NDA xa = octave_value_extract<NDA> (
x);
106 NDA ya = octave_value_extract<NDA> (y);
110 template <
typename NDA,
boolNDArray (bsxfun_rel) (const NDA&, const NDA&)>
114 NDA xa = octave_value_extract<NDA> (
x);
115 NDA ya = octave_value_extract<NDA> (y);
121 template <
typename NDA,
typename CNDA>
125 NDA xa = octave_value_extract<NDA> (
x);
126 NDA ya = octave_value_extract<NDA> (y);
127 if (! ya.all_integers () && xa.any_element_is_negative ())
136 static bool filled =
false;
140 #define REGISTER_OP_HANDLER(OP, BTYP, NDA, FUNOP) \
141 bsxfun_handler_table[OP][BTYP] = bsxfun_forward_op<NDA, FUNOP>
143 #define REGISTER_REL_HANDLER(REL, BTYP, NDA, FUNREL) \
144 bsxfun_handler_table[REL][BTYP] = bsxfun_forward_rel<NDA, FUNREL>
146 #define REGISTER_STD_HANDLERS(BTYP, NDA) \
147 REGISTER_OP_HANDLER (bsxfun_builtin_plus, BTYP, NDA, bsxfun_add); \
148 REGISTER_OP_HANDLER (bsxfun_builtin_minus, BTYP, NDA, bsxfun_sub); \
149 REGISTER_OP_HANDLER (bsxfun_builtin_times, BTYP, NDA, bsxfun_mul); \
150 REGISTER_OP_HANDLER (bsxfun_builtin_divide, BTYP, NDA, bsxfun_div); \
151 REGISTER_OP_HANDLER (bsxfun_builtin_max, BTYP, NDA, bsxfun_max); \
152 REGISTER_OP_HANDLER (bsxfun_builtin_min, BTYP, NDA, bsxfun_min); \
153 REGISTER_REL_HANDLER (bsxfun_builtin_eq, BTYP, NDA, bsxfun_eq); \
154 REGISTER_REL_HANDLER (bsxfun_builtin_ne, BTYP, NDA, bsxfun_ne); \
155 REGISTER_REL_HANDLER (bsxfun_builtin_lt, BTYP, NDA, bsxfun_lt); \
156 REGISTER_REL_HANDLER (bsxfun_builtin_le, BTYP, NDA, bsxfun_le); \
157 REGISTER_REL_HANDLER (bsxfun_builtin_gt, BTYP, NDA, bsxfun_gt); \
158 REGISTER_REL_HANDLER (bsxfun_builtin_ge, BTYP, NDA, bsxfun_ge)
179 = do_bsxfun_real_pow<NDArray, ComplexNDArray>;
181 = do_bsxfun_real_pow<FloatNDArray, FloatComplexNDArray>;
200 maybe_optimized_builtin (
const std::string& name,
227 retval = handler (a, b);
260 bool is_changed =
false;
265 if (dva(j) != 1 && k % dvc(j) != k1 % dvc(j))
319 if (args.length () != 3)
332 error (
"bsxfun: invalid function name: %s", name.c_str ());
334 else if (! (args(0).is_function_handle () || args(0).is_inline_function ()))
335 error (
"bsxfun: F must be a string or function handle");
375 if (dva(i) != dvb(i) && dva(i) != 1 && dvb(i) != 1)
376 error (
"bsxfun: dimensions of A and B must match");
383 dvc(i) = (dva(i) < 1 ? dva(i)
384 : (dvb(i) < 1 ? dvb(i)
385 : (dva(i) > dvb(i) ? dva(i)
388 if (dva == dvb || dva.
numel () == 1 || dvb.
numel () == 1)
393 retval = interp.feval (fcn, inputs, 1);
395 else if (dvc.
numel () < 1)
398 inputs(0) =
A.resize (dvc);
399 inputs(1) =
B.resize (dvc);
400 retval = interp.feval (fcn, inputs, 1);
410 bool have_ ## T = false;
436 if (maybe_update_column (Ac,
A, dva, dvc, i, idxA))
439 if (maybe_update_column (Bc,
B, dvb, dvc, i, idxB))
444 #define BSXINIT(T, CLS, EXTRACTOR) \
445 (result_type == CLS) \
448 result_ ## T = tmp(0). EXTRACTOR ## _array_value (); \
449 result_ ## T .resize (dvc); \
454 if (! tmp(0).issparse ())
456 std::string result_type = tmp(0).class_name ();
457 if (result_type ==
"double")
459 if (tmp(0).isreal ())
463 result_NDArray.
resize (dvc);
467 have_ComplexNDArray =
true;
468 result_ComplexNDArray
469 = tmp(0).complex_array_value ();
470 result_ComplexNDArray.
resize (dvc);
473 else if (result_type ==
"single")
475 if (tmp(0).isreal ())
477 have_FloatNDArray =
true;
479 = tmp(0).float_array_value ();
480 result_FloatNDArray.
resize (dvc);
484 have_FloatComplexNDArray =
true;
485 result_FloatComplexNDArray
486 = tmp(0).float_complex_array_value ();
487 result_FloatComplexNDArray.
resize (dvc);
513 update_index (
ra_idx, dvc, i);
517 if (! tmp(0).isfloat ())
519 have_NDArray =
false;
523 else if (tmp(0).isreal ())
524 result_NDArray.insert (tmp(0).array_value (),
ra_idx);
527 result_ComplexNDArray
529 result_ComplexNDArray.insert
530 (tmp(0).complex_array_value (),
ra_idx);
531 have_NDArray =
false;
532 have_ComplexNDArray =
true;
535 else if (have_FloatNDArray)
537 if (! tmp(0).isfloat ())
539 have_FloatNDArray =
false;
540 C = result_FloatNDArray;
543 else if (tmp(0).isreal ())
544 result_FloatNDArray.insert
545 (tmp(0).float_array_value (),
ra_idx);
548 result_FloatComplexNDArray
550 result_FloatComplexNDArray.insert
551 (tmp(0).float_complex_array_value (),
ra_idx);
552 have_FloatNDArray =
false;
553 have_FloatComplexNDArray =
true;
557 #define BSXLOOP(T, CLS, EXTRACTOR) \
560 if (tmp(0).class_name () != CLS) \
562 have_ ## T = false; \
564 C = cat_op (C, tmp(0), ra_idx); \
567 result_ ## T .insert (tmp(0). EXTRACTOR ## _array_value (), ra_idx); \
588 retval(0) = result_ ## T;
823 OCTAVE_END_NAMESPACE(
octave)
ComplexNDArray bsxfun_pow(const ComplexNDArray &x, const ComplexNDArray &y)
boolNDArray bsxfun_or(const boolNDArray &x, const boolNDArray &y)
boolNDArray bsxfun_and(const boolNDArray &x, const boolNDArray &y)
#define REGISTER_STD_HANDLERS(BTYP, NDA)
bsxfun_handler bsxfun_handler_table[bsxfun_num_builtin_ops][btyp_num_types]
#define BSXINIT(T, CLS, EXTRACTOR)
const char * bsxfun_builtin_names[]
#define REGISTER_REL_HANDLER(REL, BTYP, NDA, FUNREL)
#define BSXLOOP(T, CLS, EXTRACTOR)
octave_value(* bsxfun_handler)(const octave_value &, const octave_value &)
#define REGISTER_OP_HANDLER(OP, BTYP, NDA, FUNOP)
boolNDArray bsxfun_ge(const charNDArray &x, const charNDArray &y)
boolNDArray bsxfun_lt(const charNDArray &x, const charNDArray &y)
boolNDArray bsxfun_gt(const charNDArray &x, const charNDArray &y)
boolNDArray bsxfun_eq(const charNDArray &x, const charNDArray &y)
boolNDArray bsxfun_le(const charNDArray &x, const charNDArray &y)
boolNDArray bsxfun_ne(const charNDArray &x, const charNDArray &y)
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Vector representing the dimensions (size) of an Array.
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
void resize(int n, int fill_value=0)
octave_idx_type ndims() const
Number of dimensions.
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Array< octave_value > array_value() const
bool is_function_handle() const
bool is_undefined() const
octave_function * function_value(bool silent=false) const
std::string string_value(bool force=false) const
octave_value single_subsref(const std::string &type, const octave_value_list &idx)
bool is_builtin_function() const
builtin_type_t builtin_type() const
octave_value find_function(const std::string &name, const symbol_scope &search_scope=symbol_scope::invalid())
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
void() error(const char *fmt,...)
F77_RET_T const F77_INT F77_CMPLX const F77_INT F77_CMPLX * B
F77_RET_T const F77_INT F77_CMPLX * A
F77_RET_T const F77_DBLE * x
const octave_base_value const Array< octave_idx_type > & ra_idx
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value cat_op(type_info &ti, const octave_value &a, const octave_value &b, const Array< octave_idx_type > &ra_idx)