24 #if defined (HAVE_CONFIG_H) 100 template <
typename NDA, NDA (bsxfun_op) (const NDA&, const NDA&)>
104 NDA xa = octave_value_extract<NDA> (
x);
105 NDA ya = octave_value_extract<NDA> (
y);
109 template <
typename NDA,
boolNDArray (bsxfun_rel) (const NDA&, const NDA&)>
113 NDA xa = octave_value_extract<NDA> (
x);
114 NDA ya = octave_value_extract<NDA> (
y);
120 template <
typename NDA,
typename CNDA>
124 NDA xa = octave_value_extract<NDA> (
x);
125 NDA ya = octave_value_extract<NDA> (
y);
126 if (! ya.all_integers () && xa.any_element_is_negative ())
134 static bool filled =
false;
138 #define REGISTER_OP_HANDLER(OP, BTYP, NDA, FUNOP) \ 139 bsxfun_handler_table[OP][BTYP] = bsxfun_forward_op<NDA, FUNOP> 141 #define REGISTER_REL_HANDLER(REL, BTYP, NDA, FUNREL) \ 142 bsxfun_handler_table[REL][BTYP] = bsxfun_forward_rel<NDA, FUNREL> 144 #define REGISTER_STD_HANDLERS(BTYP, NDA) \ 145 REGISTER_OP_HANDLER (bsxfun_builtin_plus, BTYP, NDA, bsxfun_add); \ 146 REGISTER_OP_HANDLER (bsxfun_builtin_minus, BTYP, NDA, bsxfun_sub); \ 147 REGISTER_OP_HANDLER (bsxfun_builtin_times, BTYP, NDA, bsxfun_mul); \ 148 REGISTER_OP_HANDLER (bsxfun_builtin_divide, BTYP, NDA, bsxfun_div); \ 149 REGISTER_OP_HANDLER (bsxfun_builtin_max, BTYP, NDA, bsxfun_max); \ 150 REGISTER_OP_HANDLER (bsxfun_builtin_min, BTYP, NDA, bsxfun_min); \ 151 REGISTER_REL_HANDLER (bsxfun_builtin_eq, BTYP, NDA, bsxfun_eq); \ 152 REGISTER_REL_HANDLER (bsxfun_builtin_ne, BTYP, NDA, bsxfun_ne); \ 153 REGISTER_REL_HANDLER (bsxfun_builtin_lt, BTYP, NDA, bsxfun_lt); \ 154 REGISTER_REL_HANDLER (bsxfun_builtin_le, BTYP, NDA, bsxfun_le); \ 155 REGISTER_REL_HANDLER (bsxfun_builtin_gt, BTYP, NDA, bsxfun_gt); \ 156 REGISTER_REL_HANDLER (bsxfun_builtin_ge, BTYP, NDA, bsxfun_ge) 177 do_bsxfun_real_pow<NDArray, ComplexNDArray>;
179 do_bsxfun_real_pow<FloatNDArray, FloatComplexNDArray>;
258 bool is_changed =
false;
263 if (dva(j) != 1 &&
k % dvc(j) != k1 % dvc(j))
339 if (args.length () != 3)
352 error (
"bsxfun: invalid function name: %s",
name.c_str ());
354 else if (! (args(0).is_function_handle () || args(0).is_inline_function ()))
355 error (
"bsxfun: F must be a string or function handle");
373 if (
tmp.is_defined ())
395 if (dva(
i) != dvb(
i) && dva(
i) != 1 && dvb(
i) != 1)
396 error (
"bsxfun: dimensions of A and B must match");
403 dvc(
i) = (dva(
i) < 1 ? dva(
i)
404 : (dvb(
i) < 1 ? dvb(
i)
405 : (dva(
i) > dvb(
i) ? dva(
i)
408 if (dva == dvb || dva.
numel () == 1 || dvb.
numel () == 1)
415 else if (dvc.
numel () < 1)
418 inputs(0) =
A.resize (dvc);
419 inputs(1) =
B.resize (dvc);
430 bool have_ ## T = false; 464 #define BSXINIT(T, CLS, EXTRACTOR) \ 465 (result_type == CLS) \ 468 result_ ## T = tmp(0). EXTRACTOR ## _array_value (); \ 469 result_ ## T .resize (dvc); \ 474 if (!
tmp(0).issparse ())
479 if (
tmp(0).isreal ())
482 result_NDArray =
tmp(0).array_value ();
483 result_NDArray.resize (dvc);
487 have_ComplexNDArray =
true;
488 result_ComplexNDArray =
489 tmp(0).complex_array_value ();
490 result_ComplexNDArray.resize (dvc);
495 if (
tmp(0).isreal ())
497 have_FloatNDArray =
true;
498 result_FloatNDArray =
499 tmp(0).float_array_value ();
500 result_FloatNDArray.resize (dvc);
504 have_FloatComplexNDArray =
true;
505 result_FloatComplexNDArray =
506 tmp(0).float_complex_array_value ();
507 result_FloatComplexNDArray.resize (dvc);
539 have_NDArray =
false;
543 else if (
tmp(0).isreal ())
544 result_NDArray.insert (
tmp(0).array_value (),
ra_idx);
547 result_ComplexNDArray =
549 result_ComplexNDArray.insert
551 have_NDArray =
false;
552 have_ComplexNDArray =
true;
555 else if (have_FloatNDArray)
559 have_FloatNDArray =
false;
560 C = result_FloatNDArray;
563 else if (
tmp(0).isreal ())
564 result_FloatNDArray.insert
568 result_FloatComplexNDArray =
570 result_FloatComplexNDArray.insert
571 (
tmp(0).float_complex_array_value (),
ra_idx);
572 have_FloatNDArray =
false;
573 have_FloatComplexNDArray =
true;
577 #define BSXLOOP(T, CLS, EXTRACTOR) \ 580 if (tmp(0).class_name () != CLS) \ 582 have_ ## T = false; \ 584 C = do_cat_op (C, tmp(0), ra_idx); \ 587 result_ ## T .insert (tmp(0). EXTRACTOR ## _array_value (), ra_idx); \ 608 retval(0) = result_ ## T; OCTINTERP_API octave_value_list feval(const std::string &name, const octave_value_list &args=octave_value_list(), int nargout=0)
octave_value find_function(const std::string &name, const octave_value_list &args=octave_value_list(), bool local_funcs=true)
F77_RET_T const F77_INT F77_CMPLX const F77_INT F77_CMPLX * B
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
const octave_base_value const Array< octave_idx_type > & ra_idx
std::string string_value(bool force=false) const
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)
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)
void error(const char *fmt,...)
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)
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)
#define REGISTER_OP_HANDLER(OP, BTYP, NDA, FUNOP)
nd deftypefn *std::string name
F77_RET_T const F77_INT F77_CMPLX * A
bool is_function_handle(void) const
OCTAVE_EXPORT octave_value_list isfloat
static void update_index(Array< int > &idx, const dim_vector &dv, octave_idx_type i)
#define REGISTER_REL_HANDLER(REL, BTYP, NDA, FUNREL)
octave_function * function_value(bool silent=false) const
boolNDArray bsxfun_and(const boolNDArray &x, const boolNDArray &y)
ComplexNDArray bsxfun_pow(const ComplexNDArray &x, const ComplexNDArray &y)
boolNDArray bsxfun_ge(const charNDArray &x, const charNDArray &y)
#define BSXLOOP(T, CLS, EXTRACTOR)
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)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
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)
bool is_undefined(void) const
bool is_builtin_function(void) const
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
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[]
the element is set to zero In other the statement xample y
boolNDArray bsxfun_ne(const charNDArray &x, const charNDArray &y)
bool is_string(void) const
boolNDArray bsxfun_gt(const charNDArray &x, const charNDArray &y)
bsxfun_handler bsxfun_handler_table[bsxfun_num_builtin_ops][btyp_num_types]
octave_idx_type ndims(void) const
Number of dimensions.
#define REGISTER_STD_HANDLERS(BTYP, NDA)
Vector representing the dimensions (size) of an Array.
std::string name(void) const
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
boolNDArray bsxfun_or(const boolNDArray &x, const boolNDArray &y)
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x
#define BSXINIT(T, CLS, EXTRACTOR)
octave_value(* bsxfun_handler)(const octave_value &, const octave_value &)