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))
50 for (
int i = 0; i < nd; i++)
56 else if (yk == 1 || xk == yk)
60 (*current_liboctave_error_handler)
61 (
"bsxfun: nonconformant dimensions: %s and %s",
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);
140 template <
class R,
class X>
143 void (*op_vv) (
size_t, R *,
const X *),
144 void (*op_vs) (
size_t, R *, X))
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);
212 #define BSXFUN_OP_DEF(OP, ARRAY) \
213 ARRAY bsxfun_ ## OP (const ARRAY& x, const ARRAY& y)
215 #define BSXFUN_OP2_DEF(OP, ARRAY, ARRAY1, ARRAY2) \
216 ARRAY bsxfun_ ## OP (const ARRAY1& x, const ARRAY2& y)
218 #define BSXFUN_REL_DEF(OP, ARRAY) \
219 boolNDArray bsxfun_ ## OP (const ARRAY& x, const ARRAY& y)
221 #define BSXFUN_OP_DEF_MXLOOP(OP, ARRAY, LOOP) \
222 BSXFUN_OP_DEF(OP, ARRAY) \
223 { return do_bsxfun_op<ARRAY::element_type, ARRAY::element_type, ARRAY::element_type> \
224 (x, y, LOOP, LOOP, LOOP); }
226 #define BSXFUN_OP2_DEF_MXLOOP(OP, ARRAY, ARRAY1, ARRAY2, LOOP) \
227 BSXFUN_OP2_DEF(OP, ARRAY, ARRAY1, ARRAY2) \
228 { return do_bsxfun_op<ARRAY::element_type, ARRAY1::element_type, ARRAY2::element_type> \
229 (x, y, LOOP, LOOP, LOOP); }
231 #define BSXFUN_REL_DEF_MXLOOP(OP, ARRAY, LOOP) \
232 BSXFUN_REL_DEF(OP, ARRAY) \
233 { return do_bsxfun_op<bool, ARRAY::element_type, ARRAY::element_type> \
234 (x, y, LOOP, LOOP, LOOP); }
236 #define BSXFUN_STDOP_DEFS_MXLOOP(ARRAY) \
237 BSXFUN_OP_DEF_MXLOOP (add, ARRAY, mx_inline_add) \
238 BSXFUN_OP_DEF_MXLOOP (sub, ARRAY, mx_inline_sub) \
239 BSXFUN_OP_DEF_MXLOOP (mul, ARRAY, mx_inline_mul) \
240 BSXFUN_OP_DEF_MXLOOP (div, ARRAY, mx_inline_div) \
241 BSXFUN_OP_DEF_MXLOOP (min, ARRAY, mx_inline_xmin) \
242 BSXFUN_OP_DEF_MXLOOP (max, ARRAY, mx_inline_xmax)
244 #define BSXFUN_STDREL_DEFS_MXLOOP(ARRAY) \
245 BSXFUN_REL_DEF_MXLOOP (eq, ARRAY, mx_inline_eq) \
246 BSXFUN_REL_DEF_MXLOOP (ne, ARRAY, mx_inline_ne) \
247 BSXFUN_REL_DEF_MXLOOP (lt, ARRAY, mx_inline_lt) \
248 BSXFUN_REL_DEF_MXLOOP (le, ARRAY, mx_inline_le) \
249 BSXFUN_REL_DEF_MXLOOP (gt, ARRAY, mx_inline_gt) \
250 BSXFUN_REL_DEF_MXLOOP (ge, ARRAY, mx_inline_ge)
253 #define BSXFUN_POW_MIXED_MXLOOP(INT_TYPE) \
254 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, INT_TYPE, NDArray, mx_inline_pow) \
255 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, INT_TYPE, FloatNDArray, mx_inline_pow)\
256 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, NDArray, INT_TYPE, mx_inline_pow) \
257 BSXFUN_OP2_DEF_MXLOOP (pow, INT_TYPE, FloatNDArray, INT_TYPE, mx_inline_pow)
bool is_empty(void) const
std::string str(char sep= 'x') const
#define OCTAVE_LOCAL_BUFFER_INIT(T, buf, size, value)
octave_idx_type numel(void) const
Number of elements in the array.
dim_vector cumulative(void) const
Return cumulative dimensions.
void resize(int n, int fill_value=0)
octave_idx_type cum_compute_index(const octave_idx_type *idx) const
Compute a linear index from an index tuple.
int increment_index(octave_idx_type *idx, int start=0) const
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
dim_vector redim(int n) const
void do_inplace_bsxfun_op(Array< R > &r, const Array< X > &x, void(*op_vv)(size_t, R *, const X *), void(*op_vs)(size_t, R *, X))
Handles the reference counting for all the derived classes.
charNDArray max(char d, const charNDArray &m)
octave_idx_type compute_index(const octave_idx_type *idx) const
Compute a linear index from an index tuple.
const T * fortran_vec(void) const
F77_RET_T const double * x
Array< R > do_bsxfun_op(const Array< X > &x, const Array< Y > &y, void(*op_vv)(size_t, R *, const X *, const Y *), void(*op_sv)(size_t, R *, X, const Y *), void(*op_vs)(size_t, R *, const X *, Y))