changeset 1947:5ab3c25a3cf9

[project @ 1996-02-14 01:50:42 by jwe]
author jwe
date Wed, 14 Feb 1996 01:50:42 +0000
parents ec07d85b4152
children d7dec93d4b87
files liboctave/CColVector.cc liboctave/CRowVector.cc liboctave/dColVector.cc liboctave/dRowVector.cc
diffstat 4 files changed, 130 insertions(+), 87 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/CColVector.cc
+++ b/liboctave/CColVector.cc
@@ -435,26 +435,35 @@
 ComplexColumnVector
 operator * (const ComplexMatrix& m, const ComplexColumnVector& a)
 {
+  ComplexColumnVector retval;
+
   int nr = m.rows ();
   int nc = m.cols ();
+
   if (nc != a.length ())
+    (*current_liboctave_error_handler)
+      ("nonconformant matrix multiplication attempted");
+  else
     {
-      (*current_liboctave_error_handler)
-	("nonconformant matrix multiplication attempted");
-      return ComplexColumnVector ();
+      if (nc == 0 || nr == 0)
+	retval.resize (nr, 0.0);
+      else
+	{
+	  int ld = nr;
+
+	  retval.resize (nr);
+	  Complex *y = retval.fortran_vec ();
+
+	  F77_XFCN (zgemv, ZGEMV, ("N", nr, nc, 1.0, m.data (), ld,
+				   a.data (), 1, 0.0, y, 1, 1L));
+
+	  if (f77_exception_encountered)
+	    (*current_liboctave_error_handler)
+	      ("unrecoverable error in zgemv");
+	}
     }
 
-  if (nc == 0 || nr == 0)
-    return ComplexColumnVector (0);
-
-  int ld = nr;
-
-  Complex *y = new Complex [nr];
-
-  F77_FCN (zgemv, ZGEMV) ("N", nr, nc, 1.0, m.data (), ld, a.data (),
-			  1, 0.0, y, 1, 1L);
-
-  return ComplexColumnVector (y, nr);
+  return retval;
 }
 
 // column vector by column vector -> column vector operations
--- a/liboctave/CRowVector.cc
+++ b/liboctave/CRowVector.cc
@@ -427,30 +427,39 @@
 ComplexRowVector
 operator * (const ComplexRowVector& v, const ComplexMatrix& a)
 {
+  ComplexRowVector retval;
+
   int len = v.length ();
+
   if (a.rows () != len)
+    (*current_liboctave_error_handler)
+      ("nonconformant vector multiplication attempted");
+  else
     {
-      (*current_liboctave_error_handler)
-	("nonconformant vector multiplication attempted");
-      return ComplexRowVector ();
+      int a_nr = a.rows ();
+      int a_nc = a.cols ();
+
+      if (len == 0)
+	retval.resize (a_nc, 0.0);
+      else
+	{
+	  // Transpose A to form A'*x == (x'*A)'
+
+	  int ld = a_nr;
+
+	  retval.resize (a_nc);
+	  Complex *y = retval.fortran_vec ();
+
+	  F77_XFCN (zgemv, ZGEMV, ("T", a_nr, a_nc, 1.0, a.data (),
+				   ld, v.data (), 1, 0.0, y, 1, 1L));
+
+	  if (f77_exception_encountered)
+	    (*current_liboctave_error_handler)
+	      ("unrecoverable error in zgemv");
+	}
     }
 
-  if (len == 0)
-    return ComplexRowVector (a.cols (), 0.0);
-
-  // Transpose A to form A'*x == (x'*A)'
-
-  int a_nr = a.rows ();
-  int a_nc = a.cols ();
-
-  int ld = a_nr;
-
-  Complex *y = new Complex [a_nc];
-
-  F77_FCN (zgemv, ZGEMV) ("T", a_nr, a_nc, 1.0, a.data (), ld,
-			  v.data (), 1, 0.0, y, 1, 1L); 
-
-  return ComplexRowVector (y, a_nc);
+  return retval;
 }
 
 ComplexRowVector
