Mercurial > hg > octave-lyh
comparison liboctave/Sparse.cc @ 10352:a3635bc1ea19
remove Array2
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 23 Feb 2010 16:12:27 +0100 |
parents | 07ebe522dac2 |
children | 173e10268080 |
comparison
equal
deleted
inserted
replaced
10351:5150ceb4dbb4 | 10352:a3635bc1ea19 |
---|---|
543 } | 543 } |
544 | 544 |
545 while (cx < nc) | 545 while (cx < nc) |
546 xcidx (++cx) = ii + 1; | 546 xcidx (++cx) = ii + 1; |
547 } | 547 } |
548 } | |
549 } | |
550 | |
551 template <class T> | |
552 Sparse<T>::Sparse (const Array2<T>& a) | |
553 : dimensions (a.dims ()), idx (0), idx_count (0) | |
554 { | |
555 octave_idx_type nr = rows (); | |
556 octave_idx_type nc = cols (); | |
557 octave_idx_type len = a.length (); | |
558 octave_idx_type new_nzmx = 0; | |
559 | |
560 // First count the number of non-zero terms | |
561 for (octave_idx_type i = 0; i < len; i++) | |
562 if (a(i) != T ()) | |
563 new_nzmx++; | |
564 | |
565 rep = new typename Sparse<T>::SparseRep (nr, nc, new_nzmx); | |
566 | |
567 octave_idx_type ii = 0; | |
568 xcidx(0) = 0; | |
569 for (octave_idx_type j = 0; j < nc; j++) | |
570 { | |
571 for (octave_idx_type i = 0; i < nr; i++) | |
572 if (a.elem (i,j) != T ()) | |
573 { | |
574 xdata(ii) = a.elem (i,j); | |
575 xridx(ii++) = i; | |
576 } | |
577 xcidx(j+1) = ii; | |
578 } | 548 } |
579 } | 549 } |
580 | 550 |
581 template <class T> | 551 template <class T> |
582 Sparse<T>::Sparse (const Array<T>& a) | 552 Sparse<T>::Sparse (const Array<T>& a) |