Mercurial > hg > octave-lyh
comparison liboctave/Sparse.h @ 14792:8483286c0a13
Update Sparse sources to GNU standards (whitespace changes only)
* Sparse.cc: Fix whitespace
* Sparse.h: Ditto
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Thu, 21 Jun 2012 14:29:21 -0400 |
parents | 72c96de7a403 |
children | cda76da34693 |
comparison
equal
deleted
inserted
replaced
14791:90c131272396 | 14792:8483286c0a13 |
---|---|
69 octave_idx_type nzmx; | 69 octave_idx_type nzmx; |
70 octave_idx_type nrows; | 70 octave_idx_type nrows; |
71 octave_idx_type ncols; | 71 octave_idx_type ncols; |
72 octave_refcount<int> count; | 72 octave_refcount<int> count; |
73 | 73 |
74 SparseRep (void) : d (0), r (0), c (new octave_idx_type [1]), nzmx (0), nrows (0), | 74 SparseRep (void) |
75 ncols (0), count (1) { c[0] = 0; } | 75 : d (0), r (0), c (new octave_idx_type [1]), nzmx (0), nrows (0), |
76 | 76 ncols (0), count (1) |
77 SparseRep (octave_idx_type n) : d (0), r (0), c (new octave_idx_type [n+1]), nzmx (0), nrows (n), | 77 { |
78 c[0] = 0; | |
79 } | |
80 | |
81 SparseRep (octave_idx_type n) | |
82 : d (0), r (0), c (new octave_idx_type [n+1]), nzmx (0), nrows (n), | |
78 ncols (n), count (1) | 83 ncols (n), count (1) |
79 { | 84 { |
80 for (octave_idx_type i = 0; i < n + 1; i++) | 85 for (octave_idx_type i = 0; i < n + 1; i++) |
81 c[i] = 0; | 86 c[i] = 0; |
82 } | 87 } |
95 for (octave_idx_type i = 0; i < nc + 1; i++) | 100 for (octave_idx_type i = 0; i < nc + 1; i++) |
96 c[i] = 0; | 101 c[i] = 0; |
97 } | 102 } |
98 | 103 |
99 SparseRep (const SparseRep& a) | 104 SparseRep (const SparseRep& a) |
100 : d (new T [a.nzmx]), r (new octave_idx_type [a.nzmx]), c (new octave_idx_type [a.ncols + 1]), | 105 : d (new T [a.nzmx]), r (new octave_idx_type [a.nzmx]), |
106 c (new octave_idx_type [a.ncols + 1]), | |
101 nzmx (a.nzmx), nrows (a.nrows), ncols (a.ncols), count (1) | 107 nzmx (a.nzmx), nrows (a.nrows), ncols (a.ncols), count (1) |
102 { | 108 { |
103 octave_idx_type nz = a.nnz (); | 109 octave_idx_type nz = a.nnz (); |
104 copy_or_memcpy (nz, a.d, d); | 110 copy_or_memcpy (nz, a.d, d); |
105 copy_or_memcpy (nz, a.r, r); | 111 copy_or_memcpy (nz, a.r, r); |
142 }; | 148 }; |
143 | 149 |
144 //-------------------------------------------------------------------- | 150 //-------------------------------------------------------------------- |
145 | 151 |
146 void make_unique (void) | 152 void make_unique (void) |
147 { | 153 { |
148 if (rep->count > 1) | 154 if (rep->count > 1) |
149 { | 155 { |
150 SparseRep *r = new SparseRep (*rep); | 156 SparseRep *r = new SparseRep (*rep); |
151 | 157 |
152 if (--rep->count == 0) | 158 if (--rep->count == 0) |
153 delete rep; | 159 delete rep; |
154 | 160 |
155 rep = r; | 161 rep = r; |
156 } | 162 } |
157 } | 163 } |
158 | 164 |
159 public: | 165 public: |
160 | 166 |
161 // !!! WARNING !!! -- these should be protected, not public. You | 167 // !!! WARNING !!! -- these should be protected, not public. You |
162 // should not access these data members directly! | 168 // should not access these data members directly! |
166 dim_vector dimensions; | 172 dim_vector dimensions; |
167 | 173 |
168 private: | 174 private: |
169 | 175 |
170 typename Sparse<T>::SparseRep *nil_rep (void) const | 176 typename Sparse<T>::SparseRep *nil_rep (void) const |
171 { | 177 { |
172 static typename Sparse<T>::SparseRep nr; | 178 static typename Sparse<T>::SparseRep nr; |
173 return &nr; | 179 return &nr; |
174 } | 180 } |
175 | 181 |
176 public: | 182 public: |
177 | 183 |
178 Sparse (void) | 184 Sparse (void) |
179 : rep (nil_rep ()), dimensions (dim_vector(0,0)) | 185 : rep (nil_rep ()), dimensions (dim_vector(0,0)) |
180 { | 186 { |
181 rep->count++; | 187 rep->count++; |
182 } | 188 } |
183 | 189 |
184 explicit Sparse (octave_idx_type n) | 190 explicit Sparse (octave_idx_type n) |
185 : rep (new typename Sparse<T>::SparseRep (n)), | 191 : rep (new typename Sparse<T>::SparseRep (n)), |
186 dimensions (dim_vector (n, n)) { } | 192 dimensions (dim_vector (n, n)) { } |
187 | 193 |
191 | 197 |
192 explicit Sparse (octave_idx_type nr, octave_idx_type nc, T val); | 198 explicit Sparse (octave_idx_type nr, octave_idx_type nc, T val); |
193 | 199 |
194 Sparse (const dim_vector& dv, octave_idx_type nz) | 200 Sparse (const dim_vector& dv, octave_idx_type nz) |
195 : rep (new typename Sparse<T>::SparseRep (dv(0), dv(1), nz)), | 201 : rep (new typename Sparse<T>::SparseRep (dv(0), dv(1), nz)), |
196 dimensions (dv) { } | 202 dimensions (dv) { } |
197 | 203 |
198 Sparse (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz) | 204 Sparse (octave_idx_type nr, octave_idx_type nc, octave_idx_type nz) |
199 : rep (new typename Sparse<T>::SparseRep (nr, nc, nz)), | 205 : rep (new typename Sparse<T>::SparseRep (nr, nc, nz)), |
200 dimensions (dim_vector (nr, nc)) { } | 206 dimensions (dim_vector (nr, nc)) { } |
201 | 207 |
205 | 211 |
206 // Type conversion case. Preserves capacity (). | 212 // Type conversion case. Preserves capacity (). |
207 template <class U> | 213 template <class U> |
208 Sparse (const Sparse<U>& a) | 214 Sparse (const Sparse<U>& a) |
209 : rep (new typename Sparse<T>::SparseRep (a.rep->nrows, a.rep->ncols, a.rep->nzmx)), | 215 : rep (new typename Sparse<T>::SparseRep (a.rep->nrows, a.rep->ncols, a.rep->nzmx)), |
210 dimensions (a.dimensions) | 216 dimensions (a.dimensions) |
211 { | 217 { |
212 octave_idx_type nz = a.nnz (); | 218 octave_idx_type nz = a.nnz (); |
213 std::copy (a.rep->d, a.rep->d + nz, rep->d); | 219 std::copy (a.rep->d, a.rep->d + nz, rep->d); |
214 copy_or_memcpy (nz, a.rep->r, rep->r); | 220 copy_or_memcpy (nz, a.rep->r, rep->r); |
215 copy_or_memcpy (rep->ncols + 1, a.rep->c, rep->c); | 221 copy_or_memcpy (rep->ncols + 1, a.rep->c, rep->c); |
216 } | 222 } |
217 | 223 |
218 // No type conversion case. | 224 // No type conversion case. |
219 Sparse (const Sparse<T>& a) | 225 Sparse (const Sparse<T>& a) |
220 : rep (a.rep), dimensions (a.dimensions) | 226 : rep (a.rep), dimensions (a.dimensions) |
221 { | 227 { |
222 rep->count++; | 228 rep->count++; |
223 } | 229 } |
224 | 230 |
225 public: | 231 public: |
226 | 232 |
227 Sparse (const dim_vector& dv); | 233 Sparse (const dim_vector& dv); |
228 | 234 |
247 octave_idx_type nnz (void) const { return rep->nnz (); } | 253 octave_idx_type nnz (void) const { return rep->nnz (); } |
248 | 254 |
249 // Querying the number of elements (incl. zeros) may overflow the index type, | 255 // Querying the number of elements (incl. zeros) may overflow the index type, |
250 // so don't do it unless you really need it. | 256 // so don't do it unless you really need it. |
251 octave_idx_type numel (void) const | 257 octave_idx_type numel (void) const |
252 { | 258 { |
253 return dimensions.safe_numel (); | 259 return dimensions.safe_numel (); |
254 } | 260 } |
255 | 261 |
256 octave_idx_type nelem (void) const { return capacity (); } | 262 octave_idx_type nelem (void) const { return capacity (); } |
257 octave_idx_type length (void) const { return numel (); } | 263 octave_idx_type length (void) const { return numel (); } |
258 | 264 |
259 octave_idx_type dim1 (void) const { return dimensions(0); } | 265 octave_idx_type dim1 (void) const { return dimensions(0); } |
263 octave_idx_type cols (void) const { return dim2 (); } | 269 octave_idx_type cols (void) const { return dim2 (); } |
264 octave_idx_type columns (void) const { return dim2 (); } | 270 octave_idx_type columns (void) const { return dim2 (); } |
265 | 271 |
266 octave_idx_type get_row_index (octave_idx_type k) { return ridx (k); } | 272 octave_idx_type get_row_index (octave_idx_type k) { return ridx (k); } |
267 octave_idx_type get_col_index (octave_idx_type k) | 273 octave_idx_type get_col_index (octave_idx_type k) |
268 { | 274 { |
269 octave_idx_type ret = 0; | 275 octave_idx_type ret = 0; |
270 while (cidx(ret+1) < k) | 276 while (cidx(ret+1) < k) |
271 ret++; | 277 ret++; |
272 return ret; | 278 return ret; |
273 } | 279 } |
274 | 280 |
275 size_t byte_size (void) const | 281 size_t byte_size (void) const |
276 { | 282 { |
277 return (static_cast<size_t>(cols () + 1) * sizeof (octave_idx_type) | 283 return (static_cast<size_t>(cols () + 1) * sizeof (octave_idx_type) |
278 + static_cast<size_t> (capacity ()) * (sizeof (T) + sizeof (octave_idx_type))); | 284 + static_cast<size_t> (capacity ()) |
279 } | 285 * (sizeof (T) + sizeof (octave_idx_type))); |
286 } | |
280 | 287 |
281 dim_vector dims (void) const { return dimensions; } | 288 dim_vector dims (void) const { return dimensions; } |
282 | 289 |
283 Sparse<T> squeeze (void) const { return *this; } | 290 Sparse<T> squeeze (void) const { return *this; } |
284 | 291 |
294 T& range_error (const char *fcn, const Array<octave_idx_type>& ra_idx); | 301 T& range_error (const char *fcn, const Array<octave_idx_type>& ra_idx); |
295 | 302 |
296 // No checking, even for multiple references, ever. | 303 // No checking, even for multiple references, ever. |
297 | 304 |
298 T& xelem (octave_idx_type n) | 305 T& xelem (octave_idx_type n) |
299 { | 306 { |
300 octave_idx_type i = n % rows (), j = n / rows(); | 307 octave_idx_type i = n % rows (), j = n / rows(); |
301 return xelem (i, j); | 308 return xelem (i, j); |
302 } | 309 } |
303 | 310 |
304 T xelem (octave_idx_type n) const | 311 T xelem (octave_idx_type n) const |
305 { | 312 { |
306 octave_idx_type i = n % rows (), j = n / rows(); | 313 octave_idx_type i = n % rows (), j = n / rows(); |
307 return xelem (i, j); | 314 return xelem (i, j); |
308 } | 315 } |
309 | 316 |
310 T& xelem (octave_idx_type i, octave_idx_type j) { return rep->elem (i, j); } | 317 T& xelem (octave_idx_type i, octave_idx_type j) { return rep->elem (i, j); } |
311 T xelem (octave_idx_type i, octave_idx_type j) const { return rep->celem (i, j); } | 318 T xelem (octave_idx_type i, octave_idx_type j) const |
319 { | |
320 return rep->celem (i, j); | |
321 } | |
312 | 322 |
313 T& xelem (const Array<octave_idx_type>& ra_idx) | 323 T& xelem (const Array<octave_idx_type>& ra_idx) |
314 { return xelem (compute_index (ra_idx)); } | 324 { return xelem (compute_index (ra_idx)); } |
315 | 325 |
316 T xelem (const Array<octave_idx_type>& ra_idx) const | 326 T xelem (const Array<octave_idx_type>& ra_idx) const |
317 { return xelem (compute_index (ra_idx)); } | 327 { return xelem (compute_index (ra_idx)); } |
318 | 328 |
319 // FIXME -- would be nice to fix this so that we don't | 329 // FIXME -- would be nice to fix this so that we don't |
320 // unnecessarily force a copy, but that is not so easy, and I see no | 330 // unnecessarily force a copy, but that is not so easy, and I see no |
321 // clean way to do it. | 331 // clean way to do it. |
322 | 332 |
323 T& checkelem (octave_idx_type n) | 333 T& checkelem (octave_idx_type n) |
324 { | 334 { |
325 if (n < 0 || n >= numel ()) | 335 if (n < 0 || n >= numel ()) |
326 return range_error ("T& Sparse<T>::checkelem", n); | 336 return range_error ("T& Sparse<T>::checkelem", n); |
327 else | 337 else |
328 { | 338 { |
329 make_unique (); | 339 make_unique (); |
330 return xelem (n); | 340 return xelem (n); |
331 } | 341 } |
332 } | 342 } |
333 | 343 |
334 T& checkelem (octave_idx_type i, octave_idx_type j) | 344 T& checkelem (octave_idx_type i, octave_idx_type j) |
335 { | 345 { |
336 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ()) | 346 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ()) |
337 return range_error ("T& Sparse<T>::checkelem", i, j); | 347 return range_error ("T& Sparse<T>::checkelem", i, j); |
338 else | 348 else |
339 { | 349 { |
340 make_unique (); | 350 make_unique (); |
341 return xelem (i, j); | 351 return xelem (i, j); |
342 } | 352 } |
343 } | 353 } |
344 | 354 |
345 T& checkelem (const Array<octave_idx_type>& ra_idx) | 355 T& checkelem (const Array<octave_idx_type>& ra_idx) |
346 { | 356 { |
347 octave_idx_type i = compute_index (ra_idx); | 357 octave_idx_type i = compute_index (ra_idx); |
348 | 358 |
349 if (i < 0) | 359 if (i < 0) |
350 return range_error ("T& Sparse<T>::checkelem", ra_idx); | 360 return range_error ("T& Sparse<T>::checkelem", ra_idx); |
351 else | 361 else |
352 return elem (i); | 362 return elem (i); |
353 } | 363 } |
354 | 364 |
355 T& elem (octave_idx_type n) | 365 T& elem (octave_idx_type n) |
356 { | 366 { |
357 make_unique (); | 367 make_unique (); |
368 return xelem (n); | |
369 } | |
370 | |
371 T& elem (octave_idx_type i, octave_idx_type j) | |
372 { | |
373 make_unique (); | |
374 return xelem (i, j); | |
375 } | |
376 | |
377 T& elem (const Array<octave_idx_type>& ra_idx) | |
378 { return Sparse<T>::elem (compute_index (ra_idx)); } | |
379 | |
380 #if defined (BOUNDS_CHECKING) | |
381 T& operator () (octave_idx_type n) | |
382 { | |
383 return checkelem (n); | |
384 } | |
385 | |
386 T& operator () (octave_idx_type i, octave_idx_type j) | |
387 { | |
388 return checkelem (i, j); | |
389 } | |
390 | |
391 T& operator () (const Array<octave_idx_type>& ra_idx) | |
392 { | |
393 return checkelem (ra_idx); | |
394 } | |
395 | |
396 #else | |
397 T& operator () (octave_idx_type n) | |
398 { | |
399 return elem (n); | |
400 } | |
401 | |
402 T& operator () (octave_idx_type i, octave_idx_type j) | |
403 { | |
404 return elem (i, j); | |
405 } | |
406 | |
407 T& operator () (const Array<octave_idx_type>& ra_idx) | |
408 { | |
409 return elem (ra_idx); | |
410 } | |
411 | |
412 #endif | |
413 | |
414 T checkelem (octave_idx_type n) const | |
415 { | |
416 if (n < 0 || n >= numel ()) | |
417 return range_error ("T Sparse<T>::checkelem", n); | |
418 else | |
358 return xelem (n); | 419 return xelem (n); |
359 } | 420 } |
360 | 421 |
361 T& elem (octave_idx_type i, octave_idx_type j) | 422 T checkelem (octave_idx_type i, octave_idx_type j) const |
362 { | 423 { |
363 make_unique (); | 424 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ()) |
425 return range_error ("T Sparse<T>::checkelem", i, j); | |
426 else | |
364 return xelem (i, j); | 427 return xelem (i, j); |
365 } | 428 } |
366 | |
367 T& elem (const Array<octave_idx_type>& ra_idx) | |
368 { return Sparse<T>::elem (compute_index (ra_idx)); } | |
369 | |
370 #if defined (BOUNDS_CHECKING) | |
371 T& operator () (octave_idx_type n) { return checkelem (n); } | |
372 T& operator () (octave_idx_type i, octave_idx_type j) { return checkelem (i, j); } | |
373 T& operator () (const Array<octave_idx_type>& ra_idx) { return checkelem (ra_idx); } | |
374 #else | |
375 T& operator () (octave_idx_type n) { return elem (n); } | |
376 T& operator () (octave_idx_type i, octave_idx_type j) { return elem (i, j); } | |
377 T& operator () (const Array<octave_idx_type>& ra_idx) { return elem (ra_idx); } | |
378 #endif | |
379 | |
380 T checkelem (octave_idx_type n) const | |
381 { | |
382 if (n < 0 || n >= numel ()) | |
383 return range_error ("T Sparse<T>::checkelem", n); | |
384 else | |
385 return xelem (n); | |
386 } | |
387 | |
388 T checkelem (octave_idx_type i, octave_idx_type j) const | |
389 { | |
390 if (i < 0 || j < 0 || i >= dim1 () || j >= dim2 ()) | |
391 return range_error ("T Sparse<T>::checkelem", i, j); | |
392 else | |
393 return xelem (i, j); | |
394 } | |
395 | 429 |
396 T checkelem (const Array<octave_idx_type>& ra_idx) const | 430 T checkelem (const Array<octave_idx_type>& ra_idx) const |
397 { | 431 { |
398 octave_idx_type i = compute_index (ra_idx); | 432 octave_idx_type i = compute_index (ra_idx); |
399 | 433 |
400 if (i < 0) | 434 if (i < 0) |
401 return range_error ("T Sparse<T>::checkelem", ra_idx); | 435 return range_error ("T Sparse<T>::checkelem", ra_idx); |
402 else | 436 else |
403 return Sparse<T>::elem (i); | 437 return Sparse<T>::elem (i); |
404 } | 438 } |
405 | 439 |
406 T elem (octave_idx_type n) const { return xelem (n); } | 440 T elem (octave_idx_type n) const { return xelem (n); } |
407 | 441 |
408 T elem (octave_idx_type i, octave_idx_type j) const { return xelem (i, j); } | 442 T elem (octave_idx_type i, octave_idx_type j) const { return xelem (i, j); } |
409 | 443 |
410 T elem (const Array<octave_idx_type>& ra_idx) const | 444 T elem (const Array<octave_idx_type>& ra_idx) const |
411 { return Sparse<T>::elem (compute_index (ra_idx)); } | 445 { return Sparse<T>::elem (compute_index (ra_idx)); } |
412 | 446 |
413 #if defined (BOUNDS_CHECKING) | 447 #if defined (BOUNDS_CHECKING) |
414 T operator () (octave_idx_type n) const { return checkelem (n); } | 448 T operator () (octave_idx_type n) const { return checkelem (n); } |
415 T operator () (octave_idx_type i, octave_idx_type j) const { return checkelem (i, j); } | 449 T operator () (octave_idx_type i, octave_idx_type j) const |
416 T operator () (const Array<octave_idx_type>& ra_idx) const { return checkelem (ra_idx); } | 450 { |
451 return checkelem (i, j); | |
452 } | |
453 | |
454 T operator () (const Array<octave_idx_type>& ra_idx) const | |
455 { | |
456 return checkelem (ra_idx); | |
457 } | |
458 | |
417 #else | 459 #else |
418 T operator () (octave_idx_type n) const { return elem (n); } | 460 T operator () (octave_idx_type n) const { return elem (n); } |
419 T operator () (octave_idx_type i, octave_idx_type j) const { return elem (i, j); } | 461 T operator () (octave_idx_type i, octave_idx_type j) const |
420 T operator () (const Array<octave_idx_type>& ra_idx) const { return elem (ra_idx); } | 462 { |
463 return elem (i, j); | |
464 } | |
465 | |
466 T operator () (const Array<octave_idx_type>& ra_idx) const | |
467 { | |
468 return elem (ra_idx); | |
469 } | |
421 #endif | 470 #endif |
422 | 471 |
423 Sparse<T> maybe_compress (bool remove_zeros = false) | 472 Sparse<T> maybe_compress (bool remove_zeros = false) |
424 { | 473 { |
425 if (remove_zeros) | 474 if (remove_zeros) |
426 make_unique (); // Needs to unshare because elements are removed. | 475 make_unique (); // Needs to unshare because elements are removed. |
427 | 476 |
428 rep->maybe_compress (remove_zeros); | 477 rep->maybe_compress (remove_zeros); |
429 return (*this); | 478 return (*this); |
430 } | 479 } |
431 | 480 |
432 Sparse<T> reshape (const dim_vector& new_dims) const; | 481 Sparse<T> reshape (const dim_vector& new_dims) const; |
433 | 482 |
434 Sparse<T> permute (const Array<octave_idx_type>& vec, bool inv = false) const; | 483 Sparse<T> permute (const Array<octave_idx_type>& vec, bool inv = false) const; |
435 | 484 |
436 Sparse<T> ipermute (const Array<octave_idx_type>& vec) const | 485 Sparse<T> ipermute (const Array<octave_idx_type>& vec) const |
437 { return permute (vec, true); } | 486 { |
487 return permute (vec, true); | |
488 } | |
438 | 489 |
439 void resize1 (octave_idx_type n); | 490 void resize1 (octave_idx_type n); |
440 | 491 |
441 void resize (octave_idx_type r, octave_idx_type c); | 492 void resize (octave_idx_type r, octave_idx_type c); |
442 | 493 |
443 void resize (const dim_vector& dv); | 494 void resize (const dim_vector& dv); |
444 | 495 |
445 void change_capacity (octave_idx_type nz) | 496 void change_capacity (octave_idx_type nz) |
446 { | 497 { |
447 if (nz < nnz ()) | 498 if (nz < nnz ()) |
448 make_unique (); // Unshare now because elements will be truncated. | 499 make_unique (); // Unshare now because elements will be truncated. |
449 rep->change_length (nz); | 500 rep->change_length (nz); |
450 } | 501 } |
451 | 502 |
452 Sparse<T>& insert (const Sparse<T>& a, octave_idx_type r, octave_idx_type c); | 503 Sparse<T>& insert (const Sparse<T>& a, octave_idx_type r, octave_idx_type c); |
453 Sparse<T>& insert (const Sparse<T>& a, const Array<octave_idx_type>& idx); | 504 Sparse<T>& insert (const Sparse<T>& a, const Array<octave_idx_type>& idx); |
454 | 505 |
455 bool is_square (void) const { return (dim1 () == dim2 ()); } | 506 bool is_square (void) const { return (dim1 () == dim2 ()); } |
466 T data (octave_idx_type i) const { return rep->data (i); } | 517 T data (octave_idx_type i) const { return rep->data (i); } |
467 // FIXME -- shouldn't this be returning const T*? | 518 // FIXME -- shouldn't this be returning const T*? |
468 T* data (void) const { return rep->d; } | 519 T* data (void) const { return rep->d; } |
469 | 520 |
470 octave_idx_type* ridx (void) { make_unique (); return rep->r; } | 521 octave_idx_type* ridx (void) { make_unique (); return rep->r; } |
471 octave_idx_type& ridx (octave_idx_type i) { make_unique (); return rep->ridx (i); } | 522 octave_idx_type& ridx (octave_idx_type i) |
523 { | |
524 make_unique (); return rep->ridx (i); | |
525 } | |
526 | |
472 octave_idx_type* xridx (void) { return rep->r; } | 527 octave_idx_type* xridx (void) { return rep->r; } |
473 octave_idx_type& xridx (octave_idx_type i) { return rep->ridx (i); } | 528 octave_idx_type& xridx (octave_idx_type i) { return rep->ridx (i); } |
474 | 529 |
475 octave_idx_type ridx (octave_idx_type i) const { return rep->cridx (i); } | 530 octave_idx_type ridx (octave_idx_type i) const { return rep->cridx (i); } |
476 // FIXME -- shouldn't this be returning const octave_idx_type*? | 531 // FIXME -- shouldn't this be returning const octave_idx_type*? |
477 octave_idx_type* ridx (void) const { return rep->r; } | 532 octave_idx_type* ridx (void) const { return rep->r; } |
478 | 533 |
479 octave_idx_type* cidx (void) { make_unique (); return rep->c; } | 534 octave_idx_type* cidx (void) { make_unique (); return rep->c; } |
480 octave_idx_type& cidx (octave_idx_type i) { make_unique (); return rep->cidx (i); } | 535 octave_idx_type& cidx (octave_idx_type i) |
536 { | |
537 make_unique (); return rep->cidx (i); | |
538 } | |
539 | |
481 octave_idx_type* xcidx (void) { return rep->c; } | 540 octave_idx_type* xcidx (void) { return rep->c; } |
482 octave_idx_type& xcidx (octave_idx_type i) { return rep->cidx (i); } | 541 octave_idx_type& xcidx (octave_idx_type i) { return rep->cidx (i); } |
483 | 542 |
484 octave_idx_type cidx (octave_idx_type i) const { return rep->ccidx (i); } | 543 octave_idx_type cidx (octave_idx_type i) const { return rep->ccidx (i); } |
485 // FIXME -- shouldn't this be returning const octave_idx_type*? | 544 // FIXME -- shouldn't this be returning const octave_idx_type*? |
493 | 552 |
494 void delete_elements (const idx_vector& i, const idx_vector& j); | 553 void delete_elements (const idx_vector& i, const idx_vector& j); |
495 | 554 |
496 Sparse<T> index (const idx_vector& i, bool resize_ok = false) const; | 555 Sparse<T> index (const idx_vector& i, bool resize_ok = false) const; |
497 | 556 |
498 Sparse<T> index (const idx_vector& i, const idx_vector& j, bool resize_ok = false) const; | 557 Sparse<T> index (const idx_vector& i, const idx_vector& j, |
558 bool resize_ok = false) const; | |
499 | 559 |
500 void assign (const idx_vector& i, const Sparse<T>& rhs); | 560 void assign (const idx_vector& i, const Sparse<T>& rhs); |
501 | 561 |
502 void assign (const idx_vector& i, const idx_vector& j, const Sparse<T>& rhs); | 562 void assign (const idx_vector& i, const idx_vector& j, const Sparse<T>& rhs); |
503 | 563 |
505 | 565 |
506 // Unsafe. These functions exist to support the MEX interface. | 566 // Unsafe. These functions exist to support the MEX interface. |
507 // You should not use them anywhere else. | 567 // You should not use them anywhere else. |
508 void *mex_get_data (void) const { return const_cast<T *> (data ()); } | 568 void *mex_get_data (void) const { return const_cast<T *> (data ()); } |
509 | 569 |
510 octave_idx_type *mex_get_ir (void) const { return const_cast<octave_idx_type *> (ridx ()); } | 570 octave_idx_type *mex_get_ir (void) const |
511 | 571 { |
512 octave_idx_type *mex_get_jc (void) const { return const_cast<octave_idx_type *> (cidx ()); } | 572 return const_cast<octave_idx_type *> (ridx ()); |
573 } | |
574 | |
575 octave_idx_type *mex_get_jc (void) const | |
576 { | |
577 return const_cast<octave_idx_type *> (cidx ()); | |
578 } | |
513 | 579 |
514 Sparse<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; | 580 Sparse<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; |
515 Sparse<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, | 581 Sparse<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, |
516 sortmode mode = ASCENDING) const; | 582 sortmode mode = ASCENDING) const; |
517 | 583 |
518 Sparse<T> diag (octave_idx_type k = 0) const; | 584 Sparse<T> diag (octave_idx_type k = 0) const; |
519 | 585 |
520 // dim = -1 and dim = -2 are special; see Array<T>::cat description. | 586 // dim = -1 and dim = -2 are special; see Array<T>::cat description. |
521 static Sparse<T> | 587 static Sparse<T> |