24 #if !defined (octave_bsxfun_defs_h)
25 #define octave_bsxfun_defs_h 1
36 template <
class R,
class X,
class Y>
39 void (*op_vv) (
size_t, R *,
const X *,
const Y *),
40 void (*op_sv) (
size_t, R *, X,
const Y *),
41 void (*op_vs) (
size_t, R *,
const X *, Y))
49 for (
int i = 0; i < nd; i++)
54 else if (yk == 1 || xk == yk)
58 (*current_liboctave_error_handler)
59 (
"bsxfun: nonconformant dimensions: %s and %s",
73 for (start = 0; start < nd; start++)
75 if (dvx(start) != dvy(start))
83 op_vv (retval.
numel (), rvec, xvec, yvec);
87 bool xsing =
false, ysing =
false;
90 xsing = dvx(start) == 1;
91 ysing = dvy(start) == 1;
94 ldr *= dvx(start) * dvy(start);
123 op_sv (ldr, rvec + ridx, xvec[xidx], yvec + yidx);
125 op_vs (ldr, rvec + ridx, xvec + xidx, yvec[yidx]);
127 op_vv (ldr, rvec + ridx, xvec + xidx, yvec + yidx);
136 template <
class R,
class X>
139 void (*op_vv) (
size_t, R *,
const X *),
140 void (*op_vs) (
size_t, R *, X))
151 for (start = 0; start < nd; start++)
153 if (dvr(start) != dvx(start))
160 else if (start == nd)
161 op_vv (r.
numel (), rvec, xvec);
168 xsing = dvx(start) == 1;
171 ldr *= dvr(start) * dvx(start);
198 op_vs (ldr, rvec + ridx, xvec[xidx]);
200 op_vv (ldr, rvec + ridx, xvec + xidx);
207 #define BSXFUN_OP_DEF(OP, ARRAY) \
208 ARRAY bsxfun_ ## OP (const ARRAY& x, const ARRAY& y)
210 #define BSXFUN_OP2_DEF(OP, ARRAY, ARRAY1, ARRAY2) \
211 ARRAY bsxfun_ ## OP (const ARRAY1& x, const ARRAY2& y)
213 #define BSXFUN_REL_DEF(OP, ARRAY) \
214 boolNDArray bsxfun_ ## OP (const ARRAY& x, const ARRAY& y)
216 #define BSXFUN_OP_DEF_MXLOOP(OP, ARRAY, LOOP) \
217 BSXFUN_OP_DEF(OP, ARRAY) \
218 { return do_bsxfun_op<ARRAY::element_type, ARRAY::element_type, ARRAY::element_type> \
219 (x, y, LOOP, LOOP, LOOP); }
221 #define BSXFUN_OP2_DEF_MXLOOP(OP, ARRAY, ARRAY1, ARRAY2, LOOP) \
222 BSXFUN_OP2_DEF(OP, ARRAY, ARRAY1, ARRAY2) \
223 { return do_bsxfun_op<ARRAY::element_type, ARRAY1::element_type, ARRAY2::element_type> \
224 (x, y, LOOP, LOOP, LOOP); }
226 #define BSXFUN_REL_DEF_MXLOOP(OP, ARRAY, LOOP) \
227 BSXFUN_REL_DEF(OP, ARRAY) \
228 { return do_bsxfun_op<bool, ARRAY::element_type, ARRAY::element_type> \
229 (x, y, LOOP, LOOP, LOOP); }
231 #define BSXFUN_STDOP_DEFS_MXLOOP(ARRAY) \
232 BSXFUN_OP_DEF_MXLOOP (add, ARRAY, mx_inline_add) \
233 BSXFUN_OP_DEF_MXLOOP (sub, ARRAY, mx_inline_sub) \
234 BSXFUN_OP_DEF_MXLOOP (mul, ARRAY, mx_inline_mul) \
235 BSXFUN_OP_DEF_MXLOOP (div, ARRAY, mx_inline_div) \
236 BSXFUN_OP_DEF_MXLOOP (min, ARRAY, mx_inline_xmin) \
237 BSXFUN_OP_DEF_MXLOOP (max, ARRAY, mx_inline_xmax) \
239 #define BSXFUN_STDREL_DEFS_MXLOOP(ARRAY) \
240 BSXFUN_REL_DEF_MXLOOP (eq, ARRAY, mx_inline_eq) \
241 BSXFUN_REL_DEF_MXLOOP (ne, ARRAY, mx_inline_ne) \
242 BSXFUN_REL_DEF_MXLOOP (lt, ARRAY, mx_inline_lt) \
243 BSXFUN_REL_DEF_MXLOOP (le, ARRAY, mx_inline_le) \
244 BSXFUN_REL_DEF_MXLOOP (gt, ARRAY, mx_inline_gt) \
245 BSXFUN_REL_DEF_MXLOOP (ge, ARRAY, mx_inline_ge)
248 #define BSXFUN_POW_MIXED_MXLOOP(INT_TYPE) \
249 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, INT_TYPE, NDArray, mx_inline_pow) \
250 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, INT_TYPE, FloatNDArray, mx_inline_pow)\
251 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, NDArray, INT_TYPE, mx_inline_pow) \
252 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, FloatNDArray, INT_TYPE, mx_inline_pow)