26 #if ! defined (octave_bsxfun_defs_h)
27 #define octave_bsxfun_defs_h 1
39 template <
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))
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 ();
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 <
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 ();
152 R *rvec =
r.fortran_vec ();
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)
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))
charNDArray max(char d, const charNDArray &m)
N Dimensional Array with copy-on-write semantics.
OCTARRAY_OVERRIDABLE_FUNC_API const T * data(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API bool isempty(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
OCTARRAY_API T * fortran_vec(void)
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API int ndims(void) const
Size of the specified dimension.
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.
OCTAVE_API 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(void) const
Return cumulative dimensions.
octave_idx_type cum_compute_index(const octave_idx_type *idx) const
Compute a linear index from an index tuple.
OCTAVE_API dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
F77_RET_T const F77_DBLE * x
#define OCTAVE_LOCAL_BUFFER_INIT(T, buf, size, value)