24 #if defined (HAVE_CONFIG_H)
98 template <
typename NDA, NDA (bsxfun_op) (const NDA&, const NDA&)>
102 NDA xa = octave_value_extract<NDA> (
x);
103 NDA ya = octave_value_extract<NDA> (
y);
107 template <
typename NDA,
boolNDArray (bsxfun_rel) (const NDA&, const NDA&)>
111 NDA xa = octave_value_extract<NDA> (
x);
112 NDA ya = octave_value_extract<NDA> (
y);
118 template <
typename NDA,
typename CNDA>
122 NDA xa = octave_value_extract<NDA> (
x);
123 NDA ya = octave_value_extract<NDA> (
y);
124 if (! ya.all_integers () && xa.any_element_is_negative ())
132 static bool filled =
false;
136 #define REGISTER_OP_HANDLER(OP, BTYP, NDA, FUNOP) \
137 bsxfun_handler_table[OP][BTYP] = bsxfun_forward_op<NDA, FUNOP>
139 #define REGISTER_REL_HANDLER(REL, BTYP, NDA, FUNREL) \
140 bsxfun_handler_table[REL][BTYP] = bsxfun_forward_rel<NDA, FUNREL>
142 #define REGISTER_STD_HANDLERS(BTYP, NDA) \
143 REGISTER_OP_HANDLER (bsxfun_builtin_plus, BTYP, NDA, bsxfun_add); \
144 REGISTER_OP_HANDLER (bsxfun_builtin_minus, BTYP, NDA, bsxfun_sub); \
145 REGISTER_OP_HANDLER (bsxfun_builtin_times, BTYP, NDA, bsxfun_mul); \
146 REGISTER_OP_HANDLER (bsxfun_builtin_divide, BTYP, NDA, bsxfun_div); \
147 REGISTER_OP_HANDLER (bsxfun_builtin_max, BTYP, NDA, bsxfun_max); \
148 REGISTER_OP_HANDLER (bsxfun_builtin_min, BTYP, NDA, bsxfun_min); \
149 REGISTER_REL_HANDLER (bsxfun_builtin_eq, BTYP, NDA, bsxfun_eq); \
150 REGISTER_REL_HANDLER (bsxfun_builtin_ne, BTYP, NDA, bsxfun_ne); \
151 REGISTER_REL_HANDLER (bsxfun_builtin_lt, BTYP, NDA, bsxfun_lt); \
152 REGISTER_REL_HANDLER (bsxfun_builtin_le, BTYP, NDA, bsxfun_le); \
153 REGISTER_REL_HANDLER (bsxfun_builtin_gt, BTYP, NDA, bsxfun_gt); \
154 REGISTER_REL_HANDLER (bsxfun_builtin_ge, BTYP, NDA, bsxfun_ge)
175 do_bsxfun_real_pow<NDArray, ComplexNDArray>;
177 do_bsxfun_real_pow<FloatNDArray, FloatComplexNDArray>;
223 retval = handler (a, b);
256 bool is_changed =
false;
261 if (dva(j) != 1 && k % dvc(j) != k1 % dvc(j))
338 if (
args.length () != 3)
347 error (
"bsxfun: invalid function name: %s", name.c_str ());
349 else if (! (
args(0).is_function_handle () ||
args(0).is_inline_function ()))
350 error (
"bsxfun: F must be a string or function handle");
390 if (dva(i) != dvb(i) && dva(i) != 1 && dvb(i) != 1)
391 error (
"bsxfun: dimensions of A and B must match");
398 dvc(i) = (dva(i) < 1 ? dva(i)
399 : (dvb(i) < 1 ? dvb(i)
401 ? dva(i) : dvb(i))));
403 if (dva == dvb || dva.
numel () == 1 || dvb.
numel () == 1)
410 else if (dvc.
numel () < 1)
413 inputs(0) = A.
resize (dvc);
414 inputs(1) = B.
resize (dvc);
425 bool have_ ## T = false;
459 #define BSXINIT(T, CLS, EXTRACTOR) \
460 (result_type == CLS) \
463 result_ ## T = tmp(0). EXTRACTOR ## _array_value (); \
464 result_ ## T .resize (dvc); \
469 if (!
tmp(0).is_sparse_type ())
472 if (result_type ==
"double")
474 if (
tmp(0).is_real_type ())
477 result_NDArray =
tmp(0).array_value ();
478 result_NDArray.resize (dvc);
482 have_ComplexNDArray =
true;
483 result_ComplexNDArray =
484 tmp(0).complex_array_value ();
485 result_ComplexNDArray.resize (dvc);
488 else if (result_type ==
"single")
490 if (
tmp(0).is_real_type ())
492 have_FloatNDArray =
true;
494 =
tmp(0).float_array_value ();
495 result_FloatNDArray.resize (dvc);
499 have_ComplexNDArray =
true;
500 result_ComplexNDArray =
501 tmp(0).complex_array_value ();
502 result_ComplexNDArray.resize (dvc);
530 if (have_FloatNDArray
531 || have_FloatComplexNDArray)
533 if (!
tmp(0).is_float_type ())
535 if (have_FloatNDArray)
537 have_FloatNDArray =
false;
538 C = result_FloatNDArray;
542 have_FloatComplexNDArray =
false;
543 C = result_FloatComplexNDArray;
547 else if (
tmp(0).is_double_type ())
549 if (
tmp(0).is_complex_type ()
550 && have_FloatNDArray)
552 result_ComplexNDArray =
554 result_ComplexNDArray.insert
555 (
tmp(0).complex_array_value (), ra_idx);
556 have_FloatComplexNDArray =
false;
557 have_ComplexNDArray =
true;
563 result_NDArray.insert
564 (
tmp(0).array_value (), ra_idx);
565 have_FloatNDArray =
false;
569 else if (
tmp(0).is_real_type ())
570 result_FloatNDArray.insert
571 (
tmp(0).float_array_value (), ra_idx);
574 result_FloatComplexNDArray =
576 result_FloatComplexNDArray.insert
577 (
tmp(0).float_complex_array_value (),
579 have_FloatNDArray =
false;
580 have_FloatComplexNDArray =
true;
583 else if (have_NDArray)
585 if (!
tmp(0).is_float_type ())
587 have_NDArray =
false;
591 else if (
tmp(0).is_real_type ())
592 result_NDArray.insert (
tmp(0).array_value (),
596 result_ComplexNDArray =
598 result_ComplexNDArray.insert
599 (
tmp(0).complex_array_value (), ra_idx);
600 have_NDArray =
false;
601 have_ComplexNDArray =
true;
605 #define BSXLOOP(T, CLS, EXTRACTOR) \
608 if (tmp(0).class_name () != CLS) \
610 have_ ## T = false; \
612 C = do_cat_op (C, tmp(0), ra_idx); \
615 result_ ## T .insert (tmp(0). EXTRACTOR ## _array_value (), ra_idx); \
635 retval(0) = result_ ## T;
octave_value(* bsxfun_handler)(const octave_value &, const octave_value &)
bool is_builtin_function(void) const
bool is_object(void) const
const octave_base_value const Array< octave_idx_type > & ra_idx
octave_value do_cat_op(const octave_value &v1, const octave_value &v2, const Array< octave_idx_type > &ra_idx)
boolNDArray bsxfun_le(const charNDArray &x, const charNDArray &y)
static octave_value bsxfun_forward_op(const octave_value &x, const octave_value &y)
OCTINTERP_API void print_usage(void)
OCTAVE_EXPORT octave_value_list uint16
bool is_defined(void) const
static bsxfun_builtin_op bsxfun_builtin_lookup(const std::string &name)
void resize(int n, int fill_value=0)
static octave_value do_bsxfun_real_pow(const octave_value &x, const octave_value &y)
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
std::string name(void) const
octave_value resize(const dim_vector &dv, bool fill=false) const
boolNDArray bsxfun_lt(const charNDArray &x, const charNDArray &y)
static octave_value maybe_optimized_builtin(const std::string &name, const octave_value &a, const octave_value &b)
static octave_value find_function(const std::string &name, const octave_value_list &args=octave_value_list(), bool local_funcs=true)
bool is_function_handle(void) const
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
boolNDArray bsxfun_eq(const charNDArray &x, const charNDArray &y)
octave_value single_subsref(const std::string &type, const octave_value_list &idx)
octave_value_list do_multi_index_op(int nargout, const octave_value_list &idx)
F77_RET_T const F77_INT F77_CMPLX const F77_INT F77_CMPLX * B
#define REGISTER_OP_HANDLER(OP, BTYP, NDA, FUNOP)
std::string string_value(bool force=false) const
OCTAVE_EXPORT octave_value_list uint32
bool is_string(void) const
OCTAVE_EXPORT octave_value_list int16
static void update_index(Array< int > &idx, const dim_vector &dv, octave_idx_type i)
#define REGISTER_REL_HANDLER(REL, BTYP, NDA, FUNREL)
OCTAVE_EXPORT octave_value_list int32
boolNDArray bsxfun_and(const boolNDArray &x, const boolNDArray &y)
dim_vector dims(void) const
ComplexNDArray bsxfun_pow(const ComplexNDArray &x, const ComplexNDArray &y)
boolNDArray bsxfun_ge(const charNDArray &x, const charNDArray &y)
octave_function * function_value(bool silent=false) const
#define BSXLOOP(T, CLS, EXTRACTOR)
OCTAVE_EXPORT octave_value_list int64
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)
=val(i)}if ode{val(i)}occurs in table i
static octave_value bsxfun_forward_rel(const octave_value &x, const octave_value &y)
static void maybe_fill_table(void)
const char * bsxfun_builtin_names[]
octave_idx_type ndims(void) const
Number of dimensions.
the element is set to zero In other the statement xample y
boolNDArray bsxfun_ne(const charNDArray &x, const charNDArray &y)
bool is_undefined(void) const
boolNDArray bsxfun_gt(const charNDArray &x, const charNDArray &y)
bsxfun_handler bsxfun_handler_table[bsxfun_num_builtin_ops][btyp_num_types]
#define REGISTER_STD_HANDLERS(BTYP, NDA)
Vector representing the dimensions (size) of an Array.
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
builtin_type_t builtin_type(void) const
boolNDArray bsxfun_or(const boolNDArray &x, const boolNDArray &y)
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
#define BSXINIT(T, CLS, EXTRACTOR)
F77_RET_T const F77_INT F77_CMPLX * A