Mercurial > hg > octave-nkf
changeset 2338:18953de8c308
[project @ 1996-07-19 20:28:11 by jwe]
author | jwe |
---|---|
date | Fri, 19 Jul 1996 20:28:12 +0000 |
parents | cdf7ba6b3c9c |
children | 8d7454ead97e |
files | src/ChangeLog src/pt-const.cc |
diffstat | 2 files changed, 121 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +Fri Jul 19 15:24:36 1996 John W. Eaton <jwe@bevo.che.wisc.edu> + + * pt-const.cc: When creating octave_value_reps from ComplexMatrix + values, check to see if all the elements are actually real. + Tue Jul 16 10:53:42 1996 John W. Eaton <jwe@bevo.che.wisc.edu> * input.cc (decode_prompt_string): Swap meanings of \h anbd \H.
--- a/src/pt-const.cc +++ b/src/pt-const.cc @@ -154,6 +154,8 @@ struct_indent -= 2; } +// XXX FIXME XXX -- these should be member functions. + static bool any_element_is_complex (const ComplexMatrix& a) { @@ -168,6 +170,42 @@ return false; } +static bool +any_element_is_complex (const ComplexDiagMatrix& d) +{ + int len = d.length (); + + for (int i = 0; i < len; i++) + if (imag (d (i, i)) != 0.0) + return true; + + return false; +} + +static bool +any_element_is_complex (const ComplexRowVector& v) +{ + int len = v.length (); + + for (int i = 0; i < len; i++) + if (imag (v (i)) != 0.0) + return true; + + return false; +} + +static bool +any_element_is_complex (const ComplexColumnVector& v) +{ + int len = v.length (); + + for (int i = 0; i < len; i++) + if (imag (v (i)) != 0.0) + return true; + + return false; +} + // The following three variables could be made static members of the // octave_value class. @@ -481,6 +519,10 @@ type_tag = scalar_constant; } +// XXX FIXME XXX -- perhaps these constructors should just do the +// obvious thing and then call maybe_mutate() instead of duplicating +// most of that logic several times here... + OCT_VAL_REP::octave_value_rep (const Matrix& m) { if (m.rows () == 1 && m.columns () == 1) @@ -606,6 +648,11 @@ type_tag = complex_scalar_constant; } } + else if (! any_element_is_complex (*complex_matrix)) + { + matrix = new Matrix (::real (m)); + type_tag = matrix_constant; + } else { complex_matrix = new ComplexMatrix (m); @@ -630,6 +677,11 @@ type_tag = complex_scalar_constant; } } + else if (! any_element_is_complex (d)) + { + matrix = new Matrix (::real (d)); + type_tag = matrix_constant; + } else { complex_matrix = new ComplexMatrix (d); @@ -664,19 +716,41 @@ if (pcv) { - ComplexMatrix m (len, 1); - for (int i = 0; i < len; i++) - m (i, 0) = v (i); - complex_matrix = new ComplexMatrix (m); - type_tag = complex_matrix_constant; + if (! any_element_is_complex (v)) + { + Matrix m (len, 1); + for (int i = 0; i < len; i++) + m (i, 0) = ::real (v (i)); + matrix = new Matrix (m); + type_tag = matrix_constant; + } + else + { + ComplexMatrix m (len, 1); + for (int i = 0; i < len; i++) + m (i, 0) = v (i); + complex_matrix = new ComplexMatrix (m); + type_tag = complex_matrix_constant; + } } else { - ComplexMatrix m (1, len); - for (int i = 0; i < len; i++) - m (0, i) = v (i); - complex_matrix = new ComplexMatrix (m); - type_tag = complex_matrix_constant; + if (! any_element_is_complex (v)) + { + Matrix m (len, 1); + for (int i = 0; i < len; i++) + m (0, i) = ::real (v (i)); + matrix = new Matrix (m); + type_tag = matrix_constant; + } + else + { + ComplexMatrix m (1, len); + for (int i = 0; i < len; i++) + m (0, i) = v (i); + complex_matrix = new ComplexMatrix (m); + type_tag = complex_matrix_constant; + } } } } @@ -708,19 +782,41 @@ if (pcv) { - ComplexMatrix m (len, 1); - for (int i = 0; i < len; i++) - m (i, 0) = v (i); - complex_matrix = new ComplexMatrix (m); - type_tag = complex_matrix_constant; + if (! any_element_is_complex (v)) + { + Matrix m (len, 1); + for (int i = 0; i < len; i++) + m (i, 0) = ::real (v (i)); + matrix = new Matrix (m); + type_tag = matrix_constant; + } + else + { + ComplexMatrix m (len, 1); + for (int i = 0; i < len; i++) + m (i, 0) = v (i); + complex_matrix = new ComplexMatrix (m); + type_tag = complex_matrix_constant; + } } else { - ComplexMatrix m (1, len); - for (int i = 0; i < len; i++) - m (0, i) = v (i); - complex_matrix = new ComplexMatrix (m); - type_tag = complex_matrix_constant; + if (! any_element_is_complex (v)) + { + Matrix m (len, 1); + for (int i = 0; i < len; i++) + m (0, i) = ::real (v (i)); + matrix = new Matrix (m); + type_tag = matrix_constant; + } + else + { + ComplexMatrix m (1, len); + for (int i = 0; i < len; i++) + m (0, i) = v (i); + complex_matrix = new ComplexMatrix (m); + type_tag = complex_matrix_constant; + } } } }