annotate liboctave/array/MSparse.cc @ 20614:10ec79b47808

use new string_value method to handle value extraction errors * __voronoi__.cc, chol.cc, colamd.cc, fftw.cc: Use new string_value method.
author John W. Eaton <jwe@octave.org>
date Thu, 08 Oct 2015 18:15:56 -0400
parents 2aa4fb60ae77
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
1 /*
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
2
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18712
diff changeset
3 Copyright (C) 2004-2015 David Bateman
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10350
diff changeset
4 Copyright (C) 1998-2004 Andy Adler
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6221
diff changeset
5
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6221
diff changeset
6 This file is part of Octave.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
7
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6221
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6221
diff changeset
11 option) any later version.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
12
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
16 for more details.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
17
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6221
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6221
diff changeset
20 <http://www.gnu.org/licenses/>.
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
21
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
22 */
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
23
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
24 // sparse array with math ops.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
25
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
26 // Element by element MSparse by MSparse ops.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
27
13264
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
28 template <class T, class OP>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
29 MSparse<T>&
13264
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
30 plus_or_minus (MSparse<T>& a, const MSparse<T>& b, OP op, const char* op_name)
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
31 {
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
32 MSparse<T> r;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
33
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
34 octave_idx_type a_nr = a.rows ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
35 octave_idx_type a_nc = a.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
36
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
37 octave_idx_type b_nr = b.rows ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
38 octave_idx_type b_nc = b.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
39
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
40 if (a_nr != b_nr || a_nc != b_nc)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
41 gripe_nonconformant (op_name , a_nr, a_nc, b_nr, b_nc);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
42 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
43 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
44 r = MSparse<T> (a_nr, a_nc, (a.nnz () + b.nnz ()));
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
45
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
46 octave_idx_type jx = 0;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
47 for (octave_idx_type i = 0 ; i < a_nc ; i++)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
48 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
49 octave_idx_type ja = a.cidx (i);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
50 octave_idx_type ja_max = a.cidx (i+1);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
51 bool ja_lt_max= ja < ja_max;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
52
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
53 octave_idx_type jb = b.cidx (i);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
54 octave_idx_type jb_max = b.cidx (i+1);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
55 bool jb_lt_max = jb < jb_max;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
56
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 17769
diff changeset
57 while (ja_lt_max || jb_lt_max)
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
58 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
59 octave_quit ();
19898
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
60 if ((! jb_lt_max) || (ja_lt_max && (a.ridx (ja) < b.ridx (jb))))
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
61 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
62 r.ridx (jx) = a.ridx (ja);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
63 r.data (jx) = op (a.data (ja), 0.);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
64 jx++;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
65 ja++;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
66 ja_lt_max= ja < ja_max;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
67 }
19898
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
68 else if ((! ja_lt_max)
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
69 || (jb_lt_max && (b.ridx (jb) < a.ridx (ja))))
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
70 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
71 r.ridx (jx) = b.ridx (jb);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
72 r.data (jx) = op (0., b.data (jb));
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
73 jx++;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
74 jb++;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
75 jb_lt_max= jb < jb_max;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
76 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
77 else
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
78 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
79 if (op (a.data (ja), b.data (jb)) != 0.)
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
80 {
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
81 r.data (jx) = op (a.data (ja), b.data (jb));
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
82 r.ridx (jx) = a.ridx (ja);
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
83 jx++;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
84 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
85 ja++;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
86 ja_lt_max= ja < ja_max;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
87 jb++;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
88 jb_lt_max= jb < jb_max;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
89 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
90 }
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
91 r.cidx (i+1) = jx;
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
92 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
93
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
94 a = r.maybe_compress ();
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
95 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
96
17769
49a5a4be04a1 maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents: 17744
diff changeset
97 return a;
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
98 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
99
13264
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
100 template <typename T>
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
101 MSparse<T>&
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
102 operator += (MSparse<T>& a, const MSparse<T>& b)
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
103 {
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
104 return plus_or_minus (a, b, std::plus<T> (), "operator +=");
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
105 }
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
106
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
107 template <typename T>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
108 MSparse<T>&
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
109 operator -= (MSparse<T>& a, const MSparse<T>& b)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
110 {
13264
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
111 return plus_or_minus (a, b, std::minus<T> (), "operator -=");
11c8b60f1b68 Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 11586
diff changeset
112 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11570
diff changeset
113
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
114
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
115 // Element by element MSparse by scalar ops.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
116
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
117 template <class T, class OP>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
118 MArray<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
119 plus_or_minus (const MSparse<T>& a, const T& s, OP op)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
120 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
121 octave_idx_type nr = a.rows ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
122 octave_idx_type nc = a.cols ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
123
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
124 MArray<T> r (dim_vector (nr, nc), op (0.0, s));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
125
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
126 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
127 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
128 r.elem (a.ridx (i), j) = op (a.data (i), s);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
129 return r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
130 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
131
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
132 template <typename T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
133 MArray<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
134 operator + (const MSparse<T>& a, const T& s)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
135 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
136 return plus_or_minus (a, s, std::plus<T> ());
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
137 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
138
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
139 template <typename T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
140 MArray<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
141 operator - (const MSparse<T>& a, const T& s)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
142 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
143 return plus_or_minus (a, s, std::minus<T> ());
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
144 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
145
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
146
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
147 template <class T, class OP>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
148 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
149 times_or_divide (const MSparse<T>& a, const T& s, OP op)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
150 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
151 octave_idx_type nr = a.rows ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
152 octave_idx_type nc = a.cols ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
153 octave_idx_type nz = a.nnz ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
154
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
155 MSparse<T> r (nr, nc, nz);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
156
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
157 for (octave_idx_type i = 0; i < nz; i++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
158 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
159 r.data (i) = op (a.data (i), s);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
160 r.ridx (i) = a.ridx (i);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
161 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
162 for (octave_idx_type i = 0; i < nc + 1; i++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
163 r.cidx (i) = a.cidx (i);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
164 r.maybe_compress (true);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
165 return r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
166 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
167
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
168 template <typename T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
169 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
170 operator * (const MSparse<T>& a, const T& s)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
171 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
172 return times_or_divide (a, s, std::multiplies<T> ());
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
173 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
174
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
175 template <typename T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
176 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
177 operator / (const MSparse<T>& a, const T& s)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
178 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
179 return times_or_divide (a, s, std::divides<T> ());
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
180 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
181
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
182
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
183 // Element by element scalar by MSparse ops.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
184
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
185 template <class T, class OP>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
186 MArray<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
187 plus_or_minus (const T& s, const MSparse<T>& a, OP op)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
188 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
189 octave_idx_type nr = a.rows ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
190 octave_idx_type nc = a.cols ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
191
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
192 MArray<T> r (dim_vector (nr, nc), op (s, 0.0));
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
193
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
194 for (octave_idx_type j = 0; j < nc; j++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
195 for (octave_idx_type i = a.cidx (j); i < a.cidx (j+1); i++)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
196 r.elem (a.ridx (i), j) = op (s, a.data (i));
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
197 return r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
198 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
199
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
200 template <typename T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
201 MArray<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
202 operator + (const T& s, const MSparse<T>& a)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
203 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
204 return plus_or_minus (s, a, std::plus<T> ());
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
205 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
206
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
207 template <typename T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
208 MArray<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
209 operator - (const T& s, const MSparse<T>& a)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
210 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
211 return plus_or_minus (s, a, std::minus<T> ());
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
212 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
213
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
214 template <class T, class OP>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
215 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
216 times_or_divides (const T& s, const MSparse<T>& a, OP op)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
217 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
218 octave_idx_type nr = a.rows ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
219 octave_idx_type nc = a.cols ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
220 octave_idx_type nz = a.nnz ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
221
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
222 MSparse<T> r (nr, nc, nz);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
223
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
224 for (octave_idx_type i = 0; i < nz; i++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
225 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
226 r.data (i) = op (s, a.data (i));
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
227 r.ridx (i) = a.ridx (i);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
228 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
229 for (octave_idx_type i = 0; i < nc + 1; i++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
230 r.cidx (i) = a.cidx (i);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
231 r.maybe_compress (true);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
232 return r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
233 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
234
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
235 template <class T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
236 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
237 operator * (const T& s, const MSparse<T>& a)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
238 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
239 return times_or_divides (s, a, std::multiplies<T> ());
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
240 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
241
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
242 template <class T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
243 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
244 operator / (const T& s, const MSparse<T>& a)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
245 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
246 return times_or_divides (s, a, std::divides<T> ());
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
247 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
248
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
249
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
250 // Element by element MSparse by MSparse ops.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
251
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
252 template <class T, class OP>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
253 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
254 plus_or_minus (const MSparse<T>& a, const MSparse<T>& b, OP op,
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
255 const char* op_name, bool negate)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
256 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
257 MSparse<T> r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
258
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
259 octave_idx_type a_nr = a.rows ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
260 octave_idx_type a_nc = a.cols ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
261
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
262 octave_idx_type b_nr = b.rows ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
263 octave_idx_type b_nc = b.cols ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
264
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
265 if (a_nr == 1 && a_nc == 1)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
266 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
267 if (a.elem (0,0) == 0.)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
268 if (negate)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
269 r = -MSparse<T> (b);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
270 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
271 r = MSparse<T> (b);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
272 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
273 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
274 r = MSparse<T> (b_nr, b_nc, op (a.data (0), 0.));
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
275
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
276 for (octave_idx_type j = 0 ; j < b_nc ; j++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
277 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
278 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
279 octave_idx_type idxj = j * b_nr;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
280 for (octave_idx_type i = b.cidx (j) ; i < b.cidx (j+1) ; i++)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
281 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
282 octave_quit ();
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
283 r.data (idxj + b.ridx (i)) = op (a.data (0), b.data (i));
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
284 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
285 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
286 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
287 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
288 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
289 else if (b_nr == 1 && b_nc == 1)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
290 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
291 if (b.elem (0,0) == 0.)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
292 r = MSparse<T> (a);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
293 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
294 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
295 r = MSparse<T> (a_nr, a_nc, op (0.0, b.data (0)));
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
296
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
297 for (octave_idx_type j = 0 ; j < a_nc ; j++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
298 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
299 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
300 octave_idx_type idxj = j * a_nr;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
301 for (octave_idx_type i = a.cidx (j) ; i < a.cidx (j+1) ; i++)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
302 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
303 octave_quit ();
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
304 r.data (idxj + a.ridx (i)) = op (a.data (i), b.data (0));
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
305 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
306 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
307 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
308 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
309 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
310 else if (a_nr != b_nr || a_nc != b_nc)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
311 gripe_nonconformant (op_name, a_nr, a_nc, b_nr, b_nc);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
312 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
313 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
314 r = MSparse<T> (a_nr, a_nc, (a.nnz () + b.nnz ()));
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
315
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
316 octave_idx_type jx = 0;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
317 r.cidx (0) = 0;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
318 for (octave_idx_type i = 0 ; i < a_nc ; i++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
319 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
320 octave_idx_type ja = a.cidx (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
321 octave_idx_type ja_max = a.cidx (i+1);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
322 bool ja_lt_max= ja < ja_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
323
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
324 octave_idx_type jb = b.cidx (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
325 octave_idx_type jb_max = b.cidx (i+1);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
326 bool jb_lt_max = jb < jb_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
327
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 17769
diff changeset
328 while (ja_lt_max || jb_lt_max)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
329 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
330 octave_quit ();
19898
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
331 if ((! jb_lt_max) || (ja_lt_max && (a.ridx (ja) < b.ridx (jb))))
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
332 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
333 r.ridx (jx) = a.ridx (ja);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
334 r.data (jx) = op (a.data (ja), 0.);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
335 jx++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
336 ja++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
337 ja_lt_max= ja < ja_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
338 }
19898
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
339 else if ((! ja_lt_max)
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
340 || (jb_lt_max && (b.ridx (jb) < a.ridx (ja))))
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
341 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
342 r.ridx (jx) = b.ridx (jb);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
343 r.data (jx) = op (0., b.data (jb));
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
344 jx++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
345 jb++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
346 jb_lt_max= jb < jb_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
347 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
348 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
349 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
350 if (op (a.data (ja), b.data (jb)) != 0.)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
351 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
352 r.data (jx) = op (a.data (ja), b.data (jb));
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
353 r.ridx (jx) = a.ridx (ja);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
354 jx++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
355 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
356 ja++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
357 ja_lt_max= ja < ja_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
358 jb++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
359 jb_lt_max= jb < jb_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
360 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
361 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
362 r.cidx (i+1) = jx;
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
363 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
364
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
365 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
366 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
367
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
368 return r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
369 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
370
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
371 template <class T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
372 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
373 operator+ (const MSparse<T>& a, const MSparse<T>& b)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
374 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
375 return plus_or_minus (a, b, std::plus<T> (), "operator +", false);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
376 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
377
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
378 template <class T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
379 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
380 operator- (const MSparse<T>& a, const MSparse<T>& b)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
381 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
382 return plus_or_minus (a, b, std::minus<T> (), "operator -", true);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
383 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
384
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
385 template <class T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
386 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
387 product (const MSparse<T>& a, const MSparse<T>& b)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
388 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
389 MSparse<T> r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
390
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
391 octave_idx_type a_nr = a.rows ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
392 octave_idx_type a_nc = a.cols ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
393
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
394 octave_idx_type b_nr = b.rows ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
395 octave_idx_type b_nc = b.cols ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
396
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
397 if (a_nr == 1 && a_nc == 1)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
398 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
399 if (a.elem (0,0) == 0.)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
400 r = MSparse<T> (b_nr, b_nc);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
401 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
402 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
403 r = MSparse<T> (b);
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
404 octave_idx_type b_nnz = b.nnz ();
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
405
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
406 for (octave_idx_type i = 0 ; i < b_nnz ; i++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
407 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
408 octave_quit ();
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
409 r.data (i) = a.data (0) * r.data (i);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
410 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
411 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
412 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
413 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
414 else if (b_nr == 1 && b_nc == 1)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
415 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
416 if (b.elem (0,0) == 0.)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
417 r = MSparse<T> (a_nr, a_nc);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
418 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
419 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
420 r = MSparse<T> (a);
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
421 octave_idx_type a_nnz = a.nnz ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
422
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
423 for (octave_idx_type i = 0 ; i < a_nnz ; i++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
424 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
425 octave_quit ();
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
426 r.data (i) = r.data (i) * b.data (0);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
427 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
428 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
429 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
430 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
431 else if (a_nr != b_nr || a_nc != b_nc)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
432 gripe_nonconformant ("product", a_nr, a_nc, b_nr, b_nc);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
433 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
434 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
435 r = MSparse<T> (a_nr, a_nc, (a.nnz () > b.nnz () ? a.nnz () : b.nnz ()));
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
436
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
437 octave_idx_type jx = 0;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
438 r.cidx (0) = 0;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
439 for (octave_idx_type i = 0 ; i < a_nc ; i++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
440 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
441 octave_idx_type ja = a.cidx (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
442 octave_idx_type ja_max = a.cidx (i+1);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
443 bool ja_lt_max= ja < ja_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
444
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
445 octave_idx_type jb = b.cidx (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
446 octave_idx_type jb_max = b.cidx (i+1);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
447 bool jb_lt_max = jb < jb_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
448
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 17769
diff changeset
449 while (ja_lt_max || jb_lt_max)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
450 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
451 octave_quit ();
19898
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
452 if ((! jb_lt_max) || (ja_lt_max && (a.ridx (ja) < b.ridx (jb))))
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
453 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
454 ja++; ja_lt_max= ja < ja_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
455 }
19898
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
456 else if ((! ja_lt_max)
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
457 || (jb_lt_max && (b.ridx (jb) < a.ridx (ja))))
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
458 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
459 jb++; jb_lt_max= jb < jb_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
460 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
461 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
462 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
463 if ((a.data (ja) * b.data (jb)) != 0.)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
464 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
465 r.data (jx) = a.data (ja) * b.data (jb);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
466 r.ridx (jx) = a.ridx (ja);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
467 jx++;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
468 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
469 ja++; ja_lt_max= ja < ja_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
470 jb++; jb_lt_max= jb < jb_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
471 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
472 }
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
473 r.cidx (i+1) = jx;
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
474 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
475
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
476 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
477 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
478
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
479 return r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
480 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
481
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
482 template <class T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
483 MSparse<T>
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
484 quotient (const MSparse<T>& a, const MSparse<T>& b)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
485 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
486 MSparse<T> r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
487 T Zero = T ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
488
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
489 octave_idx_type a_nr = a.rows ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
490 octave_idx_type a_nc = a.cols ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
491
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
492 octave_idx_type b_nr = b.rows ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
493 octave_idx_type b_nc = b.cols ();
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
494
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
495 if (a_nr == 1 && a_nc == 1)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
496 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
497 T val = a.elem (0,0);
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
498 T fill = val / T ();
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
499 if (fill == T ())
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
500 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
501 octave_idx_type b_nnz = b.nnz ();
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
502 r = MSparse<T> (b);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
503 for (octave_idx_type i = 0 ; i < b_nnz ; i++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
504 r.data (i) = val / r.data (i);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
505 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
506 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
507 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
508 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
509 r = MSparse<T> (b_nr, b_nc, fill);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
510 for (octave_idx_type j = 0 ; j < b_nc ; j++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
511 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
512 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
513 octave_idx_type idxj = j * b_nr;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
514 for (octave_idx_type i = b.cidx (j) ; i < b.cidx (j+1) ; i++)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
515 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
516 octave_quit ();
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
517 r.data (idxj + b.ridx (i)) = val / b.data (i);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
518 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
519 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
520 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
521 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
522 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
523 else if (b_nr == 1 && b_nc == 1)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
524 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
525 T val = b.elem (0,0);
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
526 T fill = T () / val;
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
527 if (fill == T ())
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
528 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
529 octave_idx_type a_nnz = a.nnz ();
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
530 r = MSparse<T> (a);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
531 for (octave_idx_type i = 0 ; i < a_nnz ; i++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
532 r.data (i) = r.data (i) / val;
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
533 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
534 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
535 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
536 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
537 r = MSparse<T> (a_nr, a_nc, fill);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
538 for (octave_idx_type j = 0 ; j < a_nc ; j++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
539 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
540 octave_quit ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
541 octave_idx_type idxj = j * a_nr;
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
542 for (octave_idx_type i = a.cidx (j) ; i < a.cidx (j+1) ; i++)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
543 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
544 octave_quit ();
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
545 r.data (idxj + a.ridx (i)) = a.data (i) / val;
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
546 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
547 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
548 r.maybe_compress ();
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
549 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
550 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
551 else if (a_nr != b_nr || a_nc != b_nc)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
552 gripe_nonconformant ("quotient", a_nr, a_nc, b_nr, b_nc);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
553 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
554 {
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 17769
diff changeset
555 r = MSparse<T> (a_nr, a_nc, (Zero / Zero));
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
556
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
557 for (octave_idx_type i = 0 ; i < a_nc ; i++)
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
558 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
559 octave_idx_type ja = a.cidx (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
560 octave_idx_type ja_max = a.cidx (i+1);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
561 bool ja_lt_max= ja < ja_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
562
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
563 octave_idx_type jb = b.cidx (i);
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
564 octave_idx_type jb_max = b.cidx (i+1);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
565 bool jb_lt_max = jb < jb_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
566
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 17769
diff changeset
567 while (ja_lt_max || jb_lt_max)
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
568 {
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
569 octave_quit ();
19898
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
570 if ((! jb_lt_max) || (ja_lt_max && (a.ridx (ja) < b.ridx (jb))))
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
571 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
572 r.elem (a.ridx (ja),i) = a.data (ja) / Zero;
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
573 ja++; ja_lt_max= ja < ja_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
574 }
19898
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
575 else if ((! ja_lt_max)
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
576 || (jb_lt_max && (b.ridx (jb) < a.ridx (ja))))
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
577 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
578 r.elem (b.ridx (jb),i) = Zero / b.data (jb);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
579 jb++; jb_lt_max= jb < jb_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
580 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
581 else
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
582 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
583 r.elem (a.ridx (ja),i) = a.data (ja) / b.data (jb);
13265
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
584 ja++; ja_lt_max= ja < ja_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
585 jb++; jb_lt_max= jb < jb_max;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
586 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
587 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
588 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
589
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
590 r.maybe_compress (true);
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
591 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
592
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
593 return r;
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
594 }
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
595
89789bc755a1 Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13264
diff changeset
596
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
597
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
598 // Unary MSparse ops.
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
599
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
600 template <class T>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
601 MSparse<T>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
602 operator + (const MSparse<T>& a)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
603 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
604 return a;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
605 }
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
606
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
607 template <class T>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
608 MSparse<T>
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
609 operator - (const MSparse<T>& a)
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
610 {
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
611 MSparse<T> retval (a);
5681
233d98d95659 [project @ 2006-03-16 17:48:55 by dbateman]
dbateman
parents: 5604
diff changeset
612 octave_idx_type nz = a.nnz ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
613 for (octave_idx_type i = 0; i < nz; i++)
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
614 retval.data (i) = - retval.data (i);
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
615 return retval;
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents:
diff changeset
616 }