Mercurial > hg > octave-lyh
diff liboctave/MArray.cc @ 1230:92609e161b29
[project @ 1995-04-10 01:08:57 by jwe]
author | jwe |
---|---|
date | Mon, 10 Apr 1995 01:14:34 +0000 |
parents | 9689615b34f2 |
children | f93b7fa5e113 |
line wrap: on
line diff
--- a/liboctave/MArray.cc +++ b/liboctave/MArray.cc @@ -77,10 +77,10 @@ } #define DO_VS_OP2(OP) \ - int l = length (); \ + int l = a.length (); \ if (l > 0) \ { \ - T *tmp = fortran_vec (); \ + T *tmp = a.fortran_vec (); \ for (int i = 0; i < l; i++) \ tmp[i] OP s; \ } @@ -88,10 +88,10 @@ #define DO_VV_OP2(OP) \ do \ { \ - T *tmp = fortran_vec (); \ - const T *rhs = a.data (); \ + T *a_tmp = a.fortran_vec (); \ + const T *b_tmp = b.data (); \ for (int i = 0; i < l; i++) \ - tmp[i] += rhs[i]; \ + a_tmp[i] += b_tmp[i]; \ } \ while (0) @@ -103,52 +103,52 @@ template <class T> MArray<T>& -MArray<T>::operator += (const T& s) +operator += (MArray<T>& a, const T& s) { DO_VS_OP2 (+=) - return *this; + return a; } template <class T> MArray<T>& -MArray<T>::operator -= (const T& s) +operator -= (MArray<T>& a, const T& s) { DO_VS_OP2 (-=) - return *this; + return a; } // Element by element MArray by MArray ops. template <class T> MArray<T>& -MArray<T>::operator += (const MArray<T>& a) +operator += (MArray<T>& a, const MArray<T>& b) { - int l = length (); + int l = a.length (); if (l > 0) { - if (l != a.length ()) + if (l != b.length ()) (*current_liboctave_error_handler) \ ("nonconformant += array operation attempted"); \ else DO_VV_OP2 (+=); } - return *this; + return a; } template <class T> MArray<T>& -MArray<T>::operator -= (const MArray<T>& a) +operator -= (MArray<T>& a, const MArray<T>& b) { - int l = length (); + int l = a.length (); if (l > 0) { - if (l != a.length ()) + if (l != b.length ()) (*current_liboctave_error_handler) \ ("nonconformant -= array operation attempted"); \ else DO_VV_OP2 (-=); } - return *this; + return a; } // Element by element MArray by scalar ops. @@ -234,29 +234,29 @@ template <class T> MArray2<T>& -MArray2<T>::operator += (const T& s) +operator += (MArray2<T>& a, const T& s) { DO_VS_OP2 (+=) - return *this; + return a; } template <class T> MArray2<T>& -MArray2<T>::operator -= (const T& s) +operator -= (MArray2<T>& a, const T& s) { DO_VS_OP2 (-=) - return *this; + return a; } // Element by element MArray2 by MArray2 ops. template <class T> MArray2<T>& -MArray2<T>::operator += (const MArray2<T>& a) +operator += (MArray2<T>& a, const MArray2<T>& b) { - int r = rows (); - int c = cols (); - if (r != a.rows () || c != a.cols ()) + int r = a.rows (); + int c = a.cols (); + if (r != b.rows () || c != b.cols ()) { (*current_liboctave_error_handler) ("nonconformant += array operation attempted"); @@ -269,16 +269,16 @@ DO_VV_OP2 (+=); } } - return *this; + return a; } template <class T> MArray2<T>& -MArray2<T>::operator -= (const MArray2<T>& a) +operator -= (MArray2<T>& a, const MArray2<T>& b) { - int r = rows (); - int c = cols (); - if (r != a.rows () || c != a.cols ()) + int r = a.rows (); + int c = a.cols (); + if (r != b.rows () || c != b.cols ()) { (*current_liboctave_error_handler) ("nonconformant -= array operation attempted"); @@ -291,7 +291,7 @@ DO_VV_OP2 (-=); } } - return *this; + return a; } // Element by element MArray2 by scalar ops. @@ -371,18 +371,48 @@ template <class T> MDiagArray<T>& -MDiagArray<T>::operator += (const MDiagArray<T>& a) +operator += (MDiagArray<T>& a, const MDiagArray<T>& b) { - // XXX FIXME XXX - return *this; + int r = a.rows (); + int c = a.cols (); + if (r != b.rows () || c != b.cols ()) + { + (*current_liboctave_error_handler) + ("nonconformant array " OP_STR " attempted"); + return MArray2<T> (); + } + else + { + int l = a.length (); + T *a_tmp = a.fortran_vec (); + const T *b_tmp = b.data (); + for (int i = 0; i < l; i++) + a_tmp[i] += b_tmp[i]; + } + return a; } template <class T> MDiagArray<T>& -MDiagArray<T>::operator -= (const MDiagArray<T>& a) +operator -= (MDiagArray<T>& a, const MDiagArray<T>& b) { - // XXX FIXME XXX - return *this; + int r = a.rows (); + int c = a.cols (); + if (r != b.rows () || c != b.cols ()) + { + (*current_liboctave_error_handler) + ("nonconformant array " OP_STR " attempted"); + return MArray2<T> (); + } + else + { + int l = a.length (); + T *a_tmp = a.fortran_vec (); + const T *b_tmp = b.data (); + for (int i = 0; i < l; i++) + a_tmp[i] -= b_tmp[i]; + } + return a; } // Element by element MDiagArray by scalar ops.