Mercurial > octave
annotate libinterp/corefcn/sparse-xdiv.cc @ 23220:092078913d54
maint: Merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 22 Feb 2017 12:58:07 -0500 |
parents | ef4d915df748 3ac9f9ecfae5 |
children | c9fab0bc983e |
rev | line source |
---|---|
5164 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 2004-2017 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 | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
9 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
11 (at your option) any later version. |
5164 | 12 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
16 GNU General Public License for more details. |
5164 | 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 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21723
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
25 # include "config.h" |
5164 | 26 #endif |
27 | |
28 #include <cassert> | |
29 | |
30 #include "Array-util.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21024
diff
changeset
|
31 #include "lo-array-errwarn.h" |
5164 | 32 #include "oct-cmplx.h" |
33 #include "quit.h" | |
34 #include "error.h" | |
9003
0631d397fbe0
replace lo_ieee_isnan by xisnan, add missing includes
Jaroslav Hajek <highegg@gmail.com>
parents:
8965
diff
changeset
|
35 #include "lo-ieee.h" |
5164 | 36 |
37 #include "dSparse.h" | |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
38 #include "dDiagMatrix.h" |
5164 | 39 #include "CSparse.h" |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
40 #include "CDiagMatrix.h" |
5164 | 41 #include "oct-spparms.h" |
42 #include "sparse-xdiv.h" | |
43 | |
44 static void | |
45 solve_singularity_warning (double rcond) | |
46 { | |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
47 octave::warn_singular_matrix (rcond); |
5164 | 48 } |
49 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21112
diff
changeset
|
50 template <typename T1, typename T2> |
5164 | 51 bool |
52 mx_leftdiv_conform (const T1& a, const T2& b) | |
53 { | |
5275 | 54 octave_idx_type a_nr = a.rows (); |
55 octave_idx_type b_nr = b.rows (); | |
5164 | 56 |
57 if (a_nr != b_nr) | |
58 { | |
5275 | 59 octave_idx_type a_nc = a.cols (); |
60 octave_idx_type b_nc = b.cols (); | |
5164 | 61 |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
62 octave::err_nonconformant ("operator \\", a_nr, a_nc, b_nr, b_nc); |
5164 | 63 } |
64 | |
65 return true; | |
66 } | |
67 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
68 #define INSTANTIATE_MX_LEFTDIV_CONFORM(T1, T2) \ |
5164 | 69 template bool mx_leftdiv_conform (const T1&, const T2&) |
70 | |
71 INSTANTIATE_MX_LEFTDIV_CONFORM (SparseMatrix, SparseMatrix); | |
72 INSTANTIATE_MX_LEFTDIV_CONFORM (SparseMatrix, SparseComplexMatrix); | |
73 INSTANTIATE_MX_LEFTDIV_CONFORM (SparseComplexMatrix, SparseMatrix); | |
74 INSTANTIATE_MX_LEFTDIV_CONFORM (SparseComplexMatrix, SparseComplexMatrix); | |
75 INSTANTIATE_MX_LEFTDIV_CONFORM (SparseMatrix, Matrix); | |
76 INSTANTIATE_MX_LEFTDIV_CONFORM (SparseMatrix, ComplexMatrix); | |
77 INSTANTIATE_MX_LEFTDIV_CONFORM (SparseComplexMatrix, Matrix); | |
78 INSTANTIATE_MX_LEFTDIV_CONFORM (SparseComplexMatrix, ComplexMatrix); | |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
79 INSTANTIATE_MX_LEFTDIV_CONFORM (DiagMatrix, SparseMatrix); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
80 INSTANTIATE_MX_LEFTDIV_CONFORM (DiagMatrix, SparseComplexMatrix); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
81 INSTANTIATE_MX_LEFTDIV_CONFORM (ComplexDiagMatrix, SparseMatrix); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
82 INSTANTIATE_MX_LEFTDIV_CONFORM (ComplexDiagMatrix, SparseComplexMatrix); |
5164 | 83 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21112
diff
changeset
|
84 template <typename T1, typename T2> |
5164 | 85 bool |
86 mx_div_conform (const T1& a, const T2& b) | |
87 { | |
5275 | 88 octave_idx_type a_nc = a.cols (); |
89 octave_idx_type b_nc = b.cols (); | |
5164 | 90 |
91 if (a_nc != b_nc) | |
92 { | |
5275 | 93 octave_idx_type a_nr = a.rows (); |
94 octave_idx_type b_nr = b.rows (); | |
5164 | 95 |
22327
d0562b3159c7
move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
96 octave::err_nonconformant ("operator /", a_nr, a_nc, b_nr, b_nc); |
5164 | 97 } |
98 | |
99 return true; | |
100 } | |
101 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
102 #define INSTANTIATE_MX_DIV_CONFORM(T1, T2) \ |
5164 | 103 template bool mx_div_conform (const T1&, const T2&) |
104 | |
105 INSTANTIATE_MX_DIV_CONFORM (SparseMatrix, SparseMatrix); | |
106 INSTANTIATE_MX_DIV_CONFORM (SparseMatrix, SparseComplexMatrix); | |
107 INSTANTIATE_MX_DIV_CONFORM (SparseComplexMatrix, SparseMatrix); | |
108 INSTANTIATE_MX_DIV_CONFORM (SparseComplexMatrix, SparseComplexMatrix); | |
109 INSTANTIATE_MX_DIV_CONFORM (Matrix, SparseMatrix); | |
110 INSTANTIATE_MX_DIV_CONFORM (Matrix, SparseComplexMatrix); | |
111 INSTANTIATE_MX_DIV_CONFORM (ComplexMatrix, SparseMatrix); | |
112 INSTANTIATE_MX_DIV_CONFORM (ComplexMatrix, SparseComplexMatrix); | |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
113 INSTANTIATE_MX_DIV_CONFORM (SparseMatrix, DiagMatrix); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
114 INSTANTIATE_MX_DIV_CONFORM (SparseMatrix, ComplexDiagMatrix); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
115 INSTANTIATE_MX_DIV_CONFORM (SparseComplexMatrix, DiagMatrix); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
116 INSTANTIATE_MX_DIV_CONFORM (SparseComplexMatrix, ComplexDiagMatrix); |
5164 | 117 |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
118 // Right division functions. X / Y = X * inv (Y) = (inv (Y') * X')' |
5164 | 119 // |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
120 // Y / X: m cm sm scm |
5164 | 121 // +-- +---+----+----+----+ |
122 // sparse matrix | 1 | 3 | 5 | 7 | | |
123 // +---+----+----+----+ | |
124 // sparse complex_matrix | 2 | 4 | 6 | 8 | | |
125 // +---+----+----+----+ | |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
126 // diagonal matrix | 9 | 11 | |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
127 // +----+----+ |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
128 // complex diag. matrix | 10 | 12 | |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
129 // +----+----+ |
5164 | 130 |
131 // -*- 1 -*- | |
132 Matrix | |
5785 | 133 xdiv (const Matrix& a, const SparseMatrix& b, MatrixType &typ) |
5164 | 134 { |
135 if (! mx_div_conform (a, b)) | |
136 return Matrix (); | |
137 | |
138 Matrix atmp = a.transpose (); | |
139 SparseMatrix btmp = b.transpose (); | |
5785 | 140 MatrixType btyp = typ.transpose (); |
5164 | 141 |
5275 | 142 octave_idx_type info; |
5681 | 143 double rcond = 0.0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
144 Matrix result = btmp.solve (btyp, atmp, info, rcond, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
145 solve_singularity_warning); |
5164 | 146 |
5322 | 147 typ = btyp.transpose (); |
5164 | 148 return result.transpose (); |
149 } | |
150 | |
151 // -*- 2 -*- | |
152 ComplexMatrix | |
5785 | 153 xdiv (const Matrix& a, const SparseComplexMatrix& b, MatrixType &typ) |
5164 | 154 { |
155 if (! mx_div_conform (a, b)) | |
156 return ComplexMatrix (); | |
157 | |
158 Matrix atmp = a.transpose (); | |
159 SparseComplexMatrix btmp = b.hermitian (); | |
5785 | 160 MatrixType btyp = typ.transpose (); |
5164 | 161 |
5275 | 162 octave_idx_type info; |
5681 | 163 double rcond = 0.0; |
164 ComplexMatrix result | |
165 = btmp.solve (btyp, atmp, info, rcond, solve_singularity_warning); | |
5164 | 166 |
5322 | 167 typ = btyp.transpose (); |
5164 | 168 return result.hermitian (); |
169 } | |
170 | |
171 // -*- 3 -*- | |
172 ComplexMatrix | |
5785 | 173 xdiv (const ComplexMatrix& a, const SparseMatrix& b, MatrixType &typ) |
5164 | 174 { |
175 if (! mx_div_conform (a, b)) | |
176 return ComplexMatrix (); | |
177 | |
178 ComplexMatrix atmp = a.hermitian (); | |
179 SparseMatrix btmp = b.transpose (); | |
5785 | 180 MatrixType btyp = typ.transpose (); |
5164 | 181 |
5275 | 182 octave_idx_type info; |
5681 | 183 double rcond = 0.0; |
184 ComplexMatrix result | |
185 = btmp.solve (btyp, atmp, info, rcond, solve_singularity_warning); | |
5164 | 186 |
5322 | 187 typ = btyp.transpose (); |
5164 | 188 return result.hermitian (); |
189 } | |
190 | |
191 // -*- 4 -*- | |
192 ComplexMatrix | |
5785 | 193 xdiv (const ComplexMatrix& a, const SparseComplexMatrix& b, MatrixType &typ) |
5164 | 194 { |
195 if (! mx_div_conform (a, b)) | |
196 return ComplexMatrix (); | |
197 | |
198 ComplexMatrix atmp = a.hermitian (); | |
199 SparseComplexMatrix btmp = b.hermitian (); | |
5785 | 200 MatrixType btyp = typ.transpose (); |
5164 | 201 |
5275 | 202 octave_idx_type info; |
5681 | 203 double rcond = 0.0; |
204 ComplexMatrix result | |
205 = btmp.solve (btyp, atmp, info, rcond, solve_singularity_warning); | |
5164 | 206 |
5322 | 207 typ = btyp.transpose (); |
5164 | 208 return result.hermitian (); |
209 } | |
210 | |
211 // -*- 5 -*- | |
212 SparseMatrix | |
5785 | 213 xdiv (const SparseMatrix& a, const SparseMatrix& b, MatrixType &typ) |
5164 | 214 { |
215 if (! mx_div_conform (a, b)) | |
216 return SparseMatrix (); | |
217 | |
218 SparseMatrix atmp = a.transpose (); | |
219 SparseMatrix btmp = b.transpose (); | |
5785 | 220 MatrixType btyp = typ.transpose (); |
5164 | 221 |
5275 | 222 octave_idx_type info; |
5681 | 223 double rcond = 0.0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
224 SparseMatrix result = btmp.solve (btyp, atmp, info, rcond, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
225 solve_singularity_warning); |
5164 | 226 |
5322 | 227 typ = btyp.transpose (); |
5164 | 228 return result.transpose (); |
229 } | |
230 | |
231 // -*- 6 -*- | |
232 SparseComplexMatrix | |
5785 | 233 xdiv (const SparseMatrix& a, const SparseComplexMatrix& b, MatrixType &typ) |
5164 | 234 { |
235 if (! mx_div_conform (a, b)) | |
236 return SparseComplexMatrix (); | |
237 | |
238 SparseMatrix atmp = a.transpose (); | |
239 SparseComplexMatrix btmp = b.hermitian (); | |
5785 | 240 MatrixType btyp = typ.transpose (); |
5164 | 241 |
5275 | 242 octave_idx_type info; |
5681 | 243 double rcond = 0.0; |
244 SparseComplexMatrix result | |
245 = btmp.solve (btyp, atmp, info, rcond, solve_singularity_warning); | |
5164 | 246 |
5322 | 247 typ = btyp.transpose (); |
5164 | 248 return result.hermitian (); |
249 } | |
250 | |
251 // -*- 7 -*- | |
252 SparseComplexMatrix | |
5785 | 253 xdiv (const SparseComplexMatrix& a, const SparseMatrix& b, MatrixType &typ) |
5164 | 254 { |
255 if (! mx_div_conform (a, b)) | |
256 return SparseComplexMatrix (); | |
257 | |
258 SparseComplexMatrix atmp = a.hermitian (); | |
259 SparseMatrix btmp = b.transpose (); | |
5785 | 260 MatrixType btyp = typ.transpose (); |
5164 | 261 |
5275 | 262 octave_idx_type info; |
5681 | 263 double rcond = 0.0; |
264 SparseComplexMatrix result | |
265 = btmp.solve (btyp, atmp, info, rcond, solve_singularity_warning); | |
5164 | 266 |
5322 | 267 typ = btyp.transpose (); |
5164 | 268 return result.hermitian (); |
269 } | |
270 | |
271 // -*- 8 -*- | |
272 SparseComplexMatrix | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
273 xdiv (const SparseComplexMatrix& a, const SparseComplexMatrix& b, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
274 MatrixType &typ) |
5164 | 275 { |
276 if (! mx_div_conform (a, b)) | |
277 return SparseComplexMatrix (); | |
278 | |
279 SparseComplexMatrix atmp = a.hermitian (); | |
280 SparseComplexMatrix btmp = b.hermitian (); | |
5785 | 281 MatrixType btyp = typ.transpose (); |
5164 | 282 |
5275 | 283 octave_idx_type info; |
5681 | 284 double rcond = 0.0; |
285 SparseComplexMatrix result | |
286 = btmp.solve (btyp, atmp, info, rcond, solve_singularity_warning); | |
5164 | 287 |
5322 | 288 typ = btyp.transpose (); |
5164 | 289 return result.hermitian (); |
290 } | |
291 | |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
292 template <typename RT, typename SM, typename DM> |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
293 RT do_rightdiv_sm_dm (const SM& a, const DM& d) |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
294 { |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
295 const octave_idx_type d_nr = d.rows (); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
296 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
297 const octave_idx_type a_nr = a.rows (); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
298 const octave_idx_type a_nc = a.cols (); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
299 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
300 using std::min; |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
301 const octave_idx_type nc = min (d_nr, a_nc); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
302 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
303 if (! mx_div_conform (a, d)) |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
304 return RT (); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
305 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
306 const octave_idx_type nz = a.nnz (); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
307 RT r (a_nr, nc, nz); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
308 |
9196
c229bfb14d8d
avoid apparent MSVC bug with typedef
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
309 typedef typename DM::element_type DM_elt_type; |
c229bfb14d8d
avoid apparent MSVC bug with typedef
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
310 const DM_elt_type zero = DM_elt_type (); |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
311 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
312 octave_idx_type k_result = 0; |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
313 for (octave_idx_type j = 0; j < nc; ++j) |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
314 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
315 octave_quit (); |
9196
c229bfb14d8d
avoid apparent MSVC bug with typedef
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
316 const DM_elt_type s = d.dgelem (j); |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
317 const octave_idx_type colend = a.cidx (j+1); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
318 r.xcidx (j) = k_result; |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
319 if (s != zero) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
320 for (octave_idx_type k = a.cidx (j); k < colend; ++k) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
321 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
322 r.xdata (k_result) = a.data (k) / s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
323 r.xridx (k_result) = a.ridx (k); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
324 ++k_result; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
325 } |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
326 } |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
327 r.xcidx (nc) = k_result; |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
328 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
329 r.maybe_compress (true); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
330 return r; |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
331 } |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
332 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
333 // -*- 9 -*- |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
334 SparseMatrix |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
335 xdiv (const SparseMatrix& a, const DiagMatrix& b, MatrixType &) |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
336 { |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
337 return do_rightdiv_sm_dm<SparseMatrix> (a, b); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
338 } |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
339 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
340 // -*- 10 -*- |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
341 SparseComplexMatrix |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
342 xdiv (const SparseMatrix& a, const ComplexDiagMatrix& b, MatrixType &) |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
343 { |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
344 return do_rightdiv_sm_dm<SparseComplexMatrix> (a, b); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
345 } |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
346 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
347 // -*- 11 -*- |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
348 SparseComplexMatrix |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
349 xdiv (const SparseComplexMatrix& a, const DiagMatrix& b, MatrixType &) |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
350 { |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
351 return do_rightdiv_sm_dm<SparseComplexMatrix> (a, b); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
352 } |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
353 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
354 // -*- 12 -*- |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
355 SparseComplexMatrix |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
356 xdiv (const SparseComplexMatrix& a, const ComplexDiagMatrix& b, MatrixType &) |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
357 { |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
358 return do_rightdiv_sm_dm<SparseComplexMatrix> (a, b); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
359 } |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
360 |
5164 | 361 // Funny element by element division operations. |
362 // | |
363 // op2 \ op1: s cs | |
364 // +-- +---+----+ | |
365 // matrix | 1 | 3 | | |
366 // +---+----+ | |
367 // complex_matrix | 2 | 4 | | |
368 // +---+----+ | |
369 | |
370 Matrix | |
371 x_el_div (double a, const SparseMatrix& b) | |
372 { | |
5275 | 373 octave_idx_type nr = b.rows (); |
374 octave_idx_type nc = b.cols (); | |
5164 | 375 |
376 Matrix result; | |
377 if (a == 0.) | |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
378 result = Matrix (nr, nc, octave::numeric_limits<double>::NaN ()); |
5164 | 379 else if (a > 0.) |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
380 result = Matrix (nr, nc, octave::numeric_limits<double>::Inf ()); |
5164 | 381 else |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
382 result = Matrix (nr, nc, -octave::numeric_limits<double>::Inf ()); |
5164 | 383 |
5275 | 384 for (octave_idx_type j = 0; j < nc; j++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
385 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) |
5164 | 386 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
387 octave_quit (); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
388 result.elem (b.ridx (i), j) = a / b.data (i); |
5164 | 389 } |
390 | |
391 return result; | |
392 } | |
393 | |
394 ComplexMatrix | |
395 x_el_div (double a, const SparseComplexMatrix& b) | |
396 { | |
5275 | 397 octave_idx_type nr = b.rows (); |
398 octave_idx_type nc = b.cols (); | |
5164 | 399 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
400 ComplexMatrix result (nr, nc, Complex (octave::numeric_limits<double>::NaN (), |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22327
diff
changeset
|
401 octave::numeric_limits<double>::NaN ())); |
5164 | 402 |
5275 | 403 for (octave_idx_type j = 0; j < nc; j++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
404 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) |
5164 | 405 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
406 octave_quit (); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
407 result.elem (b.ridx (i), j) = a / b.data (i); |
5164 | 408 } |
409 | |
410 return result; | |
411 } | |
412 | |
413 ComplexMatrix | |
414 x_el_div (const Complex a, const SparseMatrix& b) | |
415 { | |
5275 | 416 octave_idx_type nr = b.rows (); |
417 octave_idx_type nc = b.cols (); | |
5164 | 418 |
419 ComplexMatrix result (nr, nc, (a / 0.0)); | |
420 | |
5275 | 421 for (octave_idx_type j = 0; j < nc; j++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
422 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) |
5164 | 423 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
424 octave_quit (); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
425 result.elem (b.ridx (i), j) = a / b.data (i); |
5164 | 426 } |
427 | |
428 return result; | |
429 } | |
430 | |
431 ComplexMatrix | |
432 x_el_div (const Complex a, const SparseComplexMatrix& b) | |
433 { | |
5275 | 434 octave_idx_type nr = b.rows (); |
435 octave_idx_type nc = b.cols (); | |
5164 | 436 |
437 ComplexMatrix result (nr, nc, (a / 0.0)); | |
438 | |
5275 | 439 for (octave_idx_type j = 0; j < nc; j++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
440 for (octave_idx_type i = b.cidx (j); i < b.cidx (j+1); i++) |
5164 | 441 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
442 octave_quit (); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
443 result.elem (b.ridx (i), j) = a / b.data (i); |
5164 | 444 } |
445 | |
446 return result; | |
447 } | |
448 | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
449 // Left division functions. X \ Y = inv (X) * Y |
5164 | 450 // |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
451 // Y \ X : sm scm dm dcm |
5164 | 452 // +-- +---+----+ |
453 // matrix | 1 | 5 | | |
454 // +---+----+ | |
455 // complex_matrix | 2 | 6 | | |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
456 // +---+----+----+----+ |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
457 // sparse matrix | 3 | 7 | 9 | 11 | |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
458 // +---+----+----+----+ |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
459 // sparse complex_matrix | 4 | 8 | 10 | 12 | |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
460 // +---+----+----+----+ |
5164 | 461 |
462 // -*- 1 -*- | |
463 Matrix | |
5785 | 464 xleftdiv (const SparseMatrix& a, const Matrix& b, MatrixType &typ) |
5164 | 465 { |
466 if (! mx_leftdiv_conform (a, b)) | |
467 return Matrix (); | |
468 | |
5275 | 469 octave_idx_type info; |
5681 | 470 double rcond = 0.0; |
471 return a.solve (typ, b, info, rcond, solve_singularity_warning); | |
5164 | 472 } |
473 | |
474 // -*- 2 -*- | |
475 ComplexMatrix | |
5785 | 476 xleftdiv (const SparseMatrix& a, const ComplexMatrix& b, MatrixType &typ) |
5164 | 477 { |
478 if (! mx_leftdiv_conform (a, b)) | |
479 return ComplexMatrix (); | |
480 | |
5275 | 481 octave_idx_type info; |
5681 | 482 double rcond = 0.0; |
483 return a.solve (typ, b, info, rcond, solve_singularity_warning); | |
5164 | 484 } |
485 | |
486 // -*- 3 -*- | |
487 SparseMatrix | |
5785 | 488 xleftdiv (const SparseMatrix& a, const SparseMatrix& b, MatrixType &typ) |
5164 | 489 { |
490 if (! mx_leftdiv_conform (a, b)) | |
491 return SparseMatrix (); | |
492 | |
5275 | 493 octave_idx_type info; |
5681 | 494 double rcond = 0.0; |
495 return a.solve (typ, b, info, rcond, solve_singularity_warning); | |
5164 | 496 } |
497 | |
498 // -*- 4 -*- | |
499 SparseComplexMatrix | |
5785 | 500 xleftdiv (const SparseMatrix& a, const SparseComplexMatrix& b, MatrixType &typ) |
5164 | 501 { |
502 if (! mx_leftdiv_conform (a, b)) | |
503 return SparseComplexMatrix (); | |
504 | |
5275 | 505 octave_idx_type info; |
5681 | 506 double rcond = 0.0; |
507 return a.solve (typ, b, info, rcond, solve_singularity_warning); | |
5164 | 508 } |
509 | |
510 // -*- 5 -*- | |
511 ComplexMatrix | |
5785 | 512 xleftdiv (const SparseComplexMatrix& a, const Matrix& b, MatrixType &typ) |
5164 | 513 { |
514 if (! mx_leftdiv_conform (a, b)) | |
515 return ComplexMatrix (); | |
516 | |
5275 | 517 octave_idx_type info; |
5681 | 518 double rcond = 0.0; |
519 return a.solve (typ, b, info, rcond, solve_singularity_warning); | |
5164 | 520 } |
521 | |
522 // -*- 6 -*- | |
523 ComplexMatrix | |
5785 | 524 xleftdiv (const SparseComplexMatrix& a, const ComplexMatrix& b, MatrixType &typ) |
5164 | 525 { |
526 if (! mx_leftdiv_conform (a, b)) | |
527 return ComplexMatrix (); | |
528 | |
5275 | 529 octave_idx_type info; |
5681 | 530 double rcond = 0.0; |
531 return a.solve (typ, b, info, rcond, solve_singularity_warning); | |
5164 | 532 } |
533 | |
534 // -*- 7 -*- | |
535 SparseComplexMatrix | |
5785 | 536 xleftdiv (const SparseComplexMatrix& a, const SparseMatrix& b, MatrixType &typ) |
5164 | 537 { |
538 if (! mx_leftdiv_conform (a, b)) | |
539 return SparseComplexMatrix (); | |
540 | |
5275 | 541 octave_idx_type info; |
5681 | 542 double rcond = 0.0; |
543 return a.solve (typ, b, info, rcond, solve_singularity_warning); | |
5164 | 544 } |
545 | |
546 // -*- 8 -*- | |
547 SparseComplexMatrix | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
548 xleftdiv (const SparseComplexMatrix& a, const SparseComplexMatrix& b, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
549 MatrixType &typ) |
5164 | 550 { |
551 if (! mx_leftdiv_conform (a, b)) | |
552 return SparseComplexMatrix (); | |
553 | |
5275 | 554 octave_idx_type info; |
5681 | 555 double rcond = 0.0; |
556 return a.solve (typ, b, info, rcond, solve_singularity_warning); | |
5164 | 557 } |
558 | |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
559 template <typename RT, typename DM, typename SM> |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
560 RT do_leftdiv_dm_sm (const DM& d, const SM& a) |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
561 { |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
562 const octave_idx_type a_nr = a.rows (); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
563 const octave_idx_type a_nc = a.cols (); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
564 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
565 const octave_idx_type d_nc = d.cols (); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
566 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
567 using std::min; |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
568 const octave_idx_type nr = min (d_nc, a_nr); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
569 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
570 if (! mx_leftdiv_conform (d, a)) |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
571 return RT (); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
572 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
573 const octave_idx_type nz = a.nnz (); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
574 RT r (nr, a_nc, nz); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
575 |
9196
c229bfb14d8d
avoid apparent MSVC bug with typedef
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
576 typedef typename DM::element_type DM_elt_type; |
c229bfb14d8d
avoid apparent MSVC bug with typedef
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
577 const DM_elt_type zero = DM_elt_type (); |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
578 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
579 octave_idx_type k_result = 0; |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
580 for (octave_idx_type j = 0; j < a_nc; ++j) |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
581 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9245
diff
changeset
|
582 octave_quit (); |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
583 const octave_idx_type colend = a.cidx (j+1); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
584 r.xcidx (j) = k_result; |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
585 for (octave_idx_type k = a.cidx (j); k < colend; ++k) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
586 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
587 const octave_idx_type i = a.ridx (k); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
588 if (i < nr) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
589 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
590 const DM_elt_type s = d.dgelem (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
591 if (s != zero) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
592 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
593 r.xdata (k_result) = a.data (k) / s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
594 r.xridx (k_result) = i; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
595 ++k_result; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
596 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
597 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
598 } |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
599 } |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
600 r.xcidx (a_nc) = k_result; |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
601 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
602 r.maybe_compress (true); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
603 return r; |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
604 } |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
605 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
606 // -*- 9 -*- |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
607 SparseMatrix |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
608 xleftdiv (const DiagMatrix& d, const SparseMatrix& a, MatrixType&) |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
609 { |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
610 return do_leftdiv_dm_sm<SparseMatrix> (d, a); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
611 } |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
612 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
613 // -*- 10 -*- |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
614 SparseComplexMatrix |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
615 xleftdiv (const DiagMatrix& d, const SparseComplexMatrix& a, MatrixType&) |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
616 { |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
617 return do_leftdiv_dm_sm<SparseComplexMatrix> (d, a); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
618 } |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
619 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
620 // -*- 11 -*- |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
621 SparseComplexMatrix |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
622 xleftdiv (const ComplexDiagMatrix& d, const SparseMatrix& a, MatrixType&) |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
623 { |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
624 return do_leftdiv_dm_sm<SparseComplexMatrix> (d, a); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
625 } |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
626 |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
627 // -*- 12 -*- |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
628 SparseComplexMatrix |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
629 xleftdiv (const ComplexDiagMatrix& d, const SparseComplexMatrix& a, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
630 MatrixType&) |
8965
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
631 { |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
632 return do_leftdiv_dm_sm<SparseComplexMatrix> (d, a); |
42aff15e059b
Implement diag \ sparse and sparse / diag.
Jason Riedy <jason@acm.org>
parents:
7017
diff
changeset
|
633 } |