Mercurial > hg > octave-nkf
diff src/pt-const.cc @ 2338:18953de8c308
[project @ 1996-07-19 20:28:11 by jwe]
author | jwe |
---|---|
date | Fri, 19 Jul 1996 20:28:12 +0000 |
parents | 5a3f1d00a474 |
children | c2c1482c34c8 |
line wrap: on
line diff
--- 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; + } } } }