Mercurial > hg > octave-lyh
changeset 10486:4e64fbbd5c58
allow non-integer values in ranges used for array indexing
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 02 Apr 2010 14:28:34 -0400 |
parents | b4e14e628fc9 |
children | 942386d6d1a5 |
files | liboctave/Array-util.cc liboctave/Array-util.h liboctave/ChangeLog liboctave/idx-vector.cc liboctave/idx-vector.h |
diffstat | 5 files changed, 35 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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,
--- 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);
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,11 @@ +2010-04-02 John W. Eaton <jwe@octave.org> + + * 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 <highegg@gmail.com> * Sparse.cc (Sparse<T>::maybe_delete_elements): Rewrite. Optimize for
--- 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) {
--- a/liboctave/idx-vector.h +++ b/liboctave/idx-vector.h @@ -521,9 +521,7 @@ idx_vector (const Array<bool>& nda); - idx_vector (const Range& r) - : rep (new idx_range_rep (r)) - { chkerr (); } + idx_vector (const Range& r); idx_vector (const Sparse<bool>& nda) : rep (new idx_vector_rep (nda)) { chkerr (); }