Mercurial > hg > octave-nkf
changeset 6214:4685a6a76229
[project @ 2006-12-08 22:15:03 by jwe]
author | jwe |
---|---|
date | Fri, 08 Dec 2006 22:15:04 +0000 |
parents | 0a259ae4375e |
children | 516d3071b34c |
files | src/ChangeLog src/ov-intx.h |
diffstat | 2 files changed, 86 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,21 @@ +2006-12-08 John W. Eaton <jwe@octave.org> + + * ov-intx.h (OCTAVE_VALUE_INT_MATRIX_T::array_value, + OCTAVE_VALUE_INT_MATRIX_T::complex_array_value, + OCTAVE_VALUE_INT_MATRIX_T::bool_array_value, + OCTAVE_VALUE_INT_MATRIX_T::char_array_value): + Use fortran_vec to avoid expensive indexing operator. + +2006-12-08 David Bateman <dbateman@free.fr> + + * ov-intx.h (OCTAVE_VALUE_INT_SCALAR_T::matrix_value, + OCTAVE_VALUE_INT_SCALAR_T::complex_matrix_value, + OCTAVE_VALUE_INT_MATRIX_T::matrix_value, + OCTAVE_VALUE_INT_MATRIX_T::comlex_matrix_value): New functions. + (OCTAVE_VALUE_INT_MATRIX_T::array_value, + OCTAVE_VALUE_INT_MATRIX_T::comlex_array_value): + Use octave_idx_type instead of int for indexing. + 2006-12-04 David Bateman <dbateman@free.fr> * xpow.cc (xpow (const Matrix&, double)): Add matrix type probing
--- a/src/ov-intx.h +++ b/src/ov-intx.h @@ -105,13 +105,50 @@ double scalar_value (bool = false) const { return double_value (); } + Matrix + matrix_value (bool = false) const + { + Matrix retval; + dim_vector dv = dims (); + if (dv.length () > 2) + error ("invalid conversion of %s to Matrix", type_name().c_str ()); + else + { + retval = Matrix (dv(0), dv(1)); + double *vec = retval.fortran_vec (); + octave_idx_type nel = matrix.numel (); + for (octave_idx_type i = 0; i < nel; i++) + vec[i] = double (matrix(i)); + } + return retval; + } + + ComplexMatrix + complex_matrix_value (bool = false) const + { + ComplexMatrix retval; + dim_vector dv = dims(); + if (dv.length () > 2) + error ("invalid conversion of %s to Matrix", type_name().c_str ()); + else + { + retval = ComplexMatrix (dv(0), dv(1)); + Complex *vec = retval.fortran_vec (); + octave_idx_type nel = matrix.numel (); + for (octave_idx_type i = 0; i < nel; i++) + vec[i] = Complex (double (matrix(i))); + } + return retval; + } + NDArray array_value (bool = false) const { NDArray retval (matrix.dims ()); - int nel = matrix.numel (); - for (int i = 0; i < nel; i++) - retval(i) = double (matrix(i)); + double *vec = retval.fortran_vec (); + octave_idx_type nel = matrix.numel (); + for (octave_idx_type i = 0; i < nel; i++) + vec[i] = double (matrix(i)); return retval; } @@ -119,9 +156,10 @@ complex_array_value (bool = false) const { ComplexNDArray retval (matrix.dims ()); - int nel = matrix.numel (); - for (int i = 0; i < nel; i++) - retval(i) = Complex (double (matrix(i))); + Complex *vec = retval.fortran_vec (); + octave_idx_type nel = matrix.numel (); + for (octave_idx_type i = 0; i < nel; i++) + vec[i] = Complex (double (matrix(i))); return retval; } @@ -135,8 +173,9 @@ if (warn && matrix.any_element_not_one_or_zero ()) gripe_logical_conversion (); + bool *vec = retval.fortran_vec (); for (octave_idx_type i = 0; i < nel; i++) - retval(i) = static_cast<bool>(matrix(i)); + vec[i] = static_cast<bool> (matrix(i)); return retval; } @@ -148,8 +187,9 @@ octave_idx_type nel = numel (); + char *vec = retval.fortran_vec (); for (octave_idx_type i = 0; i < nel; i++) - retval(i) = static_cast<char>(matrix(i)); + vec[i] = static_cast<char> (matrix(i)); return retval; } @@ -317,6 +357,24 @@ double scalar_value (bool = false) const { return double (scalar); } + + Matrix + matrix_value (bool = false) const + { + Matrix retval (1, 1); + retval(0,0) = double (scalar); + return retval; + } + + ComplexMatrix + complex_matrix_value (bool = false) const + { + ComplexMatrix retval (1, 1); + retval(0,0) = Complex (double (scalar)); + return retval; + } + + NDArray array_value (bool = false) const { @@ -341,7 +399,7 @@ if (warn && scalar != 0.0 && scalar != 1.0) gripe_logical_conversion (); - retval(0) = static_cast<bool>(scalar); + retval(0) = static_cast<bool> (scalar); return retval; } @@ -350,7 +408,7 @@ char_array_value (bool = false) const { charNDArray retval (dim_vector (1, 1)); - retval(0) = static_cast<char>(scalar); + retval(0) = static_cast<char> (scalar); return retval; }