23 #if !defined (octave_oct_binmap_h)
24 #define octave_oct_binmap_h 1
63 template<
typename R,
typename X,
typename Y,
typename F>
77 op_mm (
size_t n, R* r,
const X*
x ,
const Y* y)
79 for (
size_t i = 0; i < n; i++)
80 r[i] = f (x[i], y[i]);
84 op_sm (
size_t n, R* r, X
x,
const Y* y)
86 for (
size_t i = 0; i < n; i++)
91 op_ms (
size_t n , R* r,
const X*
x, Y y)
93 for (
size_t i = 0; i < n; i++)
99 template<
typename R,
typename X,
typename Y,
typename F>
104 template <
class U,
class T,
class R,
class F>
110 const R *y = ya.
data ();
116 for (i = 0; i < len - 3; i += 4)
120 p[i] = fcn (x, y[i]);
121 p[i+1] = fcn (x, y[i+1]);
122 p[i+2] = fcn (x, y[i+2]);
123 p[i+3] = fcn (x, y[i+3]);
129 p[i] = fcn (x, y[i]);
135 template <
class U,
class T,
class R,
class F>
141 const R *
x = xa.
data ();
147 for (i = 0; i < len - 3; i += 4)
151 p[i] = fcn (x[i], y);
152 p[i+1] = fcn (x[i+1], y);
153 p[i+2] = fcn (x[i+2], y);
154 p[i+3] = fcn (x[i+3], y);
160 p[i] = fcn (x[i], y);
166 template <
class U,
class T,
class R,
class F>
172 if (xa.
numel () == 1)
173 return binmap<U, T, R, F> (xa(0), ya, fcn);
174 else if (ya.
numel () == 1)
175 return binmap<U, T, R, F> (xa, ya(0), fcn);
192 const T *
x = xa.
data ();
193 const T *y = ya.
data ();
199 for (i = 0; i < len - 3; i += 4)
203 p[i] = fcn (x[i], y[i]);
204 p[i+1] = fcn (x[i+1], y[i+1]);
205 p[i+2] = fcn (x[i+2], y[i+2]);
206 p[i+3] = fcn (x[i+3], y[i+3]);
212 p[i] = fcn (x[i], y[i]);
218 template <
class U,
class T,
class R,
class F>
223 U fz = fcn (x, yzero);
229 std::copy (ys.
ridx (), ys.
ridx () + nz, retval.ridx ());
230 std::copy (ys.
cidx (), ys.
cidx () + ys.
cols () + 1, retval.cidx ());
237 retval.xdata (i) = fcn (x, ys.
data (i));
241 retval.maybe_compress (
true);
249 template <
class U,
class T,
class R,
class F>
254 U fz = fcn (xzero, y);
260 std::copy (xs.
ridx (), xs.
ridx () + nz, retval.ridx ());
261 std::copy (xs.
cidx (), xs.
cidx () + xs.
cols () + 1, retval.cidx ());
268 retval.xdata (i) = fcn (xs.
data (i), y);
272 retval.maybe_compress (
true);
280 template <
class U,
class T,
class R,
class F>
284 if (xs.
rows () == 1 && xs.
cols () == 1)
285 return binmap<U, T, R, F> (xs(0,0), ys, fcn);
286 else if (ys.
rows () == 1 && ys.
cols () == 1)
287 return binmap<U, T, R, F> (xs, ys(0,0), fcn);
293 U fz = fcn (xzero, yzero);
309 bool jx_lt_max = jx < jx_max;
313 bool jy_lt_max = jy < jy_max;
315 while (jx_lt_max || jy_lt_max)
318 || (jx_lt_max && (xs.
ridx (jx) < ys.
ridx (jy))))
320 retval.xridx (nz) = xs.
ridx (jx);
321 retval.xdata (nz) = fcn (xs.
data (jx), yzero);
323 jx_lt_max = jx < jx_max;
326 || (jy_lt_max && (ys.
ridx (jy) < xs.
ridx (jx))))
328 retval.xridx (nz) = ys.
ridx (jy);
329 retval.xdata (nz) = fcn (xzero, ys.
data (jy));
331 jy_lt_max = jy < jy_max;
335 retval.xridx (nz) = xs.
ridx (jx);
336 retval.xdata (nz) = fcn (xs.
data (jx), ys.
data (jy));
338 jx_lt_max = jx < jx_max;
340 jy_lt_max = jy < jy_max;
344 retval.
xcidx (j+1) = nz;
359 template <
class U,
class T,
class R>
363 {
return binmap<U, T, R, U (*) (T, R)> (xa, ya, fcn, name); }
365 template <
class U,
class T,
class R>
368 {
return binmap<U, T, R, U (*) (T, R)> (
x, ya, fcn); }
370 template <
class U,
class T,
class R>
373 {
return binmap<U, T, R, U (*) (T, R)> (xa, y, fcn); }
375 template <
class U,
class T,
class R>
379 {
return binmap<U, T, R, U (*) (T, R)> (xa, ya, fcn, name); }
381 template <
class U,
class T,
class R>
384 {
return binmap<U, T, R, U (*) (T, R)> (
x, ya, fcn); }
386 template <
class U,
class T,
class R>
389 {
return binmap<U, T, R, U (*) (T, R)> (xa, y, fcn); }
393 template <
class U,
class T,
class R>
397 {
return binmap<U, T, R, U (*) (const T&, const R&)> (xa, ya, fcn, name); }
399 template <
class U,
class T,
class R>
402 {
return binmap<U, T, R, U (*) (const T&, const R&)> (
x, ya, fcn); }
404 template <
class U,
class T,
class R>
407 {
return binmap<U, T, R, U (*) (const T&, const R&)> (xa, y, fcn); }
409 template <
class U,
class T,
class R>
413 {
return binmap<U, T, R, U (*) (const T&, const R&)> (xa, ya, fcn, name); }
415 template <
class U,
class T,
class R>
418 {
return binmap<U, T, R, U (*) (const T&, const R&)> (
x, ya, fcn); }
420 template <
class U,
class T,
class R>
423 {
return binmap<U, T, R, U (*) (const T&, const R&)> (xa, y, fcn); }
427 template <
class U,
class T,
class R>
431 {
return binmap<U, T, R, U (*) (const T&, R)> (xa, ya, fcn, name); }
433 template <
class U,
class T,
class R>
436 {
return binmap<U, T, R, U (*) (const T&, R)> (
x, ya, fcn); }
438 template <
class U,
class T,
class R>
441 {
return binmap<U, T, R, U (*) (const T&, R)> (xa, y, fcn); }
443 template <
class U,
class T,
class R>
447 {
return binmap<U, T, R, U (*) (const T&, R)> (xa, ya, fcn, name); }
449 template <
class U,
class T,
class R>
452 {
return binmap<U, T, R, U (*) (const T&, R)> (
x, ya, fcn); }
454 template <
class U,
class T,
class R>
457 {
return binmap<U, T, R, U (*) (const T&, R)> (xa, y, fcn); }
461 template <
class U,
class T,
class R>
465 {
return binmap<U, T, R, U (*) (T, const R&)> (xa, ya, fcn, name); }
467 template <
class U,
class T,
class R>
470 {
return binmap<U, T, R, U (*) (T, const R&)> (
x, ya, fcn); }
472 template <
class U,
class T,
class R>
475 {
return binmap<U, T, R, U (*) (T, const R&)> (xa, y, fcn); }
477 template <
class U,
class T,
class R>
481 {
return binmap<U, T, R, U (*) (T, const R&)> (xa, ya, fcn, name); }
483 template <
class U,
class T,
class R>
486 {
return binmap<U, T, R, U (*) (T, const R&)> (
x, ya, fcn); }
488 template <
class U,
class T,
class R>
491 {
return binmap<U, T, R, U (*) (T, const R&)> (xa, y, fcn); }
octave_idx_type cols(void) const
void gripe_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
octave_idx_type rows(void) const
dim_vector dims(void) const
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type * xcidx(void)
static void set_f(const F &f_in)
octave_idx_type * cidx(void)
static void op_sm(size_t n, R *r, X x, const Y *y)
octave_idx_type nnz(void) const
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Sparse< T > maybe_compress(bool remove_zeros=false)
const T * data(void) const
Array< U > binmap(const T &x, const Array< R > &ya, F fcn)
Handles the reference counting for all the derived classes.
static void op_mm(size_t n, R *r, const X *x, const Y *y)
octave_idx_type * ridx(void)
bool is_valid_bsxfun(const std::string &name, const dim_vector &dx, const dim_vector &dy)
const T * fortran_vec(void) const
static void op_ms(size_t n, R *r, const X *x, Y y)
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))
Array< T > array_value(void) const
void F(const TSRC *v, TRES *r, octave_idx_type m, octave_idx_type n)