30 template <
typename T,
typename OP>
42 if (a_nr != b_nr || a_nc != b_nc)
52 bool ja_lt_max = ja < ja_max;
56 bool jb_lt_max = jb < jb_max;
58 while (ja_lt_max || jb_lt_max)
61 if ((! jb_lt_max) || (ja_lt_max && (a.
ridx (ja) < b.
ridx (jb))))
63 r.ridx (jx) = a.
ridx (ja);
64 r.data (jx) = op (a.
data (ja), 0.);
67 ja_lt_max= ja < ja_max;
69 else if ((! ja_lt_max)
72 r.ridx (jx) = b.
ridx (jb);
73 r.data (jx) = op (0., b.
data (jb));
76 jb_lt_max= jb < jb_max;
80 if (op (a.
data (ja), b.
data (jb)) != 0.)
82 r.data (jx) = op (a.
data (ja), b.
data (jb));
83 r.ridx (jx) = a.
ridx (ja);
87 ja_lt_max= ja < ja_max;
89 jb_lt_max= jb < jb_max;
95 a =
r.maybe_compress ();
100 template <
typename T>
107 template <
typename T>
111 return plus_or_minus (a, b, std::minus<T> (),
"operator -=");
116 template <
typename T,
typename OP>
127 r.elem (a.
ridx (i), j) = op (a.
data (i), s);
131 template <
typename T>
138 template <
typename T>
145 template <
typename T,
typename OP>
157 r.data (i) = op (a.
data (i), s);
158 r.ridx (i) = a.
ridx (i);
161 r.cidx (i) = a.
cidx (i);
162 r.maybe_compress (
true);
166 template <
typename T>
173 template <
typename T>
182 template <
typename T,
typename OP>
193 r.elem (a.
ridx (i), j) = op (s, a.
data (i));
197 template <
typename T>
204 template <
typename T>
211 template <
typename T,
typename OP>
223 r.data (i) = op (s, a.
data (i));
224 r.ridx (i) = a.
ridx (i);
227 r.cidx (i) = a.
cidx (i);
228 r.maybe_compress (
true);
232 template <
typename T>
239 template <
typename T>
248 template <
typename T,
typename OP>
251 const char *op_name,
bool negate)
261 if (a_nr == 1 && a_nc == 1)
263 if (a.
elem (0, 0) == 0.)
285 else if (b_nr == 1 && b_nc == 1)
287 if (b.
elem (0, 0) == 0.)
306 else if (a_nr != b_nr || a_nc != b_nc)
318 bool ja_lt_max = ja < ja_max;
322 bool jb_lt_max = jb < jb_max;
324 while (ja_lt_max || jb_lt_max)
327 if ((! jb_lt_max) || (ja_lt_max && (a.
ridx (ja) < b.
ridx (jb))))
329 r.ridx (jx) = a.
ridx (ja);
330 r.data (jx) = op (a.
data (ja), 0.);
333 ja_lt_max= ja < ja_max;
335 else if ((! ja_lt_max)
338 r.ridx (jx) = b.
ridx (jb);
339 r.data (jx) = op (0., b.
data (jb));
342 jb_lt_max= jb < jb_max;
346 if (op (a.
data (ja), b.
data (jb)) != 0.)
348 r.data (jx) = op (a.
data (ja), b.
data (jb));
349 r.ridx (jx) = a.
ridx (ja);
353 ja_lt_max= ja < ja_max;
355 jb_lt_max= jb < jb_max;
367 template <
typename T>
371 return plus_or_minus (a, b, std::plus<T> (),
"operator +",
false);
374 template <
typename T>
378 return plus_or_minus (a, b, std::minus<T> (),
"operator -",
true);
381 template <
typename T>
393 if (a_nr == 1 && a_nc == 1)
395 if (a.
elem (0, 0) == 0.)
405 r.data (i) = a.
data (0) *
r.data (i);
410 else if (b_nr == 1 && b_nc == 1)
412 if (b.
elem (0, 0) == 0.)
422 r.data (i) =
r.data (i) * b.
data (0);
427 else if (a_nr != b_nr || a_nc != b_nc)
439 bool ja_lt_max = ja < ja_max;
443 bool jb_lt_max = jb < jb_max;
445 while (ja_lt_max || jb_lt_max)
448 if ((! jb_lt_max) || (ja_lt_max && (a.
ridx (ja) < b.
ridx (jb))))
450 ja++; ja_lt_max= ja < ja_max;
452 else if ((! ja_lt_max)
455 jb++; jb_lt_max= jb < jb_max;
459 if ((a.
data (ja) * b.
data (jb)) != 0.)
462 r.ridx (jx) = a.
ridx (ja);
465 ja++; ja_lt_max= ja < ja_max;
466 jb++; jb_lt_max= jb < jb_max;
478 template <
typename T>
491 if (a_nr == 1 && a_nc == 1)
493 T val = a.
elem (0, 0);
500 r.data (i) = val /
r.data (i);
513 r.data (idxj + b.
ridx (i)) = val / b.
data (i);
519 else if (b_nr == 1 && b_nc == 1)
521 T val = b.
elem (0, 0);
528 r.data (i) =
r.data (i) / val;
541 r.data (idxj + a.
ridx (i)) = a.
data (i) / val;
547 else if (a_nr != b_nr || a_nc != b_nc)
557 bool ja_lt_max = ja < ja_max;
561 bool jb_lt_max = jb < jb_max;
563 while (ja_lt_max || jb_lt_max)
566 if ((! jb_lt_max) || (ja_lt_max && (a.
ridx (ja) < b.
ridx (jb))))
568 r.elem (a.
ridx (ja), i) = a.
data (ja) / Zero;
569 ja++; ja_lt_max= ja < ja_max;
571 else if ((! ja_lt_max)
574 r.elem (b.
ridx (jb), i) = Zero / b.
data (jb);
575 jb++; jb_lt_max= jb < jb_max;
580 ja++; ja_lt_max= ja < ja_max;
581 jb++; jb_lt_max= jb < jb_max;
586 r.maybe_compress (
true);
594 template <
typename T>
601 template <
typename T>
608 retval.
data (i) = - retval.
data (i);
MSparse< T > & operator-=(MSparse< T > &a, const MSparse< T > &b)
MSparse< T > times_or_divides(const T &s, const MSparse< T > &a, OP op)
MSparse< T > & plus_or_minus(MSparse< T > &a, const MSparse< T > &b, OP op, const char *op_name)
MArray< T > operator-(const MSparse< T > &a, const T &s)
MArray< T > operator+(const MSparse< T > &a, const T &s)
MSparse< T > times_or_divide(const MSparse< T > &a, const T &s, OP op)
MSparse< T > product(const MSparse< T > &a, const MSparse< T > &b)
MSparse< T > quotient(const MSparse< T > &a, const MSparse< T > &b)
MSparse< T > & operator+=(MSparse< T > &a, const MSparse< T > &b)
MSparse< T > operator/(const MSparse< T > &a, const T &s)
MSparse< T > operator*(const MSparse< T > &a, const T &s)
Template for N-dimensional array classes with like-type math operators.
octave_idx_type cols() const
T & elem(octave_idx_type n)
octave_idx_type nnz() const
Actual number of nonzero terms.
octave_idx_type rows() const
Vector representing the dimensions (size) of an Array.
void err_nonconformant(const char *op, octave_idx_type op1_len, octave_idx_type op2_len)