28 template <
typename T,
typename OP>
50 bool ja_lt_max = ja < ja_max;
54 bool jb_lt_max = jb < jb_max;
56 while (ja_lt_max || jb_lt_max)
59 if ((! jb_lt_max) || (ja_lt_max && (
a.ridx (ja) <
b.ridx (jb))))
61 r.
ridx (jx) =
a.ridx (ja);
62 r.
data (jx) = op (
a.data (ja), 0.);
65 ja_lt_max= ja < ja_max;
67 else if ((! ja_lt_max)
68 || (jb_lt_max && (
b.ridx (jb) <
a.ridx (ja))))
70 r.
ridx (jx) =
b.ridx (jb);
71 r.
data (jx) = op (0.,
b.data (jb));
74 jb_lt_max= jb < jb_max;
78 if (op (
a.data (ja),
b.data (jb)) != 0.)
80 r.
data (jx) = op (
a.data (ja),
b.data (jb));
81 r.
ridx (jx) =
a.ridx (ja);
85 ja_lt_max= ja < ja_max;
87 jb_lt_max= jb < jb_max;
105 template <
typename T>
114 template <
typename T,
typename OP>
125 r.
elem (
a.ridx (
i), j) = op (
a.data (
i),
s);
129 template <
typename T>
136 template <
typename T>
143 template <
typename T,
typename OP>
164 template <
typename T>
171 template <
typename T>
180 template <
typename T,
typename OP>
191 r.
elem (
a.ridx (
i), j) = op (
s,
a.data (
i));
195 template <
typename T>
202 template <
typename T>
209 template <
typename T,
typename OP>
230 template <
typename T>
237 template <
typename T>
246 template <
typename T,
typename OP>
249 const char *op_name,
bool negate)
261 if (
a.elem (0,0) == 0.)
277 r.
data (idxj +
b.ridx (
i)) = op (
a.data (0),
b.data (
i));
285 if (
b.elem (0,0) == 0.)
298 r.
data (idxj +
a.ridx (
i)) = op (
a.data (
i),
b.data (0));
316 bool ja_lt_max = ja < ja_max;
320 bool jb_lt_max = jb < jb_max;
322 while (ja_lt_max || jb_lt_max)
325 if ((! jb_lt_max) || (ja_lt_max && (
a.ridx (ja) <
b.ridx (jb))))
327 r.
ridx (jx) =
a.ridx (ja);
328 r.
data (jx) = op (
a.data (ja), 0.);
331 ja_lt_max= ja < ja_max;
333 else if ((! ja_lt_max)
334 || (jb_lt_max && (
b.ridx (jb) <
a.ridx (ja))))
336 r.
ridx (jx) =
b.ridx (jb);
337 r.
data (jx) = op (0.,
b.data (jb));
340 jb_lt_max= jb < jb_max;
344 if (op (
a.data (ja),
b.data (jb)) != 0.)
346 r.
data (jx) = op (
a.data (ja),
b.data (jb));
347 r.
ridx (jx) =
a.ridx (ja);
351 ja_lt_max= ja < ja_max;
353 jb_lt_max= jb < jb_max;
365 template <
typename T>
372 template <
typename T>
379 template <
typename T>
393 if (
a.elem (0,0) == 0.)
410 if (
b.elem (0,0) == 0.)
437 bool ja_lt_max = ja < ja_max;
441 bool jb_lt_max = jb < jb_max;
443 while (ja_lt_max || jb_lt_max)
446 if ((! jb_lt_max) || (ja_lt_max && (
a.ridx (ja) <
b.ridx (jb))))
448 ja++; ja_lt_max= ja < ja_max;
450 else if ((! ja_lt_max)
451 || (jb_lt_max && (
b.ridx (jb) <
a.ridx (ja))))
453 jb++; jb_lt_max= jb < jb_max;
457 if ((
a.data (ja) *
b.data (jb)) != 0.)
459 r.
data (jx) =
a.data (ja) *
b.data (jb);
460 r.
ridx (jx) =
a.ridx (ja);
463 ja++; ja_lt_max= ja < ja_max;
464 jb++; jb_lt_max= jb < jb_max;
476 template <
typename T>
491 T
val =
a.elem (0,0);
519 T
val =
b.elem (0,0);
555 bool ja_lt_max = ja < ja_max;
559 bool jb_lt_max = jb < jb_max;
561 while (ja_lt_max || jb_lt_max)
564 if ((! jb_lt_max) || (ja_lt_max && (
a.ridx (ja) <
b.ridx (jb))))
566 r.
elem (
a.ridx (ja),
i) =
a.data (ja) / Zero;
567 ja++; ja_lt_max= ja < ja_max;
569 else if ((! ja_lt_max)
570 || (jb_lt_max && (
b.ridx (jb) <
a.ridx (ja))))
572 r.
elem (
b.ridx (jb),
i) = Zero /
b.data (jb);
573 jb++; jb_lt_max= jb < jb_max;
577 r.
elem (
a.ridx (ja),
i) =
a.data (ja) /
b.data (jb);
578 ja++; ja_lt_max= ja < ja_max;
579 jb++; jb_lt_max= jb < jb_max;
592 template <
typename T>
599 template <
typename T>
Template for N-dimensional array classes with like-type math operators.
MSparse< T > operator*(const MSparse< T > &a, const T &s)
identity matrix If supplied two scalar respectively For allows like xample val
MSparse< T > & operator-=(MSparse< T > &a, const MSparse< T > &b)
octave_idx_type * cidx(void)
MSparse< T > product(const MSparse< T > &a, const MSparse< T > &b)
T & elem(octave_idx_type n)
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
MSparse< T > times_or_divide(const MSparse< T > &a, const T &s, OP op)
MSparse< T > quotient(const MSparse< T > &a, const MSparse< T > &b)
T & elem(octave_idx_type n)
void err_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)
octave_idx_type * ridx(void)
MSparse< T > times_or_divides(const T &s, const MSparse< T > &a, OP op)
MSparse< T > operator/(const MSparse< T > &a, const T &s)
MSparse< T > & operator+=(MSparse< T > &a, const MSparse< T > &b)
MArray< T > operator-(const MSparse< T > &a, const T &s)
MSparse< T > & plus_or_minus(MSparse< T > &a, const MSparse< T > &b, OP op, const char *op_name)
Sparse< T > maybe_compress(bool remove_zeros=false)
MArray< T > operator+(const MSparse< T > &a, const T &s)
Vector representing the dimensions (size) of an Array.