comparison liboctave/Sparse.h @ 10425:0677c5d80b77

rewrite 1D sparse indexing
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 19 Mar 2010 13:00:06 +0100
parents 99e9bae2d81e
children ded9beac7582
comparison
equal deleted inserted replaced
10424:0b05b204775b 10425:0677c5d80b77
235 // terms. 235 // terms.
236 octave_idx_type nzmax (void) const { return rep->length (); } 236 octave_idx_type nzmax (void) const { return rep->length (); }
237 octave_idx_type capacity (void) const { return nzmax (); } 237 octave_idx_type capacity (void) const { return nzmax (); }
238 octave_idx_type nnz (void) const { return rep->nnz (); } 238 octave_idx_type nnz (void) const { return rep->nnz (); }
239 239
240 // Paranoid number of elements test for case of dims = (-1,-1) 240 // Querying the number of elements (incl. zeros) may overflow the index type,
241 // so don't do it unless you really need it.
241 octave_idx_type numel (void) const 242 octave_idx_type numel (void) const
242 { 243 {
243 if (dim1() < 0 || dim2() < 0) 244 return dimensions.safe_numel ();
244 return 0;
245 else
246 return dimensions.numel ();
247 } 245 }
248 246
249 octave_idx_type nelem (void) const { return capacity (); } 247 octave_idx_type nelem (void) const { return capacity (); }
250 octave_idx_type length (void) const { return numel (); } 248 octave_idx_type length (void) const { return numel (); }
251 249
416 Sparse<T> maybe_compress (bool remove_zeros = false) 414 Sparse<T> maybe_compress (bool remove_zeros = false)
417 { rep->maybe_compress (remove_zeros); return (*this); } 415 { rep->maybe_compress (remove_zeros); return (*this); }
418 416
419 Sparse<T> reshape (const dim_vector& new_dims) const; 417 Sparse<T> reshape (const dim_vector& new_dims) const;
420 418
421 // !!! WARNING !!! -- the following resize_no_fill functions are
422 // public because template friends don't work properly with versions
423 // of gcc earlier than 3.3. You should use these functions only in
424 // classes that are derived from Sparse<T>.
425
426 // protected:
427
428 void resize_no_fill (octave_idx_type r, octave_idx_type c);
429
430 void resize_no_fill (const dim_vector& dv);
431
432 public:
433 Sparse<T> permute (const Array<octave_idx_type>& vec, bool inv = false) const; 419 Sparse<T> permute (const Array<octave_idx_type>& vec, bool inv = false) const;
434 420
435 Sparse<T> ipermute (const Array<octave_idx_type>& vec) const 421 Sparse<T> ipermute (const Array<octave_idx_type>& vec) const
436 { return permute (vec, true); } 422 { return permute (vec, true); }
437 423
438 void resize (octave_idx_type r, octave_idx_type c) { resize_no_fill (r, c); } 424 void resize1 (octave_idx_type n);
439 425
440 void resize (const dim_vector& dv) { resize_no_fill (dv); } 426 void resize (octave_idx_type r, octave_idx_type c);
427
428 void resize (const dim_vector& dv);
441 429
442 void change_capacity (octave_idx_type nz) { rep->change_length (nz); } 430 void change_capacity (octave_idx_type nz) { rep->change_length (nz); }
443 431
444 Sparse<T>& insert (const Sparse<T>& a, octave_idx_type r, octave_idx_type c); 432 Sparse<T>& insert (const Sparse<T>& a, octave_idx_type r, octave_idx_type c);
445 Sparse<T>& insert (const Sparse<T>& a, const Array<octave_idx_type>& idx); 433 Sparse<T>& insert (const Sparse<T>& a, const Array<octave_idx_type>& idx);
512 Sparse<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const; 500 Sparse<T> sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const;
513 Sparse<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0, 501 Sparse<T> sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
514 sortmode mode = ASCENDING) const; 502 sortmode mode = ASCENDING) const;
515 503
516 Sparse<T> diag (octave_idx_type k = 0) const; 504 Sparse<T> diag (octave_idx_type k = 0) const;
505
506 Array<T> array_value (void) const;
517 507
518 template <class U, class F> 508 template <class U, class F>
519 Sparse<U> 509 Sparse<U>
520 map (F fcn) const 510 map (F fcn) const
521 { 511 {