Mercurial > hg > octave-lyh
changeset 6457:a58b5981ab65
[project @ 2007-03-26 16:51:46 by jwe]
author | jwe |
---|---|
date | Mon, 26 Mar 2007 16:51:47 +0000 |
parents | 7f5316cadaa2 |
children | 6588b4fe0869 |
files | liboctave/ChangeLog liboctave/Range.cc liboctave/idx-vector.cc |
diffstat | 3 files changed, 22 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2007-03-26 David Bateman <dbateman@free.fr> + + * Range.cc (Range::all_elements_are_ints): Improve check. + * + 2007-03-26 John W. Eaton <jwe@octave.org> * chNDArray.cc, chMatrix.cc: Also generate comparison and bool ops.
--- a/liboctave/Range.cc +++ b/liboctave/Range.cc @@ -39,11 +39,12 @@ Range::all_elements_are_ints (void) const { // If the base and increment are ints, the final value in the range - // will also be an integer, even if the limit is not. + // will also be an integer, even if the limit is not. If there is one + // or fewer elements only the base needs to be an integer return (! (xisnan (rng_base) || xisnan (rng_inc)) - && NINTbig (rng_base) == rng_base - && NINTbig (rng_inc) == rng_inc); + && (NINTbig (rng_base) == rng_base || rng_nelem < 1) + && (NINTbig (rng_inc) == rng_inc || rng_nelem <= 1)); } Matrix
--- a/liboctave/idx-vector.cc +++ b/liboctave/idx-vector.cc @@ -183,27 +183,25 @@ return; } - double b = r.base (); - double step = r.inc (); - data = new octave_idx_type [len]; - bool conversion_error = false; + // If all elements are ints, we can generate the indexes as integers + // and save tons of tests. - for (octave_idx_type i = 0; i < len; i++) - { - double val = b + i * step; + if (r.all_elements_are_ints ()) + { + octave_idx_type b = static_cast<octave_idx_type> (r.base ()); + octave_idx_type step = static_cast<octave_idx_type> (r.inc ()); - if (idx_is_inf_or_nan (val)) - return; - else - data[i] = tree_to_mat_idx (val, conversion_error); + data[0] = b - 1; + for (octave_idx_type i = 1; i < len; i++) + data[i] = data[i-1] + step; - if (conversion_error) - return; + init_state (); } - - init_state (); + else + (*current_liboctave_error_handler) + ("expecting integer index, found non integer Range"); } IDX_VEC_REP::idx_vector_rep (double d)