diff liboctave/dDiagMatrix.cc @ 9698:7c6d5d8c8d37

fix diag*diag multiplication
author Jaroslav Hajek <highegg@gmail.com>
date Tue, 06 Oct 2009 08:43:01 +0200
parents a9b37bae1802
children f80c566bc751
line wrap: on
line diff
--- a/liboctave/dDiagMatrix.cc	Tue Oct 06 08:22:56 2009 +0200
+++ b/liboctave/dDiagMatrix.cc	Tue Oct 06 08:43:01 2009 +0200
@@ -338,25 +338,16 @@
   octave_idx_type b_nc = b.cols ();
 
   if (a_nc != b_nr)
-    {
-      gripe_nonconformant ("operator *", a_nr, a_nc, b_nr, b_nc);
-      return DiagMatrix ();
-    }
-
-  if (a_nr == 0 || a_nc == 0 || b_nc == 0)
-    return DiagMatrix (a_nr, a_nc, 0.0);
+    gripe_nonconformant ("operator *", a_nr, a_nc, b_nr, b_nc);
 
   DiagMatrix c (a_nr, b_nc);
 
-  octave_idx_type len = a_nr < b_nc ? a_nr : b_nc;
+  octave_idx_type len = c.length (), lenm = len < a_nc ? len : a_nc;
 
-  for (octave_idx_type i = 0; i < len; i++)
-    {
-      double a_element = a.elem (i, i);
-      double b_element = b.elem (i, i);
-
-      c.elem (i, i) = a_element * b_element;
-    }
+  for (octave_idx_type i = 0; i < lenm; i++)
+    c.dgxelem (i) = a.dgelem (i) * b.dgelem (i);
+  for (octave_idx_type i = lenm; i < len; i++)
+    c.dgxelem (i) = 0.0;
 
   return c;
 }