Mercurial > hg > octave-nkf
annotate liboctave/Sparse.cc @ 10396:a0b51ac0f88a
optimize accumdim with summation
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 05 Mar 2010 12:31:30 +0100 |
parents | 1766c133674c |
children | 99e9bae2d81e |
rev | line source |
---|---|
5164 | 1 // Template sparse array class |
2 /* | |
3 | |
8920 | 4 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 David Bateman |
7016 | 5 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Andy Adler |
6 | |
7 This file is part of Octave. | |
5164 | 8 |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
5164 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
5164 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 #include <config.h> | |
27 #endif | |
28 | |
29 #include <cassert> | |
30 #include <climits> | |
31 | |
32 #include <iostream> | |
5765 | 33 #include <sstream> |
5164 | 34 #include <vector> |
35 | |
36 #include "Array.h" | |
37 #include "Array-util.h" | |
38 #include "Range.h" | |
39 #include "idx-vector.h" | |
40 #include "lo-error.h" | |
41 #include "quit.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8290
diff
changeset
|
42 #include "oct-locbuf.h" |
5164 | 43 |
44 #include "Sparse.h" | |
45 #include "sparse-sort.h" | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9177
diff
changeset
|
46 #include "sparse-util.h" |
5164 | 47 #include "oct-spparms.h" |
48 | |
49 template <class T> | |
50 T& | |
5275 | 51 Sparse<T>::SparseRep::elem (octave_idx_type _r, octave_idx_type _c) |
5164 | 52 { |
5275 | 53 octave_idx_type i; |
5164 | 54 |
5604 | 55 if (nzmx > 0) |
5164 | 56 { |
57 for (i = c[_c]; i < c[_c + 1]; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
58 if (r[i] == _r) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
59 return d[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
60 else if (r[i] > _r) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
61 break; |
5164 | 62 |
63 // Ok, If we've gotten here, we're in trouble.. Have to create a | |
64 // new element in the sparse array. This' gonna be slow!!! | |
5869 | 65 if (c[ncols] == nzmx) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
66 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
67 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
68 ("Sparse::SparseRep::elem (octave_idx_type, octave_idx_type): sparse matrix filled"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
69 return *d; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
70 } |
5164 | 71 |
5275 | 72 octave_idx_type to_move = c[ncols] - i; |
5164 | 73 if (to_move != 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
74 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
75 for (octave_idx_type j = c[ncols]; j > i; j--) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
76 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
77 d[j] = d[j-1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
78 r[j] = r[j-1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
79 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
80 } |
5164 | 81 |
5275 | 82 for (octave_idx_type j = _c + 1; j < ncols + 1; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
83 c[j] = c[j] + 1; |
5164 | 84 |
85 d[i] = 0.; | |
86 r[i] = _r; | |
87 | |
88 return d[i]; | |
89 } | |
90 else | |
91 { | |
92 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
93 ("Sparse::SparseRep::elem (octave_idx_type, octave_idx_type): sparse matrix filled"); |
5164 | 94 return *d; |
95 } | |
96 } | |
97 | |
98 template <class T> | |
99 T | |
5275 | 100 Sparse<T>::SparseRep::celem (octave_idx_type _r, octave_idx_type _c) const |
5164 | 101 { |
5604 | 102 if (nzmx > 0) |
5275 | 103 for (octave_idx_type i = c[_c]; i < c[_c + 1]; i++) |
5164 | 104 if (r[i] == _r) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
105 return d[i]; |
5164 | 106 return T (); |
107 } | |
108 | |
109 template <class T> | |
110 void | |
111 Sparse<T>::SparseRep::maybe_compress (bool remove_zeros) | |
112 { | |
5604 | 113 octave_idx_type ndel = nzmx - c[ncols]; |
5275 | 114 octave_idx_type nzero = 0; |
5164 | 115 |
116 if (remove_zeros) | |
5604 | 117 for (octave_idx_type i = 0; i < nzmx - ndel; i++) |
5164 | 118 if (d[i] == T ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
119 nzero++; |
5164 | 120 |
121 if (!ndel && !nzero) | |
122 return; | |
123 | |
124 if (!nzero) | |
125 { | |
5604 | 126 octave_idx_type new_nzmx = nzmx - ndel; |
127 | |
128 T *new_data = new T [new_nzmx]; | |
129 for (octave_idx_type i = 0; i < new_nzmx; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
130 new_data[i] = d[i]; |
5164 | 131 delete [] d; |
132 d = new_data; | |
133 | |
5604 | 134 octave_idx_type *new_ridx = new octave_idx_type [new_nzmx]; |
135 for (octave_idx_type i = 0; i < new_nzmx; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
136 new_ridx[i] = r[i]; |
5164 | 137 delete [] r; |
138 r = new_ridx; | |
139 } | |
140 else | |
141 { | |
5604 | 142 octave_idx_type new_nzmx = nzmx - ndel - nzero; |
143 | |
144 T *new_data = new T [new_nzmx]; | |
145 octave_idx_type *new_ridx = new octave_idx_type [new_nzmx]; | |
5275 | 146 |
147 octave_idx_type ii = 0; | |
148 octave_idx_type ic = 0; | |
149 for (octave_idx_type j = 0; j < ncols; j++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
150 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
151 for (octave_idx_type k = ic; k < c[j+1]; k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
152 if (d[k] != T ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
153 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
154 new_data [ii] = d[k]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
155 new_ridx [ii++] = r[k]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
156 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
157 ic = c[j+1]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
158 c[j+1] = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
159 } |
5164 | 160 |
161 delete [] d; | |
162 d = new_data; | |
163 | |
164 delete [] r; | |
165 r = new_ridx; | |
166 } | |
167 | |
5604 | 168 nzmx -= ndel + nzero; |
5164 | 169 } |
170 | |
171 template <class T> | |
172 void | |
5275 | 173 Sparse<T>::SparseRep::change_length (octave_idx_type nz) |
5164 | 174 { |
5604 | 175 if (nz != nzmx) |
5164 | 176 { |
5604 | 177 octave_idx_type min_nzmx = (nz < nzmx ? nz : nzmx); |
5275 | 178 |
179 octave_idx_type * new_ridx = new octave_idx_type [nz]; | |
5604 | 180 for (octave_idx_type i = 0; i < min_nzmx; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
181 new_ridx[i] = r[i]; |
5164 | 182 |
183 delete [] r; | |
184 r = new_ridx; | |
185 | |
186 T * new_data = new T [nz]; | |
5604 | 187 for (octave_idx_type i = 0; i < min_nzmx; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
188 new_data[i] = d[i]; |
5164 | 189 |
190 delete [] d; | |
191 d = new_data; | |
192 | |
5604 | 193 if (nz < nzmx) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
194 for (octave_idx_type i = 0; i <= ncols; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
195 if (c[i] > nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
196 c[i] = nz; |
5164 | 197 |
5604 | 198 nzmx = nz; |
5164 | 199 } |
200 } | |
201 | |
202 template <class T> | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9177
diff
changeset
|
203 bool |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9177
diff
changeset
|
204 Sparse<T>::SparseRep::indices_ok (void) const |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9177
diff
changeset
|
205 { |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9177
diff
changeset
|
206 return sparse_indices_ok (r, c, nrows, ncols, nnz ()); |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9177
diff
changeset
|
207 } |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9177
diff
changeset
|
208 |
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
9177
diff
changeset
|
209 template <class T> |
5164 | 210 template <class U> |
211 Sparse<T>::Sparse (const Sparse<U>& a) | |
212 : dimensions (a.dimensions), idx (0), idx_count (0) | |
213 { | |
5681 | 214 if (a.nnz () == 0) |
5164 | 215 rep = new typename Sparse<T>::SparseRep (rows (), cols()); |
216 else | |
217 { | |
5681 | 218 rep = new typename Sparse<T>::SparseRep (rows (), cols (), a.nnz ()); |
5164 | 219 |
5681 | 220 octave_idx_type nz = a.nnz (); |
5275 | 221 octave_idx_type nc = cols (); |
222 for (octave_idx_type i = 0; i < nz; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
223 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
224 xdata (i) = T (a.data (i)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
225 xridx (i) = a.ridx (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
226 } |
5275 | 227 for (octave_idx_type i = 0; i < nc + 1; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
228 xcidx (i) = a.cidx (i); |
5164 | 229 } |
230 } | |
231 | |
232 template <class T> | |
5275 | 233 Sparse<T>::Sparse (octave_idx_type nr, octave_idx_type nc, T val) |
5630 | 234 : dimensions (dim_vector (nr, nc)), idx (0), idx_count (0) |
5164 | 235 { |
5630 | 236 if (val != T ()) |
5164 | 237 { |
5630 | 238 rep = new typename Sparse<T>::SparseRep (nr, nc, nr*nc); |
239 | |
240 octave_idx_type ii = 0; | |
241 xcidx (0) = 0; | |
242 for (octave_idx_type j = 0; j < nc; j++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
243 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
244 for (octave_idx_type i = 0; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
245 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
246 xdata (ii) = val; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
247 xridx (ii++) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
248 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
249 xcidx (j+1) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
250 } |
5630 | 251 } |
252 else | |
253 { | |
254 rep = new typename Sparse<T>::SparseRep (nr, nc, 0); | |
255 for (octave_idx_type j = 0; j < nc+1; j++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
256 xcidx(j) = 0; |
5164 | 257 } |
258 } | |
259 | |
260 template <class T> | |
261 Sparse<T>::Sparse (const dim_vector& dv) | |
262 : dimensions (dv), idx (0), idx_count (0) | |
263 { | |
264 if (dv.length() != 2) | |
265 (*current_liboctave_error_handler) | |
266 ("Sparse::Sparse (const dim_vector&): dimension mismatch"); | |
267 else | |
268 rep = new typename Sparse<T>::SparseRep (dv(0), dv(1)); | |
269 } | |
270 | |
271 template <class T> | |
272 Sparse<T>::Sparse (const Sparse<T>& a, const dim_vector& dv) | |
273 : dimensions (dv), idx (0), idx_count (0) | |
274 { | |
275 | |
276 // Work in unsigned long long to avoid overflow issues with numel | |
277 unsigned long long a_nel = static_cast<unsigned long long>(a.rows ()) * | |
278 static_cast<unsigned long long>(a.cols ()); | |
279 unsigned long long dv_nel = static_cast<unsigned long long>(dv (0)) * | |
280 static_cast<unsigned long long>(dv (1)); | |
281 | |
282 if (a_nel != dv_nel) | |
283 (*current_liboctave_error_handler) | |
284 ("Sparse::Sparse (const Sparse&, const dim_vector&): dimension mismatch"); | |
285 else | |
286 { | |
287 dim_vector old_dims = a.dims(); | |
5681 | 288 octave_idx_type new_nzmx = a.nnz (); |
5275 | 289 octave_idx_type new_nr = dv (0); |
290 octave_idx_type new_nc = dv (1); | |
291 octave_idx_type old_nr = old_dims (0); | |
292 octave_idx_type old_nc = old_dims (1); | |
5164 | 293 |
5604 | 294 rep = new typename Sparse<T>::SparseRep (new_nr, new_nc, new_nzmx); |
5164 | 295 |
5275 | 296 octave_idx_type kk = 0; |
5164 | 297 xcidx(0) = 0; |
5275 | 298 for (octave_idx_type i = 0; i < old_nc; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
299 for (octave_idx_type j = a.cidx(i); j < a.cidx(i+1); j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
300 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
301 octave_idx_type tmp = i * old_nr + a.ridx(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
302 octave_idx_type ii = tmp % new_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
303 octave_idx_type jj = (tmp - ii) / new_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
304 for (octave_idx_type k = kk; k < jj; k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
305 xcidx(k+1) = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
306 kk = jj; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
307 xdata(j) = a.data(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
308 xridx(j) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
309 } |
5275 | 310 for (octave_idx_type k = kk; k < new_nc; k++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
311 xcidx(k+1) = new_nzmx; |
5164 | 312 } |
313 } | |
314 | |
315 template <class T> | |
5275 | 316 Sparse<T>::Sparse (const Array<T>& a, const Array<octave_idx_type>& r, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
317 const Array<octave_idx_type>& c, octave_idx_type nr, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
318 octave_idx_type nc, bool sum_terms) |
5164 | 319 : dimensions (dim_vector (nr, nc)), idx (0), idx_count (0) |
320 { | |
5275 | 321 octave_idx_type a_len = a.length (); |
322 octave_idx_type r_len = r.length (); | |
323 octave_idx_type c_len = c.length (); | |
5164 | 324 bool ri_scalar = (r_len == 1); |
325 bool ci_scalar = (c_len == 1); | |
326 bool cf_scalar = (a_len == 1); | |
327 | |
328 if ((a_len != r_len && !cf_scalar && !ri_scalar) || | |
329 (a_len != c_len && !cf_scalar && !ci_scalar) || | |
330 (r_len != c_len && !ri_scalar && !ci_scalar) || nr < 0 || nc < 0) | |
331 { | |
332 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
333 ("Sparse::Sparse (const Array<T>&, const Array<octave_idx_type>&, ...): dimension mismatch"); |
5164 | 334 rep = nil_rep (); |
335 dimensions = dim_vector (0, 0); | |
336 } | |
337 else | |
338 { | |
5604 | 339 octave_idx_type max_nzmx = (r_len > c_len ? r_len : c_len); |
340 | |
341 OCTAVE_LOCAL_BUFFER (octave_sparse_sort_idxl *, sidx, max_nzmx); | |
342 OCTAVE_LOCAL_BUFFER (octave_sparse_sort_idxl, sidxX, max_nzmx); | |
343 | |
344 for (octave_idx_type i = 0; i < max_nzmx; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
345 sidx[i] = &sidxX[i]; |
5164 | 346 |
5604 | 347 octave_idx_type actual_nzmx = 0; |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
348 octave_quit (); |
5604 | 349 for (octave_idx_type i = 0; i < max_nzmx; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
350 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
351 octave_idx_type rowidx = (ri_scalar ? r(0) : r(i)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
352 octave_idx_type colidx = (ci_scalar ? c(0) : c(i)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
353 if (rowidx < nr && rowidx >= 0 && |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
354 colidx < nc && colidx >= 0 ) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
355 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
356 if ( a (cf_scalar ? 0 : i ) != T ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
357 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
358 sidx[actual_nzmx]->r = rowidx; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
359 sidx[actual_nzmx]->c = colidx; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
360 sidx[actual_nzmx]->idx = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
361 actual_nzmx++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
362 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
363 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
364 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
365 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
366 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
367 ("Sparse::Sparse : index (%d,%d) out of range", |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
368 rowidx + 1, colidx + 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
369 rep = nil_rep (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
370 dimensions = dim_vector (0, 0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
371 return; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
372 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
373 } |
5164 | 374 |
5604 | 375 if (actual_nzmx == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
376 rep = new typename Sparse<T>::SparseRep (nr, nc); |
5164 | 377 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
378 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
379 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
380 octave_sort<octave_sparse_sort_idxl *> |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
381 lsort (octave_sparse_sidxl_comp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
382 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
383 lsort.sort (sidx, actual_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
384 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
385 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
386 // Now count the unique non-zero values |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
387 octave_idx_type real_nzmx = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
388 for (octave_idx_type i = 1; i < actual_nzmx; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
389 if (sidx[i-1]->r != sidx[i]->r || sidx[i-1]->c != sidx[i]->c) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
390 real_nzmx++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
391 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
392 rep = new typename Sparse<T>::SparseRep (nr, nc, real_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
393 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
394 octave_idx_type cx = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
395 octave_idx_type prev_rval = -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
396 octave_idx_type prev_cval = -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
397 octave_idx_type ii = -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
398 xcidx (0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
399 for (octave_idx_type i = 0; i < actual_nzmx; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
400 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
401 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
402 octave_idx_type iidx = sidx[i]->idx; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
403 octave_idx_type rval = sidx[i]->r; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
404 octave_idx_type cval = sidx[i]->c; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
405 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
406 if (prev_cval < cval || (prev_rval < rval && prev_cval == cval)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
407 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
408 octave_idx_type ci = static_cast<octave_idx_type> (c (ci_scalar ? 0 : iidx)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
409 ii++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
410 while (cx < ci) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
411 xcidx (++cx) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
412 xdata(ii) = a (cf_scalar ? 0 : iidx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
413 xridx(ii) = static_cast<octave_idx_type> (r (ri_scalar ? 0 : iidx)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
414 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
415 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
416 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
417 if (sum_terms) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
418 xdata(ii) += a (cf_scalar ? 0 : iidx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
419 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
420 xdata(ii) = a (cf_scalar ? 0 : iidx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
421 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
422 prev_rval = rval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
423 prev_cval = cval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
424 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
425 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
426 while (cx < nc) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
427 xcidx (++cx) = ii + 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
428 } |
5164 | 429 } |
430 } | |
431 | |
432 template <class T> | |
433 Sparse<T>::Sparse (const Array<T>& a, const Array<double>& r, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
434 const Array<double>& c, octave_idx_type nr, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
435 octave_idx_type nc, bool sum_terms) |
5164 | 436 : dimensions (dim_vector (nr, nc)), idx (0), idx_count (0) |
437 { | |
5275 | 438 octave_idx_type a_len = a.length (); |
439 octave_idx_type r_len = r.length (); | |
440 octave_idx_type c_len = c.length (); | |
5164 | 441 bool ri_scalar = (r_len == 1); |
442 bool ci_scalar = (c_len == 1); | |
443 bool cf_scalar = (a_len == 1); | |
444 | |
445 if ((a_len != r_len && !cf_scalar && !ri_scalar) || | |
446 (a_len != c_len && !cf_scalar && !ci_scalar) || | |
447 (r_len != c_len && !ri_scalar && !ci_scalar) || nr < 0 || nc < 0) | |
448 { | |
449 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
450 ("Sparse::Sparse (const Array<T>&, const Array<double>&, ...): dimension mismatch"); |
5164 | 451 rep = nil_rep (); |
452 dimensions = dim_vector (0, 0); | |
453 } | |
454 else | |
455 { | |
5604 | 456 octave_idx_type max_nzmx = (r_len > c_len ? r_len : c_len); |
5164 | 457 |
5604 | 458 OCTAVE_LOCAL_BUFFER (octave_sparse_sort_idxl *, sidx, max_nzmx); |
459 OCTAVE_LOCAL_BUFFER (octave_sparse_sort_idxl, sidxX, max_nzmx); | |
460 | |
461 for (octave_idx_type i = 0; i < max_nzmx; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
462 sidx[i] = &sidxX[i]; |
5164 | 463 |
5604 | 464 octave_idx_type actual_nzmx = 0; |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
465 octave_quit (); |
5164 | 466 |
5604 | 467 for (octave_idx_type i = 0; i < max_nzmx; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
468 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
469 octave_idx_type rowidx = static_cast<octave_idx_type> (ri_scalar ? r(0) : r(i)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
470 octave_idx_type colidx = static_cast<octave_idx_type> (ci_scalar ? c(0) : c(i)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
471 if (rowidx < nr && rowidx >= 0 && |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
472 colidx < nc && colidx >= 0 ) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
473 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
474 if ( a (cf_scalar ? 0 : i ) != T ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
475 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
476 sidx[actual_nzmx]->r = rowidx; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
477 sidx[actual_nzmx]->c = colidx; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
478 sidx[actual_nzmx]->idx = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
479 actual_nzmx++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
480 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
481 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
482 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
483 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
484 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
485 ("Sparse::Sparse : index (%d,%d) out of range", |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
486 rowidx + 1, colidx + 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
487 rep = nil_rep (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
488 dimensions = dim_vector (0, 0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
489 return; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
490 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
491 } |
5164 | 492 |
5604 | 493 if (actual_nzmx == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
494 rep = new typename Sparse<T>::SparseRep (nr, nc); |
5164 | 495 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
496 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
497 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
498 octave_sort<octave_sparse_sort_idxl *> |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
499 lsort (octave_sparse_sidxl_comp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
500 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
501 lsort.sort (sidx, actual_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
502 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
503 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
504 // Now count the unique non-zero values |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
505 octave_idx_type real_nzmx = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
506 for (octave_idx_type i = 1; i < actual_nzmx; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
507 if (sidx[i-1]->r != sidx[i]->r || sidx[i-1]->c != sidx[i]->c) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
508 real_nzmx++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
509 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
510 rep = new typename Sparse<T>::SparseRep (nr, nc, real_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
511 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
512 octave_idx_type cx = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
513 octave_idx_type prev_rval = -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
514 octave_idx_type prev_cval = -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
515 octave_idx_type ii = -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
516 xcidx (0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
517 for (octave_idx_type i = 0; i < actual_nzmx; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
518 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
519 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
520 octave_idx_type iidx = sidx[i]->idx; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
521 octave_idx_type rval = sidx[i]->r; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
522 octave_idx_type cval = sidx[i]->c; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
523 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
524 if (prev_cval < cval || (prev_rval < rval && prev_cval == cval)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
525 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
526 octave_idx_type ci = static_cast<octave_idx_type> (c (ci_scalar ? 0 : iidx)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
527 ii++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
528 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
529 while (cx < ci) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
530 xcidx (++cx) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
531 xdata(ii) = a (cf_scalar ? 0 : iidx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
532 xridx(ii) = static_cast<octave_idx_type> (r (ri_scalar ? 0 : iidx)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
533 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
534 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
535 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
536 if (sum_terms) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
537 xdata(ii) += a (cf_scalar ? 0 : iidx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
538 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
539 xdata(ii) = a (cf_scalar ? 0 : iidx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
540 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
541 prev_rval = rval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
542 prev_cval = cval; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
543 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
544 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
545 while (cx < nc) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
546 xcidx (++cx) = ii + 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
547 } |
5164 | 548 } |
549 } | |
550 | |
551 template <class T> | |
552 Sparse<T>::Sparse (const Array<T>& a) | |
553 : dimensions (a.dims ()), idx (0), idx_count (0) | |
554 { | |
555 if (dimensions.length () > 2) | |
556 (*current_liboctave_error_handler) | |
557 ("Sparse::Sparse (const Array<T>&): dimension mismatch"); | |
558 else | |
559 { | |
5275 | 560 octave_idx_type nr = rows (); |
561 octave_idx_type nc = cols (); | |
562 octave_idx_type len = a.length (); | |
5604 | 563 octave_idx_type new_nzmx = 0; |
5164 | 564 |
565 // First count the number of non-zero terms | |
5275 | 566 for (octave_idx_type i = 0; i < len; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
567 if (a(i) != T ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
568 new_nzmx++; |
5604 | 569 |
570 rep = new typename Sparse<T>::SparseRep (nr, nc, new_nzmx); | |
5164 | 571 |
5275 | 572 octave_idx_type ii = 0; |
5164 | 573 xcidx(0) = 0; |
5275 | 574 for (octave_idx_type j = 0; j < nc; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
575 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
576 for (octave_idx_type i = 0; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
577 if (a.elem (i,j) != T ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
578 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
579 xdata(ii) = a.elem (i,j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
580 xridx(ii++) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
581 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
582 xcidx(j+1) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
583 } |
5164 | 584 } |
585 } | |
586 | |
587 template <class T> | |
588 Sparse<T>::~Sparse (void) | |
589 { | |
590 if (--rep->count <= 0) | |
591 delete rep; | |
592 | |
593 delete [] idx; | |
594 } | |
595 | |
596 template <class T> | |
7717
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
597 Sparse<T>& |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
598 Sparse<T>::operator = (const Sparse<T>& a) |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
599 { |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
600 if (this != &a) |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
601 { |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
602 if (--rep->count <= 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
603 delete rep; |
7717
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
604 |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
605 rep = a.rep; |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
606 rep->count++; |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
607 |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
608 dimensions = a.dimensions; |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
609 |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
610 delete [] idx; |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
611 idx_count = 0; |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
612 idx = 0; |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
613 } |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
614 |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
615 return *this; |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
616 } |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
617 |
ff918ee1a983
Delete idx in Sparse<T> and Array<T> operator =
David Bateman <dbateman@free.fr>
parents:
7620
diff
changeset
|
618 template <class T> |
5275 | 619 octave_idx_type |
620 Sparse<T>::compute_index (const Array<octave_idx_type>& ra_idx) const | |
5164 | 621 { |
5275 | 622 octave_idx_type retval = -1; |
623 | |
624 octave_idx_type n = dimensions.length (); | |
5164 | 625 |
626 if (n > 0 && n == ra_idx.length ()) | |
627 { | |
628 retval = ra_idx(--n); | |
629 | |
630 while (--n >= 0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
631 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
632 retval *= dimensions(n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
633 retval += ra_idx(n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
634 } |
5164 | 635 } |
636 else | |
637 (*current_liboctave_error_handler) | |
638 ("Sparse<T>::compute_index: invalid ra_idxing operation"); | |
639 | |
640 return retval; | |
641 } | |
642 | |
643 template <class T> | |
644 T | |
5275 | 645 Sparse<T>::range_error (const char *fcn, octave_idx_type n) const |
5164 | 646 { |
647 (*current_liboctave_error_handler) ("%s (%d): range error", fcn, n); | |
648 return T (); | |
649 } | |
650 | |
651 template <class T> | |
652 T& | |
5275 | 653 Sparse<T>::range_error (const char *fcn, octave_idx_type n) |
5164 | 654 { |
655 (*current_liboctave_error_handler) ("%s (%d): range error", fcn, n); | |
656 static T foo; | |
657 return foo; | |
658 } | |
659 | |
660 template <class T> | |
661 T | |
5275 | 662 Sparse<T>::range_error (const char *fcn, octave_idx_type i, octave_idx_type j) const |
5164 | 663 { |
664 (*current_liboctave_error_handler) | |
665 ("%s (%d, %d): range error", fcn, i, j); | |
666 return T (); | |
667 } | |
668 | |
669 template <class T> | |
670 T& | |
5275 | 671 Sparse<T>::range_error (const char *fcn, octave_idx_type i, octave_idx_type j) |
5164 | 672 { |
673 (*current_liboctave_error_handler) | |
674 ("%s (%d, %d): range error", fcn, i, j); | |
675 static T foo; | |
676 return foo; | |
677 } | |
678 | |
679 template <class T> | |
680 T | |
5275 | 681 Sparse<T>::range_error (const char *fcn, const Array<octave_idx_type>& ra_idx) const |
5164 | 682 { |
5765 | 683 std::ostringstream buf; |
5164 | 684 |
685 buf << fcn << " ("; | |
686 | |
5275 | 687 octave_idx_type n = ra_idx.length (); |
5164 | 688 |
689 if (n > 0) | |
690 buf << ra_idx(0); | |
691 | |
5275 | 692 for (octave_idx_type i = 1; i < n; i++) |
5164 | 693 buf << ", " << ra_idx(i); |
694 | |
695 buf << "): range error"; | |
5765 | 696 |
697 std::string buf_str = buf.str (); | |
698 | |
699 (*current_liboctave_error_handler) (buf_str.c_str ()); | |
5164 | 700 |
701 return T (); | |
702 } | |
703 | |
704 template <class T> | |
705 T& | |
5275 | 706 Sparse<T>::range_error (const char *fcn, const Array<octave_idx_type>& ra_idx) |
5164 | 707 { |
5765 | 708 std::ostringstream buf; |
5164 | 709 |
710 buf << fcn << " ("; | |
711 | |
5275 | 712 octave_idx_type n = ra_idx.length (); |
5164 | 713 |
714 if (n > 0) | |
715 buf << ra_idx(0); | |
716 | |
5275 | 717 for (octave_idx_type i = 1; i < n; i++) |
5164 | 718 buf << ", " << ra_idx(i); |
719 | |
720 buf << "): range error"; | |
721 | |
5765 | 722 std::string buf_str = buf.str (); |
723 | |
724 (*current_liboctave_error_handler) (buf_str.c_str ()); | |
5164 | 725 |
726 static T foo; | |
727 return foo; | |
728 } | |
729 | |
730 template <class T> | |
731 Sparse<T> | |
732 Sparse<T>::reshape (const dim_vector& new_dims) const | |
733 { | |
734 Sparse<T> retval; | |
6689 | 735 dim_vector dims2 = new_dims; |
736 | |
737 if (dims2.length () > 2) | |
5164 | 738 { |
6814 | 739 (*current_liboctave_warning_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
740 ("reshape: sparse reshape to N-d array smashes dims"); |
6814 | 741 |
6689 | 742 for (octave_idx_type i = 2; i < dims2.length(); i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
743 dims2(1) *= dims2(i); |
6814 | 744 |
6689 | 745 dims2.resize (2); |
746 } | |
747 | |
748 if (dimensions != dims2) | |
749 { | |
750 if (dimensions.numel () == dims2.numel ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
751 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
752 octave_idx_type new_nnz = nnz (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
753 octave_idx_type new_nr = dims2 (0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
754 octave_idx_type new_nc = dims2 (1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
755 octave_idx_type old_nr = rows (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
756 octave_idx_type old_nc = cols (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
757 retval = Sparse<T> (new_nr, new_nc, new_nnz); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
758 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
759 octave_idx_type kk = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
760 retval.xcidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
761 for (octave_idx_type i = 0; i < old_nc; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
762 for (octave_idx_type j = cidx(i); j < cidx(i+1); j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
763 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
764 octave_idx_type tmp = i * old_nr + ridx(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
765 octave_idx_type ii = tmp % new_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
766 octave_idx_type jj = (tmp - ii) / new_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
767 for (octave_idx_type k = kk; k < jj; k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
768 retval.xcidx(k+1) = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
769 kk = jj; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
770 retval.xdata(j) = data(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
771 retval.xridx(j) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
772 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
773 for (octave_idx_type k = kk; k < new_nc; k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
774 retval.xcidx(k+1) = new_nnz; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
775 } |
5164 | 776 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
777 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
778 std::string dimensions_str = dimensions.str (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
779 std::string new_dims_str = new_dims.str (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
780 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
781 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
782 ("reshape: can't reshape %s array to %s array", |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
783 dimensions_str.c_str (), new_dims_str.c_str ()); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
784 } |
5164 | 785 } |
786 else | |
787 retval = *this; | |
788 | |
789 return retval; | |
790 } | |
791 | |
792 template <class T> | |
793 Sparse<T> | |
5275 | 794 Sparse<T>::permute (const Array<octave_idx_type>& perm_vec, bool) const |
5164 | 795 { |
6813 | 796 // The only valid permutations of a sparse array are [1, 2] and [2, 1]. |
797 | |
798 bool fail = false; | |
6817 | 799 bool trans = false; |
6813 | 800 |
801 if (perm_vec.length () == 2) | |
5164 | 802 { |
6813 | 803 if (perm_vec(0) == 0 && perm_vec(1) == 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
804 /* do nothing */; |
6813 | 805 else if (perm_vec(0) == 1 && perm_vec(1) == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
806 trans = true; |
5164 | 807 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
808 fail = true; |
5164 | 809 } |
810 else | |
6813 | 811 fail = true; |
812 | |
813 if (fail) | |
814 (*current_liboctave_error_handler) | |
815 ("permutation vector contains an invalid element"); | |
816 | |
6817 | 817 return trans ? this->transpose () : *this; |
5164 | 818 } |
819 | |
820 template <class T> | |
821 void | |
822 Sparse<T>::resize_no_fill (const dim_vector& dv) | |
823 { | |
5275 | 824 octave_idx_type n = dv.length (); |
5164 | 825 |
826 if (n != 2) | |
827 { | |
828 (*current_liboctave_error_handler) ("sparse array must be 2-D"); | |
829 return; | |
830 } | |
831 | |
832 resize_no_fill (dv(0), dv(1)); | |
833 } | |
834 | |
835 template <class T> | |
836 void | |
5275 | 837 Sparse<T>::resize_no_fill (octave_idx_type r, octave_idx_type c) |
5164 | 838 { |
839 if (r < 0 || c < 0) | |
840 { | |
841 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
842 ("can't resize to negative dimension"); |
5164 | 843 return; |
844 } | |
845 | |
846 if (ndims () == 0) | |
847 dimensions = dim_vector (0, 0); | |
848 | |
849 if (r == dim1 () && c == dim2 ()) | |
850 return; | |
851 | |
5731 | 852 typename Sparse<T>::SparseRep *old_rep = rep; |
853 | |
5275 | 854 octave_idx_type nc = cols (); |
855 octave_idx_type nr = rows (); | |
5164 | 856 |
5681 | 857 if (nnz () == 0 || r == 0 || c == 0) |
5164 | 858 // Special case of redimensioning to/from a sparse matrix with |
859 // no elements | |
860 rep = new typename Sparse<T>::SparseRep (r, c); | |
861 else | |
862 { | |
5275 | 863 octave_idx_type n = 0; |
5164 | 864 Sparse<T> tmpval; |
865 if (r >= nr) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
866 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
867 if (c > nc) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
868 n = xcidx(nc); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
869 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
870 n = xcidx(c); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
871 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
872 tmpval = Sparse<T> (r, c, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
873 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
874 if (c > nc) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
875 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
876 for (octave_idx_type i = 0; i < nc + 1; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
877 tmpval.cidx(i) = xcidx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
878 for (octave_idx_type i = nc + 1; i < c + 1; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
879 tmpval.cidx(i) = tmpval.cidx(i-1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
880 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
881 else if (c <= nc) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
882 for (octave_idx_type i = 0; i < c + 1; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
883 tmpval.cidx(i) = xcidx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
884 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
885 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
886 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
887 tmpval.data(i) = xdata(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
888 tmpval.ridx(i) = xridx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
889 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
890 } |
5164 | 891 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
892 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
893 // Count how many non zero terms before we do anything |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
894 octave_idx_type min_nc = (c < nc ? c : nc); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
895 for (octave_idx_type i = 0; i < min_nc; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
896 for (octave_idx_type j = xcidx(i); j < xcidx(i+1); j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
897 if (xridx(j) < r) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
898 n++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
899 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
900 if (n) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
901 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
902 // Now that we know the size we can do something |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
903 tmpval = Sparse<T> (r, c, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
904 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
905 tmpval.cidx(0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
906 for (octave_idx_type i = 0, ii = 0; i < min_nc; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
907 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
908 for (octave_idx_type j = xcidx(i); j < xcidx(i+1); j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
909 if (xridx(j) < r) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
910 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
911 tmpval.data(ii) = xdata(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
912 tmpval.ridx(ii++) = xridx(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
913 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
914 tmpval.cidx(i+1) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
915 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
916 if (c > min_nc) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
917 for (octave_idx_type i = nc; i < c; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
918 tmpval.cidx(i+1) = tmpval.cidx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
919 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
920 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
921 tmpval = Sparse<T> (r, c); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
922 } |
5164 | 923 |
924 rep = tmpval.rep; | |
925 rep->count++; | |
926 } | |
927 | |
928 dimensions = dim_vector (r, c); | |
929 | |
930 if (--old_rep->count <= 0) | |
931 delete old_rep; | |
932 } | |
933 | |
934 template <class T> | |
935 Sparse<T>& | |
5275 | 936 Sparse<T>::insert (const Sparse<T>& a, octave_idx_type r, octave_idx_type c) |
5164 | 937 { |
5275 | 938 octave_idx_type a_rows = a.rows (); |
939 octave_idx_type a_cols = a.cols (); | |
940 octave_idx_type nr = rows (); | |
941 octave_idx_type nc = cols (); | |
5164 | 942 |
943 if (r < 0 || r + a_rows > rows () || c < 0 || c + a_cols > cols ()) | |
944 { | |
945 (*current_liboctave_error_handler) ("range error for insert"); | |
946 return *this; | |
947 } | |
948 | |
949 // First count the number of elements in the final array | |
5681 | 950 octave_idx_type nel = cidx(c) + a.nnz (); |
5164 | 951 |
952 if (c + a_cols < nc) | |
953 nel += cidx(nc) - cidx(c + a_cols); | |
954 | |
5275 | 955 for (octave_idx_type i = c; i < c + a_cols; i++) |
956 for (octave_idx_type j = cidx(i); j < cidx(i+1); j++) | |
5164 | 957 if (ridx(j) < r || ridx(j) >= r + a_rows) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
958 nel++; |
5164 | 959 |
960 Sparse<T> tmp (*this); | |
961 --rep->count; | |
962 rep = new typename Sparse<T>::SparseRep (nr, nc, nel); | |
963 | |
5275 | 964 for (octave_idx_type i = 0; i < tmp.cidx(c); i++) |
5164 | 965 { |
966 data(i) = tmp.data(i); | |
967 ridx(i) = tmp.ridx(i); | |
968 } | |
5275 | 969 for (octave_idx_type i = 0; i < c + 1; i++) |
5164 | 970 cidx(i) = tmp.cidx(i); |
971 | |
5275 | 972 octave_idx_type ii = cidx(c); |
973 | |
974 for (octave_idx_type i = c; i < c + a_cols; i++) | |
5164 | 975 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
976 octave_quit (); |
5164 | 977 |
5275 | 978 for (octave_idx_type j = tmp.cidx(i); j < tmp.cidx(i+1); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
979 if (tmp.ridx(j) < r) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
980 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
981 data(ii) = tmp.data(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
982 ridx(ii++) = tmp.ridx(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
983 } |
5164 | 984 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
985 octave_quit (); |
5164 | 986 |
5275 | 987 for (octave_idx_type j = a.cidx(i-c); j < a.cidx(i-c+1); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
988 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
989 data(ii) = a.data(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
990 ridx(ii++) = r + a.ridx(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
991 } |
5164 | 992 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
993 octave_quit (); |
5164 | 994 |
5275 | 995 for (octave_idx_type j = tmp.cidx(i); j < tmp.cidx(i+1); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
996 if (tmp.ridx(j) >= r + a_rows) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
997 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
998 data(ii) = tmp.data(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
999 ridx(ii++) = tmp.ridx(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1000 } |
5164 | 1001 |
1002 cidx(i+1) = ii; | |
1003 } | |
1004 | |
5275 | 1005 for (octave_idx_type i = c + a_cols; i < nc; i++) |
5164 | 1006 { |
5275 | 1007 for (octave_idx_type j = tmp.cidx(i); j < tmp.cidx(i+1); j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1008 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1009 data(ii) = tmp.data(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1010 ridx(ii++) = tmp.ridx(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1011 } |
5164 | 1012 cidx(i+1) = ii; |
1013 } | |
1014 | |
1015 return *this; | |
1016 } | |
1017 | |
1018 template <class T> | |
1019 Sparse<T>& | |
5275 | 1020 Sparse<T>::insert (const Sparse<T>& a, const Array<octave_idx_type>& ra_idx) |
5164 | 1021 { |
1022 | |
1023 if (ra_idx.length () != 2) | |
1024 { | |
1025 (*current_liboctave_error_handler) ("range error for insert"); | |
1026 return *this; | |
1027 } | |
1028 | |
1029 return insert (a, ra_idx (0), ra_idx (1)); | |
1030 } | |
1031 | |
1032 template <class T> | |
1033 Sparse<T> | |
1034 Sparse<T>::transpose (void) const | |
1035 { | |
1036 assert (ndims () == 2); | |
1037 | |
5275 | 1038 octave_idx_type nr = rows (); |
1039 octave_idx_type nc = cols (); | |
5648 | 1040 octave_idx_type nz = nnz (); |
5164 | 1041 Sparse<T> retval (nc, nr, nz); |
1042 | |
5648 | 1043 for (octave_idx_type i = 0; i < nz; i++) |
8987
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1044 retval.xcidx (ridx (i) + 1)++; |
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1045 // retval.xcidx[1:nr] holds the row degrees for rows 0:(nr-1) |
5648 | 1046 nz = 0; |
8987
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1047 for (octave_idx_type i = 1; i <= nr; i++) |
5164 | 1048 { |
8987
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1049 const octave_idx_type tmp = retval.xcidx (i); |
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1050 retval.xcidx (i) = nz; |
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1051 nz += tmp; |
5164 | 1052 } |
8987
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1053 // retval.xcidx[1:nr] holds row entry *start* offsets for rows 0:(nr-1) |
5648 | 1054 |
1055 for (octave_idx_type j = 0; j < nc; j++) | |
1056 for (octave_idx_type k = cidx(j); k < cidx(j+1); k++) | |
1057 { | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1058 octave_idx_type q = retval.xcidx (ridx (k) + 1)++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1059 retval.xridx (q) = j; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1060 retval.xdata (q) = data (k); |
5648 | 1061 } |
8987
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1062 assert (nnz () == retval.xcidx (nr)); |
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1063 // retval.xcidx[1:nr] holds row entry *end* offsets for rows 0:(nr-1) |
542015fada9e
Eliminate the workspace in sparse transpose.
Jason Riedy <jason@acm.org>
parents:
8920
diff
changeset
|
1064 // and retval.xcidx[0:(nr-1)] holds their row entry *start* offsets |
5164 | 1065 |
1066 return retval; | |
1067 } | |
1068 | |
1069 template <class T> | |
1070 void | |
1071 Sparse<T>::clear_index (void) | |
1072 { | |
1073 delete [] idx; | |
1074 idx = 0; | |
1075 idx_count = 0; | |
1076 } | |
1077 | |
1078 template <class T> | |
1079 void | |
1080 Sparse<T>::set_index (const idx_vector& idx_arg) | |
1081 { | |
5275 | 1082 octave_idx_type nd = ndims (); |
5164 | 1083 |
1084 if (! idx && nd > 0) | |
1085 idx = new idx_vector [nd]; | |
1086 | |
1087 if (idx_count < nd) | |
1088 { | |
1089 idx[idx_count++] = idx_arg; | |
1090 } | |
1091 else | |
1092 { | |
1093 idx_vector *new_idx = new idx_vector [idx_count+1]; | |
1094 | |
5275 | 1095 for (octave_idx_type i = 0; i < idx_count; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1096 new_idx[i] = idx[i]; |
5164 | 1097 |
1098 new_idx[idx_count++] = idx_arg; | |
1099 | |
1100 delete [] idx; | |
1101 | |
1102 idx = new_idx; | |
1103 } | |
1104 } | |
1105 | |
1106 template <class T> | |
1107 void | |
1108 Sparse<T>::maybe_delete_elements (idx_vector& idx_arg) | |
1109 { | |
5275 | 1110 octave_idx_type nr = dim1 (); |
1111 octave_idx_type nc = dim2 (); | |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1112 octave_idx_type orig_nr = nr; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1113 octave_idx_type orig_nc = nc; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1114 octave_idx_type orig_nnz = nnz (); |
5164 | 1115 |
1116 if (nr == 0 && nc == 0) | |
1117 return; | |
1118 | |
5275 | 1119 octave_idx_type n; |
5164 | 1120 if (nr == 1) |
1121 n = nc; | |
1122 else if (nc == 1) | |
1123 n = nr; | |
1124 else | |
1125 { | |
1126 // Reshape to row vector for Matlab compatibility. | |
1127 | |
1128 n = nr * nc; | |
1129 nr = 1; | |
1130 nc = n; | |
1131 } | |
1132 | |
1133 if (idx_arg.is_colon_equiv (n, 1)) | |
1134 { | |
1135 // Either A(:) = [] or A(idx) = [] with idx enumerating all | |
1136 // elements, so we delete all elements and return [](0x0). To | |
1137 // preserve the orientation of the vector, you have to use | |
1138 // A(idx,:) = [] (delete rows) or A(:,idx) (delete columns). | |
1139 | |
1140 resize_no_fill (0, 0); | |
1141 return; | |
1142 } | |
1143 | |
1144 idx_arg.sort (true); | |
1145 | |
5275 | 1146 octave_idx_type num_to_delete = idx_arg.length (n); |
5164 | 1147 |
1148 if (num_to_delete != 0) | |
1149 { | |
5275 | 1150 octave_idx_type new_n = n; |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1151 octave_idx_type new_nnz = orig_nnz; |
5275 | 1152 |
1153 octave_idx_type iidx = 0; | |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1154 octave_idx_type kk = idx_arg.elem (iidx); |
5164 | 1155 |
1156 const Sparse<T> tmp (*this); | |
1157 | |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1158 if (orig_nr == 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1159 { |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1160 for (octave_idx_type i = 0; i < n; i++) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1161 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1162 octave_quit (); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1163 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1164 if (i == kk) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1165 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1166 iidx++; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1167 kk = idx_arg.elem (iidx); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1168 new_n--; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1169 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1170 if (tmp.cidx(i) != tmp.cidx(i + 1)) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1171 new_nnz--; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1172 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1173 if (iidx == num_to_delete) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1174 break; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1175 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1176 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1177 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1178 else if (orig_nc == 1) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1179 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1180 octave_idx_type next_ridx = -1; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1181 octave_idx_type next_ridx_val = -1; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1182 if (orig_nnz > 0) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1183 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1184 next_ridx = 0; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1185 next_ridx_val = tmp.ridx (0); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1186 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1187 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1188 for (octave_idx_type i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1189 { |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1190 octave_quit (); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1191 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1192 if (i == kk) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1193 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1194 iidx++; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1195 kk = idx_arg.elem (iidx); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1196 new_n--; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1197 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1198 while (i > next_ridx_val) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1199 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1200 next_ridx++; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1201 if (next_ridx >= orig_nnz) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1202 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1203 next_ridx = -1; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1204 next_ridx_val = n; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1205 break; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1206 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1207 else |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1208 next_ridx_val = tmp.ridx (next_ridx); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1209 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1210 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1211 if (i == next_ridx_val) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1212 new_nnz--; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1213 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1214 if (iidx == num_to_delete) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1215 break; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1216 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1217 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1218 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1219 else |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1220 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1221 for (octave_idx_type i = 0; i < n; i++) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1222 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1223 octave_quit (); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1224 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1225 if (i == kk) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1226 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1227 iidx++; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1228 kk = idx_arg.elem (iidx); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1229 new_n--; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1230 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1231 if (tmp.elem (i) != T ()) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1232 new_nnz--; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1233 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1234 if (iidx == num_to_delete) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1235 break; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1236 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1237 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1238 } |
5164 | 1239 |
1240 if (new_n > 0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1241 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1242 rep->count--; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1243 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1244 if (nr == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1245 rep = new typename Sparse<T>::SparseRep (1, new_n, new_nnz); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1246 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1247 rep = new typename Sparse<T>::SparseRep (new_n, 1, new_nnz); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1248 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1249 octave_idx_type ii = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1250 octave_idx_type jj = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1251 iidx = 0; |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1252 kk = idx_arg.elem (iidx); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1253 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1254 if (orig_nr == 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1255 { |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1256 for (octave_idx_type i = 0; i < n; i++) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1257 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1258 octave_quit (); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1259 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1260 if (iidx < num_to_delete && i == kk) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1261 kk = idx_arg.elem (++iidx); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1262 else |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1263 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1264 if (tmp.cidx(i) != tmp.cidx(i + 1)) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1265 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1266 data(ii) = tmp.data (tmp.cidx(i)); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1267 ridx(ii++) = jj; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1268 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1269 jj++; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1270 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1271 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1272 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1273 else if (orig_nc == 1) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1274 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1275 octave_idx_type next_ridx = -1; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1276 octave_idx_type next_ridx_val = n; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1277 if (orig_nnz > 0) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1278 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1279 next_ridx = 0; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1280 next_ridx_val = tmp.ridx (0); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1281 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1282 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1283 for (octave_idx_type i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1284 { |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1285 octave_quit (); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1286 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1287 if (iidx < num_to_delete && i == kk) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1288 kk = idx_arg.elem (++iidx); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1289 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1290 { |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1291 while (i > next_ridx_val) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1292 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1293 next_ridx++; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1294 if (next_ridx >= orig_nnz) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1295 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1296 next_ridx = -1; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1297 next_ridx_val = n; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1298 break; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1299 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1300 else |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1301 next_ridx_val = tmp.ridx (next_ridx); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1302 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1303 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1304 if (i == next_ridx_val) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1305 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1306 data(ii) = tmp.data(next_ridx); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1307 ridx(ii++) = jj; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1308 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1309 jj++; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1310 } |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1311 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1312 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1313 else |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1314 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1315 for (octave_idx_type i = 0; i < n; i++) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1316 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1317 octave_quit (); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1318 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1319 if (iidx < num_to_delete && i == kk) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1320 kk = idx_arg.elem (++iidx); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1321 else |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1322 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1323 T el = tmp.elem (i); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1324 if (el != T ()) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1325 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1326 data(ii) = el; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1327 ridx(ii++) = jj; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1328 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1329 jj++; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1330 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1331 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1332 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1333 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1334 dimensions.resize (2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1335 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1336 if (nr == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1337 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1338 ii = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1339 cidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1340 for (octave_idx_type i = 0; i < new_n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1341 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1342 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1343 if (ridx(ii) == i) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1344 ridx(ii++) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1345 cidx(i+1) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1346 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1347 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1348 dimensions(0) = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1349 dimensions(1) = new_n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1350 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1351 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1352 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1353 cidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1354 cidx(1) = new_nnz; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1355 dimensions(0) = new_n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1356 dimensions(1) = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1357 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1358 } |
5164 | 1359 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1360 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1361 ("A(idx) = []: index out of range"); |
5164 | 1362 } |
1363 } | |
1364 | |
1365 template <class T> | |
1366 void | |
1367 Sparse<T>::maybe_delete_elements (idx_vector& idx_i, idx_vector& idx_j) | |
1368 { | |
1369 assert (ndims () == 2); | |
1370 | |
5275 | 1371 octave_idx_type nr = dim1 (); |
1372 octave_idx_type nc = dim2 (); | |
5164 | 1373 |
1374 if (nr == 0 && nc == 0) | |
1375 return; | |
1376 | |
1377 if (idx_i.is_colon ()) | |
1378 { | |
1379 if (idx_j.is_colon ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1380 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1381 // A(:,:) -- We are deleting columns and rows, so the result |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1382 // is [](0x0). |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1383 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1384 resize_no_fill (0, 0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1385 return; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1386 } |
5164 | 1387 |
1388 if (idx_j.is_colon_equiv (nc, 1)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1389 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1390 // A(:,j) -- We are deleting columns by enumerating them, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1391 // If we enumerate all of them, we should have zero columns |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1392 // with the same number of rows that we started with. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1393 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1394 resize_no_fill (nr, 0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1395 return; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1396 } |
5164 | 1397 } |
1398 | |
1399 if (idx_j.is_colon () && idx_i.is_colon_equiv (nr, 1)) | |
1400 { | |
1401 // A(i,:) -- We are deleting rows by enumerating them. If we | |
1402 // enumerate all of them, we should have zero rows with the | |
1403 // same number of columns that we started with. | |
1404 | |
1405 resize_no_fill (0, nc); | |
1406 return; | |
1407 } | |
1408 | |
1409 if (idx_i.is_colon_equiv (nr, 1)) | |
1410 { | |
1411 if (idx_j.is_colon_equiv (nc, 1)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1412 resize_no_fill (0, 0); |
5164 | 1413 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1414 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1415 idx_j.sort (true); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1416 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1417 octave_idx_type num_to_delete = idx_j.length (nc); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1418 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1419 if (num_to_delete != 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1420 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1421 if (nr == 1 && num_to_delete == nc) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1422 resize_no_fill (0, 0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1423 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1424 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1425 octave_idx_type new_nc = nc; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1426 octave_idx_type new_nnz = nnz (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1427 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1428 octave_idx_type iidx = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1429 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1430 for (octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1431 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1432 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1433 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1434 if (j == idx_j.elem (iidx)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1435 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1436 iidx++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1437 new_nc--; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1438 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1439 new_nnz -= cidx(j+1) - cidx(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1440 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1441 if (iidx == num_to_delete) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1442 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1443 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1444 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1445 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1446 if (new_nc > 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1447 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1448 const Sparse<T> tmp (*this); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1449 --rep->count; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1450 rep = new typename Sparse<T>::SparseRep (nr, new_nc, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1451 new_nnz); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1452 octave_idx_type ii = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1453 octave_idx_type jj = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1454 iidx = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1455 cidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1456 for (octave_idx_type j = 0; j < nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1457 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1458 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1459 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1460 if (iidx < num_to_delete && j == idx_j.elem (iidx)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1461 iidx++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1462 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1463 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1464 for (octave_idx_type i = tmp.cidx(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1465 i < tmp.cidx(j+1); i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1466 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1467 data(jj) = tmp.data(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1468 ridx(jj++) = tmp.ridx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1469 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1470 cidx(++ii) = jj; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1471 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1472 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1473 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1474 dimensions.resize (2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1475 dimensions(1) = new_nc; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1476 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1477 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1478 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1479 ("A(idx) = []: index out of range"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1480 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1481 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1482 } |
5164 | 1483 } |
1484 else if (idx_j.is_colon_equiv (nc, 1)) | |
1485 { | |
1486 if (idx_i.is_colon_equiv (nr, 1)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1487 resize_no_fill (0, 0); |
5164 | 1488 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1489 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1490 idx_i.sort (true); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1491 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1492 octave_idx_type num_to_delete = idx_i.length (nr); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1493 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1494 if (num_to_delete != 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1495 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1496 if (nc == 1 && num_to_delete == nr) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1497 resize_no_fill (0, 0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1498 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1499 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1500 octave_idx_type new_nr = nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1501 octave_idx_type new_nnz = nnz (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1502 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1503 octave_idx_type iidx = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1504 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1505 for (octave_idx_type i = 0; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1506 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1507 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1508 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1509 if (i == idx_i.elem (iidx)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1510 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1511 iidx++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1512 new_nr--; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1513 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1514 for (octave_idx_type j = 0; j < nnz (); j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1515 if (ridx(j) == i) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1516 new_nnz--; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1517 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1518 if (iidx == num_to_delete) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1519 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1520 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1521 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1522 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1523 if (new_nr > 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1524 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1525 const Sparse<T> tmp (*this); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1526 --rep->count; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1527 rep = new typename Sparse<T>::SparseRep (new_nr, nc, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1528 new_nnz); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1529 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1530 octave_idx_type jj = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1531 cidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1532 for (octave_idx_type i = 0; i < nc; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1533 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1534 iidx = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1535 for (octave_idx_type j = tmp.cidx(i); j < tmp.cidx(i+1); j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1536 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1537 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1538 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1539 octave_idx_type ri = tmp.ridx(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1540 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1541 while (iidx < num_to_delete && |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1542 ri > idx_i.elem (iidx)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1543 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1544 iidx++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1545 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1546 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1547 if (iidx == num_to_delete || |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1548 ri != idx_i.elem(iidx)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1549 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1550 data(jj) = tmp.data(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1551 ridx(jj++) = ri - iidx; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1552 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1553 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1554 cidx(i+1) = jj; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1555 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1556 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1557 dimensions.resize (2); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1558 dimensions(0) = new_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1559 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1560 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1561 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1562 ("A(idx) = []: index out of range"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1563 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1564 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1565 } |
5164 | 1566 } |
1567 } | |
1568 | |
1569 template <class T> | |
1570 void | |
1571 Sparse<T>::maybe_delete_elements (Array<idx_vector>& ra_idx) | |
1572 { | |
1573 if (ra_idx.length () == 1) | |
1574 maybe_delete_elements (ra_idx(0)); | |
1575 else if (ra_idx.length () == 2) | |
1576 maybe_delete_elements (ra_idx(0), ra_idx(1)); | |
1577 else | |
1578 (*current_liboctave_error_handler) | |
1579 ("range error for maybe_delete_elements"); | |
1580 } | |
1581 | |
1582 template <class T> | |
1583 Sparse<T> | |
1584 Sparse<T>::value (void) | |
1585 { | |
1586 Sparse<T> retval; | |
1587 | |
1588 int n_idx = index_count (); | |
1589 | |
1590 if (n_idx == 2) | |
1591 { | |
1592 idx_vector *tmp = get_idx (); | |
1593 | |
1594 idx_vector idx_i = tmp[0]; | |
1595 idx_vector idx_j = tmp[1]; | |
1596 | |
1597 retval = index (idx_i, idx_j); | |
1598 } | |
1599 else if (n_idx == 1) | |
1600 { | |
1601 retval = index (idx[0]); | |
1602 } | |
1603 else | |
1604 (*current_liboctave_error_handler) | |
1605 ("Sparse<T>::value: invalid number of indices specified"); | |
1606 | |
1607 clear_index (); | |
1608 | |
1609 return retval; | |
1610 } | |
1611 | |
1612 template <class T> | |
1613 Sparse<T> | |
1614 Sparse<T>::index (idx_vector& idx_arg, int resize_ok) const | |
1615 { | |
1616 Sparse<T> retval; | |
1617 | |
1618 assert (ndims () == 2); | |
1619 | |
5275 | 1620 octave_idx_type nr = dim1 (); |
1621 octave_idx_type nc = dim2 (); | |
5681 | 1622 octave_idx_type nz = nnz (); |
5275 | 1623 |
1624 octave_idx_type orig_len = nr * nc; | |
5164 | 1625 |
1626 dim_vector idx_orig_dims = idx_arg.orig_dimensions (); | |
1627 | |
5275 | 1628 octave_idx_type idx_orig_rows = idx_arg.orig_rows (); |
1629 octave_idx_type idx_orig_columns = idx_arg.orig_columns (); | |
5164 | 1630 |
1631 if (idx_orig_dims.length () > 2) | |
1632 (*current_liboctave_error_handler) | |
1633 ("Sparse<T>::index: Can not index Sparse<T> with an N-D Array"); | |
1634 else if (idx_arg.is_colon ()) | |
1635 { | |
1636 // Fast magic colon processing. | |
1637 retval = Sparse<T> (nr * nc, 1, nz); | |
1638 | |
5275 | 1639 for (octave_idx_type i = 0; i < nc; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1640 for (octave_idx_type j = cidx(i); j < cidx(i+1); j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1641 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1642 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1643 retval.xdata(j) = data(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1644 retval.xridx(j) = ridx(j) + i * nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1645 } |
5164 | 1646 retval.xcidx(0) = 0; |
1647 retval.xcidx(1) = nz; | |
1648 } | |
1649 else if (nr == 1 && nc == 1) | |
1650 { | |
1651 // You have to be pretty sick to get to this bit of code, | |
1652 // since you have a scalar stored as a sparse matrix, and | |
1653 // then want to make a dense matrix with sparse | |
1654 // representation. Ok, we'll do it, but you deserve what | |
1655 // you get!! | |
5275 | 1656 octave_idx_type n = idx_arg.freeze (length (), "sparse vector", resize_ok); |
5164 | 1657 if (n == 0) |
7573
755bf7ecc29b
eliminate one_zero stuff from idx_vector
John W. Eaton <jwe@octave.org>
parents:
7546
diff
changeset
|
1658 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1659 retval = Sparse<T> (idx_orig_dims); |
5164 | 1660 else if (nz < 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1661 if (n >= idx_orig_dims.numel ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1662 retval = Sparse<T> (idx_orig_dims); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1663 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1664 retval = Sparse<T> (dim_vector (n, 1)); |
5164 | 1665 else if (n >= idx_orig_dims.numel ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1666 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1667 T el = elem (0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1668 octave_idx_type new_nr = idx_orig_rows; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1669 octave_idx_type new_nc = idx_orig_columns; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1670 for (octave_idx_type i = 2; i < idx_orig_dims.length (); i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1671 new_nc *= idx_orig_dims (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1672 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1673 retval = Sparse<T> (new_nr, new_nc, idx_arg.ones_count ()); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1674 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1675 octave_idx_type ic = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1676 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1677 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1678 if (i % new_nr == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1679 retval.xcidx(i / new_nr) = ic; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1680 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1681 octave_idx_type ii = idx_arg.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1682 if (ii == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1683 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1684 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1685 retval.xdata(ic) = el; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1686 retval.xridx(ic++) = i % new_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1687 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1688 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1689 retval.xcidx (new_nc) = ic; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1690 } |
5164 | 1691 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1692 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1693 T el = elem (0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1694 retval = Sparse<T> (n, 1, nz); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1695 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1696 for (octave_idx_type i = 0; i < nz; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1697 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1698 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1699 retval.xdata(i) = el; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1700 retval.xridx(i) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1701 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1702 retval.xcidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1703 retval.xcidx(1) = n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1704 } |
5164 | 1705 } |
1706 else if (nr == 1 || nc == 1) | |
1707 { | |
1708 // If indexing a vector with a matrix, return value has same | |
1709 // shape as the index. Otherwise, it has same orientation as | |
1710 // indexed object. | |
5275 | 1711 octave_idx_type len = length (); |
1712 octave_idx_type n = idx_arg.freeze (len, "sparse vector", resize_ok); | |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1713 octave_idx_type l, u; |
5164 | 1714 if (n == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1715 if (nr == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1716 retval = Sparse<T> (dim_vector (1, 0)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1717 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1718 retval = Sparse<T> (dim_vector (0, 1)); |
5164 | 1719 else if (nz < 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1720 if (idx_orig_rows == 1 || idx_orig_columns == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1721 retval = Sparse<T> ((nr == 1 ? 1 : n), (nr == 1 ? n : 1)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1722 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1723 retval = Sparse<T> (idx_orig_dims); |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1724 else if (idx_arg.is_range () && idx_arg.is_cont_range (n, l, u)) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1725 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1726 // Special case of indexing a sparse vector by a continuous range |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1727 if (nr == 1) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1728 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1729 octave_idx_type new_nzmx = cidx(u) - cidx(l); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1730 retval = Sparse<T> (1, n, new_nzmx); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1731 octave_idx_type *iidx = retval.xcidx (); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1732 copy_or_memcpy (n + 1, rep->c + l, iidx); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1733 octave_idx_type ii = iidx[0]; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1734 if (ii != 0) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1735 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1736 for (octave_idx_type i = 0; i < n + 1; i++) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1737 iidx[i] -= ii; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1738 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1739 copy_or_memcpy (new_nzmx, rep->d + ii, retval.rep->d); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1740 copy_or_memcpy (new_nzmx, rep->r + ii, retval.rep->r); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1741 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1742 else |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1743 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1744 octave_idx_type j1 = -1; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1745 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1746 octave_idx_type new_nzmx = 0; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1747 for (octave_idx_type j = 0; j < nz; j++) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1748 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1749 octave_idx_type j2 = ridx (j); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1750 if (j2 >= l && j2 < u) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1751 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1752 new_nzmx++; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1753 if (j1 < 0) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1754 j1 = j; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1755 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1756 if (j2 >= u) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1757 break; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1758 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1759 |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1760 retval = Sparse<T> (n, 1, new_nzmx); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1761 if (new_nzmx > 0) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1762 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1763 retval.xcidx(0) = 0; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1764 retval.xcidx(1) = new_nzmx; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1765 copy_or_memcpy (new_nzmx, rep->d + j1, retval.rep->d); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1766 octave_idx_type *iidx = retval.xridx (); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1767 copy_or_memcpy (new_nzmx, rep->r + j1, iidx); |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1768 if (l != 0) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1769 { |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1770 for (octave_idx_type i = 0; i < new_nzmx; i++) |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1771 iidx[i] -= l; |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1772 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1773 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1774 } |
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1775 } |
5164 | 1776 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1777 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1778 octave_idx_type new_nzmx = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1779 if (nr == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1780 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1781 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1782 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1783 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1784 octave_idx_type ii = idx_arg.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1785 if (ii < len) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1786 if (cidx(ii) != cidx(ii+1)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1787 new_nzmx++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1788 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1789 else |
10382
1766c133674c
Special case sparse index method for ranges and maybe_delete_elements method for sparse vectors
David Bateman <dbateman@free.fr>
parents:
10367
diff
changeset
|
1790 for (octave_idx_type i = 0; i < n; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1791 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1792 octave_idx_type ii = idx_arg.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1793 if (ii < len) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1794 for (octave_idx_type j = 0; j < nz; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1795 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1796 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1797 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1798 if (ridx(j) == ii) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1799 new_nzmx++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1800 if (ridx(j) >= ii) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1801 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1802 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1803 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1804 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1805 if (idx_orig_rows == 1 || idx_orig_columns == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1806 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1807 if (nr == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1808 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1809 retval = Sparse<T> (1, n, new_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1810 octave_idx_type jj = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1811 retval.xcidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1812 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1813 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1814 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1815 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1816 octave_idx_type ii = idx_arg.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1817 if (ii < len) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1818 if (cidx(ii) != cidx(ii+1)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1819 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1820 retval.xdata(jj) = data(cidx(ii)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1821 retval.xridx(jj++) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1822 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1823 retval.xcidx(i+1) = jj; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1824 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1825 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1826 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1827 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1828 retval = Sparse<T> (n, 1, new_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1829 retval.xcidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1830 retval.xcidx(1) = new_nzmx; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1831 octave_idx_type jj = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1832 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1833 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1834 octave_idx_type ii = idx_arg.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1835 if (ii < len) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1836 for (octave_idx_type j = 0; j < nz; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1837 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1838 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1839 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1840 if (ridx(j) == ii) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1841 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1842 retval.xdata(jj) = data(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1843 retval.xridx(jj++) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1844 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1845 if (ridx(j) >= ii) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1846 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1847 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1848 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1849 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1850 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1851 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1852 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1853 octave_idx_type new_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1854 octave_idx_type new_nc; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1855 if (n >= idx_orig_dims.numel ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1856 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1857 new_nr = idx_orig_rows; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1858 new_nc = idx_orig_columns; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1859 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1860 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1861 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1862 new_nr = n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1863 new_nc = 1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1864 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1865 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1866 retval = Sparse<T> (new_nr, new_nc, new_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1867 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1868 if (nr == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1869 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1870 octave_idx_type jj = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1871 retval.xcidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1872 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1873 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1874 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1875 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1876 octave_idx_type ii = idx_arg.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1877 if (ii < len) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1878 if (cidx(ii) != cidx(ii+1)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1879 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1880 retval.xdata(jj) = data(cidx(ii)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1881 retval.xridx(jj++) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1882 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1883 retval.xcidx(i/new_nr+1) = jj; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1884 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1885 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1886 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1887 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1888 octave_idx_type jj = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1889 retval.xcidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1890 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1891 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1892 octave_idx_type ii = idx_arg.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1893 if (ii < len) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1894 for (octave_idx_type j = 0; j < nz; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1895 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1896 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1897 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1898 if (ridx(j) == ii) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1899 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1900 retval.xdata(jj) = data(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1901 retval.xridx(jj++) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1902 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1903 if (ridx(j) >= ii) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1904 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1905 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1906 retval.xcidx(i/new_nr+1) = jj; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1907 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1908 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1909 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1910 } |
5164 | 1911 } |
1912 else | |
1913 { | |
7573
755bf7ecc29b
eliminate one_zero stuff from idx_vector
John W. Eaton <jwe@octave.org>
parents:
7546
diff
changeset
|
1914 (*current_liboctave_warning_with_id_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1915 ("Octave:fortran-indexing", "single index used for sparse matrix"); |
5164 | 1916 |
1917 // This code is only for indexing matrices. The vector | |
1918 // cases are handled above. | |
1919 | |
1920 idx_arg.freeze (nr * nc, "matrix", resize_ok); | |
1921 | |
1922 if (idx_arg) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1923 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1924 octave_idx_type result_nr = idx_orig_rows; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1925 octave_idx_type result_nc = idx_orig_columns; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1926 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1927 if (nz < 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1928 retval = Sparse<T> (result_nr, result_nc); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1929 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1930 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1931 // Count number of non-zero elements |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1932 octave_idx_type new_nzmx = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1933 octave_idx_type kk = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1934 for (octave_idx_type j = 0; j < result_nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1935 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1936 for (octave_idx_type i = 0; i < result_nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1937 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1938 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1939 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1940 octave_idx_type ii = idx_arg.elem (kk++); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1941 if (ii < orig_len) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1942 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1943 octave_idx_type fr = ii % nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1944 octave_idx_type fc = (ii - fr) / nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1945 for (octave_idx_type k = cidx(fc); k < cidx(fc+1); k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1946 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1947 if (ridx(k) == fr) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1948 new_nzmx++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1949 if (ridx(k) >= fr) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1950 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1951 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1952 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1953 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1954 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1955 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1956 retval = Sparse<T> (result_nr, result_nc, new_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1957 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1958 kk = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1959 octave_idx_type jj = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1960 retval.xcidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1961 for (octave_idx_type j = 0; j < result_nc; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1962 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1963 for (octave_idx_type i = 0; i < result_nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1964 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1965 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1966 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1967 octave_idx_type ii = idx_arg.elem (kk++); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1968 if (ii < orig_len) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1969 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1970 octave_idx_type fr = ii % nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1971 octave_idx_type fc = (ii - fr) / nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1972 for (octave_idx_type k = cidx(fc); k < cidx(fc+1); k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1973 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1974 if (ridx(k) == fr) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1975 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1976 retval.xdata(jj) = data(k); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1977 retval.xridx(jj++) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1978 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1979 if (ridx(k) >= fr) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1980 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1981 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1982 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1983 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1984 retval.xcidx(j+1) = jj; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1985 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1986 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1987 // idx_vector::freeze() printed an error message for us. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1988 } |
5164 | 1989 } |
1990 | |
1991 return retval; | |
1992 } | |
1993 | |
6988 | 1994 struct |
1995 idx_node | |
1996 { | |
1997 octave_idx_type i; | |
1998 struct idx_node *next; | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
1999 }; |
6988 | 2000 |
5164 | 2001 template <class T> |
2002 Sparse<T> | |
2003 Sparse<T>::index (idx_vector& idx_i, idx_vector& idx_j, int resize_ok) const | |
2004 { | |
2005 Sparse<T> retval; | |
2006 | |
2007 assert (ndims () == 2); | |
2008 | |
5275 | 2009 octave_idx_type nr = dim1 (); |
2010 octave_idx_type nc = dim2 (); | |
2011 | |
2012 octave_idx_type n = idx_i.freeze (nr, "row", resize_ok); | |
2013 octave_idx_type m = idx_j.freeze (nc, "column", resize_ok); | |
5164 | 2014 |
2015 if (idx_i && idx_j) | |
2016 { | |
2017 if (idx_i.orig_empty () || idx_j.orig_empty () || n == 0 || m == 0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2018 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2019 retval.resize_no_fill (n, m); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2020 } |
5681 | 2021 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2022 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2023 int idx_i_colon = idx_i.is_colon_equiv (nr); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2024 int idx_j_colon = idx_j.is_colon_equiv (nc); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2025 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2026 if (idx_i_colon && idx_j_colon) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2027 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2028 retval = *this; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2029 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2030 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2031 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2032 // Identify if the indices have any repeated values |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2033 bool permutation = true; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2034 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2035 OCTAVE_LOCAL_BUFFER (octave_idx_type, itmp, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2036 (nr > nc ? nr : nc)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2037 octave_sort<octave_idx_type> lsort; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2038 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2039 if (n > nr || m > nc) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2040 permutation = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2041 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2042 if (permutation && ! idx_i_colon) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2043 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2044 // Can't use something like |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2045 // idx_vector tmp_idx = idx_i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2046 // tmp_idx.sort (true); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2047 // if (tmp_idx.length(nr) != n) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2048 // permutation = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2049 // here as there is no make_unique function |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2050 // for idx_vector type. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2051 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2052 itmp [i] = idx_i.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2053 lsort.sort (itmp, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2054 for (octave_idx_type i = 1; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2055 if (itmp[i-1] == itmp[i]) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2056 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2057 permutation = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2058 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2059 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2060 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2061 if (permutation && ! idx_j_colon) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2062 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2063 for (octave_idx_type i = 0; i < m; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2064 itmp [i] = idx_j.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2065 lsort.sort (itmp, m); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2066 for (octave_idx_type i = 1; i < m; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2067 if (itmp[i-1] == itmp[i]) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2068 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2069 permutation = false; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2070 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2071 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2072 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2073 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2074 if (permutation) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2075 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2076 // Special case permutation like indexing for speed |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2077 retval = Sparse<T> (n, m, nnz ()); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2078 octave_idx_type *ri = retval.xridx (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2079 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2080 std::vector<T> X (n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2081 for (octave_idx_type i = 0; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2082 itmp [i] = -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2083 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2084 itmp[idx_i.elem(i)] = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2085 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2086 octave_idx_type kk = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2087 retval.xcidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2088 for (octave_idx_type j = 0; j < m; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2089 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2090 octave_idx_type jj = idx_j.elem (j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2091 for (octave_idx_type i = cidx(jj); i < cidx(jj+1); i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2092 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2093 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2094 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2095 octave_idx_type ii = itmp [ridx(i)]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2096 if (ii >= 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2097 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2098 X [ii] = data (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2099 retval.xridx (kk++) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2100 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2101 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2102 lsort.sort (ri + retval.xcidx (j), kk - retval.xcidx (j)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2103 for (octave_idx_type p = retval.xcidx (j); p < kk; p++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2104 retval.xdata (p) = X [retval.xridx (p)]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2105 retval.xcidx(j+1) = kk; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2106 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2107 retval.maybe_compress (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2108 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2109 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2110 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2111 OCTAVE_LOCAL_BUFFER (struct idx_node, nodes, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2112 OCTAVE_LOCAL_BUFFER (octave_idx_type, start_nodes, nr); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2113 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2114 for (octave_idx_type i = 0; i < nr; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2115 start_nodes[i] = -1; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2116 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2117 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2118 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2119 octave_idx_type ii = idx_i.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2120 nodes[i].i = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2121 nodes[i].next = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2122 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2123 octave_idx_type node = start_nodes[ii]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2124 if (node == -1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2125 start_nodes[ii] = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2126 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2127 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2128 while (nodes[node].next) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2129 node = nodes[node].next->i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2130 nodes[node].next = nodes + i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2131 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2132 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2133 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2134 // First count the number of non-zero elements |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2135 octave_idx_type new_nzmx = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2136 for (octave_idx_type j = 0; j < m; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2137 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2138 octave_idx_type jj = idx_j.elem (j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2139 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2140 if (jj < nc) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2141 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2142 for (octave_idx_type i = cidx(jj); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2143 i < cidx(jj+1); i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2144 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2145 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2146 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2147 octave_idx_type ii = start_nodes [ridx(i)]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2148 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2149 if (ii >= 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2150 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2151 struct idx_node inode = nodes[ii]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2152 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2153 while (true) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2154 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2155 if (idx_i.elem (inode.i) < nr) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2156 new_nzmx ++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2157 if (inode.next == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2158 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2159 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2160 inode = *inode.next; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2161 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2162 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2163 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2164 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2165 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2166 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2167 std::vector<T> X (n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2168 retval = Sparse<T> (n, m, new_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2169 octave_idx_type *ri = retval.xridx (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2170 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2171 octave_idx_type kk = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2172 retval.xcidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2173 for (octave_idx_type j = 0; j < m; j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2174 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2175 octave_idx_type jj = idx_j.elem (j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2176 if (jj < nc) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2177 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2178 for (octave_idx_type i = cidx(jj); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2179 i < cidx(jj+1); i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2180 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2181 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2182 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2183 octave_idx_type ii = start_nodes [ridx(i)]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2184 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2185 if (ii >= 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2186 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2187 struct idx_node inode = nodes[ii]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2188 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2189 while (true) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2190 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2191 if (idx_i.elem (inode.i) < nr) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2192 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2193 X [inode.i] = data (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2194 retval.xridx (kk++) = inode.i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2195 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2196 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2197 if (inode.next == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2198 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2199 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2200 inode = *inode.next; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2201 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2202 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2203 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2204 lsort.sort (ri + retval.xcidx (j), |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2205 kk - retval.xcidx (j)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2206 for (octave_idx_type p = retval.xcidx (j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2207 p < kk; p++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2208 retval.xdata (p) = X [retval.xridx (p)]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2209 retval.xcidx(j+1) = kk; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2210 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2211 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2212 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2213 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2214 } |
5164 | 2215 } |
2216 // idx_vector::freeze() printed an error message for us. | |
2217 | |
2218 return retval; | |
2219 } | |
2220 | |
2221 template <class T> | |
2222 Sparse<T> | |
2223 Sparse<T>::index (Array<idx_vector>& ra_idx, int resize_ok) const | |
2224 { | |
2225 | |
2226 if (ra_idx.length () != 2) | |
2227 { | |
2228 (*current_liboctave_error_handler) ("range error for index"); | |
2229 return *this; | |
2230 } | |
2231 | |
2232 return index (ra_idx (0), ra_idx (1), resize_ok); | |
2233 } | |
2234 | |
7433 | 2235 // Can't use versions of these in Array.cc due to duplication of the |
2236 // instantiations for Array<double and Sparse<double>, etc | |
2237 template <class T> | |
2238 bool | |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2239 sparse_ascending_compare (typename ref_param<T>::type a, |
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2240 typename ref_param<T>::type b) |
7433 | 2241 { |
2242 return (a < b); | |
2243 } | |
2244 | |
2245 template <class T> | |
2246 bool | |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2247 sparse_descending_compare (typename ref_param<T>::type a, |
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2248 typename ref_param<T>::type b) |
7433 | 2249 { |
2250 return (a > b); | |
2251 } | |
2252 | |
2253 template <class T> | |
2254 Sparse<T> | |
2255 Sparse<T>::sort (octave_idx_type dim, sortmode mode) const | |
2256 { | |
2257 Sparse<T> m = *this; | |
2258 | |
2259 octave_idx_type nr = m.rows (); | |
2260 octave_idx_type nc = m.columns (); | |
2261 | |
2262 if (m.length () < 1) | |
2263 return m; | |
2264 | |
2265 if (dim > 0) | |
2266 { | |
2267 m = m.transpose (); | |
2268 nr = m.rows (); | |
2269 nc = m.columns (); | |
2270 } | |
2271 | |
2272 octave_sort<T> lsort; | |
2273 | |
2274 if (mode == ASCENDING) | |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2275 lsort.set_compare (sparse_ascending_compare<T>); |
7433 | 2276 else if (mode == DESCENDING) |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2277 lsort.set_compare (sparse_descending_compare<T>); |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2278 else |
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2279 abort (); |
7433 | 2280 |
2281 T *v = m.data (); | |
2282 octave_idx_type *mcidx = m.cidx (); | |
2283 octave_idx_type *mridx = m.ridx (); | |
2284 | |
2285 for (octave_idx_type j = 0; j < nc; j++) | |
2286 { | |
2287 octave_idx_type ns = mcidx [j + 1] - mcidx [j]; | |
2288 lsort.sort (v, ns); | |
2289 | |
2290 octave_idx_type i; | |
2291 if (mode == ASCENDING) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2292 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2293 for (i = 0; i < ns; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2294 if (sparse_ascending_compare<T> (static_cast<T> (0), v [i])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2295 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2296 } |
7433 | 2297 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2298 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2299 for (i = 0; i < ns; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2300 if (sparse_descending_compare<T> (static_cast<T> (0), v [i])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2301 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2302 } |
7433 | 2303 for (octave_idx_type k = 0; k < i; k++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2304 mridx [k] = k; |
7433 | 2305 for (octave_idx_type k = i; k < ns; k++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2306 mridx [k] = k - ns + nr; |
7433 | 2307 |
2308 v += ns; | |
2309 mridx += ns; | |
2310 } | |
2311 | |
2312 if (dim > 0) | |
2313 m = m.transpose (); | |
2314 | |
2315 return m; | |
2316 } | |
2317 | |
2318 template <class T> | |
2319 Sparse<T> | |
2320 Sparse<T>::sort (Array<octave_idx_type> &sidx, octave_idx_type dim, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2321 sortmode mode) const |
7433 | 2322 { |
2323 Sparse<T> m = *this; | |
2324 | |
2325 octave_idx_type nr = m.rows (); | |
2326 octave_idx_type nc = m.columns (); | |
2327 | |
2328 if (m.length () < 1) | |
2329 { | |
2330 sidx = Array<octave_idx_type> (dim_vector (nr, nc)); | |
2331 return m; | |
2332 } | |
2333 | |
2334 if (dim > 0) | |
2335 { | |
2336 m = m.transpose (); | |
2337 nr = m.rows (); | |
2338 nc = m.columns (); | |
2339 } | |
2340 | |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2341 octave_sort<T> indexed_sort; |
7433 | 2342 |
2343 if (mode == ASCENDING) | |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2344 indexed_sort.set_compare (sparse_ascending_compare<T>); |
7433 | 2345 else if (mode == DESCENDING) |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2346 indexed_sort.set_compare (sparse_descending_compare<T>); |
7463
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2347 else |
2467639bd8c0
eliminate UNDEFINED sort mode
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2348 abort (); |
7433 | 2349 |
2350 T *v = m.data (); | |
2351 octave_idx_type *mcidx = m.cidx (); | |
2352 octave_idx_type *mridx = m.ridx (); | |
2353 | |
2354 sidx = Array<octave_idx_type> (dim_vector (nr, nc)); | |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2355 OCTAVE_LOCAL_BUFFER (octave_idx_type, vi, nr); |
7433 | 2356 |
2357 for (octave_idx_type j = 0; j < nc; j++) | |
2358 { | |
2359 octave_idx_type ns = mcidx [j + 1] - mcidx [j]; | |
2360 octave_idx_type offset = j * nr; | |
2361 | |
2362 if (ns == 0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2363 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2364 for (octave_idx_type k = 0; k < nr; k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2365 sidx (offset + k) = k; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2366 } |
7433 | 2367 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2368 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2369 for (octave_idx_type i = 0; i < ns; i++) |
8752
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2370 vi[i] = mridx[i]; |
06b9903a029b
fix & clean up complex & sparse sorting
Jaroslav Hajek <highegg@gmail.com>
parents:
8677
diff
changeset
|
2371 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2372 indexed_sort.sort (v, vi, ns); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2373 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2374 octave_idx_type i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2375 if (mode == ASCENDING) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2376 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2377 for (i = 0; i < ns; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2378 if (sparse_ascending_compare<T> (static_cast<T> (0), v[i])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2379 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2380 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2381 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2382 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2383 for (i = 0; i < ns; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2384 if (sparse_descending_compare<T> (static_cast<T> (0), v[i])) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2385 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2386 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2387 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2388 octave_idx_type ii = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2389 octave_idx_type jj = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2390 for (octave_idx_type k = 0; k < nr; k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2391 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2392 if (ii < ns && mridx[ii] == k) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2393 ii++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2394 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2395 sidx (offset + jj++) = k; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2396 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2397 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2398 for (octave_idx_type k = 0; k < i; k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2399 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2400 sidx (k + offset) = vi [k]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2401 mridx [k] = k; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2402 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2403 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2404 for (octave_idx_type k = i; k < ns; k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2405 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2406 sidx (k - ns + nr + offset) = vi [k]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2407 mridx [k] = k - ns + nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2408 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2409 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2410 v += ns; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2411 mridx += ns; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2412 } |
7433 | 2413 } |
2414 | |
2415 if (dim > 0) | |
2416 { | |
2417 m = m.transpose (); | |
2418 sidx = sidx.transpose (); | |
2419 } | |
2420 | |
2421 return m; | |
2422 } | |
2423 | |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2424 template <class T> |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2425 Sparse<T> |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2426 Sparse<T>::diag (octave_idx_type k) const |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2427 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2428 octave_idx_type nnr = rows (); |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2429 octave_idx_type nnc = cols (); |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2430 Sparse<T> d; |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2431 |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2432 if (nnr == 0 || nnc == 0) |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2433 ; // do nothing |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2434 else if (nnr != 1 && nnc != 1) |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2435 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2436 if (k > 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2437 nnc -= k; |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2438 else if (k < 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2439 nnr += k; |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2440 |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2441 if (nnr > 0 && nnc > 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2442 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2443 octave_idx_type ndiag = (nnr < nnc) ? nnr : nnc; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2444 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2445 // Count the number of non-zero elements |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2446 octave_idx_type nel = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2447 if (k > 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2448 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2449 for (octave_idx_type i = 0; i < ndiag; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2450 if (elem (i, i+k) != 0.) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2451 nel++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2452 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2453 else if ( k < 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2454 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2455 for (octave_idx_type i = 0; i < ndiag; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2456 if (elem (i-k, i) != 0.) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2457 nel++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2458 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2459 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2460 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2461 for (octave_idx_type i = 0; i < ndiag; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2462 if (elem (i, i) != 0.) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2463 nel++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2464 } |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2465 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2466 d = Sparse<T> (ndiag, 1, nel); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2467 d.xcidx (0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2468 d.xcidx (1) = nel; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2469 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2470 octave_idx_type ii = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2471 if (k > 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2472 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2473 for (octave_idx_type i = 0; i < ndiag; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2474 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2475 T tmp = elem (i, i+k); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2476 if (tmp != 0.) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2477 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2478 d.xdata (ii) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2479 d.xridx (ii++) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2480 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2481 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2482 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2483 else if ( k < 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2484 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2485 for (octave_idx_type i = 0; i < ndiag; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2486 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2487 T tmp = elem (i-k, i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2488 if (tmp != 0.) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2489 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2490 d.xdata (ii) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2491 d.xridx (ii++) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2492 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2493 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2494 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2495 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2496 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2497 for (octave_idx_type i = 0; i < ndiag; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2498 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2499 T tmp = elem (i, i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2500 if (tmp != 0.) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2501 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2502 d.xdata (ii) = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2503 d.xridx (ii++) = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2504 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2505 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2506 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2507 } |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2508 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2509 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2510 ("diag: requested diagonal out of range"); |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2511 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2512 else if (nnr != 0 && nnc != 0) |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2513 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2514 octave_idx_type roff = 0; |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2515 octave_idx_type coff = 0; |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2516 if (k > 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2517 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2518 roff = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2519 coff = k; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2520 } |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2521 else if (k < 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2522 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2523 roff = -k; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2524 coff = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2525 } |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2526 |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2527 if (nnr == 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2528 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2529 octave_idx_type n = nnc + std::abs (k); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2530 octave_idx_type nz = nzmax (); |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2531 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2532 d = Sparse<T> (n, n, nz); |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2533 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2534 if (nnz () > 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2535 { |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2536 for (octave_idx_type i = 0; i < coff+1; i++) |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2537 d.xcidx (i) = 0; |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2538 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2539 for (octave_idx_type j = 0; j < nnc; j++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2540 { |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2541 for (octave_idx_type i = cidx(j); i < cidx(j+1); i++) |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2542 { |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2543 d.xdata (i) = data (i); |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2544 d.xridx (i) = j + roff; |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2545 } |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2546 d.xcidx (j + coff + 1) = cidx(j+1); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2547 } |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2548 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2549 for (octave_idx_type i = nnc + coff + 1; i < n + 1; i++) |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2550 d.xcidx (i) = nz; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2551 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2552 } |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2553 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2554 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2555 octave_idx_type n = nnr + std::abs (k); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2556 octave_idx_type nz = nzmax (); |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2557 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2558 d = Sparse<T> (n, n, nz); |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2559 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2560 if (nnz () > 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2561 { |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2562 octave_idx_type ii = 0; |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2563 octave_idx_type ir = ridx(0); |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2564 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2565 for (octave_idx_type i = 0; i < coff+1; i++) |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2566 d.xcidx (i) = 0; |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2567 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2568 for (octave_idx_type i = 0; i < nnr; i++) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2569 { |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2570 if (ir == i) |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2571 { |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2572 d.xdata (ii) = data (ii); |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2573 d.xridx (ii++) = ir + roff; |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2574 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2575 if (ii != nz) |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2576 ir = ridx (ii); |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2577 } |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2578 d.xcidx (i + coff + 1) = ii; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2579 } |
10367
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2580 |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2581 for (octave_idx_type i = nnr + coff + 1; i < n+1; i++) |
173e10268080
avoid indexing nonexistent elements in sparse diag
John W. Eaton <jwe@octave.org>
parents:
10352
diff
changeset
|
2582 d.xcidx (i) = nz; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2583 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2584 } |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2585 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2586 |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2587 return d; |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2588 } |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7573
diff
changeset
|
2589 |
5775 | 2590 // FIXME |
5164 | 2591 // Unfortunately numel can overflow for very large but very sparse matrices. |
2592 // For now just flag an error when this happens. | |
2593 template <class LT, class RT> | |
2594 int | |
2595 assign1 (Sparse<LT>& lhs, const Sparse<RT>& rhs) | |
2596 { | |
2597 int retval = 1; | |
2598 | |
2599 idx_vector *idx_tmp = lhs.get_idx (); | |
2600 | |
2601 idx_vector lhs_idx = idx_tmp[0]; | |
2602 | |
5275 | 2603 octave_idx_type lhs_len = lhs.numel (); |
2604 octave_idx_type rhs_len = rhs.numel (); | |
5164 | 2605 |
5828 | 2606 uint64_t long_lhs_len = |
2607 static_cast<uint64_t> (lhs.rows ()) * | |
2608 static_cast<uint64_t> (lhs.cols ()); | |
2609 | |
2610 uint64_t long_rhs_len = | |
2611 static_cast<uint64_t> (rhs.rows ()) * | |
2612 static_cast<uint64_t> (rhs.cols ()); | |
2613 | |
2614 if (long_rhs_len != static_cast<uint64_t>(rhs_len) || | |
2615 long_lhs_len != static_cast<uint64_t>(lhs_len)) | |
5164 | 2616 { |
2617 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2618 ("A(I) = X: Matrix dimensions too large to ensure correct\n", |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2619 "operation. This is an limitation that should be removed\n", |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2620 "in the future."); |
5164 | 2621 |
2622 lhs.clear_index (); | |
2623 return 0; | |
2624 } | |
2625 | |
5275 | 2626 octave_idx_type nr = lhs.rows (); |
2627 octave_idx_type nc = lhs.cols (); | |
5681 | 2628 octave_idx_type nz = lhs.nnz (); |
5275 | 2629 |
5781 | 2630 octave_idx_type n = lhs_idx.freeze (lhs_len, "vector", true); |
5164 | 2631 |
2632 if (n != 0) | |
2633 { | |
5275 | 2634 octave_idx_type max_idx = lhs_idx.max () + 1; |
5164 | 2635 max_idx = max_idx < lhs_len ? lhs_len : max_idx; |
2636 | |
2637 // Take a constant copy of lhs. This means that elem won't | |
2638 // create missing elements. | |
2639 const Sparse<LT> c_lhs (lhs); | |
2640 | |
2641 if (rhs_len == n) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2642 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2643 octave_idx_type new_nzmx = lhs.nnz (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2644 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2645 OCTAVE_LOCAL_BUFFER (octave_idx_type, rhs_idx, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2646 if (! lhs_idx.is_colon ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2647 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2648 // Ok here we have to be careful with the indexing, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2649 // to treat cases like "a([3,2,1]) = b", and still |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2650 // handle the need for strict sorting of the sparse |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2651 // elements. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2652 OCTAVE_LOCAL_BUFFER (octave_idx_vector_sort *, sidx, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2653 OCTAVE_LOCAL_BUFFER (octave_idx_vector_sort, sidxX, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2654 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2655 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2656 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2657 sidx[i] = &sidxX[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2658 sidx[i]->i = lhs_idx.elem(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2659 sidx[i]->idx = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2660 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2661 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2662 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2663 octave_sort<octave_idx_vector_sort *> |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2664 sort (octave_idx_vector_comp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2665 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2666 sort.sort (sidx, n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2667 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2668 intNDArray<octave_idx_type> new_idx (dim_vector (n,1)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2669 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2670 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2671 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2672 new_idx.xelem(i) = sidx[i]->i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2673 rhs_idx[i] = sidx[i]->idx; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2674 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2675 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2676 lhs_idx = idx_vector (new_idx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2677 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2678 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2679 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2680 rhs_idx[i] = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2681 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2682 // First count the number of non-zero elements |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2683 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2684 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2685 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2686 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2687 octave_idx_type ii = lhs_idx.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2688 if (i < n - 1 && lhs_idx.elem (i + 1) == ii) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2689 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2690 if (ii < lhs_len && c_lhs.elem(ii) != LT ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2691 new_nzmx--; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2692 if (rhs.elem(rhs_idx[i]) != RT ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2693 new_nzmx++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2694 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2695 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2696 if (nr > 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2697 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2698 Sparse<LT> tmp ((max_idx > nr ? max_idx : nr), 1, new_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2699 tmp.cidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2700 tmp.cidx(1) = new_nzmx; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2701 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2702 octave_idx_type i = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2703 octave_idx_type ii = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2704 if (i < nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2705 ii = c_lhs.ridx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2706 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2707 octave_idx_type j = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2708 octave_idx_type jj = lhs_idx.elem(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2709 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2710 octave_idx_type kk = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2711 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2712 while (j < n || i < nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2713 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2714 if (j < n - 1 && lhs_idx.elem (j + 1) == jj) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2715 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2716 j++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2717 jj = lhs_idx.elem (j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2718 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2719 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2720 if (j == n || (i < nz && ii < jj)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2721 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2722 tmp.xdata (kk) = c_lhs.data (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2723 tmp.xridx (kk++) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2724 if (++i < nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2725 ii = c_lhs.ridx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2726 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2727 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2728 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2729 RT rtmp = rhs.elem (rhs_idx[j]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2730 if (rtmp != RT ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2731 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2732 tmp.xdata (kk) = rtmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2733 tmp.xridx (kk++) = jj; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2734 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2735 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2736 if (ii == jj && i < nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2737 if (++i < nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2738 ii = c_lhs.ridx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2739 if (++j < n) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2740 jj = lhs_idx.elem(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2741 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2742 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2743 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2744 lhs = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2745 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2746 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2747 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2748 Sparse<LT> tmp (1, (max_idx > nc ? max_idx : nc), new_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2749 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2750 octave_idx_type i = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2751 octave_idx_type ii = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2752 while (ii < nc && c_lhs.cidx(ii+1) <= i) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2753 ii++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2754 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2755 octave_idx_type j = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2756 octave_idx_type jj = lhs_idx.elem(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2757 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2758 octave_idx_type kk = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2759 octave_idx_type ic = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2760 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2761 while (j < n || i < nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2762 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2763 if (j < n - 1 && lhs_idx.elem (j + 1) == jj) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2764 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2765 j++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2766 jj = lhs_idx.elem (j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2767 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2768 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2769 if (j == n || (i < nz && ii < jj)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2770 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2771 while (ic <= ii) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2772 tmp.xcidx (ic++) = kk; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2773 tmp.xdata (kk) = c_lhs.data (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2774 tmp.xridx (kk++) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2775 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2776 while (ii < nc && c_lhs.cidx(ii+1) <= i) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2777 ii++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2778 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2779 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2780 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2781 while (ic <= jj) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2782 tmp.xcidx (ic++) = kk; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2783 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2784 RT rtmp = rhs.elem (rhs_idx[j]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2785 if (rtmp != RT ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2786 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2787 tmp.xdata (kk) = rtmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2788 tmp.xridx (kk++) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2789 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2790 if (ii == jj) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2791 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2792 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2793 while (ii < nc && c_lhs.cidx(ii+1) <= i) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2794 ii++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2795 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2796 j++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2797 if (j < n) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2798 jj = lhs_idx.elem(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2799 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2800 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2801 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2802 for (octave_idx_type iidx = ic; iidx < max_idx+1; iidx++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2803 tmp.xcidx(iidx) = kk; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2804 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2805 lhs = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2806 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2807 } |
5164 | 2808 else if (rhs_len == 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2809 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2810 octave_idx_type new_nzmx = lhs.nnz (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2811 RT scalar = rhs.elem (0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2812 bool scalar_non_zero = (scalar != RT ()); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2813 lhs_idx.sort (true); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2814 n = lhs_idx.length (n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2815 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2816 // First count the number of non-zero elements |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2817 if (scalar != RT ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2818 new_nzmx += n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2819 for (octave_idx_type i = 0; i < n; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2820 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2821 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2822 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2823 octave_idx_type ii = lhs_idx.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2824 if (ii < lhs_len && c_lhs.elem(ii) != LT ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2825 new_nzmx--; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2826 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2827 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2828 if (nr > 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2829 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2830 Sparse<LT> tmp ((max_idx > nr ? max_idx : nr), 1, new_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2831 tmp.cidx(0) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2832 tmp.cidx(1) = new_nzmx; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2833 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2834 octave_idx_type i = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2835 octave_idx_type ii = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2836 if (i < nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2837 ii = c_lhs.ridx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2838 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2839 octave_idx_type j = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2840 octave_idx_type jj = lhs_idx.elem(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2841 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2842 octave_idx_type kk = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2843 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2844 while (j < n || i < nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2845 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2846 if (j == n || (i < nz && ii < jj)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2847 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2848 tmp.xdata (kk) = c_lhs.data (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2849 tmp.xridx (kk++) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2850 if (++i < nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2851 ii = c_lhs.ridx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2852 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2853 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2854 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2855 if (scalar_non_zero) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2856 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2857 tmp.xdata (kk) = scalar; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2858 tmp.xridx (kk++) = jj; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2859 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2860 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2861 if (ii == jj && i < nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2862 if (++i < nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2863 ii = c_lhs.ridx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2864 if (++j < n) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2865 jj = lhs_idx.elem(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2866 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2867 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2868 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2869 lhs = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2870 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2871 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2872 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2873 Sparse<LT> tmp (1, (max_idx > nc ? max_idx : nc), new_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2874 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2875 octave_idx_type i = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2876 octave_idx_type ii = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2877 while (ii < nc && c_lhs.cidx(ii+1) <= i) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2878 ii++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2879 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2880 octave_idx_type j = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2881 octave_idx_type jj = lhs_idx.elem(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2882 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2883 octave_idx_type kk = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2884 octave_idx_type ic = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2885 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2886 while (j < n || i < nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2887 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2888 if (j == n || (i < nz && ii < jj)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2889 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2890 while (ic <= ii) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2891 tmp.xcidx (ic++) = kk; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2892 tmp.xdata (kk) = c_lhs.data (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2893 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2894 while (ii < nc && c_lhs.cidx(ii+1) <= i) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2895 ii++; |
9177
39be2c4531c8
fix sparse indexing bug
Jaroslav Hajek <highegg@gmail.com>
parents:
8987
diff
changeset
|
2896 tmp.xridx (kk++) = 0; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2897 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2898 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2899 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2900 while (ic <= jj) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2901 tmp.xcidx (ic++) = kk; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2902 if (scalar_non_zero) |
9177
39be2c4531c8
fix sparse indexing bug
Jaroslav Hajek <highegg@gmail.com>
parents:
8987
diff
changeset
|
2903 { |
39be2c4531c8
fix sparse indexing bug
Jaroslav Hajek <highegg@gmail.com>
parents:
8987
diff
changeset
|
2904 tmp.xdata (kk) = scalar; |
39be2c4531c8
fix sparse indexing bug
Jaroslav Hajek <highegg@gmail.com>
parents:
8987
diff
changeset
|
2905 tmp.xridx (kk++) = 0; |
39be2c4531c8
fix sparse indexing bug
Jaroslav Hajek <highegg@gmail.com>
parents:
8987
diff
changeset
|
2906 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2907 if (ii == jj) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2908 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2909 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2910 while (ii < nc && c_lhs.cidx(ii+1) <= i) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2911 ii++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2912 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2913 j++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2914 if (j < n) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2915 jj = lhs_idx.elem(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2916 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2917 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2918 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2919 for (octave_idx_type iidx = ic; iidx < max_idx+1; iidx++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2920 tmp.xcidx(iidx) = kk; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2921 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2922 lhs = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2923 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2924 } |
5164 | 2925 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2926 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2927 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2928 ("A(I) = X: X must be a scalar or a vector with same length as I"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2929 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2930 retval = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2931 } |
5164 | 2932 } |
2933 else if (lhs_idx.is_colon ()) | |
2934 { | |
2935 if (lhs_len == 0) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2936 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2937 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2938 octave_idx_type new_nzmx = rhs.nnz (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2939 Sparse<LT> tmp (1, rhs_len, new_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2940 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2941 octave_idx_type ii = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2942 octave_idx_type jj = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2943 for (octave_idx_type i = 0; i < rhs.cols(); i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2944 for (octave_idx_type j = rhs.cidx(i); j < rhs.cidx(i+1); j++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2945 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2946 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2947 for (octave_idx_type k = jj; k <= i * rhs.rows() + rhs.ridx(j); k++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2948 tmp.cidx(jj++) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2949 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2950 tmp.data(ii) = rhs.data(j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2951 tmp.ridx(ii++) = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2952 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2953 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2954 for (octave_idx_type i = jj; i < rhs_len + 1; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2955 tmp.cidx(i) = ii; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2956 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2957 lhs = tmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2958 } |
5164 | 2959 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2960 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2961 ("A(:) = X: A must be the same size as X"); |
5164 | 2962 } |
2963 else if (! (rhs_len == 1 || rhs_len == 0)) | |
2964 { | |
2965 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
2966 ("A([]) = X: X must also be an empty matrix or a scalar"); |
5164 | 2967 |
2968 retval = 0; | |
2969 } | |
2970 | |
2971 lhs.clear_index (); | |
2972 | |
2973 return retval; | |
2974 } | |
2975 | |
2976 template <class LT, class RT> | |
2977 int | |
2978 assign (Sparse<LT>& lhs, const Sparse<RT>& rhs) | |
2979 { | |
2980 int retval = 1; | |
2981 | |
2982 int n_idx = lhs.index_count (); | |
2983 | |
5275 | 2984 octave_idx_type lhs_nr = lhs.rows (); |
2985 octave_idx_type lhs_nc = lhs.cols (); | |
5681 | 2986 octave_idx_type lhs_nz = lhs.nnz (); |
5275 | 2987 |
2988 octave_idx_type rhs_nr = rhs.rows (); | |
2989 octave_idx_type rhs_nc = rhs.cols (); | |
5164 | 2990 |
2991 idx_vector *tmp = lhs.get_idx (); | |
2992 | |
2993 idx_vector idx_i; | |
2994 idx_vector idx_j; | |
2995 | |
2996 if (n_idx > 2) | |
2997 { | |
2998 (*current_liboctave_error_handler) | |
2999 ("A(I, J) = X: can only have 1 or 2 indexes for sparse matrices"); | |
6092 | 3000 |
3001 lhs.clear_index (); | |
5164 | 3002 return 0; |
3003 } | |
3004 | |
3005 if (n_idx > 1) | |
3006 idx_j = tmp[1]; | |
3007 | |
3008 if (n_idx > 0) | |
3009 idx_i = tmp[0]; | |
3010 | |
6988 | 3011 // Take a constant copy of lhs. This means that ridx and family won't |
3012 // call make_unique. | |
3013 const Sparse<LT> c_lhs (lhs); | |
3014 | |
5164 | 3015 if (n_idx == 2) |
3016 { | |
5781 | 3017 octave_idx_type n = idx_i.freeze (lhs_nr, "row", true); |
3018 octave_idx_type m = idx_j.freeze (lhs_nc, "column", true); | |
5164 | 3019 |
3020 int idx_i_is_colon = idx_i.is_colon (); | |
3021 int idx_j_is_colon = idx_j.is_colon (); | |
3022 | |
7238 | 3023 if (lhs_nr == 0 && lhs_nc == 0) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3024 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3025 if (idx_i_is_colon) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3026 n = rhs_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3027 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3028 if (idx_j_is_colon) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3029 m = rhs_nc; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3030 } |
5164 | 3031 |
3032 if (idx_i && idx_j) | |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3033 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3034 if (rhs_nr == 1 && rhs_nc == 1 && n >= 0 && m >= 0) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3035 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3036 if (n > 0 && m > 0) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3037 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3038 idx_i.sort (true); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3039 n = idx_i.length (n); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3040 idx_j.sort (true); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3041 m = idx_j.length (m); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3042 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3043 octave_idx_type max_row_idx = idx_i_is_colon ? rhs_nr : |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3044 idx_i.max () + 1; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3045 octave_idx_type max_col_idx = idx_j_is_colon ? rhs_nc : |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3046 idx_j.max () + 1; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3047 octave_idx_type new_nr = max_row_idx > lhs_nr ? |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3048 max_row_idx : lhs_nr; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3049 octave_idx_type new_nc = max_col_idx > lhs_nc ? |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3050 max_col_idx : lhs_nc; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3051 RT scalar = rhs.elem (0, 0); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3052 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3053 // Count the number of non-zero terms |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3054 octave_idx_type new_nzmx = lhs.nnz (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3055 for (octave_idx_type j = 0; j < m; j++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3056 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3057 octave_idx_type jj = idx_j.elem (j); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3058 if (jj < lhs_nc) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3059 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3060 for (octave_idx_type i = 0; i < n; i++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3061 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
3062 octave_quit (); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3063 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3064 octave_idx_type ii = idx_i.elem (i); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3065 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3066 if (ii < lhs_nr) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3067 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3068 for (octave_idx_type k = c_lhs.cidx(jj); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3069 k < c_lhs.cidx(jj+1); k++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3070 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3071 if (c_lhs.ridx(k) == ii) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3072 new_nzmx--; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3073 if (c_lhs.ridx(k) >= ii) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3074 break; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3075 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3076 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3077 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3078 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3079 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3080 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3081 if (scalar != RT()) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3082 new_nzmx += m * n; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3083 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3084 Sparse<LT> stmp (new_nr, new_nc, new_nzmx); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3085 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3086 octave_idx_type jji = 0; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3087 octave_idx_type jj = idx_j.elem (jji); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3088 octave_idx_type kk = 0; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3089 stmp.cidx(0) = 0; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3090 for (octave_idx_type j = 0; j < new_nc; j++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3091 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3092 if (jji < m && jj == j) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3093 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3094 octave_idx_type iii = 0; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3095 octave_idx_type ii = idx_i.elem (iii); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3096 octave_idx_type ppp = 0; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3097 octave_idx_type ppi = (j >= lhs_nc ? 0 : |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3098 c_lhs.cidx(j+1) - |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3099 c_lhs.cidx(j)); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3100 octave_idx_type pp = (ppp < ppi ? |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3101 c_lhs.ridx(c_lhs.cidx(j)+ppp) : |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3102 new_nr); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3103 while (ppp < ppi || iii < n) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3104 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3105 if (iii < n && ii <= pp) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3106 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3107 if (scalar != RT ()) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3108 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3109 stmp.data(kk) = scalar; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3110 stmp.ridx(kk++) = ii; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3111 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3112 if (ii == pp) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3113 pp = (++ppp < ppi ? c_lhs.ridx(c_lhs.cidx(j)+ppp) : new_nr); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3114 if (++iii < n) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3115 ii = idx_i.elem(iii); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3116 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3117 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3118 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3119 stmp.data(kk) = |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3120 c_lhs.data(c_lhs.cidx(j)+ppp); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3121 stmp.ridx(kk++) = pp; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3122 pp = (++ppp < ppi ? c_lhs.ridx(c_lhs.cidx(j)+ppp) : new_nr); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3123 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3124 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3125 if (++jji < m) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3126 jj = idx_j.elem(jji); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3127 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3128 else if (j < lhs_nc) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3129 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3130 for (octave_idx_type i = c_lhs.cidx(j); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3131 i < c_lhs.cidx(j+1); i++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3132 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3133 stmp.data(kk) = c_lhs.data(i); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3134 stmp.ridx(kk++) = c_lhs.ridx(i); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3135 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3136 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3137 stmp.cidx(j+1) = kk; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3138 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3139 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3140 lhs = stmp; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3141 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3142 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3143 { |
7253 | 3144 #if 0 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3145 // FIXME -- the following code will make this |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3146 // function behave the same as the full matrix |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3147 // case for things like |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3148 // |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3149 // x = sparse (ones (2)); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3150 // x([],3) = 2; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3151 // |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3152 // x = |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3153 // |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3154 // Compressed Column Sparse (rows = 2, cols = 3, nnz = 4) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3155 // |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3156 // (1, 1) -> 1 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3157 // (2, 1) -> 1 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3158 // (1, 2) -> 1 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3159 // (2, 2) -> 1 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3160 // |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3161 // However, Matlab doesn't resize in this case |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3162 // even though it does in the full matrix case. |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3163 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3164 if (n > 0) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3165 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3166 octave_idx_type max_row_idx = idx_i_is_colon ? |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3167 rhs_nr : idx_i.max () + 1; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3168 octave_idx_type new_nr = max_row_idx > lhs_nr ? |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3169 max_row_idx : lhs_nr; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3170 octave_idx_type new_nc = lhs_nc; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3171 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3172 lhs.resize (new_nr, new_nc); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3173 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3174 else if (m > 0) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3175 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3176 octave_idx_type max_col_idx = idx_j_is_colon ? |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3177 rhs_nc : idx_j.max () + 1; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3178 octave_idx_type new_nr = lhs_nr; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3179 octave_idx_type new_nc = max_col_idx > lhs_nc ? |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3180 max_col_idx : lhs_nc; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3181 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3182 lhs.resize (new_nr, new_nc); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3183 } |
7253 | 3184 #endif |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3185 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3186 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3187 else if (n == rhs_nr && m == rhs_nc) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3188 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3189 if (n > 0 && m > 0) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3190 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3191 octave_idx_type max_row_idx = idx_i_is_colon ? rhs_nr : |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3192 idx_i.max () + 1; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3193 octave_idx_type max_col_idx = idx_j_is_colon ? rhs_nc : |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3194 idx_j.max () + 1; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3195 octave_idx_type new_nr = max_row_idx > lhs_nr ? |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3196 max_row_idx : lhs_nr; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3197 octave_idx_type new_nc = max_col_idx > lhs_nc ? |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3198 max_col_idx : lhs_nc; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3199 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3200 OCTAVE_LOCAL_BUFFER (octave_idx_type, rhs_idx_i, n); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3201 if (! idx_i.is_colon ()) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3202 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3203 // Ok here we have to be careful with the indexing, |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3204 // to treat cases like "a([3,2,1],:) = b", and still |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3205 // handle the need for strict sorting of the sparse |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3206 // elements. |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3207 OCTAVE_LOCAL_BUFFER (octave_idx_vector_sort *, |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3208 sidx, n); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3209 OCTAVE_LOCAL_BUFFER (octave_idx_vector_sort, |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3210 sidxX, n); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3211 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3212 for (octave_idx_type i = 0; i < n; i++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3213 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3214 sidx[i] = &sidxX[i]; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3215 sidx[i]->i = idx_i.elem(i); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3216 sidx[i]->idx = i; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3217 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3218 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
3219 octave_quit (); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3220 octave_sort<octave_idx_vector_sort *> |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3221 sort (octave_idx_vector_comp); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3222 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3223 sort.sort (sidx, n); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3224 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3225 intNDArray<octave_idx_type> new_idx (dim_vector (n,1)); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3226 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3227 for (octave_idx_type i = 0; i < n; i++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3228 { |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
3229 new_idx.xelem(i) = sidx[i]->i; |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3230 rhs_idx_i[i] = sidx[i]->idx; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3231 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3232 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3233 idx_i = idx_vector (new_idx); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3234 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3235 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3236 for (octave_idx_type i = 0; i < n; i++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3237 rhs_idx_i[i] = i; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3238 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3239 OCTAVE_LOCAL_BUFFER (octave_idx_type, rhs_idx_j, m); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3240 if (! idx_j.is_colon ()) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3241 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3242 // Ok here we have to be careful with the indexing, |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3243 // to treat cases like "a([3,2,1],:) = b", and still |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3244 // handle the need for strict sorting of the sparse |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3245 // elements. |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3246 OCTAVE_LOCAL_BUFFER (octave_idx_vector_sort *, |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3247 sidx, m); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3248 OCTAVE_LOCAL_BUFFER (octave_idx_vector_sort, |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3249 sidxX, m); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3250 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3251 for (octave_idx_type i = 0; i < m; i++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3252 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3253 sidx[i] = &sidxX[i]; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3254 sidx[i]->i = idx_j.elem(i); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3255 sidx[i]->idx = i; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3256 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3257 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
3258 octave_quit (); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3259 octave_sort<octave_idx_vector_sort *> |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3260 sort (octave_idx_vector_comp); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3261 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3262 sort.sort (sidx, m); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3263 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3264 intNDArray<octave_idx_type> new_idx (dim_vector (m,1)); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3265 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3266 for (octave_idx_type i = 0; i < m; i++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3267 { |
8290
7cbe01c21986
improve dense array indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
3268 new_idx.xelem(i) = sidx[i]->i; |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3269 rhs_idx_j[i] = sidx[i]->idx; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3270 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3271 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3272 idx_j = idx_vector (new_idx); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3273 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3274 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3275 for (octave_idx_type i = 0; i < m; i++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3276 rhs_idx_j[i] = i; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3277 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3278 // Maximum number of non-zero elements |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3279 octave_idx_type new_nzmx = lhs.nnz() + rhs.nnz(); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3280 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3281 Sparse<LT> stmp (new_nr, new_nc, new_nzmx); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3282 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3283 octave_idx_type jji = 0; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3284 octave_idx_type jj = idx_j.elem (jji); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3285 octave_idx_type kk = 0; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3286 stmp.cidx(0) = 0; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3287 for (octave_idx_type j = 0; j < new_nc; j++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3288 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3289 if (jji < m && jj == j) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3290 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3291 octave_idx_type iii = 0; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3292 octave_idx_type ii = idx_i.elem (iii); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3293 octave_idx_type ppp = 0; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3294 octave_idx_type ppi = (j >= lhs_nc ? 0 : |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3295 c_lhs.cidx(j+1) - |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3296 c_lhs.cidx(j)); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3297 octave_idx_type pp = (ppp < ppi ? |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3298 c_lhs.ridx(c_lhs.cidx(j)+ppp) : |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3299 new_nr); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3300 while (ppp < ppi || iii < n) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3301 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3302 if (iii < n && ii <= pp) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3303 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3304 if (iii < n - 1 && |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3305 idx_i.elem (iii + 1) == ii) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3306 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3307 iii++; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3308 ii = idx_i.elem(iii); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3309 continue; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3310 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3311 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3312 RT rtmp = rhs.elem (rhs_idx_i[iii], |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3313 rhs_idx_j[jji]); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3314 if (rtmp != RT ()) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3315 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3316 stmp.data(kk) = rtmp; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3317 stmp.ridx(kk++) = ii; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3318 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3319 if (ii == pp) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3320 pp = (++ppp < ppi ? c_lhs.ridx(c_lhs.cidx(j)+ppp) : new_nr); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3321 if (++iii < n) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3322 ii = idx_i.elem(iii); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3323 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3324 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3325 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3326 stmp.data(kk) = |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3327 c_lhs.data(c_lhs.cidx(j)+ppp); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3328 stmp.ridx(kk++) = pp; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3329 pp = (++ppp < ppi ? c_lhs.ridx(c_lhs.cidx(j)+ppp) : new_nr); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3330 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3331 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3332 if (++jji < m) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3333 jj = idx_j.elem(jji); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3334 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3335 else if (j < lhs_nc) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3336 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3337 for (octave_idx_type i = c_lhs.cidx(j); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3338 i < c_lhs.cidx(j+1); i++) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3339 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3340 stmp.data(kk) = c_lhs.data(i); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3341 stmp.ridx(kk++) = c_lhs.ridx(i); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3342 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3343 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3344 stmp.cidx(j+1) = kk; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3345 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3346 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3347 stmp.maybe_compress(); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3348 lhs = stmp; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3349 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3350 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3351 else if (n == 0 && m == 0) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3352 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3353 if (! ((rhs_nr == 1 && rhs_nc == 1) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3354 || (rhs_nr == 0 || rhs_nc == 0))) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3355 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3356 (*current_liboctave_error_handler) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3357 ("A([], []) = X: X must be an empty matrix or a scalar"); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3358 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3359 retval = 0; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3360 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3361 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3362 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3363 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3364 (*current_liboctave_error_handler) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3365 ("A(I, J) = X: X must be a scalar or the number of elements in I must"); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3366 (*current_liboctave_error_handler) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3367 ("match the number of rows in X and the number of elements in J must"); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3368 (*current_liboctave_error_handler) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3369 ("match the number of columns in X"); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3370 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3371 retval = 0; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3372 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3373 } |
5164 | 3374 // idx_vector::freeze() printed an error message for us. |
3375 } | |
3376 else if (n_idx == 1) | |
3377 { | |
3378 int lhs_is_empty = lhs_nr == 0 || lhs_nc == 0; | |
3379 | |
3380 if (lhs_is_empty || (lhs_nr == 1 && lhs_nc == 1)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3381 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3382 octave_idx_type lhs_len = lhs.length (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3383 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3384 // Called for side-effects on idx_i. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3385 idx_i.freeze (lhs_len, 0, true); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3386 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3387 if (idx_i) |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3388 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3389 if (lhs_is_empty |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3390 && idx_i.is_colon () |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3391 && ! (rhs_nr == 1 || rhs_nc == 1)) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3392 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3393 (*current_liboctave_warning_with_id_handler) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3394 ("Octave:fortran-indexing", |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3395 "A(:) = X: X is not a vector or scalar"); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3396 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3397 else |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3398 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3399 octave_idx_type idx_nr = idx_i.orig_rows (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3400 octave_idx_type idx_nc = idx_i.orig_columns (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3401 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3402 if (! (rhs_nr == idx_nr && rhs_nc == idx_nc)) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3403 (*current_liboctave_warning_with_id_handler) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3404 ("Octave:fortran-indexing", |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3405 "A(I) = X: X does not have same shape as I"); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3406 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3407 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3408 if (! assign1 (lhs, rhs)) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3409 retval = 0; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3410 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3411 // idx_vector::freeze() printed an error message for us. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3412 } |
5164 | 3413 else if (lhs_nr == 1) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3414 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3415 idx_i.freeze (lhs_nc, "vector", true); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3416 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3417 if (idx_i) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3418 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3419 if (! assign1 (lhs, rhs)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3420 retval = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3421 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3422 // idx_vector::freeze() printed an error message for us. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3423 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3424 else if (lhs_nc == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3425 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3426 idx_i.freeze (lhs_nr, "vector", true); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3427 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3428 if (idx_i) |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3429 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3430 if (! assign1 (lhs, rhs)) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3431 retval = 0; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
7717
diff
changeset
|
3432 } |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3433 // idx_vector::freeze() printed an error message for us. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3434 } |
5164 | 3435 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3436 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3437 if (! idx_i.is_colon ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3438 (*current_liboctave_warning_with_id_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3439 ("Octave:fortran-indexing", "single index used for matrix"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3440 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3441 octave_idx_type lhs_len = lhs.length (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3442 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3443 octave_idx_type len = idx_i.freeze (lhs_nr * lhs_nc, "matrix"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3444 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3445 if (idx_i) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3446 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3447 if (len == 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3448 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3449 if (! ((rhs_nr == 1 && rhs_nc == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3450 || (rhs_nr == 0 || rhs_nc == 0))) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3451 (*current_liboctave_error_handler) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3452 ("A([]) = X: X must be an empty matrix or scalar"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3453 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3454 else if (len == rhs_nr * rhs_nc) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3455 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3456 octave_idx_type new_nzmx = lhs_nz; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3457 OCTAVE_LOCAL_BUFFER (octave_idx_type, rhs_idx, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3458 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3459 if (! idx_i.is_colon ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3460 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3461 // Ok here we have to be careful with the indexing, to |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3462 // treat cases like "a([3,2,1]) = b", and still handle |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3463 // the need for strict sorting of the sparse elements. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3464 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3465 OCTAVE_LOCAL_BUFFER (octave_idx_vector_sort *, sidx, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3466 len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3467 OCTAVE_LOCAL_BUFFER (octave_idx_vector_sort, sidxX, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3468 len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3469 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3470 for (octave_idx_type i = 0; i < len; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3471 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3472 sidx[i] = &sidxX[i]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3473 sidx[i]->i = idx_i.elem(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3474 sidx[i]->idx = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3475 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3476 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3477 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3478 octave_sort<octave_idx_vector_sort *> |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3479 sort (octave_idx_vector_comp); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3480 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3481 sort.sort (sidx, len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3482 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3483 intNDArray<octave_idx_type> new_idx (dim_vector (len,1)); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3484 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3485 for (octave_idx_type i = 0; i < len; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3486 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3487 new_idx.xelem(i) = sidx[i]->i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3488 rhs_idx[i] = sidx[i]->idx; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3489 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3490 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3491 idx_i = idx_vector (new_idx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3492 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3493 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3494 for (octave_idx_type i = 0; i < len; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3495 rhs_idx[i] = i; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3496 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3497 // First count the number of non-zero elements |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3498 for (octave_idx_type i = 0; i < len; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3499 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3500 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3501 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3502 octave_idx_type ii = idx_i.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3503 if (i < len - 1 && idx_i.elem (i + 1) == ii) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3504 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3505 if (ii < lhs_len && c_lhs.elem(ii) != LT ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3506 new_nzmx--; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3507 if (rhs.elem(rhs_idx[i]) != RT ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3508 new_nzmx++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3509 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3510 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3511 Sparse<LT> stmp (lhs_nr, lhs_nc, new_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3512 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3513 octave_idx_type i = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3514 octave_idx_type ii = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3515 octave_idx_type ic = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3516 if (i < lhs_nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3517 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3518 while (ic < lhs_nc && i >= c_lhs.cidx(ic+1)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3519 ic++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3520 ii = ic * lhs_nr + c_lhs.ridx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3521 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3522 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3523 octave_idx_type j = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3524 octave_idx_type jj = idx_i.elem (j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3525 octave_idx_type jr = jj % lhs_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3526 octave_idx_type jc = (jj - jr) / lhs_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3527 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3528 octave_idx_type kk = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3529 octave_idx_type kc = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3530 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3531 while (j < len || i < lhs_nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3532 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3533 if (j < len - 1 && idx_i.elem (j + 1) == jj) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3534 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3535 j++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3536 jj = idx_i.elem (j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3537 jr = jj % lhs_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3538 jc = (jj - jr) / lhs_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3539 continue; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3540 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3541 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3542 if (j == len || (i < lhs_nz && ii < jj)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3543 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3544 while (kc <= ic) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3545 stmp.xcidx (kc++) = kk; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3546 stmp.xdata (kk) = c_lhs.data (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3547 stmp.xridx (kk++) = c_lhs.ridx (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3548 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3549 while (ic < lhs_nc && i >= c_lhs.cidx(ic+1)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3550 ic++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3551 if (i < lhs_nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3552 ii = ic * lhs_nr + c_lhs.ridx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3553 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3554 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3555 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3556 while (kc <= jc) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3557 stmp.xcidx (kc++) = kk; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3558 RT rtmp = rhs.elem (rhs_idx[j]); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3559 if (rtmp != RT ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3560 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3561 stmp.xdata (kk) = rtmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3562 stmp.xridx (kk++) = jr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3563 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3564 if (ii == jj) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3565 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3566 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3567 while (ic < lhs_nc && i >= c_lhs.cidx(ic+1)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3568 ic++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3569 if (i < lhs_nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3570 ii = ic * lhs_nr + c_lhs.ridx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3571 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3572 j++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3573 if (j < len) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3574 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3575 jj = idx_i.elem (j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3576 jr = jj % lhs_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3577 jc = (jj - jr) / lhs_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3578 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3579 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3580 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3581 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3582 for (octave_idx_type iidx = kc; iidx < lhs_nc+1; iidx++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3583 stmp.xcidx(iidx) = kk; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3584 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3585 lhs = stmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3586 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3587 else if (rhs_nr == 1 && rhs_nc == 1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3588 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3589 RT scalar = rhs.elem (0, 0); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3590 octave_idx_type new_nzmx = lhs_nz; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3591 idx_i.sort (true); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3592 len = idx_i.length (len); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3593 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3594 // First count the number of non-zero elements |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3595 if (scalar != RT ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3596 new_nzmx += len; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3597 for (octave_idx_type i = 0; i < len; i++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3598 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3599 octave_quit (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3600 octave_idx_type ii = idx_i.elem (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3601 if (ii < lhs_len && c_lhs.elem(ii) != LT ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3602 new_nzmx--; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3603 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3604 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3605 Sparse<LT> stmp (lhs_nr, lhs_nc, new_nzmx); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3606 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3607 octave_idx_type i = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3608 octave_idx_type ii = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3609 octave_idx_type ic = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3610 if (i < lhs_nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3611 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3612 while (ic < lhs_nc && i >= c_lhs.cidx(ic+1)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3613 ic++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3614 ii = ic * lhs_nr + c_lhs.ridx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3615 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3616 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3617 octave_idx_type j = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3618 octave_idx_type jj = idx_i.elem (j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3619 octave_idx_type jr = jj % lhs_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3620 octave_idx_type jc = (jj - jr) / lhs_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3621 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3622 octave_idx_type kk = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3623 octave_idx_type kc = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3624 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3625 while (j < len || i < lhs_nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3626 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3627 if (j == len || (i < lhs_nz && ii < jj)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3628 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3629 while (kc <= ic) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3630 stmp.xcidx (kc++) = kk; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3631 stmp.xdata (kk) = c_lhs.data (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3632 stmp.xridx (kk++) = c_lhs.ridx (i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3633 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3634 while (ic < lhs_nc && i >= c_lhs.cidx(ic+1)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3635 ic++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3636 if (i < lhs_nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3637 ii = ic * lhs_nr + c_lhs.ridx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3638 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3639 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3640 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3641 while (kc <= jc) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3642 stmp.xcidx (kc++) = kk; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3643 if (scalar != RT ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3644 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3645 stmp.xdata (kk) = scalar; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3646 stmp.xridx (kk++) = jr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3647 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3648 if (ii == jj) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3649 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3650 i++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3651 while (ic < lhs_nc && i >= c_lhs.cidx(ic+1)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3652 ic++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3653 if (i < lhs_nz) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3654 ii = ic * lhs_nr + c_lhs.ridx(i); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3655 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3656 j++; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3657 if (j < len) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3658 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3659 jj = idx_i.elem (j); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3660 jr = jj % lhs_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3661 jc = (jj - jr) / lhs_nr; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3662 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3663 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3664 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3665 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3666 for (octave_idx_type iidx = kc; iidx < lhs_nc+1; iidx++) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3667 stmp.xcidx(iidx) = kk; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3668 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3669 lhs = stmp; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3670 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3671 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3672 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3673 (*current_liboctave_error_handler) |
5164 | 3674 ("A(I) = X: X must be a scalar or a matrix with the same size as I"); |
3675 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3676 retval = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3677 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3678 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3679 // idx_vector::freeze() printed an error message for us. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3680 } |
5164 | 3681 } |
3682 else | |
3683 { | |
3684 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
3685 ("invalid number of indices for matrix expression"); |
5164 | 3686 |
3687 retval = 0; | |
3688 } | |
3689 | |
3690 lhs.clear_index (); | |
3691 | |
3692 return retval; | |
3693 } | |
3694 | |
7356 | 3695 /* |
3696 * Tests | |
3697 * | |
3698 | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3699 %!function x = set_slice(x, dim, slice, arg) |
7356 | 3700 %! switch dim |
3701 %! case 11 | |
3702 %! x(slice) = 2; | |
3703 %! case 21 | |
3704 %! x(slice, :) = 2; | |
3705 %! case 22 | |
3706 %! x(:, slice) = 2; | |
3707 %! otherwise | |
3708 %! error("invalid dim, '%d'", dim); | |
3709 %! endswitch | |
3710 %! endfunction | |
3711 | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3712 %!function x = set_slice2(x, dim, slice) |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3713 %! switch dim |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3714 %! case 11 |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3715 %! x(slice) = 2 * ones (size(slice)); |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3716 %! case 21 |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3717 %! x(slice, :) = 2 * ones (length(slice), columns (x)); |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3718 %! case 22 |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3719 %! x(:, slice) = 2 * ones (rows (x), length(slice)); |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3720 %! otherwise |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3721 %! error("invalid dim, '%d'", dim); |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3722 %! endswitch |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3723 %! endfunction |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3724 |
7356 | 3725 %!function test_sparse_slice(size, dim, slice) |
3726 %! x = ones(size); | |
3727 %! s = set_slice(sparse(x), dim, slice); | |
3728 %! f = set_slice(x, dim, slice); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3729 %! assert (nnz(s), nnz(f)); |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3730 %! assert(full(s), f); |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3731 %! s = set_slice2(sparse(x), dim, slice); |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3732 %! f = set_slice2(x, dim, slice); |
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3733 %! assert (nnz(s), nnz(f)); |
7356 | 3734 %! assert(full(s), f); |
3735 %! endfunction | |
3736 | |
3737 #### 1d indexing | |
3738 | |
3739 ## size = [2 0] | |
3740 %!test test_sparse_slice([2 0], 11, []); | |
3741 %!assert(set_slice(sparse(ones([2 0])), 11, 1), sparse([2 0]')); # sparse different from full | |
3742 %!assert(set_slice(sparse(ones([2 0])), 11, 2), sparse([0 2]')); # sparse different from full | |
3743 %!assert(set_slice(sparse(ones([2 0])), 11, 3), sparse([0 0 2]')); # sparse different from full | |
3744 %!assert(set_slice(sparse(ones([2 0])), 11, 4), sparse([0 0 0 2]')); # sparse different from full | |
3745 | |
3746 ## size = [0 2] | |
3747 %!test test_sparse_slice([0 2], 11, []); | |
3748 %!assert(set_slice(sparse(ones([0 2])), 11, 1), sparse(1,2)); # sparse different from full | |
3749 %!test test_sparse_slice([0 2], 11, 2); | |
3750 %!test test_sparse_slice([0 2], 11, 3); | |
3751 %!test test_sparse_slice([0 2], 11, 4); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3752 %!test test_sparse_slice([0 2], 11, [4, 4]); |
7356 | 3753 |
3754 ## size = [2 1] | |
3755 %!test test_sparse_slice([2 1], 11, []); | |
3756 %!test test_sparse_slice([2 1], 11, 1); | |
3757 %!test test_sparse_slice([2 1], 11, 2); | |
3758 %!test test_sparse_slice([2 1], 11, 3); | |
3759 %!test test_sparse_slice([2 1], 11, 4); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3760 %!test test_sparse_slice([2 1], 11, [4, 4]); |
7356 | 3761 |
3762 ## size = [1 2] | |
3763 %!test test_sparse_slice([1 2], 11, []); | |
3764 %!test test_sparse_slice([1 2], 11, 1); | |
3765 %!test test_sparse_slice([1 2], 11, 2); | |
3766 %!test test_sparse_slice([1 2], 11, 3); | |
3767 %!test test_sparse_slice([1 2], 11, 4); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3768 %!test test_sparse_slice([1 2], 11, [4, 4]); |
7356 | 3769 |
3770 ## size = [2 2] | |
3771 %!test test_sparse_slice([2 2], 11, []); | |
3772 %!test test_sparse_slice([2 2], 11, 1); | |
3773 %!test test_sparse_slice([2 2], 11, 2); | |
3774 %!test test_sparse_slice([2 2], 11, 3); | |
3775 %!test test_sparse_slice([2 2], 11, 4); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3776 %!test test_sparse_slice([2 2], 11, [4, 4]); |
7356 | 3777 # These 2 errors are the same as in the full case |
3778 %!error <invalid matrix index = 5> set_slice(sparse(ones([2 2])), 11, 5); | |
3779 %!error <invalid matrix index = 6> set_slice(sparse(ones([2 2])), 11, 6); | |
3780 | |
3781 | |
3782 #### 2d indexing | |
3783 | |
3784 ## size = [2 0] | |
3785 %!test test_sparse_slice([2 0], 21, []); | |
3786 %!test test_sparse_slice([2 0], 21, 1); | |
3787 %!test test_sparse_slice([2 0], 21, 2); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3788 %!test test_sparse_slice([2 0], 21, [2,2]); |
7356 | 3789 %!assert(set_slice(sparse(ones([2 0])), 21, 3), sparse(2,0)); # sparse different from full |
3790 %!assert(set_slice(sparse(ones([2 0])), 21, 4), sparse(2,0)); # sparse different from full | |
3791 %!test test_sparse_slice([2 0], 22, []); | |
3792 %!test test_sparse_slice([2 0], 22, 1); | |
3793 %!test test_sparse_slice([2 0], 22, 2); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3794 %!test test_sparse_slice([2 0], 22, [2,2]); |
7356 | 3795 %!assert(set_slice(sparse(ones([2 0])), 22, 3), sparse([0 0 2;0 0 2])); # sparse different from full |
3796 %!assert(set_slice(sparse(ones([2 0])), 22, 4), sparse([0 0 0 2;0 0 0 2])); # sparse different from full | |
3797 | |
3798 ## size = [0 2] | |
3799 %!test test_sparse_slice([0 2], 21, []); | |
3800 %!test test_sparse_slice([0 2], 21, 1); | |
3801 %!test test_sparse_slice([0 2], 21, 2); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3802 %!test test_sparse_slice([0 2], 21, [2,2]); |
7356 | 3803 %!assert(set_slice(sparse(ones([0 2])), 21, 3), sparse([0 0;0 0;2 2])); # sparse different from full |
3804 %!assert(set_slice(sparse(ones([0 2])), 21, 4), sparse([0 0;0 0;0 0;2 2])); # sparse different from full | |
3805 %!test test_sparse_slice([0 2], 22, []); | |
3806 %!test test_sparse_slice([0 2], 22, 1); | |
3807 %!test test_sparse_slice([0 2], 22, 2); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3808 %!test test_sparse_slice([0 2], 22, [2,2]); |
7356 | 3809 %!assert(set_slice(sparse(ones([0 2])), 22, 3), sparse(0,2)); # sparse different from full |
3810 %!assert(set_slice(sparse(ones([0 2])), 22, 4), sparse(0,2)); # sparse different from full | |
3811 | |
3812 ## size = [2 1] | |
3813 %!test test_sparse_slice([2 1], 21, []); | |
3814 %!test test_sparse_slice([2 1], 21, 1); | |
3815 %!test test_sparse_slice([2 1], 21, 2); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3816 %!test test_sparse_slice([2 1], 21, [2,2]); |
7356 | 3817 %!test test_sparse_slice([2 1], 21, 3); |
3818 %!test test_sparse_slice([2 1], 21, 4); | |
3819 %!test test_sparse_slice([2 1], 22, []); | |
3820 %!test test_sparse_slice([2 1], 22, 1); | |
3821 %!test test_sparse_slice([2 1], 22, 2); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3822 %!test test_sparse_slice([2 1], 22, [2,2]); |
7356 | 3823 %!test test_sparse_slice([2 1], 22, 3); |
3824 %!test test_sparse_slice([2 1], 22, 4); | |
3825 | |
3826 ## size = [1 2] | |
3827 %!test test_sparse_slice([1 2], 21, []); | |
3828 %!test test_sparse_slice([1 2], 21, 1); | |
3829 %!test test_sparse_slice([1 2], 21, 2); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3830 %!test test_sparse_slice([1 2], 21, [2,2]); |
7356 | 3831 %!test test_sparse_slice([1 2], 21, 3); |
3832 %!test test_sparse_slice([1 2], 21, 4); | |
3833 %!test test_sparse_slice([1 2], 22, []); | |
3834 %!test test_sparse_slice([1 2], 22, 1); | |
3835 %!test test_sparse_slice([1 2], 22, 2); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3836 %!test test_sparse_slice([1 2], 22, [2,2]); |
7356 | 3837 %!test test_sparse_slice([1 2], 22, 3); |
3838 %!test test_sparse_slice([1 2], 22, 4); | |
3839 | |
3840 ## size = [2 2] | |
3841 %!test test_sparse_slice([2 2], 21, []); | |
3842 %!test test_sparse_slice([2 2], 21, 1); | |
3843 %!test test_sparse_slice([2 2], 21, 2); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3844 %!test test_sparse_slice([2 2], 21, [2,2]); |
7356 | 3845 %!test test_sparse_slice([2 2], 21, 3); |
3846 %!test test_sparse_slice([2 2], 21, 4); | |
3847 %!test test_sparse_slice([2 2], 22, []); | |
3848 %!test test_sparse_slice([2 2], 22, 1); | |
3849 %!test test_sparse_slice([2 2], 22, 2); | |
7546
4249c6fb6e09
Treat repeated indices in the sparse assignments
David Bateman <dbateman@free.fr>
parents:
7463
diff
changeset
|
3850 %!test test_sparse_slice([2 2], 22, [2,2]); |
7356 | 3851 %!test test_sparse_slice([2 2], 22, 3); |
3852 %!test test_sparse_slice([2 2], 22, 4); | |
3853 | |
3854 */ | |
3855 | |
5164 | 3856 template <class T> |
3857 void | |
3858 Sparse<T>::print_info (std::ostream& os, const std::string& prefix) const | |
3859 { | |
3860 os << prefix << "rep address: " << rep << "\n" | |
5604 | 3861 << prefix << "rep->nzmx: " << rep->nzmx << "\n" |
5164 | 3862 << prefix << "rep->nrows: " << rep->nrows << "\n" |
3863 << prefix << "rep->ncols: " << rep->ncols << "\n" | |
3864 << prefix << "rep->data: " << static_cast<void *> (rep->d) << "\n" | |
3865 << prefix << "rep->ridx: " << static_cast<void *> (rep->r) << "\n" | |
3866 << prefix << "rep->cidx: " << static_cast<void *> (rep->c) << "\n" | |
3867 << prefix << "rep->count: " << rep->count << "\n"; | |
3868 } |