26#if ! defined (octave_bsxfun_defs_h)
27#define octave_bsxfun_defs_h 1
39template <
typename R,
typename X,
typename Y>
42 void (*op_vv) (std::size_t, R *,
const X *,
const Y *),
43 void (*op_sv) (std::size_t, R *, X,
const Y *),
44 void (*op_vs) (std::size_t, R *,
const X *, Y))
46 int nd = std::max (
x.ndims (), y.
ndims ());
53 for (
int i = 0; i < nd; i++)
59 else if (yk == 1 || xk == yk)
63 (
"bsxfun: nonconformant dimensions: %s and %s",
64 x.dims ().str ().c_str (), y.
dims ().
str ().c_str ());
69 const X *xvec =
x.data ();
70 const Y *yvec = y.
data ();
71 R *rvec = retval.
rwdata ();
75 for (start = 0; start < nd; start++)
77 if (dvx(start) != dvy(start))
85 op_vv (retval.
numel (), rvec, xvec, yvec);
93 xsing = dvx(start) == 1;
94 ysing = dvy(start) == 1;
97 ldr *= dvx(start) * dvy(start);
127 op_sv (ldr, rvec + ridx, xvec[xidx], yvec + yidx);
129 op_vs (ldr, rvec + ridx, xvec + xidx, yvec[yidx]);
131 op_vv (ldr, rvec + ridx, xvec + xidx, yvec + yidx);
140template <
typename R,
typename X>
143 void (*op_vv) (std::size_t, R *,
const X *),
144 void (*op_vs) (std::size_t, R *, X))
149 dvx = dvx.
redim (nd);
151 const X *xvec =
x.data ();
156 for (start = 0; start < nd; start++)
158 if (dvr(start) != dvx(start))
165 else if (start == nd)
166 op_vv (r.
numel (), rvec, xvec);
173 xsing = dvx(start) == 1;
176 ldr *= dvr(start) * dvx(start);
203 op_vs (ldr, rvec + ridx, xvec[xidx]);
205 op_vv (ldr, rvec + ridx, xvec + xidx);
214template <
typename R,
typename X,
typename Y>
217 void (*op_vv) (std::size_t, R *,
const X *,
const Y *,
219 void (*op_sv) (std::size_t, R *, X,
const Y *,
const bool),
220 void (*op_vs) (std::size_t, R *,
const X *, Y,
const bool))
222 int nd = std::max (
x.ndims (), y.
ndims ());
229 for (
int i = 0; i < nd; i++)
235 else if (yk == 1 || xk == yk)
239 (
"bsxfun: nonconformant dimensions: %s and %s",
240 x.dims ().str ().c_str (), y.
dims ().
str ().c_str ());
245 const X *xvec =
x.data ();
246 const Y *yvec = y.
data ();
247 R *rvec = retval.
rwdata ();
251 for (start = 0; start < nd; start++)
253 if (dvx(start) != dvy(start))
260 else if (start == nd)
261 op_vv (retval.
numel (), rvec, xvec, yvec, nanflag);
269 xsing = dvx(start) == 1;
270 ysing = dvy(start) == 1;
273 ldr *= dvx(start) * dvy(start);
303 op_sv (ldr, rvec + ridx, xvec[xidx], yvec + yidx, nanflag);
305 op_vs (ldr, rvec + ridx, xvec + xidx, yvec[yidx], nanflag);
307 op_vv (ldr, rvec + ridx, xvec + xidx, yvec + yidx, nanflag);
316template <
typename R,
typename X,
typename Y>
320 void (*op_vv) (std::size_t, R *,
const X *,
const Y *,
321 const bool,
const bool),
322 void (*op_sv) (std::size_t, R *, X,
const Y *,
323 const bool,
const bool),
324 void (*op_vs) (std::size_t, R *,
const X *, Y,
325 const bool,
const bool))
327 int nd = std::max (
x.ndims (), y.
ndims ());
334 for (
int i = 0; i < nd; i++)
340 else if (yk == 1 || xk == yk)
344 (
"bsxfun: nonconformant dimensions: %s and %s",
345 x.dims ().str ().c_str (), y.
dims ().
str ().c_str ());
350 const X *xvec =
x.data ();
351 const Y *yvec = y.
data ();
352 R *rvec = retval.
rwdata ();
356 for (start = 0; start < nd; start++)
358 if (dvx(start) != dvy(start))
365 else if (start == nd)
366 op_vv (retval.
numel (), rvec, xvec, yvec, nanflag, realabs);
374 xsing = dvx(start) == 1;
375 ysing = dvy(start) == 1;
378 ldr *= dvx(start) * dvy(start);
408 op_sv (ldr, rvec + ridx, xvec[xidx], yvec + yidx, nanflag, realabs);
410 op_vs (ldr, rvec + ridx, xvec + xidx, yvec[yidx], nanflag, realabs);
412 op_vv (ldr, rvec + ridx, xvec + xidx, yvec + yidx, nanflag, realabs);
421#define BSXFUN_OP_DEF(OP, ARRAY) \
422 ARRAY bsxfun_ ## OP (const ARRAY& x, const ARRAY& y)
424#define BSXFUN1_OP_DEF(OP, ARRAY) \
425 ARRAY bsxfun_ ## OP (const ARRAY& x, const ARRAY& y, \
428#define BSXFUN2_OP_DEF(OP, ARRAY) \
429 ARRAY bsxfun_ ## OP (const ARRAY& x, const ARRAY& y, \
430 const bool nanflag, const bool realabs)
432#define BSXFUN_OP2_DEF(OP, ARRAY, ARRAY1, ARRAY2) \
433 ARRAY bsxfun_ ## OP (const ARRAY1& x, const ARRAY2& y)
435#define BSXFUN_REL_DEF(OP, ARRAY) \
436 boolNDArray bsxfun_ ## OP (const ARRAY& x, const ARRAY& y)
438#define BSXFUN_OP_DEF_MXLOOP(OP, ARRAY, LOOP) \
439 BSXFUN_OP_DEF(OP, ARRAY) \
440 { return do_bsxfun_op<ARRAY::element_type, ARRAY::element_type, ARRAY::element_type> \
441 (x, y, LOOP, LOOP, LOOP); }
443#define BSXFUN1_OP_DEF_MXLOOP(OP, ARRAY, LOOP) \
444 BSXFUN1_OP_DEF(OP, ARRAY) \
445 { return do_bsxfun1_op<ARRAY::element_type, ARRAY::element_type, ARRAY::element_type> \
446 (x, y, nanflag, LOOP, LOOP, LOOP); }
448#define BSXFUN2_OP_DEF_MXLOOP(OP, ARRAY, LOOP) \
449 BSXFUN2_OP_DEF(OP, ARRAY) \
450 { return do_bsxfun2_op<ARRAY::element_type, ARRAY::element_type, ARRAY::element_type> \
451 (x, y, nanflag, realabs, LOOP, LOOP, LOOP); }
453#define BSXFUN_OP2_DEF_MXLOOP(OP, ARRAY, ARRAY1, ARRAY2, LOOP) \
454 BSXFUN_OP2_DEF(OP, ARRAY, ARRAY1, ARRAY2) \
455 { return do_bsxfun_op<ARRAY::element_type, ARRAY1::element_type, ARRAY2::element_type> \
456 (x, y, LOOP, LOOP, LOOP); }
458#define BSXFUN_REL_DEF_MXLOOP(OP, ARRAY, LOOP) \
459 BSXFUN_REL_DEF(OP, ARRAY) \
460 { return do_bsxfun_op<bool, ARRAY::element_type, ARRAY::element_type> \
461 (x, y, LOOP, LOOP, LOOP); }
463#define BSXFUN_STDOP_DEFS_MXLOOP(ARRAY) \
464 BSXFUN_OP_DEF_MXLOOP (add, ARRAY, mx_inline_add) \
465 BSXFUN_OP_DEF_MXLOOP (sub, ARRAY, mx_inline_sub) \
466 BSXFUN_OP_DEF_MXLOOP (mul, ARRAY, mx_inline_mul) \
467 BSXFUN_OP_DEF_MXLOOP (div, ARRAY, mx_inline_div) \
468 BSXFUN_OP_DEF_MXLOOP (min, ARRAY, mx_inline_xmin) \
469 BSXFUN_OP_DEF_MXLOOP (max, ARRAY, mx_inline_xmax) \
470 BSXFUN1_OP_DEF_MXLOOP (min, ARRAY, mx_inline_xmin) \
471 BSXFUN1_OP_DEF_MXLOOP (max, ARRAY, mx_inline_xmax) \
472 BSXFUN2_OP_DEF_MXLOOP (min, ARRAY, mx_inline_xmin) \
473 BSXFUN2_OP_DEF_MXLOOP (max, ARRAY, mx_inline_xmax)
475#define BSXFUN_STDREL_DEFS_MXLOOP(ARRAY) \
476 BSXFUN_REL_DEF_MXLOOP (eq, ARRAY, mx_inline_eq) \
477 BSXFUN_REL_DEF_MXLOOP (ne, ARRAY, mx_inline_ne) \
478 BSXFUN_REL_DEF_MXLOOP (lt, ARRAY, mx_inline_lt) \
479 BSXFUN_REL_DEF_MXLOOP (le, ARRAY, mx_inline_le) \
480 BSXFUN_REL_DEF_MXLOOP (gt, ARRAY, mx_inline_gt) \
481 BSXFUN_REL_DEF_MXLOOP (ge, ARRAY, mx_inline_ge)
484#define BSXFUN_POW_MIXED_MXLOOP(INT_TYPE) \
485 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, INT_TYPE, NDArray, mx_inline_pow) \
486 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, INT_TYPE, FloatNDArray, mx_inline_pow) \
487 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, NDArray, INT_TYPE, mx_inline_pow) \
488 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, FloatNDArray, INT_TYPE, mx_inline_pow)
Array< R > do_bsxfun1_op(const Array< X > &x, const Array< Y > &y, const bool nanflag, void(*op_vv)(std::size_t, R *, const X *, const Y *, const bool), void(*op_sv)(std::size_t, R *, X, const Y *, const bool), void(*op_vs)(std::size_t, R *, const X *, Y, const bool))
Array< R > do_bsxfun_op(const Array< X > &x, const Array< Y > &y, void(*op_vv)(std::size_t, R *, const X *, const Y *), void(*op_sv)(std::size_t, R *, X, const Y *), void(*op_vs)(std::size_t, R *, const X *, Y))
void do_inplace_bsxfun_op(Array< R > &r, const Array< X > &x, void(*op_vv)(std::size_t, R *, const X *), void(*op_vs)(std::size_t, R *, X))
Array< R > do_bsxfun2_op(const Array< X > &x, const Array< Y > &y, const bool nanflag, const bool realabs, void(*op_vv)(std::size_t, R *, const X *, const Y *, const bool, const bool), void(*op_sv)(std::size_t, R *, X, const Y *, const bool, const bool), void(*op_vs)(std::size_t, R *, const X *, Y, const bool, const bool))
N Dimensional Array with copy-on-write semantics.
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
int ndims() const
Size of the specified dimension.
bool isempty() const
Size of the specified dimension.
const T * data() const
Size of the specified dimension.
T * rwdata()
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
Vector representing the dimensions (size) of an Array.
octave_idx_type compute_index(const octave_idx_type *idx) const
Linear index from an index tuple.
std::string str(char sep='x') const
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)
int increment_index(octave_idx_type *idx, int start=0) const
Increment a multi-dimensional index tuple, optionally starting from an offset position and return the...
dim_vector cumulative() const
Return cumulative dimensions.
octave_idx_type cum_compute_index(const octave_idx_type *idx) const
Compute a linear index from an index tuple.
dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
#define OCTAVE_LOCAL_BUFFER_INIT(T, buf, size, value)
F77_RET_T const F77_DBLE * x