Mercurial > hg > octave-lojdl
changeset 10487:942386d6d1a5
style fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 02 Apr 2010 15:15:41 -0400 |
parents | 4e64fbbd5c58 |
children | acf2b099532d |
files | liboctave/Array-util.cc liboctave/ChangeLog liboctave/idx-vector.cc liboctave/idx-vector.h |
diffstat | 4 files changed, 228 insertions(+), 129 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array-util.cc +++ b/liboctave/Array-util.cc @@ -486,12 +486,15 @@ struct sub2ind_helper { octave_idx_type *ind, n; + sub2ind_helper (octave_idx_type *_ind, octave_idx_type _n) : ind(_ind), n(_n) { } + void operator ()(octave_idx_type k) { (*ind++ *= n) += k; } }; -idx_vector sub2ind (const dim_vector& dv, const Array<idx_vector>& idxa) +idx_vector +sub2ind (const dim_vector& dv, const Array<idx_vector>& idxa) { idx_vector retval; octave_idx_type len = idxa.length (); @@ -561,7 +564,8 @@ return retval; } -Array<idx_vector> ind2sub (const dim_vector& dv, const idx_vector& idx) +Array<idx_vector> +ind2sub (const dim_vector& dv, const idx_vector& idx) { octave_idx_type len = idx.length (0), n = dv.length (); Array<idx_vector> retval(n, 1); @@ -633,6 +637,7 @@ gripe_nonconformant (const char *op, int op1_len, int op2_len) { const char *err_id = error_id_nonconformant_args; + (*current_liboctave_error_with_id_handler) (err_id, "%s: nonconformant arguments (op1 len: %d, op2 len: %d)", op, op1_len, op2_len); @@ -643,6 +648,7 @@ int op2_nr, int op2_nc) { const char *err_id = error_id_nonconformant_args; + (*current_liboctave_error_with_id_handler) (err_id, "%s: nonconformant arguments (op1 is %dx%d, op2 is %dx%d)", op, op1_nr, op1_nc, op2_nr, op2_nc); @@ -653,6 +659,7 @@ const dim_vector& op2_dims) { const char *err_id = error_id_nonconformant_args; + std::string op1_dims_str = op1_dims.str (); std::string op2_dims_str = op2_dims.str (); @@ -661,10 +668,12 @@ op, op1_dims_str.c_str (), op2_dims_str.c_str ()); } -void gripe_index_out_of_range (int nd, int dim, - octave_idx_type idx, octave_idx_type ext) +void +gripe_index_out_of_range (int nd, int dim, octave_idx_type idx, + octave_idx_type ext) { const char *err_id = error_id_index_out_of_bounds; + switch (nd) { case 1: @@ -672,11 +681,13 @@ (err_id, "A(I): index out of bounds; value %d out of bound %d", idx, ext); break; + case 2: (*current_liboctave_error_with_id_handler) (err_id, "A(I,J): %s index out of bounds; value %d out of bound %d", (dim == 1) ? "row" : "column", idx, ext); break; + default: (*current_liboctave_error_with_id_handler) (err_id, "A(I,J,...): index to dimension %d out of bounds; value %d out of bound %d", @@ -685,16 +696,19 @@ } } -void gripe_del_index_out_of_range (bool is1d, octave_idx_type idx, - octave_idx_type ext) +void +gripe_del_index_out_of_range (bool is1d, octave_idx_type idx, + octave_idx_type ext) { const char *err_id = error_id_index_out_of_bounds; + (*current_liboctave_error_with_id_handler) (err_id, "A(%s) = []: index out of bounds; value %d out of bound %d", is1d ? "I" : "..,I,..", idx, ext); } -void gripe_invalid_index (bool err) +void +gripe_invalid_index (bool err) { const char *err_id = error_id_invalid_index; @@ -712,7 +726,9 @@ // Anyway, propagating various error messages into procedure is, IMHO, // a nonsense. If anything, we should change error handling here (and // throughout liboctave) to allow custom handling of errors -void gripe_invalid_resize (void) + +void +gripe_invalid_resize (void) { (*current_liboctave_error_with_id_handler) ("Octave:invalid-resize",
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,7 @@ +2010-04-02 John W. Eaton <jwe@octave.org> + + * Array-util.cc, idx-vector.cc, idx-vector.h: Style fixes. + 2010-04-02 John W. Eaton <jwe@octave.org> * idx-vector.cc (idx_vector::idx_vector (const Range&)):
--- a/liboctave/idx-vector.cc +++ b/liboctave/idx-vector.cc @@ -226,7 +226,10 @@ { if (i <= 0) conv_error = true; - if (ext < i) ext = i; + + if (ext < i) + ext = i; + return i - 1; } @@ -234,6 +237,7 @@ convert_index (double x, bool& conv_error, octave_idx_type& ext) { octave_idx_type i = static_cast<octave_idx_type> (x); + if (static_cast<double> (i) != x) conv_error = true; @@ -252,6 +256,7 @@ octave_idx_type& ext) { octave_idx_type i = octave_int<octave_idx_type> (x).value (); + return convert_index (i, conv_error, ext); } @@ -261,8 +266,11 @@ idx_vector::idx_scalar_rep::idx_scalar_rep (T x) { octave_idx_type dummy = 0; + data = convert_index (x, err, dummy); - if (err) gripe_invalid_index (); + + if (err) + gripe_invalid_index (); } idx_vector::idx_scalar_rep::idx_scalar_rep (octave_idx_type i) @@ -278,7 +286,9 @@ octave_idx_type idx_vector::idx_scalar_rep::checkelem (octave_idx_type i) const { - if (i != 0) gripe_index_out_of_range (); + if (i != 0) + gripe_index_out_of_range (); + return data; } @@ -321,7 +331,8 @@ d[i] = convert_index (nda.xelem (i), err, ext); data = d; - if (err) gripe_invalid_index (); + if (err) + gripe_invalid_index (); } } @@ -345,14 +356,15 @@ ext = max + 1; - if (err) gripe_invalid_index (); + if (err) + gripe_invalid_index (); } } idx_vector::idx_vector_rep::idx_vector_rep (const Array<octave_idx_type>& inda, octave_idx_type _ext, direct) : data (inda.data ()), len (inda.numel ()), ext (_ext), - aowner (new Array<octave_idx_type> (inda)), orig_dims (inda.dims ()) + aowner (new Array<octave_idx_type> (inda)), orig_dims (inda.dims ()) { // No checking. if (ext < 0) @@ -399,7 +411,8 @@ octave_idx_type k = 0; for (octave_idx_type i = 0; i < ntot; i++) - if (bnda.xelem (i)) d[k++] = i; + if (bnda.xelem (i)) + d[k++] = i; data = d; @@ -595,9 +608,12 @@ idx_vector::idx_vector_rep::print (std::ostream& os) const { os << '['; + for (octave_idx_type ii = 0; ii < len - 1; ii++) os << data[ii] << ',' << ' '; - if (len > 0) os << data[len-1]; os << ']'; + + if (len > 0) + os << data[len-1]; os << ']'; return os; } @@ -708,9 +724,12 @@ idx_vector::idx_mask_rep::print (std::ostream& os) const { os << '['; + for (octave_idx_type ii = 0; ii < ext - 1; ii++) os << data[ii] << ',' << ' '; - if (ext > 0) os << data[ext-1]; os << ']'; + + if (ext > 0) + os << data[ext-1]; os << ']'; return os; } @@ -787,8 +806,9 @@ chkerr (); } -bool idx_vector::maybe_reduce (octave_idx_type n, const idx_vector& j, - octave_idx_type nj) +bool +idx_vector::maybe_reduce (octave_idx_type n, const idx_vector& j, + octave_idx_type nj) { bool reduced = false; @@ -818,6 +838,7 @@ // (:,:) reduces to (:) reduced = true; break; + case class_scalar: { // (i,:) reduces to a range. @@ -825,8 +846,9 @@ octave_idx_type k = r->get_data (); *this = new idx_range_rep (k, nj, n, DIRECT); reduced = true; - break; } + break; + case class_range: { // (i:k:end,:) reduces to a range if i <= k and k divides n. @@ -838,12 +860,14 @@ *this = new idx_range_rep (s, l * nj, t, DIRECT); reduced = true; } - break; } + break; + default: break; } break; + case class_range: switch (rep->idx_class ()) { @@ -857,8 +881,9 @@ *this = new idx_range_rep (sj * n, lj * n, 1, DIRECT); reduced = true; } - break; } + break; + case class_scalar: { // (k,i:d:j) reduces to a range. @@ -869,8 +894,9 @@ octave_idx_type tj = rj->get_step (); *this = new idx_range_rep (n * sj + k, lj, n * tj, DIRECT); reduced = true; - break; } + break; + case class_range: { // (i:k:end,p:q) reduces to a range if i <= k and k divides n. @@ -886,12 +912,14 @@ *this = new idx_range_rep (s + n * sj, l * lj, t, DIRECT); reduced = true; } - break; } + break; + default: break; } break; + case class_scalar: switch (rep->idx_class ()) { @@ -903,8 +931,9 @@ octave_idx_type k = r->get_data () + n * rj->get_data (); *this = new idx_scalar_rep (k, DIRECT); reduced = true; - break; } + break; + case class_range: { // (i:d:j,k) reduces to a range. @@ -915,8 +944,9 @@ octave_idx_type k = rj->get_data (); *this = new idx_range_rep (n * k + s, l, t, DIRECT); reduced = true; - break; } + break; + case class_colon: { // (:,k) reduces to a range. @@ -924,12 +954,14 @@ octave_idx_type k = rj->get_data (); *this = new idx_range_rep (n * k, n, 1, DIRECT); reduced = true; - break; } + break; + default: break; } break; + default: break; } @@ -942,12 +974,14 @@ octave_idx_type& l, octave_idx_type& u) const { bool res = false; + switch (rep->idx_class ()) { case class_colon: l = 0; u = n; res = true; break; + case class_range: { idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); @@ -959,6 +993,7 @@ } } break; + case class_scalar: { idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); @@ -967,6 +1002,7 @@ res = true; } break; + case class_mask: { idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); @@ -978,6 +1014,7 @@ res = true; } } + default: break; } @@ -989,21 +1026,28 @@ idx_vector::increment (void) const { octave_idx_type retval = 0; + switch (rep->idx_class ()) { case class_colon: retval = 1; + // fall through... + case class_range: retval = dynamic_cast<idx_range_rep *> (rep) -> get_step (); break; + case class_vector: { if (length (0) > 1) retval = elem (1) - elem (0); } + break; + default: break; } + return retval; } @@ -1014,7 +1058,9 @@ *this = idx_vector (as_array (), extent (0)); idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); + assert (r != 0); + return r->get_data (); } @@ -1028,37 +1074,40 @@ case class_colon: current_liboctave_error_handler ("colon not allowed"); break; + case class_range: - { - idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); - octave_idx_type start = r->get_start (), step = r->get_step (); - octave_idx_type i, j; - if (step == 1) - for (i = start, j = start + len; i < j; i++) *data++ = i; - else if (step == -1) - for (i = start, j = start - len; i > j; i--) *data++ = i; - else - for (i = 0, j = start; i < len; i++, j += step) *data++ = j; - } + { + idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); + octave_idx_type start = r->get_start (), step = r->get_step (); + octave_idx_type i, j; + if (step == 1) + for (i = start, j = start + len; i < j; i++) *data++ = i; + else if (step == -1) + for (i = start, j = start - len; i > j; i--) *data++ = i; + else + for (i = 0, j = start; i < len; i++, j += step) *data++ = j; + } break; + case class_scalar: - { - idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); - *data = r->get_data (); - } + { + idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); + *data = r->get_data (); + } break; + case class_vector: - { - idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); - const octave_idx_type *rdata = r->get_data (); - copy_or_memcpy (len, rdata, data); - } + { + idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); + const octave_idx_type *rdata = r->get_data (); + copy_or_memcpy (len, rdata, data); + } break; + default: assert (false); break; } - } idx_vector @@ -1079,8 +1128,10 @@ } octave_idx_type len = cnt, *data = new octave_idx_type[len]; + for (octave_idx_type i = 0, j = 0; i < n; i++) - if (left[i]) data[j++] = i; + if (left[i]) + data[j++] = i; return new idx_vector_rep (data, len, len ? data[len-1]+1 : 0, @@ -1111,7 +1162,6 @@ break; } } - } return retval; @@ -1126,11 +1176,15 @@ const bool *data = r->get_data (); octave_idx_type ext = r->extent (0), len = r->length (0); octave_idx_type *idata = new octave_idx_type [len]; + for (octave_idx_type i = 0, j = 0; i < ext; i++) if (data[i]) idata[j++] = i; + ext = len > 0 ? idata[len - 1] : 0; - return new idx_vector_rep (idata, len, ext, r->orig_dimensions (), DIRECT); + + return new idx_vector_rep (idata, len, ext, r->orig_dimensions (), + DIRECT); } else return *this; @@ -1145,30 +1199,35 @@ { case class_colon: break; + case class_range: - { - idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); - range = r->unconvert (); - } + { + idx_range_rep *r = dynamic_cast<idx_range_rep *> (rep); + range = r->unconvert (); + } break; + case class_scalar: - { - idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); - scalar = r->unconvert (); - } + { + idx_scalar_rep *r = dynamic_cast<idx_scalar_rep *> (rep); + scalar = r->unconvert (); + } break; + case class_vector: - { - idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); - array = r->unconvert (); - } + { + idx_vector_rep *r = dynamic_cast<idx_vector_rep *> (rep); + array = r->unconvert (); + } break; + case class_mask: - { - idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); - mask = r->unconvert (); - } + { + idx_mask_rep *r = dynamic_cast<idx_mask_rep *> (rep); + mask = r->unconvert (); + } break; + default: assert (false); break; @@ -1199,11 +1258,16 @@ idx_vector::ones_count () const { octave_idx_type n = 0; + if (is_colon ()) n = 1; else - for (octave_idx_type i = 0; i < length (1); i++) - if (xelem (i) == 0) n++; + { + for (octave_idx_type i = 0; i < length (1); i++) + if (xelem (i) == 0) + n++; + } + return n; }
--- a/liboctave/idx-vector.h +++ b/liboctave/idx-vector.h @@ -93,12 +93,10 @@ virtual idx_base_rep *sort_idx (Array<octave_idx_type>&) = 0; // Checks whether the index is colon or a range equivalent to colon. - virtual bool is_colon_equiv (octave_idx_type) const - { return false; } + virtual bool is_colon_equiv (octave_idx_type) const { return false; } // The original dimensions of this object (used when subscribing by matrices). - virtual dim_vector orig_dimensions (void) const - { return dim_vector (); } + virtual dim_vector orig_dimensions (void) const { return dim_vector (); } // i/o virtual std::ostream& print (std::ostream& os) const = 0; @@ -123,26 +121,22 @@ idx_colon_rep (char c); - octave_idx_type xelem (octave_idx_type i) const - { return i; } + octave_idx_type xelem (octave_idx_type i) const { return i; } octave_idx_type checkelem (octave_idx_type i) const; - octave_idx_type length (octave_idx_type n) const - { return n; } + octave_idx_type length (octave_idx_type n) const { return n; } - octave_idx_type extent (octave_idx_type n) const - { return n; } + octave_idx_type extent (octave_idx_type n) const { return n; } idx_class_type idx_class (void) const { return class_colon; } - idx_base_rep *sort_uniq_clone (bool = false) + idx_base_rep *sort_uniq_clone (bool = false) { count++; return this; } idx_base_rep *sort_idx (Array<octave_idx_type>&); - bool is_colon_equiv (octave_idx_type) const - { return true; } + bool is_colon_equiv (octave_idx_type) const { return true; } std::ostream& print (std::ostream& os) const; @@ -179,8 +173,7 @@ octave_idx_type checkelem (octave_idx_type i) const; - octave_idx_type length (octave_idx_type) const - { return len; } + octave_idx_type length (octave_idx_type) const { return len; } octave_idx_type extent (octave_idx_type n) const { return len ? std::max (n, (start + 1 + (step < 0 ? 0 : step * (len - 1)))) : n; } @@ -234,13 +227,11 @@ template <class T> idx_scalar_rep (T x); - octave_idx_type xelem (octave_idx_type) const - { return data; } + octave_idx_type xelem (octave_idx_type) const { return data; } octave_idx_type checkelem (octave_idx_type i) const; - octave_idx_type length (octave_idx_type) const - { return 1; } + octave_idx_type length (octave_idx_type) const { return 1; } octave_idx_type extent (octave_idx_type n) const { return std::max (n, data + 1); } @@ -255,8 +246,7 @@ bool is_colon_equiv (octave_idx_type n) const { return n == 1 && data == 0; } - dim_vector orig_dimensions (void) const - { return dim_vector (1, 1); } + dim_vector orig_dimensions (void) const { return dim_vector (1, 1); } octave_idx_type get_data (void) const { return data; } @@ -307,13 +297,11 @@ ~idx_vector_rep (void); - octave_idx_type xelem (octave_idx_type i) const - { return data[i]; } + octave_idx_type xelem (octave_idx_type i) const { return data[i]; } octave_idx_type checkelem (octave_idx_type i) const; - octave_idx_type length (octave_idx_type) const - { return len; } + octave_idx_type length (octave_idx_type) const { return len; } octave_idx_type extent (octave_idx_type n) const { return std::max (n, ext); } @@ -324,8 +312,7 @@ idx_base_rep *sort_idx (Array<octave_idx_type>&); - dim_vector orig_dimensions (void) const - { return orig_dims; } + dim_vector orig_dimensions (void) const { return orig_dims; } const octave_idx_type *get_data (void) const { return data; } @@ -345,11 +332,12 @@ const octave_idx_type *data; octave_idx_type len, ext; - // This is a trick to allow user-given zero-based arrays to be used as indices - // without copying. If the following pointer is nonzero, we do not own the data, - // but rather have an Array<octave_idx_type> object that provides us the data. - // Note that we need a pointer because we deferred the Array<T> declaration and - // we do not want it yet to be defined. + // This is a trick to allow user-given zero-based arrays to be used + // as indices without copying. If the following pointer is nonzero, + // we do not own the data, but rather have an Array<octave_idx_type> + // object that provides us the data. Note that we need a pointer + // because we deferred the Array<T> declaration and we do not want + // it yet to be defined. Array<octave_idx_type> *aowner; @@ -379,8 +367,7 @@ octave_idx_type checkelem (octave_idx_type i) const; - octave_idx_type length (octave_idx_type) const - { return len; } + octave_idx_type length (octave_idx_type) const { return len; } octave_idx_type extent (octave_idx_type n) const { return std::max (n, ext); } @@ -392,8 +379,7 @@ idx_base_rep *sort_idx (Array<octave_idx_type>&); - dim_vector orig_dimensions (void) const - { return orig_dims; } + dim_vector orig_dimensions (void) const { return orig_dims; } bool is_colon_equiv (octave_idx_type n) const { return len == n && ext == n; } @@ -416,15 +402,16 @@ const bool *data; octave_idx_type len, ext; - // FIXME: I'm not sure if this is a good design. Maybe it would be better to - // employ some sort of generalized iteration scheme. + // FIXME: I'm not sure if this is a good design. Maybe it would be + // better to employ some sort of generalized iteration scheme. mutable octave_idx_type lsti, lste; - // This is a trick to allow user-given mask arrays to be used as indices - // without copying. If the following pointer is nonzero, we do not own the data, - // but rather have an Array<bool> object that provides us the data. - // Note that we need a pointer because we deferred the Array<T> declaration and - // we do not want it yet to be defined. + // This is a trick to allow user-given mask arrays to be used as + // indices without copying. If the following pointer is nonzero, we + // do not own the data, but rather have an Array<bool> object that + // provides us the data. Note that we need a pointer because we + // deferred the Array<T> declaration and we do not want it yet to be + // defined. Array<bool> *aowner; @@ -433,7 +420,8 @@ idx_vector (idx_base_rep *r) : rep (r) { } - // The shared empty vector representation (for fast default constructor) + // The shared empty vector representation (for fast default + // constructor). static idx_vector_rep *nil_rep (void) { static idx_vector_rep ivr; @@ -448,8 +436,8 @@ return &ivr; } - // If there was an error in constructing the rep, replace it with empty vector - // for safety. + // If there was an error in constructing the rep, replace it with + // empty vector for safety. void chkerr (void) { if (rep->err) @@ -622,11 +610,13 @@ index (const T *src, octave_idx_type n, T *dest) const { octave_idx_type len = rep->length (n); + switch (rep->idx_class ()) { case class_colon: copy_or_memcpy (len, src, dest); break; + case class_range: { idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); @@ -645,12 +635,14 @@ } } break; + case class_scalar: { idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); dest[0] = src[r->get_data ()]; } break; + case class_vector: { idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); @@ -659,6 +651,7 @@ dest[i] = src[data[i]]; } break; + case class_mask: { idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); @@ -668,6 +661,7 @@ if (data[i]) *dest++ = src[i]; } break; + default: assert (false); break; @@ -689,11 +683,13 @@ assign (const T *src, octave_idx_type n, T *dest) const { octave_idx_type len = rep->length (n); + switch (rep->idx_class ()) { case class_colon: copy_or_memcpy (len, src, dest); break; + case class_range: { idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); @@ -710,12 +706,14 @@ } } break; + case class_scalar: { idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); dest[r->get_data ()] = src[0]; } break; + case class_vector: { idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); @@ -724,6 +722,7 @@ dest[data[i]] = src[i]; } break; + case class_mask: { idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); @@ -733,6 +732,7 @@ if (data[i]) dest[i] = *src++; } break; + default: assert (false); break; @@ -754,11 +754,13 @@ fill (const T& val, octave_idx_type n, T *dest) const { octave_idx_type len = rep->length (n); + switch (rep->idx_class ()) { case class_colon: std::fill (dest, dest + len, val); break; + case class_range: { idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); @@ -775,12 +777,14 @@ } } break; + case class_scalar: { idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); dest[r->get_data ()] = val; } break; + case class_vector: { idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); @@ -789,6 +793,7 @@ dest[data[i]] = val; } break; + case class_mask: { idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); @@ -798,6 +803,7 @@ if (data[i]) dest[i] = val; } break; + default: assert (false); break; @@ -806,24 +812,24 @@ return len; } - // Generic non-breakable indexed loop. The loop body should be encapsulated in a - // single functor body. - // This is equivalent to the following loop (but faster, at least for simple - // inlined bodies): + // Generic non-breakable indexed loop. The loop body should be + // encapsulated in a single functor body. This is equivalent to the + // following loop (but faster, at least for simple inlined bodies): // // for (octave_idx_type i = 0; i < idx->length (n); i++) body (idx(i)); - // template <class Functor> void loop (octave_idx_type n, Functor body) const { octave_idx_type len = rep->length (n); + switch (rep->idx_class ()) { case class_colon: for (octave_idx_type i = 0; i < len; i++) body (i); break; + case class_range: { idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); @@ -837,12 +843,14 @@ for (i = 0, j = start; i < len; i++, j += step) body (j); } break; + case class_scalar: { idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); body (r->get_data ()); } break; + case class_vector: { idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); @@ -850,6 +858,7 @@ for (octave_idx_type i = 0; i < len; i++) body (data[i]); } break; + case class_mask: { idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); @@ -859,6 +868,7 @@ if (data[i]) body (i); } break; + default: assert (false); break; @@ -866,10 +876,9 @@ } - // Generic breakable indexed loop. The loop body should be encapsulated in a - // single functor body. - // This is equivalent to the following loop (but faster, at least for simple - // inlined bodies): + // Generic breakable indexed loop. The loop body should be + // encapsulated in a single functor body. This is equivalent to the + // following loop (but faster, at least for simple inlined bodies): // // for (octave_idx_type i = 0; i < idx->length (n); i++) // if (body (idx(i))) break; @@ -881,6 +890,7 @@ bloop (octave_idx_type n, Functor body) const { octave_idx_type len = rep->length (n), ret; + switch (rep->idx_class ()) { case class_colon: @@ -890,6 +900,7 @@ ret = i; } break; + case class_range: { idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); @@ -904,12 +915,14 @@ ret = i; } break; + case class_scalar: { idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); ret = body (r->get_data ()) ? 1 : 0; } break; + case class_vector: { idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); @@ -919,6 +932,7 @@ ret = i; } break; + case class_mask: { idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); @@ -938,6 +952,7 @@ ret = j; } break; + default: assert (false); break; @@ -948,9 +963,9 @@ // Rationale: // This method is the key to "smart indexing". When indexing cartesian - // arrays, sometimes consecutive index vectors can be reduced into a single - // index. If rows (A) = k and i.maybe_reduce (j) gives k, then A(i,j)(:) is - // equal to A(k)(:). + // arrays, sometimes consecutive index vectors can be reduced into a + // single index. If rows (A) = k and i.maybe_reduce (j) gives k, then + // A(i,j)(:) is equal to A(k)(:). // If the next index can be reduced, returns true and updates this. bool maybe_reduce (octave_idx_type n, const idx_vector& j, @@ -981,8 +996,8 @@ Array<octave_idx_type> as_array (void) const; - // Raw pointer to index array. This is non-const because it may be necessary - // to mutate the index. + // Raw pointer to index array. This is non-const because it may be + // necessary to mutate the index. const octave_idx_type *raw (void); // FIXME -- these are here for compatibility. They should be removed