diff liboctave/dDiagMatrix.cc @ 8366:8b1a2555c4e2

implement diagonal matrix objects * * *
author Jaroslav Hajek <highegg@gmail.com>
date Wed, 03 Dec 2008 13:32:57 +0100
parents 4976f66d469b
children 445d27d79f4e
line wrap: on
line diff
--- a/liboctave/dDiagMatrix.cc	Wed Dec 03 20:57:27 2008 -0500
+++ b/liboctave/dDiagMatrix.cc	Wed Dec 03 13:32:57 2008 +0100
@@ -139,6 +139,15 @@
 }
 
 DiagMatrix
+DiagMatrix::abs (void) const
+{
+  DiagMatrix retval (rows (), cols ());
+  for (octave_idx_type i = 0; i < rows (); i++)
+    retval(i, i) = std::abs (elem (i, i));
+  return retval;
+}
+
+DiagMatrix
 real (const ComplexDiagMatrix& a)
 {
   DiagMatrix retval;
@@ -309,7 +318,7 @@
 
   if (a_nc != b_nr)
     {
-      gripe_nonconformant ("operaotr *", a_nr, a_nc, b_nr, b_nc);
+      gripe_nonconformant ("operator *", a_nr, a_nc, b_nr, b_nc);
       return DiagMatrix ();
     }
 
@@ -325,14 +334,7 @@
       double a_element = a.elem (i, i);
       double b_element = b.elem (i, i);
 
-      if (a_element == 0.0 || b_element == 0.0)
-        c.elem (i, i) = 0.0;
-      else if (a_element == 1.0)
-        c.elem (i, i) = b_element;
-      else if (b_element == 1.0)
-        c.elem (i, i) = a_element;
-      else
-        c.elem (i, i) = a_element * b_element;
+      c.elem (i, i) = a_element * b_element;
     }
 
   return c;