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