# HG changeset patch # User John W. Eaton # Date 1270232914 14400 # Node ID 4e64fbbd5c5869109b5c9bce5fafd0a2315752be # Parent b4e14e628fc9ba39a815ebaca453e81b0da82fe1 allow non-integer values in ranges used for array indexing diff --git a/liboctave/Array-util.cc b/liboctave/Array-util.cc --- a/liboctave/Array-util.cc +++ b/liboctave/Array-util.cc @@ -694,11 +694,16 @@ is1d ? "I" : "..,I,..", idx, ext); } -void gripe_invalid_index (void) +void gripe_invalid_index (bool err) { const char *err_id = error_id_invalid_index; - (*current_liboctave_error_with_id_handler) - (err_id, "subscript indices must be either positive integers or logicals."); + + if (err) + (*current_liboctave_error_with_id_handler) + (err_id, "subscript indices must be either positive integers or logicals"); + else + (*current_liboctave_warning_with_id_handler) + (err_id, "non-integer subscripts in index expression"); } // FIXME -- the following is a common error message to resize, diff --git a/liboctave/Array-util.h b/liboctave/Array-util.h --- a/liboctave/Array-util.h +++ b/liboctave/Array-util.h @@ -114,7 +114,7 @@ extern void OCTAVE_API gripe_del_index_out_of_range (bool is1d, octave_idx_type iext, octave_idx_type ext); -extern void OCTAVE_API gripe_invalid_index (void); +extern void OCTAVE_API gripe_invalid_index (bool err = true); extern void OCTAVE_API gripe_invalid_resize (void); diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,11 @@ +2010-04-02 John W. Eaton + + * idx-vector.cc (idx_vector::idx_vector (const Range&)): + Move here from idx-vector.h. Allow non-integer values in ranges, + but warn by default (for Matlab compatibility). + * Array-util.h, Array-util.cc (gripe_invalid_index): New arg, ERR. + If ERR is false, generate warning instead of error. + 2010-04-02 Jaroslav Hajek * Sparse.cc (Sparse::maybe_delete_elements): Rewrite. Optimize for diff --git a/liboctave/idx-vector.cc b/liboctave/idx-vector.cc --- a/liboctave/idx-vector.cc +++ b/liboctave/idx-vector.cc @@ -770,6 +770,23 @@ rep = new idx_mask_rep (bnda, nnz); } +idx_vector::idx_vector (const Range& r) + : rep (0) +{ + if (r.nelem () > 0 && ! r.all_elements_are_ints ()) + { + gripe_invalid_index (false); + + Matrix m = r.matrix_value (); + + rep = new idx_vector_rep (m.map (xround)); + } + else + rep = new idx_range_rep (r); + + chkerr (); +} + bool idx_vector::maybe_reduce (octave_idx_type n, const idx_vector& j, octave_idx_type nj) { diff --git a/liboctave/idx-vector.h b/liboctave/idx-vector.h --- a/liboctave/idx-vector.h +++ b/liboctave/idx-vector.h @@ -521,9 +521,7 @@ idx_vector (const Array& nda); - idx_vector (const Range& r) - : rep (new idx_range_rep (r)) - { chkerr (); } + idx_vector (const Range& r); idx_vector (const Sparse& nda) : rep (new idx_vector_rep (nda)) { chkerr (); }