diff liboctave/dSparse.cc @ 8366:8b1a2555c4e2

implement diagonal matrix objects * * *
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 03 Dec 2008 13:32:57 +0100
parents 64cf956a109c
children 25bc2d31e1bf
line wrap: on
line diff
--- a/liboctave/dSparse.cc
+++ b/liboctave/dSparse.cc
@@ -139,6 +139,23 @@
     }
 }
 
+SparseMatrix::SparseMatrix (const DiagMatrix& a)
+  : MSparse<double> (a.rows (), a.cols (), a.nnz ())
+{
+  octave_idx_type nz = a.nnz (), l = a.length ();
+  for (octave_idx_type i = 0, j = 0; i < l; i++)
+    {
+      if (a(i, i) != 0.0)
+        {
+          data (j) = a(i, i);
+          ridx (j) = i;
+          cidx (j) = j;
+          j++;
+        }
+    }
+  cidx (nz) = nz;
+}
+
 bool
 SparseMatrix::operator == (const SparseMatrix& a) const
 {