26 #if defined (HAVE_CONFIG_H)
102 template <
typename NDA, NDA (bsxfun_op) (const NDA&, const NDA&)>
106 NDA xa = octave_value_extract<NDA> (
x);
107 NDA ya = octave_value_extract<NDA> (y);
111 template <
typename NDA,
boolNDArray (bsxfun_rel) (const NDA&, const NDA&)>
115 NDA xa = octave_value_extract<NDA> (
x);
116 NDA ya = octave_value_extract<NDA> (y);
122 template <
typename NDA,
typename CNDA>
126 NDA xa = octave_value_extract<NDA> (
x);
127 NDA ya = octave_value_extract<NDA> (y);
128 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>;
260 bool is_changed =
false;
265 if (dva(j) != 1 && k % dvc(j) != k1 % dvc(j))
341 if (args.length () != 3)
354 error (
"bsxfun: invalid function name: %s",
name.c_str ());
356 else if (! (args(0).is_function_handle () || args(0).is_inline_function ()))
357 error (
"bsxfun: F must be a string or function handle");
397 if (dva(i) != dvb(i) && dva(i) != 1 && dvb(i) != 1)
398 error (
"bsxfun: dimensions of A and B must match");
405 dvc(i) = (dva(i) < 1 ? dva(i)
406 : (dvb(i) < 1 ? dvb(i)
407 : (dva(i) > dvb(i) ? dva(i)
410 if (dva == dvb || dva.
numel () == 1 || dvb.
numel () == 1)
417 else if (dvc.
numel () < 1)
420 inputs(0) =
A.resize (dvc);
421 inputs(1) =
B.resize (dvc);
432 bool have_ ## T = false;
466 #define BSXINIT(T, CLS, EXTRACTOR) \
467 (result_type == CLS) \
470 result_ ## T = tmp(0). EXTRACTOR ## _array_value (); \
471 result_ ## T .resize (dvc); \
476 if (! tmp(0).issparse ())
478 std::string result_type = tmp(0).class_name ();
479 if (result_type ==
"double")
481 if (tmp(0).isreal ())
485 result_NDArray.
resize (dvc);
489 have_ComplexNDArray =
true;
490 result_ComplexNDArray
491 = tmp(0).complex_array_value ();
492 result_ComplexNDArray.
resize (dvc);
495 else if (result_type ==
"single")
497 if (tmp(0).isreal ())
499 have_FloatNDArray =
true;
501 = tmp(0).float_array_value ();
502 result_FloatNDArray.
resize (dvc);
506 have_FloatComplexNDArray =
true;
507 result_FloatComplexNDArray
508 = tmp(0).float_complex_array_value ();
509 result_FloatComplexNDArray.
resize (dvc);
539 if (! tmp(0).isfloat ())
541 have_NDArray =
false;
545 else if (tmp(0).isreal ())
546 result_NDArray.insert (tmp(0).array_value (),
ra_idx);
549 result_ComplexNDArray
551 result_ComplexNDArray.insert
552 (tmp(0).complex_array_value (),
ra_idx);
553 have_NDArray =
false;
554 have_ComplexNDArray =
true;
557 else if (have_FloatNDArray)
559 if (! tmp(0).isfloat ())
561 have_FloatNDArray =
false;
562 C = result_FloatNDArray;
565 else if (tmp(0).isreal ())
566 result_FloatNDArray.insert
567 (tmp(0).float_array_value (),
ra_idx);
570 result_FloatComplexNDArray
572 result_FloatComplexNDArray.insert
573 (tmp(0).float_complex_array_value (),
ra_idx);
574 have_FloatNDArray =
false;
575 have_FloatComplexNDArray =
true;
579 #define BSXLOOP(T, CLS, EXTRACTOR) \
582 if (tmp(0).class_name () != CLS) \
584 have_ ## T = false; \
586 C = do_cat_op (C, tmp(0), ra_idx); \
589 result_ ## T .insert (tmp(0). EXTRACTOR ## _array_value (), ra_idx); \
610 retval(0) = result_ ## T;
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)
static octave_value bsxfun_forward_rel(const octave_value &x, const octave_value &y)
static bool maybe_update_column(octave_value &Ac, const octave_value &A, const dim_vector &dva, const dim_vector &dvc, octave_idx_type i, octave_value_list &idx)
static octave_value bsxfun_forward_op(const octave_value &x, const octave_value &y)
#define REGISTER_STD_HANDLERS(BTYP, NDA)
static octave_value do_bsxfun_real_pow(const octave_value &x, const octave_value &y)
bsxfun_handler bsxfun_handler_table[bsxfun_num_builtin_ops][btyp_num_types]
static bsxfun_builtin_op bsxfun_builtin_lookup(const std::string &name)
#define BSXINIT(T, CLS, EXTRACTOR)
static void update_index(Array< int > &idx, const dim_vector &dv, octave_idx_type i)
const char * bsxfun_builtin_names[]
#define REGISTER_REL_HANDLER(REL, BTYP, NDA, FUNREL)
#define BSXLOOP(T, CLS, EXTRACTOR)
static octave_value maybe_optimized_builtin(const std::string &name, const octave_value &a, const octave_value &b)
octave_value(* bsxfun_handler)(const octave_value &, const octave_value &)
static void maybe_fill_table(void)
#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(void) const
Number of dimensions.
octave_value find_function(const std::string &name, const symbol_scope &search_scope=symbol_scope())
std::string name(void) const
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Array< octave_value > array_value(void) const
builtin_type_t builtin_type(void) const
bool is_builtin_function(void) const
bool is_string(void) const
bool is_defined(void) const
bool is_function_handle(void) 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_undefined(void) const
OCTINTERP_API void print_usage(void)
#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
octave_value_list feval(const char *name, const octave_value_list &args, int nargout)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
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::octave_value(const Array< char > &chm, char type) return retval
OCTINTERP_API octave_value do_cat_op(octave::type_info &ti, const octave_value &a, const octave_value &b, const Array< octave_idx_type > &ra_idx)