26#if ! defined (octave_oct_binmap_h)
27#define octave_oct_binmap_h 1
29#include "octave-config.h"
68template <
typename R,
typename X,
typename Y,
typename F>
84 op_mm (std::size_t n, R *r,
const X *
x,
const Y *y)
86 for (std::size_t i = 0; i < n; i++)
87 r[i] = s_fcn (
x[i], y[i]);
91 op_sm (std::size_t n, R *r, X
x,
const Y *y)
93 for (std::size_t i = 0; i < n; i++)
94 r[i] = s_fcn (
x, y[i]);
98 op_ms (std::size_t n, R *r,
const X *
x, Y y)
100 for (std::size_t i = 0; i < n; i++)
101 r[i] = s_fcn (
x[i], y);
106template <
typename R,
typename X,
typename Y,
typename F>
110template <
typename U,
typename T,
typename R,
typename F>
116 const R *y = ya.
data ();
122 for (i = 0; i <
len - 3; i += 4)
126 p[i] = fcn (
x, y[i]);
127 p[i+1] = fcn (
x, y[i+1]);
128 p[i+2] = fcn (
x, y[i+2]);
129 p[i+3] = fcn (
x, y[i+3]);
135 p[i] = fcn (
x, y[i]);
141template <
typename U,
typename T,
typename R,
typename F>
147 const R *
x = xa.
data ();
153 for (i = 0; i <
len - 3; i += 4)
157 p[i] = fcn (
x[i], y);
158 p[i+1] = fcn (
x[i+1], y);
159 p[i+2] = fcn (
x[i+2], y);
160 p[i+3] = fcn (
x[i+3], y);
166 p[i] = fcn (
x[i], y);
172template <
typename U,
typename T,
typename R,
typename F>
178 if (xa.
numel () == 1)
179 return binmap<U, T, R, F> (xa(0), ya, fcn);
180 else if (ya.
numel () == 1)
181 return binmap<U, T, R, F> (xa, ya(0), fcn);
185 octave::err_nonconformant (name, xad, yad);
196 const T *
x = xa.
data ();
197 const T *y = ya.
data ();
203 for (i = 0; i <
len - 3; i += 4)
207 p[i] = fcn (
x[i], y[i]);
208 p[i+1] = fcn (
x[i+1], y[i+1]);
209 p[i+2] = fcn (
x[i+2], y[i+2]);
210 p[i+3] = fcn (
x[i+3], y[i+3]);
216 p[i] = fcn (
x[i], y[i]);
222template <
typename U,
typename T,
typename R,
typename F>
227 U fz = fcn (
x, yzero);
233 std::copy (ys.
ridx (), ys.
ridx () + nz, retval.
ridx ());
251template <
typename U,
typename T,
typename R,
typename F>
256 U fz = fcn (xzero, y);
262 std::copy (xs.
ridx (), xs.
ridx () + nz, retval.
ridx ());
280template <
typename U,
typename T,
typename R,
typename 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);
289 octave::err_nonconformant (name, xs.
dims (), ys.
dims ());
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))))
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))))
329 retval.
xdata (nz) = fcn (xzero, ys.
data (jy));
331 jy_lt_max = jy < jy_max;
338 jx_lt_max = jx < jx_max;
340 jy_lt_max = jy < jy_max;
344 retval.
xcidx (j+1) = nz;
359template <
typename U,
typename T,
typename R>
363{
return binmap<U, T, R, U (*) (T, R)> (xa, ya, fcn, name); }
365template <
typename U,
typename T,
typename R>
368{
return binmap<U, T, R, U (*) (T, R)> (
x, ya, fcn); }
370template <
typename U,
typename T,
typename R>
373{
return binmap<U, T, R, U (*) (T, R)> (xa, y, fcn); }
375template <
typename U,
typename T,
typename R>
379{
return binmap<U, T, R, U (*) (T, R)> (xa, ya, fcn, name); }
381template <
typename U,
typename T,
typename R>
384{
return binmap<U, T, R, U (*) (T, R)> (
x, ya, fcn); }
386template <
typename U,
typename T,
typename R>
389{
return binmap<U, T, R, U (*) (T, R)> (xa, y, fcn); }
393template <
typename U,
typename T,
typename R>
397{
return binmap<U, T, R, U (*) (const T&, const R&)> (xa, ya, fcn, name); }
399template <
typename U,
typename T,
typename R>
402{
return binmap<U, T, R, U (*) (const T&, const R&)> (
x, ya, fcn); }
404template <
typename U,
typename T,
typename R>
407{
return binmap<U, T, R, U (*) (const T&, const R&)> (xa, y, fcn); }
409template <
typename U,
typename T,
typename R>
413{
return binmap<U, T, R, U (*) (const T&, const R&)> (xa, ya, fcn, name); }
415template <
typename U,
typename T,
typename R>
418{
return binmap<U, T, R, U (*) (const T&, const R&)> (
x, ya, fcn); }
420template <
typename U,
typename T,
typename R>
423{
return binmap<U, T, R, U (*) (const T&, const R&)> (xa, y, fcn); }
427template <
typename U,
typename T,
typename R>
431{
return binmap<U, T, R, U (*) (const T&, R)> (xa, ya, fcn, name); }
433template <
typename U,
typename T,
typename R>
436{
return binmap<U, T, R, U (*) (const T&, R)> (
x, ya, fcn); }
438template <
typename U,
typename T,
typename R>
441{
return binmap<U, T, R, U (*) (const T&, R)> (xa, y, fcn); }
443template <
typename U,
typename T,
typename R>
447{
return binmap<U, T, R, U (*) (const T&, R)> (xa, ya, fcn, name); }
449template <
typename U,
typename T,
typename R>
452{
return binmap<U, T, R, U (*) (const T&, R)> (
x, ya, fcn); }
454template <
typename U,
typename T,
typename R>
457{
return binmap<U, T, R, U (*) (const T&, R)> (xa, y, fcn); }
461template <
typename U,
typename T,
typename R>
465{
return binmap<U, T, R, U (*) (T, const R&)> (xa, ya, fcn, name); }
467template <
typename U,
typename T,
typename R>
470{
return binmap<U, T, R, U (*) (T, const R&)> (
x, ya, fcn); }
472template <
typename U,
typename T,
typename R>
475{
return binmap<U, T, R, U (*) (T, const R&)> (xa, y, fcn); }
477template <
typename U,
typename T,
typename R>
481{
return binmap<U, T, R, U (*) (T, const R&)> (xa, ya, fcn, name); }
483template <
typename U,
typename T,
typename R>
486{
return binmap<U, T, R, U (*) (T, const R&)> (
x, ya, fcn); }
488template <
typename U,
typename T,
typename R>
491{
return binmap<U, T, R, U (*) (T, const R&)> (xa, y, fcn); }
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))
bool is_valid_bsxfun(const std::string &name, const dim_vector &xdv, const dim_vector &ydv)
N Dimensional Array with copy-on-write semantics.
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
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.
octave_idx_type cols() const
Array< T > array_value() const
Sparse< T, Alloc > maybe_compress(bool remove_zeros=false)
octave_idx_type nnz() const
Actual number of nonzero terms.
octave_idx_type rows() const
octave_idx_type * xcidx()
octave_idx_type * xridx()
static void op_sm(std::size_t n, R *r, X x, const Y *y)
static void op_mm(std::size_t n, R *r, const X *x, const Y *y)
static void op_ms(std::size_t n, R *r, const X *x, Y y)
static void set_f(const F &f_in)
Vector representing the dimensions (size) of an Array.
F77_RET_T const F77_DBLE * x
Array< U > binmap(const T &x, const Array< R > &ya, F fcn)