# HG changeset patch # User jwe # Date 824262642 0 # Node ID 5ab3c25a3cf9c88680d8ea10fc58d371977e9198 # Parent ec07d85b4152e0774c73e6f2a75792463cde21f0 [project @ 1996-02-14 01:50:42 by jwe] diff -r ec07d85b4152 -r 5ab3c25a3cf9 liboctave/CColVector.cc --- a/liboctave/CColVector.cc Wed Feb 14 01:19:57 1996 +0000 +++ b/liboctave/CColVector.cc Wed Feb 14 01:50:42 1996 +0000 @@ -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 diff -r ec07d85b4152 -r 5ab3c25a3cf9 liboctave/CRowVector.cc --- a/liboctave/CRowVector.cc Wed Feb 14 01:19:57 1996 +0000 +++ b/liboctave/CRowVector.cc Wed Feb 14 01:50:42 1996 +0000 @@ -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 diff -r ec07d85b4152 -r 5ab3c25a3cf9 liboctave/dColVector.cc --- a/liboctave/dColVector.cc Wed Feb 14 01:19:57 1996 +0000 +++ b/liboctave/dColVector.cc Wed Feb 14 01:50:42 1996 +0000 @@ -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 diff -r ec07d85b4152 -r 5ab3c25a3cf9 liboctave/dRowVector.cc --- a/liboctave/dRowVector.cc Wed Feb 14 01:19:57 1996 +0000 +++ b/liboctave/dRowVector.cc Wed Feb 14 01:50:42 1996 +0000 @@ -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