Mercurial > octave
annotate liboctave/array/MSparse.cc @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
5164 | 1 /* |
2 | |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 Copyright (C) 1998-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26381
diff
changeset
|
4 |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26381
diff
changeset
|
5 See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26381
diff
changeset
|
6 or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26381
diff
changeset
|
7 |
7016 | 8 |
9 This file is part of Octave. | |
5164 | 10 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
11 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
12 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
13 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 (at your option) any later version. |
5164 | 15 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
16 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
17 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
19 GNU General Public License for more details. |
5164 | 20 |
21 You should have received a copy of the GNU General Public License | |
7016 | 22 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
23 <https://www.gnu.org/licenses/>. |
5164 | 24 |
25 */ | |
26 | |
27 // sparse array with math ops. | |
28 | |
29 // Element by element MSparse by MSparse ops. | |
30 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
31 template <typename T, typename OP> |
5164 | 32 MSparse<T>& |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
33 plus_or_minus (MSparse<T>& a, const MSparse<T>& b, OP op, const char *op_name) |
5164 | 34 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
35 MSparse<T> r; |
5164 | 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 a_nr = a.rows (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
38 octave_idx_type a_nc = a.cols (); |
5164 | 39 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
40 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
|
41 octave_idx_type b_nc = b.cols (); |
5164 | 42 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
43 if (a_nr != b_nr || a_nc != b_nc) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
44 octave::err_nonconformant (op_name , a_nr, a_nc, b_nr, b_nc); |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
45 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
46 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
|
47 |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
48 octave_idx_type jx = 0; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
49 for (octave_idx_type i = 0 ; i < a_nc ; i++) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
50 { |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
51 octave_idx_type ja = a.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
52 octave_idx_type ja_max = a.cidx (i+1); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
53 bool ja_lt_max = ja < ja_max; |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
54 |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
55 octave_idx_type jb = b.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
56 octave_idx_type jb_max = b.cidx (i+1); |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
57 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
|
58 |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
59 while (ja_lt_max || jb_lt_max) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
60 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
61 octave_quit (); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
62 if ((! jb_lt_max) || (ja_lt_max && (a.ridx (ja) < b.ridx (jb)))) |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
63 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
64 r.ridx (jx) = a.ridx (ja); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
65 r.data (jx) = op (a.data (ja), 0.); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
66 jx++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
67 ja++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
68 ja_lt_max= ja < ja_max; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
69 } |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
70 else if ((! ja_lt_max) |
26381
3c5a676cd95b
MSparse.cc: Fix static analyzer detected V560 issues (bug #55347)
Andreas Weber <octave@josoansi.de>
parents:
26376
diff
changeset
|
71 || (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
|
72 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
73 r.ridx (jx) = b.ridx (jb); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
74 r.data (jx) = op (0., b.data (jb)); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
75 jx++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
76 jb++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
77 jb_lt_max= jb < jb_max; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
78 } |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
79 else |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
80 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
81 if (op (a.data (ja), b.data (jb)) != 0.) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
82 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
83 r.data (jx) = op (a.data (ja), b.data (jb)); |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
84 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
|
85 jx++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
86 } |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
87 ja++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
88 ja_lt_max= ja < ja_max; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
89 jb++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
90 jb_lt_max= jb < jb_max; |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
91 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
92 } |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
93 r.cidx (i+1) = jx; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
94 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
95 |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
96 a = r.maybe_compress (); |
5164 | 97 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
98 return a; |
5164 | 99 } |
100 | |
13264
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
101 template <typename T> |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
102 MSparse<T>& |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
103 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
|
104 { |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
105 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
|
106 } |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
107 |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
108 template <typename T> |
5164 | 109 MSparse<T>& |
110 operator -= (MSparse<T>& a, const MSparse<T>& b) | |
111 { | |
13264
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
112 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
|
113 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
114 |
5164 | 115 // Element by element MSparse by scalar ops. |
116 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
117 template <typename T, typename OP> |
13265
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 | 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 | 145 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
146 template <typename T, typename OP> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
147 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
148 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
|
149 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
150 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
|
151 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
|
152 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
|
153 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
154 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
|
155 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
156 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
|
157 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
158 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
|
159 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
|
160 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
161 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
|
162 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
|
163 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
|
164 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
165 } |
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 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
168 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
169 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
|
170 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
171 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
|
172 } |
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 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
175 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
176 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
|
177 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
178 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
|
179 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
180 |
5164 | 181 // Element by element scalar by MSparse ops. |
182 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
183 template <typename T, typename OP> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
184 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
185 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
|
186 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
187 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
|
188 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
|
189 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
190 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
|
191 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
196 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
197 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
198 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
199 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
200 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
|
201 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
202 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
|
203 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
204 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
205 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
206 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
207 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
|
208 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
209 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
|
210 } |
5164 | 211 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
212 template <typename T, typename OP> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
213 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
214 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
|
215 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
216 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
|
217 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
|
218 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
|
219 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
220 MSparse<T> r (nr, nc, nz); |
5164 | 221 |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
222 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
|
223 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
224 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
|
225 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
|
226 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
227 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
|
228 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
|
229 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
|
230 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
231 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
232 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
233 template <typename T> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
234 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
235 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
|
236 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
237 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
|
238 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
239 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
240 template <typename T> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
241 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
242 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
|
243 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
244 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
|
245 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
246 |
5164 | 247 // Element by element MSparse by MSparse ops. |
248 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
249 template <typename T, typename OP> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
250 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
251 plus_or_minus (const MSparse<T>& a, const MSparse<T>& b, OP op, |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
252 const char *op_name, bool negate) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
253 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
254 MSparse<T> r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
255 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
256 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
|
257 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
|
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 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
|
260 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
|
261 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
262 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
|
263 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
264 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
|
265 if (negate) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
266 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
|
267 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
268 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
|
269 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
270 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
271 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
|
272 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
273 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
|
274 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
275 octave_quit (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
276 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
|
277 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
|
278 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
279 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
280 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
|
281 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
282 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
283 r.maybe_compress (); |
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 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
|
287 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
288 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
|
289 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
|
290 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
291 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
292 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
|
293 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
294 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
|
295 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
296 octave_quit (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
297 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
|
298 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
|
299 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
300 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
301 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
|
302 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
303 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
304 r.maybe_compress (); |
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 else if (a_nr != b_nr || a_nc != b_nc) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
308 octave::err_nonconformant (op_name, a_nr, a_nc, b_nr, b_nc); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
309 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
310 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
311 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
|
312 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
313 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
|
314 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
|
315 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
|
316 { |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
317 octave_idx_type ja = a.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
318 octave_idx_type ja_max = a.cidx (i+1); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
319 bool ja_lt_max = ja < ja_max; |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
320 |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
321 octave_idx_type jb = b.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
322 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
|
323 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
|
324 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
325 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
|
326 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
327 octave_quit (); |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
328 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
|
329 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
330 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
|
331 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
|
332 jx++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
333 ja++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
334 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
|
335 } |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
336 else if ((! ja_lt_max) |
26381
3c5a676cd95b
MSparse.cc: Fix static analyzer detected V560 issues (bug #55347)
Andreas Weber <octave@josoansi.de>
parents:
26376
diff
changeset
|
337 || (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
|
338 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
339 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
|
340 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
|
341 jx++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
342 jb++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
343 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
|
344 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
345 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
346 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
347 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
|
348 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
349 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
|
350 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
|
351 jx++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
352 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
353 ja++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
354 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
|
355 jb++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
356 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
|
357 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
358 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
359 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
|
360 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
361 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
362 r.maybe_compress (); |
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 return r; |
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 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
368 template <typename T> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
369 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
370 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
|
371 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
372 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
|
373 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
374 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
375 template <typename T> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
376 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
377 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
|
378 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
379 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
|
380 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
381 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
382 template <typename T> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
383 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
384 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
|
385 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
386 MSparse<T> r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
387 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
388 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
|
389 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
|
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 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
|
392 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
|
393 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
394 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
|
395 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
396 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
|
397 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
|
398 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
399 { |
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); |
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
|
401 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
|
402 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
403 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
|
404 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
405 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
406 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
|
407 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
408 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
409 } |
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 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
|
412 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
413 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
|
414 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
|
415 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
416 { |
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); |
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
|
418 octave_idx_type a_nnz = a.nnz (); |
5164 | 419 |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
420 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
|
421 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
422 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
423 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
|
424 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
425 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
426 } |
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 else if (a_nr != b_nr || a_nc != b_nc) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
429 octave::err_nonconformant ("product", a_nr, a_nc, b_nr, b_nc); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
430 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
431 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
432 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
|
433 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
434 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
|
435 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
|
436 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
|
437 { |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
438 octave_idx_type ja = a.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
439 octave_idx_type ja_max = a.cidx (i+1); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
440 bool ja_lt_max = ja < ja_max; |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
441 |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
442 octave_idx_type jb = b.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
443 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
|
444 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
|
445 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
446 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
|
447 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
448 octave_quit (); |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
449 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
|
450 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
451 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
|
452 } |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
453 else if ((! ja_lt_max) |
26381
3c5a676cd95b
MSparse.cc: Fix static analyzer detected V560 issues (bug #55347)
Andreas Weber <octave@josoansi.de>
parents:
26376
diff
changeset
|
454 || (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
|
455 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
456 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
|
457 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
458 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
459 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
460 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
|
461 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
462 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
|
463 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
|
464 jx++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
465 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
466 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
|
467 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
|
468 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
469 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
470 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
|
471 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
472 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
473 r.maybe_compress (); |
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 return r; |
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 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
479 template <typename T> |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
480 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
481 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
|
482 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
483 MSparse<T> r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
484 T Zero = T (); |
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 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
|
487 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
|
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 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
|
490 octave_idx_type b_nc = b.cols (); |
5164 | 491 |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
492 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
|
493 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
494 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
|
495 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
|
496 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
|
497 { |
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 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
|
499 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
|
500 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
|
501 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
|
502 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
503 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
504 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
505 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
506 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
|
507 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
|
508 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
509 octave_quit (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
510 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
|
511 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
|
512 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
513 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
514 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
|
515 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
516 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
517 r.maybe_compress (); |
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 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
|
521 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
522 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
|
523 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
|
524 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
|
525 { |
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 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
|
527 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
|
528 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
|
529 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
|
530 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
531 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
532 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
533 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
534 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
|
535 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
|
536 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
537 octave_quit (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
538 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
|
539 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
|
540 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
541 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
542 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
|
543 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
544 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
545 r.maybe_compress (); |
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 else if (a_nr != b_nr || a_nc != b_nc) |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
549 octave::err_nonconformant ("quotient", a_nr, a_nc, b_nr, b_nc); |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
550 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
551 { |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
552 r = MSparse<T> (a_nr, a_nc, (Zero / Zero)); |
5164 | 553 |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
554 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
|
555 { |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
556 octave_idx_type ja = a.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
557 octave_idx_type ja_max = a.cidx (i+1); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
558 bool ja_lt_max = ja < ja_max; |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
559 |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
560 octave_idx_type jb = b.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
561 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
|
562 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
|
563 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
564 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
|
565 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
566 octave_quit (); |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
567 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
|
568 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
569 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
|
570 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
|
571 } |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
572 else if ((! ja_lt_max) |
26381
3c5a676cd95b
MSparse.cc: Fix static analyzer detected V560 issues (bug #55347)
Andreas Weber <octave@josoansi.de>
parents:
26376
diff
changeset
|
573 || (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
|
574 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
575 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
|
576 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
|
577 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
578 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
579 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
580 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
|
581 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
|
582 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
|
583 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
584 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
585 } |
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 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
|
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 return r; |
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 |
5164 | 593 // Unary MSparse ops. |
594 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
595 template <typename T> |
5164 | 596 MSparse<T> |
597 operator + (const MSparse<T>& a) | |
598 { | |
599 return a; | |
600 } | |
601 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
602 template <typename T> |
5164 | 603 MSparse<T> |
604 operator - (const MSparse<T>& a) | |
605 { | |
606 MSparse<T> retval (a); | |
5681 | 607 octave_idx_type nz = a.nnz (); |
5275 | 608 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
|
609 retval.data (i) = - retval.data (i); |
5164 | 610 return retval; |
611 } |