--- a/liboctave/dColVector.cc
+++ b/liboctave/dColVector.cc
@@ -210,26 +210,35 @@
 ColumnVector
 operator * (const Matrix& m, const ColumnVector& a)
 {
+  ColumnVector retval;
+
   int nr = m.rows ();
   int nc = m.cols ();
+
   if (nc != a.length ())
+    (*current_liboctave_error_handler)
+      ("nonconformant matrix multiplication attempted");
+  else
     {
-      (*current_liboctave_error_handler)
-	("nonconformant matrix multiplication attempted");
-      return ColumnVector ();
+      if (nr == 0 || nc == 0)
+	retval.resize (nr, 0.0);
+      else
+	{
+	  int ld = nr;
+
+	  retval.resize (nr);
+	  double *y = retval.fortran_vec ();
+
+	  F77_XFCN (dgemv, DGEMV, ("N", nr, nc, 1.0, m.data (), ld,
+				   a.data (), 1, 0.0, y, 1, 1L));
+
+	  if (f77_exception_encountered)
+	    (*current_liboctave_error_handler)
+	      ("unrecoverable error in dgemv");
+	}
     }
 
-  if (nr == 0 || nc == 0)
-    return ColumnVector (0);
-
-  int ld = nr;
-
-  double *y = new double [nr];
-
-  F77_FCN (dgemv, DGEMV) ("N", nr, nc, 1.0, m.data (), ld, a.data (),
-			  1, 0.0, y, 1, 1L);
-
-  return ColumnVector (y, nr);
+  return retval;
 }
 
 // diagonal matrix by column vector -> column vector operations
@@ -237,28 +246,33 @@
 ColumnVector
 operator * (const DiagMatrix& m, const ColumnVector& a)
 {
+  ColumnVector retval;
+
   int nr = m.rows ();
   int nc = m.cols ();
+
   int a_len = a.length ();
+
   if (nc != a_len)
+    (*current_liboctave_error_handler)
+      ("nonconformant matrix multiplication attempted");
+  else
     {
-      (*current_liboctave_error_handler)
-	("nonconformant matrix multiplication attempted");
-      return ColumnVector ();
+      if (nr == 0 || nc == 0)
+	retval.resize (nr, 0.0);
+      else
+	{
+	  retval.resize (nr);
+
+	  for (int i = 0; i < a_len; i++)
+	    retval.elem (i) = a.elem (i) * m.elem (i, i);
+
+	  for (int i = a_len; i < nr; i++)
+	    retval.elem (i) = 0.0;
+	}
     }
 
-  if (nc == 0 || nr == 0)
-    return ColumnVector (0);
-
-  ColumnVector result (nr);
-
-  for (int i = 0; i < a_len; i++)
-    result.elem (i) = a.elem (i) * m.elem (i, i);
-
-  for (int i = a_len; i < nr; i++)
-    result.elem (i) = 0.0;
-
-  return result;
+  return retval;
 }
 
 // other operations
--- a/liboctave/dRowVector.cc
+++ b/liboctave/dRowVector.cc
@@ -211,30 +211,39 @@
 RowVector
 operator * (const RowVector& v, const Matrix& a)
 {
+  RowVector retval;
+
   int len = v.length ();
+
   if (a.rows () != len)
+    (*current_liboctave_error_handler)
+      ("nonconformant vector multiplication attempted");
+  else
     {
-      (*current_liboctave_error_handler)
-	("nonconformant vector multiplication attempted");
-      return RowVector ();
+      int a_nr = a.rows ();
+      int a_nc = a.cols ();
+
+      if (len == 0)
+	retval.resize (a_nc, 0.0);
+      else
+	{
+	  // Transpose A to form A'*x == (x'*A)'
+
+	  int ld = a_nr;
+
+	  retval.resize (a_nc);
+	  double *y = retval.fortran_vec ();
+
+	  F77_XFCN (dgemv, DGEMV, ("T", a_nr, a_nc, 1.0, a.data (),
+				   ld, v.data (), 1, 0.0, y, 1, 1L));
+
+	  if (f77_exception_encountered)
+	    (*current_liboctave_error_handler)
+	      ("unrecoverable error in dgemv");
+	}
     }
 
-  if (len == 0)
-    return RowVector (a.cols (), 0.0);
-
-  // Transpose A to form A'*x == (x'*A)'
-
-  int a_nr = a.rows ();
-  int a_nc = a.cols ();
-
-  int ld = a_nr;
-
-  double *y = new double [a_nc];
-
-  F77_FCN (dgemv, DGEMV) ("T", a_nr, a_nc, 1.0, a.data (), ld,
-			  v.data (), 1, 0.0, y, 1, 1L);
-
-  return RowVector (y, a_nc);
+  return retval;
 }
 
 // other operations
@@ -353,15 +362,17 @@
 double
 operator * (const RowVector& v, const ColumnVector& a)
 {
+  double retval = 0.0;
+
   int len = v.length ();
+
   if (len != a.length ())
-    {
-      (*current_liboctave_error_handler)
-	("nonconformant vector multiplication attempted");
-      return 0.0;
-    }
+    (*current_liboctave_error_handler)
+      ("nonconformant vector multiplication attempted");
+  else if (len != 0)
+    retval = F77_FCN (ddot, DDOT) (len, v.data (), 1, a.data (), 1);
 
-  return F77_FCN (ddot, DDOT) (len, v.data (), 1, a.data (), 1);
+  return retval;
 }
 
 Complex