Mercurial > hg > octave-lojdl
changeset 4821:22f024a25c4a
[project @ 2004-03-05 16:19:11 by jwe]
author | jwe |
---|---|
date | Fri, 05 Mar 2004 16:19:11 +0000 |
parents | a436d388b041 |
children | d0aa1a59b73b |
files | liboctave/Array.cc liboctave/ChangeLog |
diffstat | 2 files changed, 60 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -1540,6 +1540,9 @@ dim_vector lhs_dims = dims (); + if (lhs_dims.all_zero ()) + return; + int n_lhs_dims = lhs_dims.length (); Array<int> idx_is_colon (n_idx, 0); @@ -1791,60 +1794,68 @@ } else if (n_idx == 1) { - // This handle cases where we only have one index (not colon). - // The index denotes which elements we should delete in the array - // which can be of any dimension. We return a column vector, except - // for the case where we are operating on a row column. The elements - // are numerated columns by column. + // This handle cases where we only have one index (not + // colon). The index denotes which elements we should + // delete in the array which can be of any dimension. We + // return a column vector, except for the case where we are + // operating on a row vector. The elements are numerated + // column by column. // // A(3,3,3)=2; // A(3:5) = []; A(6)=[] - // - idx_vector idx_vec = ra_idx(0); - - int num_to_delete = idx_vec.capacity (); int lhs_numel = numel (); - int new_numel = lhs_numel - num_to_delete; - - T *new_data = new T[new_numel]; - - Array<int> lhs_ra_idx (ndims (), 0); - - int ii = 0; - int iidx = 0; - - for (int i = 0; i < lhs_numel; i++) + idx_vector idx_vec = ra_idx(0); + + idx_vec.freeze (lhs_numel, 0, true, liboctave_wrore_flag); + + idx_vec.sort (true); + + int num_to_delete = idx_vec.length (lhs_numel); + + if (num_to_delete > 0) { - if (iidx < num_to_delete && i == idx_vec.elem (iidx)) + int new_numel = lhs_numel - num_to_delete; + + T *new_data = new T[new_numel]; + + Array<int> lhs_ra_idx (ndims (), 0); + + int ii = 0; + int iidx = 0; + + for (int i = 0; i < lhs_numel; i++) { - iidx++; + if (iidx < num_to_delete && i == idx_vec.elem (iidx)) + { + iidx++; + } + else + { + new_data[ii++] = elem (lhs_ra_idx); + } + + increment_index (lhs_ra_idx, lhs_dims); + } + + if (--(Array<T>::rep)->count <= 0) + delete Array<T>::rep; + + Array<T>::rep = new typename Array<T>::ArrayRep (new_data, new_numel); + + dimensions.resize (2); + + if (lhs_dims.length () == 2 && lhs_dims(1) == 1) + { + dimensions(0) = new_numel; + dimensions(1) = 1; } else { - new_data[ii++] = elem (lhs_ra_idx); + dimensions(0) = 1; + dimensions(1) = new_numel; } - - increment_index (lhs_ra_idx, lhs_dims); - } - - if (--(Array<T>::rep)->count <= 0) - delete Array<T>::rep; - - Array<T>::rep = new typename Array<T>::ArrayRep (new_data, new_numel); - - dimensions.resize (2); - - if (lhs_dims.length () == 2 && lhs_dims(1) == 1) - { - dimensions(0) = new_numel; - dimensions(1) = 1; - } - else - { - dimensions(0) = 1; - dimensions(1) = new_numel; } } else if (num_ones (idx_is_colon) < n_idx)
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,10 @@ +2004-03-05 John W. Eaton <jwe@bevo.che.wisc.edu> + + * Array.cc (Array<T>::maybe_delete_elements): Return immediately + if all LHS dimensions are zero. For one index case, freeze and + sort idx_vec before checking length, and do nothing if + num_to_delete is zero. + 2004-03-04 David Bateman <dbateman@free.fr> * dNDArray.cc (NDArray::ifourier): Arg is int, not const int.