Mercurial > octave
annotate liboctave/array/MSparse.cc @ 30564:796f54d4ddbf stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
In all .txi and .texi files except gpl.txi and gpl.texi in the
doc/liboctave and doc/interpreter directories, change the copyright
to "Octave Project Developers", the same as used for other source
files. Update copyright notices for 2022 (not done since 2019). For
gpl.txi and gpl.texi, change the copyright notice to be "Free Software
Foundation, Inc." and leave the date at 2007 only because this file
only contains the text of the GPL, not anything created by the Octave
Project Developers.
Add Paul Thomas to contributors.in.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Dec 2021 18:22:40 -0500 |
parents | f3f3e3793fb5 |
children | 597f3ee61a48 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30394
diff
changeset
|
3 // Copyright (C) 1998-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
5164 | 25 |
26 // sparse array with math ops. | |
27 | |
28 // Element by element MSparse by MSparse ops. | |
29 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
30 template <typename T, typename OP> |
5164 | 31 MSparse<T>& |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
32 plus_or_minus (MSparse<T>& a, const MSparse<T>& b, OP op, const char *op_name) |
5164 | 33 { |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
34 MSparse<T> r; |
5164 | 35 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
36 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
|
37 octave_idx_type a_nc = a.cols (); |
5164 | 38 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
39 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
|
40 octave_idx_type b_nc = b.cols (); |
5164 | 41 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
42 if (a_nr != b_nr || a_nc != b_nc) |
27933
863ae57eee69
maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
43 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
|
44 |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
45 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
|
46 |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
47 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
|
48 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
|
49 { |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
50 octave_idx_type ja = a.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
51 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
|
52 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
|
53 |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
54 octave_idx_type jb = b.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
55 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
|
56 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
|
57 |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
58 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
|
59 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
60 octave_quit (); |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
61 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
|
62 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
63 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
|
64 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
|
65 jx++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
66 ja++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
67 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
|
68 } |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
69 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
|
70 || (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
|
71 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
72 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
|
73 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
|
74 jx++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
75 jb++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
76 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
|
77 } |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
78 else |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
79 { |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
80 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
|
81 { |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
82 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
|
83 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
|
84 jx++; |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
85 } |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
86 ja++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
87 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
|
88 jb++; |
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
89 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
|
90 } |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
91 } |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
92 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
|
93 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
94 |
21120
499b851fbfae
Replace pattern if/err_XXX/else/code with if/err_XXX/ code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
95 a = r.maybe_compress (); |
5164 | 96 |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
97 return a; |
5164 | 98 } |
99 | |
13264
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
100 template <typename T> |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
101 MSparse<T>& |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
102 operator += (MSparse<T>& a, const MSparse<T>& b) |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
103 { |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
104 return plus_or_minus (a, b, std::plus<T> (), "operator +="); |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
105 } |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
106 |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
107 template <typename T> |
5164 | 108 MSparse<T>& |
109 operator -= (MSparse<T>& a, const MSparse<T>& b) | |
110 { | |
13264
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
111 return plus_or_minus (a, b, std::minus<T> (), "operator -="); |
11c8b60f1b68
Eliminate duplicate code for op+= and op-= for MSparse
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
11586
diff
changeset
|
112 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
113 |
5164 | 114 // Element by element MSparse by scalar ops. |
115 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
116 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
|
117 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
118 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
|
119 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
120 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
|
121 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
|
122 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
123 MArray<T> r (dim_vector (nr, nc), op (0.0, s)); |
5164 | 124 |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
125 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
|
126 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
|
127 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
|
128 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
129 } |
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 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
132 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
133 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
|
134 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
135 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
|
136 } |
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 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
139 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
140 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
|
141 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
142 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
|
143 } |
5164 | 144 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
145 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
|
146 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
147 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
|
148 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
149 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
|
150 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
|
151 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
|
152 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
153 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
|
154 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
155 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
|
156 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
157 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
|
158 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
|
159 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
160 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
|
161 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
|
162 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
|
163 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
164 } |
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 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
167 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
168 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
|
169 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
170 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
|
171 } |
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 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
174 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
175 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
|
176 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
177 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
|
178 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
179 |
5164 | 180 // Element by element scalar by MSparse ops. |
181 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
182 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
|
183 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
184 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
|
185 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
186 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
|
187 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
|
188 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
189 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
|
190 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
195 } |
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 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
198 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
199 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
|
200 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
201 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
|
202 } |
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 template <typename T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
205 MArray<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
206 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
|
207 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
208 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
|
209 } |
5164 | 210 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
211 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
|
212 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
213 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
|
214 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
215 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
|
216 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
|
217 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
|
218 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
219 MSparse<T> r (nr, nc, nz); |
5164 | 220 |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
221 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
|
222 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
223 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
|
224 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
|
225 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
226 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
|
227 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
|
228 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
|
229 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
230 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
231 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
232 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
|
233 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
234 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
|
235 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
236 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
|
237 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
238 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
239 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
|
240 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
241 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
|
242 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
243 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
|
244 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
245 |
5164 | 246 // Element by element MSparse by MSparse ops. |
247 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
248 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
|
249 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
250 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
|
251 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
|
252 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
253 MSparse<T> r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
254 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
255 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
|
256 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
|
257 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
258 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
|
259 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
|
260 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
261 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
|
262 { |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29667
diff
changeset
|
263 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
|
264 if (negate) |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
265 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
|
266 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
267 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
|
268 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
269 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
270 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
|
271 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
272 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
|
273 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
274 octave_quit (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
275 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
|
276 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
|
277 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
278 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
279 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
|
280 } |
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 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
283 } |
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 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
|
286 { |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29667
diff
changeset
|
287 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
|
288 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
|
289 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
290 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
291 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
|
292 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
293 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
|
294 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
295 octave_quit (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
296 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
|
297 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
|
298 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
299 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
300 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
|
301 } |
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 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
304 } |
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 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
|
307 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
|
308 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
309 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
310 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
|
311 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 { |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
316 octave_idx_type ja = a.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
317 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
|
318 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
|
319 |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
320 octave_idx_type jb = b.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
321 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
|
322 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
|
323 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
324 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
|
325 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
326 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
|
327 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
|
328 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
329 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
|
330 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
|
331 jx++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
332 ja++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
333 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
|
334 } |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
335 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
|
336 || (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
|
337 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
338 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
|
339 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
|
340 jx++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
341 jb++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
342 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
|
343 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
344 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
345 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
346 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
|
347 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
348 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
|
349 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
|
350 jx++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
351 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
352 ja++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
353 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
|
354 jb++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
355 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
|
356 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
357 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
358 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
|
359 } |
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 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
362 } |
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 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
365 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
366 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
367 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
|
368 MSparse<T> |
29667
1311b9a3590e
MSparse.cc: Remove API flags from template definitions.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29659
diff
changeset
|
369 operator + (const MSparse<T>& a, const MSparse<T>& b) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
370 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
371 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
|
372 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
373 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
374 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
|
375 MSparse<T> |
29667
1311b9a3590e
MSparse.cc: Remove API flags from template definitions.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29659
diff
changeset
|
376 operator - (const MSparse<T>& a, const MSparse<T>& b) |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
377 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
378 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
|
379 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
380 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
381 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
|
382 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
383 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
|
384 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
385 MSparse<T> r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
386 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
387 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
|
388 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
|
389 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
390 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
|
391 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
|
392 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
393 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
|
394 { |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29667
diff
changeset
|
395 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
|
396 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
|
397 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
398 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
399 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
|
400 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
|
401 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
402 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
|
403 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
404 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
405 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
|
406 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
407 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
408 } |
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 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
|
411 { |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29667
diff
changeset
|
412 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
|
413 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
|
414 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
415 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
416 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
|
417 octave_idx_type a_nnz = a.nnz (); |
5164 | 418 |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
419 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
|
420 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
421 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
422 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
|
423 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
424 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
425 } |
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 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
|
428 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
|
429 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
430 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
431 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
|
432 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
433 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
|
434 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
|
435 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
|
436 { |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
437 octave_idx_type ja = a.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
438 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
|
439 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
|
440 |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
441 octave_idx_type jb = b.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
442 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
|
443 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
|
444 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
445 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
|
446 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
447 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
|
448 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
|
449 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
450 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
|
451 } |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
452 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
|
453 || (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
|
454 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
455 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
|
456 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
457 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
458 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
459 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
|
460 { |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
461 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
|
462 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
|
463 jx++; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
464 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
465 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
|
466 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
|
467 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
468 } |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
469 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
|
470 } |
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 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
473 } |
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 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
476 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
477 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
478 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
|
479 MSparse<T> |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
480 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
|
481 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
482 MSparse<T> r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
483 T Zero = T (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
484 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
485 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
|
486 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
|
487 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
488 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
|
489 octave_idx_type b_nc = b.cols (); |
5164 | 490 |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
491 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
|
492 { |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29667
diff
changeset
|
493 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
|
494 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
|
495 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
|
496 { |
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
|
497 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
|
498 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
|
499 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
|
500 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
|
501 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
502 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
503 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
504 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
505 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
|
506 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
|
507 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
508 octave_quit (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
509 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
|
510 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
|
511 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
512 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
513 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
|
514 } |
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 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
517 } |
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 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
|
520 { |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29667
diff
changeset
|
521 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
|
522 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
|
523 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
|
524 { |
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
|
525 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
|
526 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
|
527 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
|
528 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
|
529 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
530 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
531 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
532 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
533 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
|
534 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
|
535 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
536 octave_quit (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
537 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
|
538 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
|
539 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
540 octave_quit (); |
15018
3d8ace26c5b4
maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents:
14846
diff
changeset
|
541 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
|
542 } |
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 r.maybe_compress (); |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
545 } |
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 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
|
548 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
|
549 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
550 { |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
551 r = MSparse<T> (a_nr, a_nc, (Zero / Zero)); |
5164 | 552 |
13265
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
553 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
|
554 { |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
555 octave_idx_type ja = a.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
556 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
|
557 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
|
558 |
21562
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
559 octave_idx_type jb = b.cidx (i); |
6c2fd62db1f7
maint: Eliminate accidental double spaces in code.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
560 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
|
561 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
|
562 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
17769
diff
changeset
|
563 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
|
564 { |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
565 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
|
566 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
|
567 { |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29667
diff
changeset
|
568 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
|
569 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
|
570 } |
19864
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
571 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
|
572 || (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
|
573 { |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29667
diff
changeset
|
574 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
|
575 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
|
576 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
577 else |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
578 { |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29667
diff
changeset
|
579 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
|
580 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
|
581 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
|
582 } |
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 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
|
587 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
588 |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
589 return r; |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
590 } |
89789bc755a1
Use more templates in MSparse operators. Death to macros! ☠
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13264
diff
changeset
|
591 |
5164 | 592 // Unary MSparse ops. |
593 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
594 template <typename T> |
5164 | 595 MSparse<T> |
596 operator + (const MSparse<T>& a) | |
597 { | |
598 return a; | |
599 } | |
600 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21120
diff
changeset
|
601 template <typename T> |
5164 | 602 MSparse<T> |
603 operator - (const MSparse<T>& a) | |
604 { | |
605 MSparse<T> retval (a); | |
5681 | 606 octave_idx_type nz = a.nnz (); |
5275 | 607 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
|
608 retval.data (i) = - retval.data (i); |
5164 | 609 return retval; |
610 } |