Mercurial > hg > octave-terminal
changeset 2410:367485171742
[project @ 1996-10-15 16:50:27 by jwe]
author | jwe |
---|---|
date | Tue, 15 Oct 1996 16:50:28 +0000 |
parents | 47e5f57fb4bd |
children | 31a279f31070 |
files | src/ov-base.h src/ov-complex.cc src/ov-complex.h src/ov-cx-mat.cc src/ov-cx-mat.h src/ov-range.cc src/ov-range.h src/ov-re-mat.cc src/ov-re-mat.h src/ov.cc src/ov.h |
diffstat | 11 files changed, 100 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ov-base.h +++ b/src/ov-base.h @@ -67,8 +67,11 @@ void operator delete (void *p, size_t size); #endif - numeric_conv_fcn numeric_conversion_function (void) const - { return (numeric_conv_fcn) 0; } + type_conv_fcn numeric_conversion_function (void) const + { return (type_conv_fcn) 0; } + + octave_value *try_narrowing_conversion (void) + { return (octave_value *) 0; } octave_value index (const octave_value_list& idx) const;
--- a/src/ov-complex.cc +++ b/src/ov-complex.cc @@ -31,7 +31,9 @@ #include "lo-ieee.h" #include "oct-obj.h" +#include "ops.h" #include "ov-complex.h" +#include "ov-scalar.h" #include "gripes.h" #include "pr-output.h" @@ -39,6 +41,17 @@ const string octave_complex::t_name ("complex scalar"); +octave_value * +octave_complex::try_narrowing_conversion (void) +{ + octave_value *retval = 0; + + if (imag (scalar) == 0.0) + retval = new octave_scalar (::real (scalar)); + + return retval; +} + static inline bool valid_scalar_indices (const octave_value_list& args) {
--- a/src/ov-complex.h +++ b/src/ov-complex.h @@ -70,6 +70,8 @@ void operator delete (void *p, size_t size); #endif + octave_value *try_narrowing_conversion (void); + octave_value index (const octave_value_list& idx) const; int rows (void) const { return 1; }
--- a/src/ov-cx-mat.cc +++ b/src/ov-cx-mat.cc @@ -33,7 +33,11 @@ #include "gripes.h" #include "oct-obj.h" +#include "ops.h" +#include "ov-complex.h" #include "ov-cx-mat.h" +#include "ov-re-mat.h" +#include "ov-scalar.h" #include "pr-output.h" int octave_complex_matrix::t_id = -1; @@ -52,7 +56,30 @@ matrix ((pcv < 0 && Vprefer_column_vectors) || pcv ? ComplexMatrix (v) : ComplexMatrix (v.transpose ())) { } -extern void assign (Array2<Complex>&, const Array2<Complex>&); +octave_value * +octave_complex_matrix::try_narrowing_conversion (void) +{ + octave_value *retval = 0; + + int nr = matrix.rows (); + int nc = matrix.cols (); + + if (nr == 1 && nc == 1) + { + Complex c = matrix (0, 0); + + if (imag (c) == 0.0) + retval = new octave_scalar (::real (c)); + else + retval = new octave_complex (c); + } + else if (nr == 0 && nc == 0) + retval = new octave_matrix (Matrix ()); + else if (matrix.all_elements_are_real ()) + retval = new octave_matrix (::real (matrix)); + + return retval; +} octave_value octave_complex_matrix::index (const octave_value_list& idx) const @@ -88,6 +115,8 @@ return retval; } +extern void assign (Array2<Complex>&, const Array2<Complex>&); + void octave_complex_matrix::assign (const octave_value_list& idx, const ComplexMatrix& rhs)
--- a/src/ov-cx-mat.h +++ b/src/ov-cx-mat.h @@ -77,6 +77,8 @@ void operator delete (void *p, size_t size); #endif + octave_value *try_narrowing_conversion (void); + octave_value index (const octave_value_list& idx) const; void assign (const octave_value_list& idx, const ComplexMatrix& rhs);
--- a/src/ov-range.cc +++ b/src/ov-range.cc @@ -35,6 +35,7 @@ #include "ops.h" #include "ov-range.h" #include "ov-re-mat.h" +#include "ov-scalar.h" #include "pr-output.h" int octave_range::t_id = -1; @@ -49,12 +50,34 @@ return new octave_matrix (v.matrix_value ()); } -octave_value::numeric_conv_fcn +octave_value::type_conv_fcn octave_range::numeric_conversion_function (void) const { return default_numeric_conversion_function; } +octave_value * +octave_range::try_narrowing_conversion (void) +{ + octave_value *retval = 0; + + switch (range.nelem ()) + { + case 1: + retval = new octave_scalar (range.base ()); + break; + + case 0: + retval = new octave_matrix (Matrix ()); + break; + + default: + break; + } + + return retval; +} + double octave_range::double_value (bool) const {
--- a/src/ov-range.h +++ b/src/ov-range.h @@ -85,7 +85,9 @@ void operator delete (void *p, size_t size); #endif - numeric_conv_fcn numeric_conversion_function (void) const; + type_conv_fcn numeric_conversion_function (void) const; + + octave_value *try_narrowing_conversion (void); idx_vector index_vector (void) const { return idx_vector (range); }
--- a/src/ov-re-mat.cc +++ b/src/ov-re-mat.cc @@ -35,6 +35,8 @@ #include "gripes.h" #include "mappers.h" #include "oct-obj.h" +#include "ops.h" +#include "ov-scalar.h" #include "ov-re-mat.h" #include "pr-output.h" @@ -54,6 +56,20 @@ #include <iostream.h> +octave_value * +octave_matrix::try_narrowing_conversion (void) +{ + octave_value *retval = 0; + + int nr = matrix.rows (); + int nc = matrix.cols (); + + if (nr == 1 && nc == 1) + retval = new octave_scalar (matrix (0, 0)); + + return retval; +} + octave_value octave_matrix::index (const octave_value_list& idx) const {
--- a/src/ov-re-mat.h +++ b/src/ov-re-mat.h @@ -77,6 +77,8 @@ void operator delete (void *p, size_t size); #endif + octave_value *try_narrowing_conversion (void); + octave_value index (const octave_value_list& idx) const; void assign (const octave_value_list& idx, const Matrix& rhs);
--- a/src/ov.cc +++ b/src/ov.cc @@ -303,7 +303,7 @@ void octave_value::maybe_mutate (void) { - octave_value *tmp = rep->try_narrow_conversion (); + octave_value *tmp = rep->try_narrowing_conversion (); if (tmp && tmp != rep) {
--- a/src/ov.h +++ b/src/ov.h @@ -178,8 +178,8 @@ void maybe_mutate (void); - virtual octave_value *try_narrow_conversion (void) - { return rep->try_narrow_conversion (); } + virtual octave_value *try_narrowing_conversion (void) + { return rep->try_narrowing_conversion (); } virtual octave_value index (const octave_value_list& idx) const { return rep->index (idx); }