Mercurial > hg > octave-lyh
diff liboctave/CRowVector.cc @ 1205:8302fab9fe24
[project @ 1995-04-04 02:05:01 by jwe]
author | jwe |
---|---|
date | Tue, 04 Apr 1995 02:05:01 +0000 |
parents | b6360f2d4fa6 |
children | 0bf4d2b7def4 |
line wrap: on
line diff
--- a/liboctave/CRowVector.cc +++ b/liboctave/CRowVector.cc @@ -63,57 +63,6 @@ elem (i) = a.elem (i); } -#if 0 -ComplexRowVector& -ComplexRowVector::resize (int n) -{ - if (n < 0) - { - (*current_liboctave_error_handler) - ("can't resize to negative dimension"); - return *this; - } - - Complex *new_data = 0; - if (n > 0) - { - new_data = new Complex [n]; - int min_len = len < n ? len : n; - - for (int i = 0; i < min_len; i++) - new_data[i] = data[i]; - } - - delete [] data; - len = n; - data = new_data; - - return *this; -} - -ComplexRowVector& -ComplexRowVector::resize (int n, double val) -{ - int old_len = len; - resize (n); - for (int i = old_len; i < len; i++) - data[i] = val; - - return *this; -} - -ComplexRowVector& -ComplexRowVector::resize (int n, const Complex& val) -{ - int old_len = len; - resize (n); - for (int i = old_len; i < len; i++) - data[i] = val; - - return *this; -} -#endif - int ComplexRowVector::operator == (const ComplexRowVector& a) const { @@ -255,26 +204,6 @@ return ComplexColumnVector (dup (data (), len), len); } -RowVector -real (const ComplexRowVector& a) -{ - int a_len = a.length (); - RowVector retval; - if (a_len > 0) - retval = RowVector (real_dup (a.data (), a_len), a_len); - return retval; -} - -RowVector -imag (const ComplexRowVector& a) -{ - int a_len = a.length (); - RowVector retval; - if (a_len > 0) - retval = RowVector (imag_dup (a.data (), a_len), a_len); - return retval; -} - ComplexRowVector conj (const ComplexRowVector& a) { @@ -414,6 +343,34 @@ return ComplexRowVector (divide (v.data (), len, s), len); } +ComplexRowVector +operator + (const RowVector& v, const Complex& s) +{ + int len = v.length (); + return ComplexRowVector (add (v.data (), len, s), len); +} + +ComplexRowVector +operator - (const RowVector& v, const Complex& s) +{ + int len = v.length (); + return ComplexRowVector (subtract (v.data (), len, s), len); +} + +ComplexRowVector +operator * (const RowVector& v, const Complex& s) +{ + int len = v.length (); + return ComplexRowVector (multiply (v.data (), len, s), len); +} + +ComplexRowVector +operator / (const RowVector& v, const Complex& s) +{ + int len = v.length (); + return ComplexRowVector (divide (v.data (), len, s), len); +} + // scalar by row vector -> row vector operations ComplexRowVector @@ -444,32 +401,28 @@ return ComplexRowVector (divide (s, a.data (), a_len), a_len); } -// row vector by column vector -> scalar - -Complex -operator * (const ComplexRowVector& v, const ColumnVector& a) +ComplexRowVector +operator + (const Complex& s, const RowVector& a) { - ComplexColumnVector tmp (a); - return v * tmp; + return ComplexRowVector (); } -Complex -operator * (const ComplexRowVector& v, const ComplexColumnVector& a) +ComplexRowVector +operator - (const Complex& s, const RowVector& a) { - int len = v.length (); - if (len != a.length ()) - { - (*current_liboctave_error_handler) - ("nonconformant vector multiplication attempted"); - return 0.0; - } + return ComplexRowVector (); +} - Complex retval (0.0, 0.0); +ComplexRowVector +operator * (const Complex& s, const RowVector& a) +{ + return ComplexRowVector (); +} - for (int i = 0; i < len; i++) - retval += v.elem (i) * a.elem (i); - - return retval; +ComplexRowVector +operator / (const Complex& s, const RowVector& a) +{ + return ComplexRowVector (); } // row vector by matrix -> row vector @@ -507,6 +460,13 @@ return ComplexRowVector (y, len); } +ComplexRowVector +operator * (const RowVector& v, const ComplexMatrix& a) +{ + ComplexRowVector tmp (v); + return tmp * a; +} + // row vector by row vector -> row vector operations ComplexRowVector @@ -544,6 +504,40 @@ } ComplexRowVector +operator + (const RowVector& v, const ComplexRowVector& a) +{ + int len = v.length (); + if (len != a.length ()) + { + (*current_liboctave_error_handler) + ("nonconformant vector addition attempted"); + return ComplexRowVector (); + } + + if (len == 0) + return ComplexRowVector (0); + + return ComplexRowVector (add (v.data (), a.data (), len), len); +} + +ComplexRowVector +operator - (const RowVector& v, const ComplexRowVector& a) +{ + int len = v.length (); + if (len != a.length ()) + { + (*current_liboctave_error_handler) + ("nonconformant vector subtraction attempted"); + return ComplexRowVector (); + } + + if (len == 0) + return ComplexRowVector (0); + + return ComplexRowVector (subtract (v.data (), a.data (), len), len); +} + +ComplexRowVector product (const ComplexRowVector& v, const RowVector& a) { int len = v.length (); @@ -577,6 +571,40 @@ return ComplexRowVector (divide (v.data (), a.data (), len), len); } +ComplexRowVector +product (const RowVector& v, const ComplexRowVector& a) +{ + int len = v.length (); + if (len != a.length ()) + { + (*current_liboctave_error_handler) + ("nonconformant vector product attempted"); + return ComplexRowVector (); + } + + if (len == 0) + return ComplexRowVector (0); + + return ComplexRowVector (multiply (v.data (), a.data (), len), len); +} + +ComplexRowVector +quotient (const RowVector& v, const ComplexRowVector& a) +{ + int len = v.length (); + if (len != a.length ()) + { + (*current_liboctave_error_handler) + ("nonconformant vector quotient attempted"); + return ComplexRowVector (); + } + + if (len == 0) + return ComplexRowVector (0); + + return ComplexRowVector (divide (v.data (), a.data (), len), len); +} + // other operations ComplexRowVector @@ -587,16 +615,6 @@ return b; } -RowVector -map (d_c_Mapper f, const ComplexRowVector& a) -{ - int a_len = a.length (); - RowVector b (a_len); - for (int i = 0; i < a_len; i++) - b.elem (i) = f (a.elem (i)); - return b; -} - void ComplexRowVector::map (c_c_Mapper f) { @@ -604,24 +622,6 @@ elem (i) = f (elem (i)); } -ComplexRowVector -linspace (const Complex& x1, const Complex& x2, int n) -{ - ComplexRowVector retval; - - if (n > 0) - { - retval.resize (n); - Complex delta = (x2 - x1) / (n - 1); - retval.elem (0) = x1; - for (int i = 1; i < n-1; i++) - retval.elem (i) = x1 + i * delta; - retval.elem (n-1) = x2; - } - - return retval; -} - Complex ComplexRowVector::min (void) const { @@ -695,6 +695,56 @@ return is; } +// row vector by column vector -> scalar + +// row vector by column vector -> scalar + +Complex +operator * (const ComplexRowVector& v, const ColumnVector& a) +{ + ComplexColumnVector tmp (a); + return v * tmp; +} + +Complex +operator * (const ComplexRowVector& v, const ComplexColumnVector& a) +{ + int len = v.length (); + if (len != a.length ()) + { + (*current_liboctave_error_handler) + ("nonconformant vector multiplication attempted"); + return 0.0; + } + + Complex retval (0.0, 0.0); + + for (int i = 0; i < len; i++) + retval += v.elem (i) * a.elem (i); + + return retval; +} + +// other operations + +ComplexRowVector +linspace (const Complex& x1, const Complex& x2, int n) +{ + ComplexRowVector retval; + + if (n > 0) + { + retval.resize (n); + Complex delta = (x2 - x1) / (n - 1); + retval.elem (0) = x1; + for (int i = 1; i < n-1; i++) + retval.elem (i) = x1 + i * delta; + retval.elem (n-1) = x2; + } + + return retval; +} + /* ;;; Local Variables: *** ;;; mode: C++ ***